This commit is contained in:
Francesco Mangiacrapa 2022-03-01 12:19:37 +01:00
parent 29609dc7e0
commit da8ab06772
14 changed files with 696 additions and 1 deletions

View File

@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.0.0-SNAPSHOT] - 2022-02-28
#### Enhancements
- [#22883] Integrate the configurations exposed by geoportal-client
## [v1.3.0] - 2021-12-03
#### Enhancements

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.application</groupId>
<artifactId>geoportal-data-common</artifactId>
<version>1.3.0</version>
<version>2.0.0-SNAPSHOT</version>
<description>GeoPortal Data Common is common library used by GUI components developed for GeoNA</description>
<scm>
@ -85,10 +85,16 @@
<scope>compile</scope>
</dependency>
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<!-- JUNIT -->

View File

@ -0,0 +1,129 @@
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;
}
}

View File

@ -0,0 +1,52 @@
package org.gcube.application.geoportalcommon;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.gcube.application.geoportalcommon.geoportalconfig.DocumentConfig;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigVO;
public class MockDocumentConfigurationReader {
private DocumentConfigVO documentConfigVO;
public MockDocumentConfigurationReader() {
try {
loadDocumentConfiguration();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void loadDocumentConfiguration() throws Exception {
System.out.println("loadDocumentConfiguration called");
String filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config.json";
String theFile = readFile(filePath);
System.out.println("the file is: "+theFile);
DocumentConfig dc = org.gcube.application.geoportal.client.utils.Serialization.read(theFile,
DocumentConfig.class);
System.out.println(dc);
DocumentConfigVO dcVO = ConvertToDataValueObjectModel.toDocumentConfigVO(dc);
documentConfigVO = dcVO;
}
private static String readFile(String filePath) {
String content = "";
try {
content = new String(Files.readAllBytes(Paths.get(filePath)));
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
public DocumentConfigVO getDocumentConfigVO() {
return documentConfigVO;
}
}

View File

@ -0,0 +1,17 @@
package org.gcube.application.geoportalcommon.geoportalconfig;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Data
@XmlRootElement(name = "configuration")
@Slf4j
public class Configuration{
private List<GcubeProfile> gcubeProfiles;
}

View File

@ -0,0 +1,24 @@
package org.gcube.application.geoportalcommon.geoportalconfig;
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Data
@XmlRootElement
@Slf4j
public class DocumentConfig {
@JsonProperty
private String id;
@JsonProperty
private String type;
@JsonProperty
private Configuration configuration;
}

View File

@ -0,0 +1,23 @@
package org.gcube.application.geoportalcommon.geoportalconfig;
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Data
@XmlRootElement(name = "filePaths")
@Slf4j
public class FilePath {
@JsonProperty
String fieldDefinition;
@JsonProperty
String fieldName;
public FilePath() {
}
}

View File

@ -0,0 +1,54 @@
package org.gcube.application.geoportalcommon.geoportalconfig;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Data
@XmlRootElement(name = "gcubeProfiles")
@Slf4j
public class GcubeProfile {
private static final String FILE_PATHS = "filePaths";
public static final int MIN_MAX_NOT_SPECIFIED = -1;
public GcubeProfile() {}
@JsonProperty
private String gcubeSecondaryType;
@JsonProperty
private String gcubeName;
@JsonProperty
private String sectionName;
@JsonProperty
private String sectionTitle;
/**
* 0: Not specified means Not Mandatory. The Gcube Profile is not mandatory and means that all its fields must be optional in the gCube Meta Profile.
* N: is the MIN number of Occurrences
* Default is 1 occurrence
*/
@JsonProperty
private int minOccurs = 1;
/**
* 0: Not specified means max number of Occurrences is arbitrary.
* N: is the MAX number of Occurrences
*/
@JsonProperty
private int maxOccurs = 1;
@JsonProperty(FILE_PATHS)
private List<FilePath> filePaths;
}

View File

@ -0,0 +1,35 @@
package org.gcube.application.geoportalcommon.shared.geoportalconfig;
import java.io.Serializable;
import java.util.List;
public class ConfigurationVO implements Serializable {
/**
*
*/
private static final long serialVersionUID = 372838411789432170L;
private List<GcubeProfileVO> gcubeProfiles;
public ConfigurationVO() {
}
public List<GcubeProfileVO> getGcubeProfiles() {
return gcubeProfiles;
}
public void setGcubeProfiles(List<GcubeProfileVO> gcubeProfiles) {
this.gcubeProfiles = gcubeProfiles;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ConfigurationVO [gcubeProfiles=");
builder.append(gcubeProfiles);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,55 @@
package org.gcube.application.geoportalcommon.shared.geoportalconfig;
import java.io.Serializable;
public class DocumentConfigVO implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7538079431272352662L;
private String id;
private String type;
private ConfigurationVO configuration;
public DocumentConfigVO() {
}
public String getId() {
return id;
}
public String getType() {
return type;
}
public ConfigurationVO getConfiguration() {
return configuration;
}
public void setId(String id) {
this.id = id;
}
public void setType(String type) {
this.type = type;
}
public void setConfiguration(ConfigurationVO configuration) {
this.configuration = configuration;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("DocumentConfigVO [id=");
builder.append(id);
builder.append(", type=");
builder.append(type);
builder.append(", configuration=");
builder.append(configuration);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,45 @@
package org.gcube.application.geoportalcommon.shared.geoportalconfig;
import java.io.Serializable;
public class FilePathVO implements Serializable {
/**
*
*/
private static final long serialVersionUID = -9186437393759442989L;
private String fieldName;
private String fieldDefinition;
public FilePathVO() {
}
public String getFieldName() {
return fieldName;
}
public String getFieldDefinition() {
return fieldDefinition;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public void setFieldDefinition(String fieldDefinition) {
this.fieldDefinition = fieldDefinition;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FilePathVO [fieldName=");
builder.append(fieldName);
builder.append(", fieldDefinition=");
builder.append(fieldDefinition);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,115 @@
package org.gcube.application.geoportalcommon.shared.geoportalconfig;
import java.io.Serializable;
import java.util.List;
public class GcubeProfileVO implements Serializable {
/**
*
*/
private static final long serialVersionUID = -7910384776524845043L;
public static final int MIN_MAX_NOT_SPECIFIED = -1;
private String gcubeSecondaryType;
private String gcubeName;
private String sectionName;
private String sectionTitle;
/**
* 0: Not specified means Not Mandatory. The Gcube Profile is not mandatory and
* means that all its fields must be optional in the gCube Meta Profile. N: is
* the MIN number of Occurrences Default is 1 occurrence
*/
private int minOccurs = 1;
/**
* 0: Not specified means max number of Occurrences is arbitrary. N: is the MAX
* number of Occurrences
*/
private int maxOccurs = 1;
private List<FilePathVO> filePaths;
public GcubeProfileVO() {
}
public String getGcubeSecondaryType() {
return gcubeSecondaryType;
}
public String getGcubeName() {
return gcubeName;
}
public String getSectionName() {
return sectionName;
}
public String getSectionTitle() {
return sectionTitle;
}
public int getMinOccurs() {
return minOccurs;
}
public int getMaxOccurs() {
return maxOccurs;
}
public List<FilePathVO> getFilePaths() {
return filePaths;
}
public void setGcubeSecondaryType(String gcubeSecondaryType) {
this.gcubeSecondaryType = gcubeSecondaryType;
}
public void setGcubeName(String gcubeName) {
this.gcubeName = gcubeName;
}
public void setSectionName(String sectionName) {
this.sectionName = sectionName;
}
public void setSectionTitle(String sectionTitle) {
this.sectionTitle = sectionTitle;
}
public void setMinOccurs(int minOccurs) {
this.minOccurs = minOccurs;
}
public void setMaxOccurs(int maxOccurs) {
this.maxOccurs = maxOccurs;
}
public void setFilePaths(List<FilePathVO> filePaths) {
this.filePaths = filePaths;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GcubeProfileVO [gcubeSecondaryType=");
builder.append(gcubeSecondaryType);
builder.append(", gcubeName=");
builder.append(gcubeName);
builder.append(", sectionName=");
builder.append(sectionName);
builder.append(", sectionTitle=");
builder.append(sectionTitle);
builder.append(", minOccurs=");
builder.append(minOccurs);
builder.append(", maxOccurs=");
builder.append(maxOccurs);
builder.append(", filePaths=");
builder.append(filePaths);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,45 @@
package org.gcube.application;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.gcube.application.geoportalcommon.geoportalconfig.DocumentConfig;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Test;
public class LoadDocumentConfiguration {
private static String TOKEN = "";
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String USERNAME = "francesco.mangiacrapa";
// @Before
public void init() {
ScopeProvider.instance.set(CONTEXT);
}
@Test
public void loadDocumentConfiguration() throws Exception {
System.out.println("loadDocumentConfiguration called");
String filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config.json";
String theFile = readFile(filePath);
System.out.println("the file is: "+theFile);
DocumentConfig dc = org.gcube.application.geoportal.client.utils.Serialization.read(theFile,
DocumentConfig.class);
System.out.println(dc);
}
private static String readFile(String filePath) {
String content = "";
try {
content = new String(Files.readAllBytes(Paths.get(filePath)));
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
}

View File

@ -0,0 +1,88 @@
{
"id": "geoportal-data-entry-app",
"type": "DATA_ENTRY_GUI",
"configuration": {
"gcubeProfiles": [
{
"gcubeSecondaryType": "GeoNaMetadata",
"gcubeName": "Informazioni_di_progetto",
"sectionName": "$.",
"sectionTitle": "Informazioni di Progetto"
},
{
"gcubeSecondaryType": "GeoNaMetadata",
"gcubeName": "Abstract_Relazione_di_Scavo",
"sectionName": "abstractRelazione",
"sectionTitle": "Abstract Relazione Scavo",
"parentName": "$.",
"filePaths": [
{
"fieldDefinition": "Carica Abstract Ita (in PDF)",
"fieldName": "filesetIta"
},
{
"fieldDefinition": "Carica Abstract Ita (in PDF)",
"fieldName": "filesetEng"
}
]
},
{
"gcubeSecondaryType": "GeoNaMetadata",
"gcubeName": "Relazione_di_Scavo",
"sectionName": "relazioneScavo",
"sectionTitle": "Relazione di Scavo",
"parentName": "$.",
"filePaths": [
{
"fieldDefinition": "Relazione di fine scavo (in PDF)",
"fieldName": "fileset"
}
]
},
{
"gcubeSecondaryType": "GeoNaMetadata",
"gcubeName": "Immagine_Rappresentativa_di_Scavo",
"sectionName": "immagini",
"sectionTitle": "Immagini Rappresentative",
"minOccurs": 1,
"maxOccurs": 8,
"parentName": "$.",
"filePaths": [
{
"fieldDefinition": "Immagine",
"fieldName": "fileset"
}
]
},
{
"gcubeSecondaryType": "GeoNaMetadata",
"gcubeName": "Pianta_di_fine_Scavo",
"sectionName": "posizionamentoScavo",
"sectionTitle": "Posizionamento dell'Area di Indagine",
"parentName": "$.",
"filePaths": [
{
"fieldDefinition": "File",
"fieldName": "fileset"
}
]
},
{
"gcubeSecondaryType": "GeoNaMetadata",
"gcubeName": "Posizionamento_dell_area_di_indagine",
"sectionName": "pianteFineScavo",
"sectionTitle": "Posizionamento dell'Area di Indagine",
"parentName": "$.",
"minOccurs": 0,
"maxOccurs": 0,
"filePaths": [
{
"fieldDefinition": "File",
"fieldName": "fileset"
}
]
}
],
"saveStep": "SUBMIT-FOR-REVIEW"
}
}