diff --git a/CHANGELOG.md b/CHANGELOG.md index 156528d..b42d60f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pom.xml b/pom.xml index a8c2a27..a91283a 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,12 @@ + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.8.11 + + org.gcube.portlets.user gcube-url-shortener diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java index 9c6bb0d..ae8014a 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java +++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java @@ -914,6 +914,15 @@ public class ConvertToDataValueObjectModel { Object value = document.get(key); String keyLower = key.toLowerCase(); + +// String listAsStringValue = null; +// if(value instanceof LinkedHashMap) { +// LinkedHashMap toListView = (LinkedHashMap) 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) { diff --git a/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java index 574467a..393c87d 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java @@ -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 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 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. diff --git a/src/main/java/org/gcube/application/geoportalcommon/SerializerUtil.java b/src/main/java/org/gcube/application/geoportalcommon/SerializerUtil.java index 1d3693f..f3b5efb 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/SerializerUtil.java +++ b/src/main/java/org/gcube/application/geoportalcommon/SerializerUtil.java @@ -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 read(String jsonString,Class clazz) throws JsonProcessingException, IOException { - return mapper.readerFor(clazz).readValue(jsonString); + /** + * Read JSON. + * + * @param 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 readJSON(String string, Class clazz) throws JsonProcessingException, IOException { + return mapper.readerFor(clazz).readValue(string); + } + + + /** + * Read XML. + * + * @param 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 readXML(String string, Class clazz) throws JsonProcessingException, IOException { + return mapperXML.readerFor(clazz).readValue(string); + } + + /** + * Unmarshal XML. + * + * @param the generic type + * @param string the string + * @param theClass the the class + * @return the class + * @throws Exception the exception + */ + public static T unmarshalXML(String string, Class 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; + } } } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataEntryConfigProfile.java b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataEntryConfigProfile.java index 922a2f3..eb3d5a4 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataEntryConfigProfile.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataEntryConfigProfile.java @@ -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 listItemFields; private List 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 listItemFields, List permissionsForRole) { - super(); - this.listItemFields = listItemFields; + public GNADataEntryConfigProfile(List 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 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 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(); } + + } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/guipresentation/BodyWelcome.java b/src/main/java/org/gcube/application/geoportalcommon/shared/guipresentation/BodyWelcome.java new file mode 100644 index 0000000..0a07c40 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/guipresentation/BodyWelcome.java @@ -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(); + } + + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/guipresentation/DataEntryGUIPresentationConfig.java b/src/main/java/org/gcube/application/geoportalcommon/shared/guipresentation/DataEntryGUIPresentationConfig.java new file mode 100644 index 0000000..73729be --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/guipresentation/DataEntryGUIPresentationConfig.java @@ -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(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/guipresentation/Header.java b/src/main/java/org/gcube/application/geoportalcommon/shared/guipresentation/Header.java new file mode 100644 index 0000000..9538f4f --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/guipresentation/Header.java @@ -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(); + } + +} diff --git a/src/test/java/org/gcube/application/IS_Read_Configurations_Tests.java b/src/test/java/org/gcube/application/IS_Read_Configurations_Tests.java new file mode 100644 index 0000000..d6fb19b --- /dev/null +++ b/src/test/java/org/gcube/application/IS_Read_Configurations_Tests.java @@ -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()); + + } +} diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index 1ffd157..22698e0 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -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(); } diff --git a/src/test/java/org/gcube/application/UCD_Tests.java b/src/test/java/org/gcube/application/UCD_Tests.java index 95657b5..79b8ed4 100644 --- a/src/test/java/org/gcube/application/UCD_Tests.java +++ b/src/test/java/org/gcube/application/UCD_Tests.java @@ -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;