diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/AbstractMapper.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/AbstractMapper.java deleted file mode 100644 index 98fdb76b..00000000 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/AbstractMapper.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * (c) Copyright Ascensio System SIA 2023 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.onlyoffice.integration.mappers; - -import com.onlyoffice.integration.entities.AbstractEntity; -import com.onlyoffice.integration.documentserver.models.AbstractModel; -import org.modelmapper.Converter; -import org.modelmapper.ModelMapper; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.Objects; - -public abstract class AbstractMapper implements Mapper { - @Autowired - private ModelMapper mapper; - - private Class modelClass; - - AbstractMapper(final Class modelClassParam) { - this.modelClass = modelClassParam; - } - - @Override - public M toModel(final E entity) { // convert the entity to the model - return Objects.isNull(entity) // check if an entity is not empty - ? null - : mapper.map(entity, modelClass); // and add it to the model mapper - } - - Converter modelConverter() { // specify the model converter - return context -> { - E source = context.getSource(); // get the source entity - M destination = context.getDestination(); // get the destination model - handleSpecificFields(source, destination); // map the entity to the model - return context.getDestination(); - }; - } - - - void handleSpecificFields(final E source, final M destination) { - } -} diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/Mapper.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/Mapper.java deleted file mode 100644 index a6201724..00000000 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/Mapper.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * - * (c) Copyright Ascensio System SIA 2023 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.onlyoffice.integration.mappers; - -import com.onlyoffice.integration.entities.AbstractEntity; -import com.onlyoffice.integration.documentserver.models.AbstractModel; - -// specify the model mapper functions -public interface Mapper { - M toModel(E entity); // convert the entity to the model -} diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/PermissionsMapper.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/PermissionsMapper.java deleted file mode 100644 index 710defd5..00000000 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/PermissionsMapper.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * - * (c) Copyright Ascensio System SIA 2023 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.onlyoffice.integration.mappers; - -import com.onlyoffice.integration.entities.Permission; -import com.onlyoffice.integration.documentserver.models.filemodel.CommentGroup; -import org.modelmapper.ModelMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.util.stream.Collectors; - -@Component -@Primary -public class PermissionsMapper extends AbstractMapper { - @Autowired - private ModelMapper mapper; - - public PermissionsMapper() { - super(com.onlyoffice.integration.documentserver.models.filemodel.Permission.class); - } - - @PostConstruct - public void configure() { // configure the permission mapper - mapper.createTypeMap(Permission.class, com.onlyoffice.integration.documentserver.models.filemodel - .Permission.class) // create the type map - .setPostConverter(modelConverter()); // and apply the post converter to it - } - - @Override - void handleSpecificFields(final Permission source, - final com.onlyoffice.integration.documentserver.models.filemodel - .Permission destination) { // handle specific permission fields - destination.setReviewGroups(source.getReviewGroups().stream() - .map(g -> g.getName()) - .collect(Collectors.toList())); // set the reviewGroups parameter - - // set the commentGroups parameter - destination.setCommentGroups( - new CommentGroup( - source.getCommentsViewGroups().stream().map(g -> g.getName()).collect(Collectors.toList()), - source.getCommentsEditGroups().stream().map(g -> g.getName()).collect(Collectors.toList()), - source.getCommentsRemoveGroups().stream().map(g -> g.getName()).collect(Collectors.toList()) - ) - ); - destination.setUserInfoGroups(source.getUserInfoGroups().stream() - .map(g -> g.getName()) - .collect(Collectors.toList())); - } -} diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/UsersMapper.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/UsersMapper.java deleted file mode 100644 index c60e941d..00000000 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/mappers/UsersMapper.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * (c) Copyright Ascensio System SIA 2023 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.onlyoffice.integration.mappers; - -import com.onlyoffice.integration.entities.User; -import org.modelmapper.ModelMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; - -@Component -@Primary -public class UsersMapper extends AbstractMapper { - @Autowired - private ModelMapper mapper; - - public UsersMapper() { - super(com.onlyoffice.integration.documentserver.models.filemodel.User.class); - } - - @PostConstruct - public void configure() { // configure the users mapper - mapper.createTypeMap(User.class, com.onlyoffice.integration.documentserver.models.filemodel - .User.class) // create the type map - .setPostConverter(modelConverter()); // and apply the post converter to it - } - - @Override - public void handleSpecificFields(final User source, - final com.onlyoffice.integration.documentserver.models.filemodel - .User destination) { // handle specific users fields - destination.setGroup(source.getGroup() != null - ? source.getGroup().getName() : null); // set the Group parameter - } -}