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