This commit is contained in:
Francesco Mangiacrapa 2022-09-26 16:16:26 +02:00
parent a84dca5230
commit 8a6b30872b
12 changed files with 377 additions and 67 deletions

View File

@ -12,6 +12,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- [#22883] Integrated the configurations exposed by (the new) geoportal-client (>= 1.1.0-SNAPSHOT)
- Passed to UCD/Projects geoportal client/service
- [#23835] Integrated with WORKFLOW_ACTION_LIST_GUI configuration
- [#23909] Declared lombok and jaxb-api required for JDK_11
- [#23913] Integrated with GUI presentation configurations read from IS
## [v1.4.0] - 2022-06-08

View File

@ -78,6 +78,12 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.8.11</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-url-shortener</artifactId>

View File

@ -914,6 +914,15 @@ public class ConvertToDataValueObjectModel {
Object value = document.get(key);
String keyLower = key.toLowerCase();
// String listAsStringValue = null;
// if(value instanceof LinkedHashMap) {
// LinkedHashMap<String, Object> toListView = (LinkedHashMap<String, Object>) value;
// for (String listValue : toListView.keySet()) {
// listAsStringValue+=""
// }
//
// }
/*
* ObjectMapper objectMapper = new ObjectMapper(); JavaTimeModule javaTimeModule
@ -934,16 +943,6 @@ public class ConvertToDataValueObjectModel {
LOG.debug("value " + value + " is instance of: " + value.getClass());
String asDate = instantToDateFormatString(value.toString());
// Document documentDate = new Document((Map) value);
// String jsonValue = documentDate.toJson();
// LOG.debug("jsonValue " + value);
//
// // LocalDate asDate =
// // objectMapper.readerFor(LocalDate.class).readValue(jsonValue);
//
// LocalDateTime asDate = org.gcube.application.geoportal.client.utils.Serialization.read(jsonValue,
// LocalDateTime.class);
// LOG.info("Casted as date: " + asDate);
value = asDate;
break;
} catch (Exception e) {

View File

@ -24,7 +24,9 @@ import org.gcube.application.geoportalcommon.shared.config.RoleRights;
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
import org.gcube.application.geoportalcommon.shared.exception.ApplicationProfileNotFoundException;
import org.gcube.application.geoportalcommon.shared.exception.GNAConfigException;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.gcube.application.geoportalcommon.shared.guipresentation.BodyWelcome;
import org.gcube.application.geoportalcommon.shared.guipresentation.DataEntryGUIPresentationConfig;
import org.gcube.application.geoportalcommon.shared.guipresentation.Header;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
@ -49,7 +51,10 @@ public class GNADataEntryConfigProfileReader {
public static final String GENERIC_RESOURCE_NAME = "Geoportal-DataEntry-Configs";
private static final String PATH_TO_PERMISSIONS_PATH = RESOURCE_PROFILE_BODY + "/permssions_for_role";
private static final String PATH_TO_ITEM_FIELDS_CONFIG = RESOURCE_PROFILE_BODY + "/item_fields_config";
// private static final String PATH_TO_ITEM_FIELDS_CONFIG = RESOURCE_PROFILE_BODY + "/item_fields_config";
private static final String PATH_TO_HEADER_GUI_PRESENTATION = RESOURCE_PROFILE_BODY + "/gui_presentation/data_entry_facility/header";
private static final String PATH_TO_BODY_WELCOME_GUI_PRESENTATION = RESOURCE_PROFILE_BODY + "/gui_presentation/data_entry_facility/body_welcome";
private String scope;
@ -67,7 +72,7 @@ public class GNADataEntryConfigProfileReader {
* @return the map
* @throws Exception the exception
*/
protected GNADataEntryConfigProfile readProfileFromInfrastrucure() throws Exception {
public GNADataEntryConfigProfile readProfileFromInfrastrucure() throws Exception {
LOG.info("called readProfileFromInfrastrucure");
String queryString = getGcubeGenericQueryString(SECONDARY_TYPE, GENERIC_RESOURCE_NAME);
this.scope = ScopeProvider.instance.get();
@ -115,23 +120,32 @@ public class GNADataEntryConfigProfileReader {
List<RoleRights> listRoleRights = readRoleRightsConfig(value_with_new_lines);
gnDEC.setPermissionsForRole(listRoleRights);
xPathExp = PATH_TO_ITEM_FIELDS_CONFIG + "/text()";
//GUI PRESENTATION CONFIGS
DataEntryGUIPresentationConfig deGUIP = new DataEntryGUIPresentationConfig();
xPathExp = PATH_TO_HEADER_GUI_PRESENTATION;
currValue = helper.evaluate(xPathExp);
LOG.debug("read " + PATH_TO_HEADER_GUI_PRESENTATION + ": " + currValue);
if (currValue != null && currValue.size() > 0) {
item_fields = currValue.get(0);
String headerGUI = currValue.get(0);
Header headerClass = SerializerUtil.readXML(headerGUI, Header.class);
LOG.debug("serialized " + Header.class + ": " + headerClass);
deGUIP.setHeader(headerClass);
} else
throw new Exception("I'm not able to read the path: " + xPathExp);
// replacing \n with new_line string
LOG.debug("read " + PATH_TO_ITEM_FIELDS_CONFIG + ": " + item_fields);
value_with_new_lines = item_fields.replaceAll("\\\\n", System.lineSeparator());
LOG.debug(PATH_TO_ITEM_FIELDS_CONFIG + " with new lines: " + value_with_new_lines);
GNAConfigsConverter gnc = new GNAConfigsConverter();
List<ItemFieldDV> listItemFieldsConfig = gnc.readListItemsConfig(value_with_new_lines);
gnDEC.setListItemFields(listItemFieldsConfig);
xPathExp = PATH_TO_BODY_WELCOME_GUI_PRESENTATION;
currValue = helper.evaluate(xPathExp);
LOG.debug("read " + PATH_TO_BODY_WELCOME_GUI_PRESENTATION + ": " + currValue);
if (currValue != null && currValue.size() > 0) {
String bodyWelcome = currValue.get(0);
BodyWelcome bodyWelcomeClass = SerializerUtil.readXML(bodyWelcome, BodyWelcome.class);
LOG.debug("serialized " + BodyWelcome.class + ": " + bodyWelcomeClass);
deGUIP.setBodyWelcome(bodyWelcomeClass);
} else
throw new Exception("I'm not able to read the path: " + xPathExp);
gnDEC.setDataEntryGUIPresentation(deGUIP);
LOG.info("returning: " + gnDEC);
return gnDEC;
}
@ -145,6 +159,7 @@ public class GNADataEntryConfigProfileReader {
}
}
/**
* To gcube user role.

View File

@ -1,32 +1,112 @@
package org.gcube.application.geoportalcommon;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
/**
* The Class SerializerUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Sep 26, 2022
*/
public class SerializerUtil {
private static Logger LOG = LoggerFactory.getLogger(SerializerUtil.class);
private static ObjectMapper mapper;
private static ObjectMapper mapperXML;
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.registerModule(new JavaTimeModule());
SimpleModule s=new SimpleModule();
SimpleModule s = new SimpleModule();
mapper.registerModule(s);
}
static {
mapperXML = new XmlMapper();
}
public static <T> T read(String jsonString,Class<T> clazz) throws JsonProcessingException, IOException {
return mapper.readerFor(clazz).readValue(jsonString);
/**
* Read JSON.
*
* @param <T> the generic type
* @param string the string
* @param clazz the clazz
* @return the t
* @throws JsonProcessingException the json processing exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public static <T> T readJSON(String string, Class<T> clazz) throws JsonProcessingException, IOException {
return mapper.readerFor(clazz).readValue(string);
}
/**
* Read XML.
*
* @param <T> the generic type
* @param string the string
* @param clazz the clazz
* @return the t
* @throws JsonProcessingException the json processing exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public static <T> T readXML(String string, Class<T> clazz) throws JsonProcessingException, IOException {
return mapperXML.readerFor(clazz).readValue(string);
}
/**
* Unmarshal XML.
*
* @param <T> the generic type
* @param string the string
* @param theClass the the class
* @return the class
* @throws Exception the exception
*/
public static <T> T unmarshalXML(String string, Class<T> theClass) throws Exception {
LOG.debug("unmarshalXML: " + string.trim());
try {
JAXBContext jaxbContext = JAXBContext.newInstance(theClass);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
if (string == null || string.length() == 0)
throw new Exception("Input string is null or empty");
InputStream stream = new ByteArrayInputStream(string.getBytes());
T umarshalledClass = (T) jaxbUnmarshaller.unmarshal(stream);
LOG.debug("returning: " + umarshalledClass);
return (T) umarshalledClass;
} catch (Exception e) {
LOG.error("An error occurred on unmarshalling " + string + "as " + theClass, e);
return null;
}
}
}

View File

@ -4,7 +4,7 @@ import java.io.Serializable;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.gcube.application.geoportalcommon.shared.guipresentation.DataEntryGUIPresentationConfig;
/**
* The Class GNADataEntryConfigProfile.
@ -15,12 +15,9 @@ import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV
*/
public class GNADataEntryConfigProfile implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5152380669677928785L;
private List<ItemFieldDV> listItemFields;
private List<RoleRights> permissionsForRole;
private DataEntryGUIPresentationConfig dataEntryGUIPresentation;
/**
* Instantiates a new GNA data entry config profile.
@ -29,34 +26,28 @@ public class GNADataEntryConfigProfile implements Serializable {
}
/**
* Instantiates a new GNA data entry config profile.
*
* @param listItemFields the list item fields
* @param permissionsForRole the permissions for role
*/
public GNADataEntryConfigProfile(List<ItemFieldDV> listItemFields, List<RoleRights> permissionsForRole) {
super();
this.listItemFields = listItemFields;
public GNADataEntryConfigProfile(List<RoleRights> permissionsForRole,
DataEntryGUIPresentationConfig dataEntryGUIPresentation) {
this.permissionsForRole = permissionsForRole;
this.dataEntryGUIPresentation = dataEntryGUIPresentation;
}
/**
* Gets the list item fields.
* Gets the data entry GUI presentation.
*
* @return the list item fields
* @return the data entry GUI presentation
*/
public List<ItemFieldDV> getListItemFields() {
return listItemFields;
public DataEntryGUIPresentationConfig getDataEntryGUIPresentation() {
return dataEntryGUIPresentation;
}
/**
* Sets the list item fields.
* Sets the data entry GUI presentation.
*
* @param listItemFields the new list item fields
* @param dataEntryGUIPresentation the new data entry GUI presentation
*/
public void setListItemFields(List<ItemFieldDV> listItemFields) {
this.listItemFields = listItemFields;
public void setDataEntryGUIPresentation(DataEntryGUIPresentationConfig dataEntryGUIPresentation) {
this.dataEntryGUIPresentation = dataEntryGUIPresentation;
}
/**
@ -77,18 +68,17 @@ public class GNADataEntryConfigProfile implements Serializable {
this.permissionsForRole = permissionsForRole;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GNADataEntryConfigProfile [listItemFields=");
builder.append(listItemFields);
builder.append("GNADataEntryConfigProfile [permissionsForRole=");
builder.append(permissionsForRole);
builder.append(", dataEntryGUIPresentation=");
builder.append(dataEntryGUIPresentation);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,53 @@
package org.gcube.application.geoportalcommon.shared.guipresentation;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "body_welcome")
@XmlAccessorType(XmlAccessType.FIELD)
public class BodyWelcome implements Serializable {
private static final long serialVersionUID = 801731912505360534L;
@XmlAttribute
private String title;
@XmlAttribute
private String description;
public BodyWelcome() {
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("BodyWelcome [title=");
builder.append(title);
builder.append(", description=");
builder.append(description);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,55 @@
package org.gcube.application.geoportalcommon.shared.guipresentation;
import java.io.Serializable;
/**
* The Class DataEntryGUIPresentationConfig.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Sep 26, 2022
*/
public class DataEntryGUIPresentationConfig implements Serializable {
/**
*
*/
private static final long serialVersionUID = 6007504380531152501L;
private Header header;
private BodyWelcome bodyWelcome;
/**
* Instantiates a new data entry GUI presentation config.
*/
public DataEntryGUIPresentationConfig() {
}
public Header getHeader() {
return header;
}
public BodyWelcome getBodyWelcome() {
return bodyWelcome;
}
public void setHeader(Header header) {
this.header = header;
}
public void setBodyWelcome(BodyWelcome bodyWelcome) {
this.bodyWelcome = bodyWelcome;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("DataEntryGUIPresentationConfig [header=");
builder.append(header);
builder.append(", bodyWelcome=");
builder.append(bodyWelcome);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,83 @@
package org.gcube.application.geoportalcommon.shared.guipresentation;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
/**
* The Class Header.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Sep 26, 2022
*/
@XmlRootElement(name = "header")
@XmlAccessorType(XmlAccessType.FIELD)
public class Header implements Serializable {
private static final long serialVersionUID = 1914492109448706008L;
@XmlAttribute
private String title;
@XmlAttribute
private String subtitle;
/**
* Instantiates a new header.
*/
public Header() {
}
/**
* Gets the title.
*
* @return the title
*/
public String getTitle() {
return title;
}
/**
* Gets the subtitle.
*
* @return the subtitle
*/
public String getSubtitle() {
return subtitle;
}
/**
* Sets the title.
*
* @param title the new title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Sets the subtitle.
*
* @param subtitle the new subtitle
*/
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Header [title=");
builder.append(title);
builder.append(", subtitle=");
builder.append(subtitle);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,33 @@
package org.gcube.application;
import org.gcube.application.geoportalcommon.GNADataEntryConfigProfileReader;
import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;
import org.junit.Test;
public class IS_Read_Configurations_Tests {
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String TOKEN = ""; // devVRE
//@Before
public void getClient() {
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
}
@Test
public void loadGNA_DataEntry_Configs() throws Exception{
ScopeProvider.instance.set(CONTEXT);
GNADataEntryConfigProfileReader dataEntryConfigs = new GNADataEntryConfigProfileReader();
GNADataEntryConfigProfile configProfile = dataEntryConfigs.readProfileFromInfrastrucure();
System.out.println(configProfile);
System.out.println("GUI presentantion: "+configProfile.getDataEntryGUIPresentation());
System.out.println("GUI permissions: "+configProfile.getPermissionsForRole());
}
}

View File

@ -110,11 +110,6 @@ public class TestGNACommon {
System.out.println(++i + " " + role);
}
System.out.println("Item Fields are:");
i = 0;
for (ItemFieldDV item : configurations.getListItemFields()) {
System.out.println(++i + " " + item);
}
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -6,7 +6,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import org.gcube.application.geoportal.client.utils.Serialization;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;