package org.gcube.application.geoportalcommon; import java.util.ArrayList; import java.util.List; import org.gcube.application.geoportalcommon.geoportalconfig.Configuration; import org.gcube.application.geoportalcommon.geoportalconfig.DocumentConfig; import org.gcube.application.geoportalcommon.geoportalconfig.FilePath; import org.gcube.application.geoportalcommon.geoportalconfig.GcubeProfile; import org.gcube.application.geoportalcommon.shared.geoportalconfig.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV; import org.gcube.application.geoportalcommon.shared.geoportalconfig.FilePathDV; import org.gcube.application.geoportalcommon.shared.geoportalconfig.GcubeProfileDV; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * The Class ConvertToDataValueObjectModel. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Mar 4, 2022 */ public class ConvertToDataValueObjectModel { private static Logger LOG = LoggerFactory.getLogger(ConvertToDataValueObjectModel.class); /** * To document config DV. * * @param dc the dc * @return the document config DV */ public static DocumentConfigDV toDocumentConfigDV(DocumentConfig dc) { LOG.trace("toDocumentConfigDV called"); if (dc == null) { LOG.warn(DocumentConfig.class.getSimpleName() + " is null"); return null; } DocumentConfigDV dcVO = new DocumentConfigDV(); dcVO.setId(dc.getId()); dcVO.setType(dc.getType()); dcVO.setItemType(dc.getItem_type()); Configuration config = dc.getConfiguration(); if (config == null) { LOG.warn(Configuration.class.getSimpleName() + " is null"); return null; } List gCubeProfiles = config.getGcubeProfiles(); if (gCubeProfiles == null) { LOG.warn("List of " + GcubeProfile.class.getSimpleName() + " is null"); return null; } ConfigurationDV configVO = new ConfigurationDV(); List gCubeProfilesVO = new ArrayList(gCubeProfiles.size()); for (GcubeProfile gCubeProfile : gCubeProfiles) { gCubeProfilesVO.add(toGcubeProfileDV(gCubeProfile)); } configVO.setGcubeProfiles(gCubeProfilesVO); dcVO.setConfiguration(configVO); LOG.debug("returning: " + dcVO); return dcVO; } /** * To gcube profile DV. * * @param gCubeProfile the g cube profile * @return the gcube profile DV */ public static GcubeProfileDV toGcubeProfileDV(GcubeProfile gCubeProfile) { LOG.trace("toGcubeProfileDV called"); if (gCubeProfile == null) { LOG.warn(GcubeProfile.class.getSimpleName() + " is null"); return null; } GcubeProfileDV gpVO = new GcubeProfileDV(); gpVO.setGcubeName(gCubeProfile.getGcubeName()); gpVO.setGcubeSecondaryType(gCubeProfile.getGcubeSecondaryType()); gpVO.setMinOccurs(gCubeProfile.getMinOccurs()); gpVO.setMaxOccurs(gCubeProfile.getMaxOccurs()); gpVO.setSectionName(gCubeProfile.getSectionName()); gpVO.setSectionTitle(gCubeProfile.getSectionTitle()); gpVO.setParentName(gCubeProfile.getParentName()); List filePaths = gCubeProfile.getFilePaths(); if (filePaths != null) { LOG.warn("List of " + FilePath.class.getSimpleName() + " is null"); List filePathsVO = new ArrayList(filePaths.size()); for (FilePath filePath : filePaths) { filePathsVO.add(toFilePathDV(filePath)); } gpVO.setFilePaths(filePathsVO); } LOG.info("returning: " + gpVO); return gpVO; } /** * To file path DV. * * @param filePath the file path * @return the file path DV */ public static FilePathDV toFilePathDV(FilePath filePath) { LOG.trace("toFilePathDV called"); if (filePath == null) { LOG.warn("List of " + FilePath.class.getSimpleName() + " is null"); return null; } FilePathDV fpVO = new FilePathDV(); fpVO.setFieldName(filePath.getFieldName()); fpVO.setFieldDefinition(filePath.getFieldDefinition()); LOG.info("returning: " + fpVO); return fpVO; } }