com.arextest.web.model.mapper.SceneInfoMapper Maven / Gradle / Ivy
package com.arextest.web.model.mapper;
import com.arextest.web.model.contract.contracts.QuerySceneInfoResponseType;
import com.arextest.web.model.dao.mongodb.iosummary.SceneInfoCollection;
import com.arextest.web.model.dto.iosummary.SceneInfo;
import com.arextest.web.model.dto.iosummary.SubSceneInfo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.mapstruct.AfterMapping;
import org.mapstruct.Builder;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
/**
* Created by rchen9 on 2023/2/28.
*/
@Mapper(builder = @Builder(disableBuilder = true))
public interface SceneInfoMapper {
SceneInfoMapper INSTANCE = Mappers.getMapper(SceneInfoMapper.class);
SceneInfoCollection daoFromDto(SceneInfo dto);
SceneInfo dtoFromDao(SceneInfoCollection dao);
QuerySceneInfoResponseType.SceneInfoType contractFromDto(SceneInfo dto);
default List mapSubScenes(SceneInfo dto) {
List subSceneInfos = dto.getSubScenes();
// the new scene information is stored in subSceneInfoMap
Map infoMap = dto.getSubSceneInfoMap();
if (infoMap != null) {
subSceneInfos = new ArrayList<>(infoMap.values());
}
return Optional.ofNullable(subSceneInfos).orElse(Collections.emptyList()).stream()
.map(SubSceneInfoMapper.INSTANCE::contractFromDto).collect(Collectors.toList());
}
@AfterMapping
default void mapSubScenesAfterMapping(SceneInfo dto,
@MappingTarget QuerySceneInfoResponseType.SceneInfoType sceneInfoType) {
List subSceneInfoTypes = mapSubScenes(dto);
sceneInfoType.setSubScenes(subSceneInfoTypes);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy