130 lines
3.8 KiB
Java
130 lines
3.8 KiB
Java
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.ConfigurationVO;
|
|
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigVO;
|
|
import org.gcube.application.geoportalcommon.shared.geoportalconfig.FilePathVO;
|
|
import org.gcube.application.geoportalcommon.shared.geoportalconfig.GcubeProfileVO;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* The Class ConvertToDataValueObjectModel.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
*
|
|
* Mar 1, 2022
|
|
*/
|
|
public class ConvertToDataValueObjectModel {
|
|
|
|
private static Logger LOG = LoggerFactory.getLogger(ConvertToDataValueObjectModel.class);
|
|
|
|
/**
|
|
* To document config VO.
|
|
*
|
|
* @param dc the dc
|
|
* @return the document config VO
|
|
*/
|
|
public static DocumentConfigVO toDocumentConfigVO(DocumentConfig dc) {
|
|
LOG.trace("toDocumentConfigVO called");
|
|
|
|
if (dc == null) {
|
|
LOG.warn(DocumentConfig.class.getSimpleName() + " is null");
|
|
return null;
|
|
}
|
|
|
|
DocumentConfigVO dcVO = new DocumentConfigVO();
|
|
dcVO.setId(dc.getId());
|
|
dcVO.setType(dc.getType());
|
|
|
|
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;
|
|
}
|
|
|
|
ConfigurationVO configVO = new ConfigurationVO();
|
|
List<GcubeProfileVO> gCubeProfilesVO = new ArrayList<GcubeProfileVO>(gCubeProfiles.size());
|
|
for (GcubeProfile gCubeProfile : gCubeProfiles) {
|
|
gCubeProfilesVO.add(toGcubeProfileVO(gCubeProfile));
|
|
}
|
|
configVO.setGcubeProfiles(gCubeProfilesVO);
|
|
dcVO.setConfiguration(configVO);
|
|
|
|
LOG.debug("returning: " + dcVO);
|
|
return dcVO;
|
|
}
|
|
|
|
/**
|
|
* To gcube profile VO.
|
|
*
|
|
* @param gCubeProfile the g cube profile
|
|
* @return the gcube profile VO
|
|
*/
|
|
public static GcubeProfileVO toGcubeProfileVO(GcubeProfile gCubeProfile) {
|
|
LOG.trace("toGcubeProfileVO called");
|
|
|
|
if (gCubeProfile == null) {
|
|
LOG.warn(GcubeProfile.class.getSimpleName() + " is null");
|
|
return null;
|
|
}
|
|
|
|
GcubeProfileVO gpVO = new GcubeProfileVO();
|
|
gpVO.setGcubeName(gCubeProfile.getGcubeName());
|
|
gpVO.setGcubeSecondaryType(gCubeProfile.getGcubeSecondaryType());
|
|
gpVO.setMinOccurs(gCubeProfile.getMinOccurs());
|
|
gpVO.setMaxOccurs(gCubeProfile.getMaxOccurs());
|
|
gpVO.setSectionName(gCubeProfile.getSectionName());
|
|
gpVO.setSectionTitle(gCubeProfile.getSectionTitle());
|
|
|
|
List<FilePath> filePaths = gCubeProfile.getFilePaths();
|
|
|
|
if (filePaths != null) {
|
|
LOG.warn("List of " + FilePath.class.getSimpleName() + " is null");
|
|
List<FilePathVO> filePathsVO = new ArrayList<FilePathVO>(filePaths.size());
|
|
for (FilePath filePath : filePaths) {
|
|
filePathsVO.add(toFilePathVO(filePath));
|
|
}
|
|
gpVO.setFilePaths(filePathsVO);
|
|
}
|
|
|
|
LOG.info("returning: " + gpVO);
|
|
return gpVO;
|
|
}
|
|
|
|
/**
|
|
* To file path VO.
|
|
*
|
|
* @param filePath the file path
|
|
* @return the file path VO
|
|
*/
|
|
public static FilePathVO toFilePathVO(FilePath filePath) {
|
|
LOG.trace("toFilePathVO called");
|
|
|
|
if (filePath == null) {
|
|
LOG.warn("List of " + FilePath.class.getSimpleName() + " is null");
|
|
return null;
|
|
}
|
|
|
|
FilePathVO fpVO = new FilePathVO();
|
|
fpVO.setFieldName(filePath.getFieldName());
|
|
fpVO.setFieldDefinition(filePath.getFieldDefinition());
|
|
|
|
LOG.info("returning: " + fpVO);
|
|
return fpVO;
|
|
}
|
|
|
|
}
|