delete: unused mappers (PermissionsMapper, UsersMapper)

This commit is contained in:
Aleksandr Fedorov
2023-12-13 14:56:10 +03:00
parent 11ead2e57f
commit a7fc3d38e4
4 changed files with 0 additions and 207 deletions

View File

@ -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<E extends AbstractEntity, M extends AbstractModel> implements Mapper<E, M> {
@Autowired
private ModelMapper mapper;
private Class<M> modelClass;
AbstractMapper(final Class<M> 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<E, M> 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) {
}
}

View File

@ -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<E extends AbstractEntity, M extends AbstractModel> {
M toModel(E entity); // convert the entity to the model
}

View File

@ -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<Permission,
com.onlyoffice.integration.documentserver.models.filemodel.Permission> {
@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()));
}
}

View File

@ -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<User, com.onlyoffice.integration.documentserver.models.filemodel.User> {
@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
}
}