From ae1cc32387336f189e36f2025c6a8e86ff74d9b8 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 6 Dec 2021 16:07:03 +0100 Subject: [PATCH 01/12] Added classes to read configurations and common classes to GNA DataEntry and Viewer --- CHANGELOG.md | 6 + pom.xml | 2 +- .../geoportalcommon/GeoportalCommon.java | 22 ++ .../geoportalcommon/MongoServiceCommon.java | 233 +++++++++++++++ .../geoportalcommon/config/CSVFile.java | 152 ++++++++++ .../geoportalcommon/config/CSVReader.java | 192 ++++++++++++ .../geoportalcommon/config/CSVRow.java | 81 +++++ .../geoportalcommon/config/FileUtil.java | 100 +++++++ .../config/GNADataEntryConfigs.java | 38 +++ .../GNADataEntryConfigsProfileReader.java | 282 ++++++++++++++++++ .../shared/GNADataConfigProfile.java | 40 +++ .../geoportalcommon/shared/ItemField.java | 90 ++++++ .../shared/ResultSetPaginatedData.java | 184 ++++++++++++ .../shared/SearchingFilter.java | 156 ++++++++++ .../shared/config/ACTION_ON_ITEM.java | 29 ++ .../config/GNAUserRightsConfigException.java | 8 + .../shared/config/GcubeUserRole.java | 55 ++++ .../shared/config/RoleRights.java | 100 +++++++ .../org/gcube/application/TestGNACommon.java | 71 +++++ .../gcube/application/TestGeonaReader.java | 43 --- 20 files changed, 1840 insertions(+), 44 deletions(-) create mode 100644 src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/config/CSVFile.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/config/CSVReader.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/config/CSVRow.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/config/FileUtil.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigs.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigsProfileReader.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/ItemField.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/ResultSetPaginatedData.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/config/ACTION_ON_ITEM.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/config/GNAUserRightsConfigException.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/config/GcubeUserRole.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/config/RoleRights.java create mode 100644 src/test/java/org/gcube/application/TestGNACommon.java delete mode 100644 src/test/java/org/gcube/application/TestGeonaReader.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 678b54d..ca98b5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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). +## [v1.3.0-SNAPSHOT] - 2021-12-03 + +#### Enhancements + +- [#22506] Added classes to read configurations and common classes to GNA DataEntry and Viewer + ## [v1.2.0] - 2021-09-29 #### Enhancements diff --git a/pom.xml b/pom.xml index 2495530..20ef6f2 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.application geoportal-data-common - 1.2.0 + 1.3.0-SNAPSHOT GeoPortal Data Common is common library used by GUI components developed for GeoNA diff --git a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java index 5a00505..c81eb62 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java @@ -2,10 +2,14 @@ package org.gcube.application.geoportalcommon; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; +import org.gcube.application.geoportalcommon.shared.GNADataConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.PublicLink; import org.gcube.portlets.user.urlshortener.UrlShortener; import org.slf4j.Logger; @@ -176,5 +180,23 @@ public class GeoportalCommon { public GeoNaDataViewerProfile getGeonaDataProfile() { return geonaDataProfile; } + + public GNADataConfigProfile getGNADataConfig(){ + + List listItemFields = new ArrayList(); + listItemFields.add(new ItemField("Name", Arrays.asList("nome"), true, true, true)); + listItemFields.add(new ItemField("Introduction", Arrays.asList("introduzione"), true, false, true)); + listItemFields.add(new ItemField("Author/s", Arrays.asList("authors"), true, true, true)); + listItemFields.add(new ItemField("Project Start/End Date", + Arrays.asList("dataInizioProgetto", "dataFineProgetto"), true, false, false)); + + listItemFields.add(new ItemField("Created", Arrays.asList("creationTime"), true, true, false)); + listItemFields.add(new ItemField("Created by", Arrays.asList("creationUser"), true, true, true)); + listItemFields.add(new ItemField("Published with", Arrays.asList("recordStatus"), true, true, false)); + + GNADataConfigProfile gnaDCP = new GNADataConfigProfile(); + gnaDCP.setListItemFields(listItemFields); + return gnaDCP; + } } diff --git a/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java b/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java new file mode 100644 index 0000000..24e9c08 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java @@ -0,0 +1,233 @@ +package org.gcube.application.geoportalcommon; + +import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.bson.Document; +import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest; +import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction; +import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest; +import org.gcube.application.geoportal.common.rest.MongoConcessioni; +import org.gcube.application.geoportalcommon.shared.ItemField; +import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; +import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.mongodb.BasicDBObject; +import com.mongodb.BasicDBObjectBuilder; + +/** + * The Class MongoServiceCommon. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 3, 2021 + */ +public class MongoServiceCommon { + + private static Logger LOG = LoggerFactory.getLogger(MongoServiceCommon.class); + + /** + * Gets the instance mongo concessioni. + * + * @return the instance mongo concessioni + */ + public MongoConcessioni getInstanceMongoConcessioni() { + return mongoConcessioni().build(); + } + + /** + * Gets the list of concessioni. + * + * @param reloadFromService the reload from service + * @return the list of concessioni + * @throws Exception the exception + */ + public List getListOfConcessioni() throws Exception { + LOG.info("called getListOfConcessioni"); + + List listOfConcessioni = new ArrayList(); + LOG.info("Loading list of concessioni from client mongo"); + MongoConcessioni clientMongo = getInstanceMongoConcessioni(); + + Iterator concessioni = clientMongo.getList(); + if (concessioni != null) { + while (concessioni.hasNext()) { + Concessione concessione = (Concessione) concessioni.next(); + listOfConcessioni.add(concessione); + + } + } + + LOG.info("read list of concessioni with size: " + listOfConcessioni.size()); + return listOfConcessioni; + } + + /** + * Query on mongo. + * + * @param offset the offset + * @param limit the limit + * @param filter the filter + * @param recordType the record type + * @return the result set paginated data + * @throws Exception the exception + */ + public ResultSetPaginatedData queryOnMongo(Integer totalItems, Integer offset, Integer limit, SearchingFilter filter, String recordType) throws Exception { + + try { + + if (recordType.equalsIgnoreCase("concessione")) { + MongoConcessioni clientMongo = getInstanceMongoConcessioni(); + + if(totalItems==null || totalItems < 0) { + // TODO MUST BE REPLACED BY COUNT + List listOfConcessioni = getListOfConcessioni(); + int listConcessioniSize = listOfConcessioni.size(); + totalItems = listConcessioniSize; + } + + Integer offsetIndex = offset; + Integer limitIndex = limit; + + if (offset == null || offset<0) { + offsetIndex = 0; + } + if (limit == null || limit<0) { + limitIndex = totalItems; + } + + ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false); + searchedData.setTotalItems(totalItems); + + List toReturnList = new ArrayList(); + Direction sDirection = null; + List orderingFields = new ArrayList(); + + if (filter == null) { + LOG.info("No filter found, creating empty filter"); + filter = new SearchingFilter(); + } + + ORDER order = filter.getOrder(); + + if (order == null) { + order = ORDER.ASC; + LOG.info("No direction/order found, using default: " + order); + } + + switch (order) { + case ASC: + sDirection = Direction.ASCENDING; + break; + case DESC: + sDirection = Direction.DESCENDING; + break; + } + + List orderByFields = filter.getOrderByFields(); + + if(orderByFields==null) { + orderByFields = new ArrayList(); + } + + if(orderByFields.isEmpty()) { + ItemField orderD = new ItemField("", Arrays.asList("name"), false, false, false); + LOG.info("Order by is null, adding default: " + orderD); + orderByFields.add(orderD); + } + + for (ItemField itemField : orderByFields) { + if (itemField.getJsonFields() != null) { + for (String field : itemField.getJsonFields()) { + orderingFields.add(field); + } + } + + } + + QueryRequest request = new QueryRequest(); + PagedRequest paging = new PagedRequest(); + paging.setOffset(offsetIndex); + paging.setLimit(limitIndex); + request.setPaging(paging); + + OrderedRequest ordering = new OrderedRequest(); + ordering.setDirection(sDirection); + ordering.setFields(orderingFields); + + request.setOrdering(ordering); + + Document query = null; + if (filter.getSearchInto() != null) { + Map searchFields = filter.getSearchInto(); + BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); + for (String key : searchFields.keySet()) { + // using regex and case-insensitive + BasicDBObject bs = new BasicDBObject(); + bs.append("$regex", searchFields.get(key)); + bs.append("$options", "i"); + builder.append(key, bs); + } + query = new Document(builder.get().toMap()); + request.setFilter(query); + } + + LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex); + LOG.info("Direction: " + sDirection); + LOG.info("Order by Fields: " + orderingFields); + LOG.info("Search for: " + filter.getSearchInto()); + if (query != null) { + LOG.info("Search query to JSON: " + query.toJson()); + } + + Iterator concessioni = clientMongo.query(request); + int i = 0; + while (concessioni.hasNext()) { + Concessione concessione = concessioni.next(); + ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); + toReturnList.add(concessioneDV); + i++; + LOG.trace("converted: " + concessioneDV); + } + LOG.debug("read " + toReturnList + " project/s"); + + searchedData.setData(toReturnList); + + // TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT + // AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE + if (filter.getSearchInto() != null) { + searchedData.setTotalItems(toReturnList.size()); + } + + if (totalItems == limit || totalItems == 0) { + LOG.debug("Page completed returning " + totalItems + " items"); + int newOffset = offsetIndex + limitIndex; + searchedData.setServerSearchFinished(newOffset > totalItems || totalItems == 0); + LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); + + } + + return searchedData; + } + + } catch (Exception e) { + LOG.error("Error on loading paginated and filtered list of concessioni: ", e); + throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage()); + } + + return null; + + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/config/CSVFile.java b/src/main/java/org/gcube/application/geoportalcommon/config/CSVFile.java new file mode 100644 index 0000000..23458da --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/config/CSVFile.java @@ -0,0 +1,152 @@ +/** + * + */ +package org.gcube.application.geoportalcommon.config; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * The Class CSVFile. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jan 29, 2019 + */ +public class CSVFile implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 6408321963787244600L; + private CSVRow headerRow; + private List valueRows; + private String fileName; + + /** + * Instantiates a new CSV file. + */ + public CSVFile(){ + + } + + + /** + * Instantiates a new csv file. + * + * @param fileName the file name + * @param headerRow the header row + * @param valueRows the value rows + */ + public CSVFile(String fileName, CSVRow headerRow, List valueRows) { + this.fileName = fileName; + this.headerRow = headerRow; + this.valueRows = valueRows; + } + + + /** + * Gets the header row. + * + * @return the headerRow + */ + public CSVRow getHeaderRow() { + + return headerRow; + } + + /** + * Adds the value row. + * + * @param row the row + */ + public void addValueRow(CSVRow row) { + if(valueRows==null) + valueRows = new ArrayList(); + + valueRows.add(row); + } + + + /** + * Sets the value rows. + * + * @param valueRows the new value rows + */ + public void setValueRows(List valueRows) { + this.valueRows = valueRows; + } + + + /** + * Gets the value rows. + * + * @return the valueRows + */ + public List getValueRows() { + + return valueRows; + } + + + /** + * Sets the header row. + * + * @param headerRow the headerRow to set + */ + public void setHeaderRow(CSVRow headerRow) { + + this.headerRow = headerRow; + } + + + + + /** + * Gets the file name. + * + * @return the fileName + */ + public String getFileName() { + + return fileName; + } + + + + /** + * Sets the file name. + * + * @param fileName the fileName to set + */ + public void setFileName(String fileName) { + + this.fileName = fileName; + } + + + /** + * To string. + * + * @return the string + */ + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("CSVFile [headerRow="); + builder.append(headerRow); + builder.append(", valueRows="); + builder.append(valueRows); + builder.append(", fileName="); + builder.append(fileName); + builder.append("]"); + return builder.toString(); + } + + + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/config/CSVReader.java b/src/main/java/org/gcube/application/geoportalcommon/config/CSVReader.java new file mode 100644 index 0000000..5c1cbe1 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/config/CSVReader.java @@ -0,0 +1,192 @@ +/** + * + */ + +package org.gcube.application.geoportalcommon.config; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * The Class CSVReader. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jan 29, 2019 + */ +public class CSVReader { + + public static final char DEFAULT_SEPARATOR = ','; + public static final char DEFAULT_QUOTE = '"'; + private File file; + private CSVFile csvFile; + + /** + * Instantiates a new CSV reader. + * + * @param file the file + * @throws FileNotFoundException the file not found exception + */ + public CSVReader(File file) throws FileNotFoundException { + + this.file = file; + this.csvFile = new CSVFile(); + readCSV(file); + } + + /** + * Read csv. + * + * @param file the file + * @throws FileNotFoundException the file not found exception + */ + private void readCSV(File file) throws FileNotFoundException { + + Scanner scanner = new Scanner(file); + csvFile.setFileName(file.getName()); + int i = 0; + while (scanner.hasNext()) { + CSVRow csvRow = new CSVRow(); + List line = parseLine(scanner.nextLine()); + csvRow.setListValues(line); + + if(i==0){ + csvFile.setHeaderRow(csvRow); + }else{ + csvFile.addValueRow(csvRow); + } + i++; + + } + scanner.close(); + } + + /** + * Parses the line. + * + * @param cvsLine the cvs line + * @return the list + */ + public static List parseLine(String cvsLine) { + + return parseLine(cvsLine, DEFAULT_SEPARATOR, DEFAULT_QUOTE); + } + + /** + * Parses the line. + * + * @param cvsLine the cvs line + * @param separators the separators + * @return the list + */ + public static List parseLine(String cvsLine, char separators) { + + return parseLine(cvsLine, separators, DEFAULT_QUOTE); + } + + /** + * Parses the line. + * + * @param cvsLine the cvs line + * @param separators the separators + * @param customQuote the custom quote + * @return the list + */ + private static List parseLine(String cvsLine, char separators, char customQuote) { + + List result = new ArrayList<>(); + // if empty, return! + if (cvsLine == null || cvsLine.isEmpty()) { + return result; + } + if (customQuote == ' ') { + customQuote = DEFAULT_QUOTE; + } + if (separators == ' ') { + separators = DEFAULT_SEPARATOR; + } + StringBuffer curVal = new StringBuffer(); + boolean inQuotes = false; + boolean startCollectChar = false; + boolean doubleQuotesInColumn = false; + char[] chars = cvsLine.toCharArray(); + for (char ch : chars) { + if (inQuotes) { + startCollectChar = true; + if (ch == customQuote) { + inQuotes = false; + doubleQuotesInColumn = false; + } + else { + // Fixed : allow "" in custom quote enclosed + if (ch == '\"') { + if (!doubleQuotesInColumn) { + curVal.append(ch); + doubleQuotesInColumn = true; + } + } + else { + curVal.append(ch); + } + } + } + else { + if (ch == customQuote) { + inQuotes = true; + // Fixed : allow "" in empty quote enclosed + if (chars[0] != '"' && customQuote == '\"') { + curVal.append('"'); + } + // double quotes in column will hit this! + if (startCollectChar) { + curVal.append('"'); + } + } + else if (ch == separators) { + result.add(curVal.toString()); + curVal = new StringBuffer(); + startCollectChar = false; + } + else if (ch == '\r') { + // ignore LF characters + continue; + } + else if (ch == '\n') { + // the end, break! + break; + } + else { + curVal.append(ch); + } + } + } + result.add(curVal.toString()); + return result; + } + + + /** + * Gets the csv file. + * + * @return the csvFile + */ + public CSVFile getCsvFile() { + + return csvFile; + } + + + /** + * Gets the file. + * + * @return the file + */ + public File getFile() { + + return file; + } + + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/config/CSVRow.java b/src/main/java/org/gcube/application/geoportalcommon/config/CSVRow.java new file mode 100644 index 0000000..edf9b37 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/config/CSVRow.java @@ -0,0 +1,81 @@ +/** + * + */ +package org.gcube.application.geoportalcommon.config; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +/** + * The Class CSVRow. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jan 29, 2019 + */ +public class CSVRow implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 6254861811998867626L; + + private List listValues; + + /** + * Instantiates a new CSV row. + */ + public CSVRow(){ + + } + + + /** + * Gets the list values. + * + * @return the listValues + */ + public List getListValues() { + + return listValues; + } + + + + /** + * @param listValues the listValues to set + */ + public void setListValues(List listValues) { + + this.listValues = listValues; + } + + + /** + * Adds the value. + * + * @param value the value + */ + public void addValue(String value) { + if(listValues==null) + listValues = new ArrayList(); + + listValues.add(value); + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("CSVRow [listValues="); + builder.append(listValues); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/config/FileUtil.java b/src/main/java/org/gcube/application/geoportalcommon/config/FileUtil.java new file mode 100644 index 0000000..5281ab8 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/config/FileUtil.java @@ -0,0 +1,100 @@ +package org.gcube.application.geoportalcommon.config; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +/** + * The Class FileUtil. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 2, 2021 + */ +public class FileUtil { + + /** + * Input stream to temp file. + * + * @param inputStream the input stream + * @param fileName the file name + * @return the file + * @throws IOException Signals that an I/O exception has occurred. + */ + // InputStream -> Temp File + public static File inputStreamToTempFile(InputStream inputStream, String fileName) throws IOException { + + File tempFile = File.createTempFile(fileName, ".tmp"); + // File tempFile = File.createTempFile("MyAppName-", ".tmp"); + try (FileOutputStream outputStream = new FileOutputStream(tempFile)) { + + int read; + byte[] bytes = new byte[1024]; + + while ((read = inputStream.read(bytes)) != -1) { + outputStream.write(bytes, 0, read); + } + + return tempFile; + + } finally { + tempFile.deleteOnExit(); + } + + } + + /** + * Input stream to temp file. + * + * @param copyString the copy string + * @return + * @throws IOException Signals that an I/O exception has occurred. + */ + public static File inputStreamToTempFile(String copyString, String prefixFile) throws IOException { + + File targetFile = null; + try { + InputStream initialStream = new ByteArrayInputStream(copyString.getBytes()); + targetFile = File.createTempFile(prefixFile, ".tmp"); + + java.nio.file.Files.copy(initialStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + + try { + if (initialStream != null) { + initialStream.close(); + } + } catch (IOException ioe) { + // ignore + } + return targetFile; + } finally { + try { + if (targetFile != null) + targetFile.deleteOnExit(); + } catch (Exception e) { + + } + } + } + + /** + * Copy input stream to file. + * + * @param is the is + * @param to the to + * @return the file + * @throws IOException Signals that an I/O exception has occurred. + */ + public static File copyInputStreamToFile(InputStream is, String to) throws IOException { + Path dest = Paths.get(to); + Files.copy(is, dest); + return new File(to); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigs.java b/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigs.java new file mode 100644 index 0000000..77d1995 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigs.java @@ -0,0 +1,38 @@ +package org.gcube.application.geoportalcommon.config; + +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.config.RoleRights; + + +public class GNADataEntryConfigs { + + List permissionsForRole = null; + + public GNADataEntryConfigs() { + + } + + public GNADataEntryConfigs(List permissionsForRole) { + super(); + this.permissionsForRole = permissionsForRole; + } + + public List getPermissionsForRole() { + return permissionsForRole; + } + + public void setPermissionsForRole(List permissionsForRole) { + this.permissionsForRole = permissionsForRole; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GNADataEntryConfigs [permissionsForRole="); + builder.append(permissionsForRole); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigsProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigsProfileReader.java new file mode 100644 index 0000000..deac0d2 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigsProfileReader.java @@ -0,0 +1,282 @@ +package org.gcube.application.geoportalcommon.config; + +import static org.gcube.resources.discovery.icclient.ICFactory.client; + +import java.io.File; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; +import org.gcube.application.geoportalcommon.shared.config.GNAUserRightsConfigException; +import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole; +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.common.resources.gcore.utils.XPathHelper; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.Query; +import org.gcube.resources.discovery.client.queries.impl.QueryBox; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + +/** + * The Class GNADataEntryConfigsProfileReader. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 2, 2021 + */ +public class GNADataEntryConfigsProfileReader { + + private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body"; + public static final String SECONDARY_TYPE = "ApplicationProfile"; + public static final String GENERIC_RESOURCE_NAME = "GNA-DataEntry-Configs"; + private static final String TEMP_ROLE_RIGHTS_CONFIG_FILENAME = "GNA_RoleRights_Configurations"; + + private String scope; + + private static final Logger LOG = LoggerFactory.getLogger(GNADataEntryConfigsProfileReader.class); + + /** + * Instantiates a new application profile reader. + */ + public GNADataEntryConfigsProfileReader() { + } + + /** + * Read profile from infrastrucure. + * + * @return the map + * @throws Exception the exception + */ + public GNADataEntryConfigs readProfileFromInfrastrucure() throws Exception { + LOG.info("called readProfileFromInfrastrucure"); + String queryString = getGcubeGenericQueryString(SECONDARY_TYPE, GENERIC_RESOURCE_NAME); + LOG.info("Scope " + scope + ", trying to perform query: " + queryString); + this.scope = ScopeProvider.instance.get(); + + if (scope == null) + throw new Exception("Scope is null, set scope into ScopeProvider"); + + GNADataEntryConfigs gnDEC = new GNADataEntryConfigs(); + String permissions_for_role = ""; + try { + + LOG.info("Trying to fetch GR named: " + GENERIC_RESOURCE_NAME + ", in the scope: " + scope + + ", SecondaryType: " + SECONDARY_TYPE); + Query q = new QueryBox(queryString); + DiscoveryClient client = client(); + List appProfile = client.submit(q); + + if (appProfile == null || appProfile.size() == 0) + throw new ApplicationProfileNotFoundException("GR with SecondaryType: " + SECONDARY_TYPE + + ", and name: " + GENERIC_RESOURCE_NAME + " is not registered in the scope: " + scope); + else { + String elem = appProfile.get(0); + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document doc = docBuilder.parse(new InputSource(new StringReader(elem))); + + XPathHelper helper = new XPathHelper(doc.getDocumentElement()); + + List currValue = null; + String xPathExp = RESOURCE_PROFILE_BODY + "/permssions_for_role/text()"; + currValue = helper.evaluate(xPathExp); + + if (currValue != null && currValue.size() > 0) { + permissions_for_role = currValue.get(0); + } else + throw new Exception("I'm not able to read the path: " + xPathExp); + + //replacing \n with new_line string + LOG.debug("read permissions_for_role: " + permissions_for_role); + String pfr_with_new_lines = permissions_for_role.replaceAll("\\\\n", System.lineSeparator()); + LOG.debug("permissions_for_role with new lines: " + pfr_with_new_lines); + + List listRoleRights = readRoleRightsConfig(pfr_with_new_lines); + gnDEC.setPermissionsForRole(listRoleRights); + LOG.info("returning: " + gnDEC); + return gnDEC; + } + + } catch (Exception e) { + LOG.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType " + + GENERIC_RESOURCE_NAME + " from scope " + scope, e); + return null; + } finally { + + } + + } + + /** + * To gcube user role. + * + * @param name the name + * @return the gcube user role + */ + public static GcubeUserRole toGcubeUserRole(String name) { + + for (GcubeUserRole gCubeUserRole : GcubeUserRole.values()) { + if (gCubeUserRole.getName().equalsIgnoreCase(name)) + return gCubeUserRole; + } + + return null; + } + + /** + * Read user rights config. + * + * @param permissions_for_role the permissions for role + * @return the list + * @throws GNAUserRightsConfigException the GNA user rights config not found + * exception + */ + public List readRoleRightsConfig(String permissions_for_role) throws GNAUserRightsConfigException { + LOG.debug("readRoleRightsConfig called"); + + File configurationFile = null; + List listUserRights = new ArrayList(); + try { + configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, TEMP_ROLE_RIGHTS_CONFIG_FILENAME); + + CSVReader reader = new CSVReader(configurationFile); + CSVFile csvFile = reader.getCsvFile(); + + List headerKeys = csvFile.getHeaderRow().getListValues(); + List rows = csvFile.getValueRows(); + + // MAPPING OPERATION TYPE AS READ, WRITE, etc. + Map mapOperationTypes = new HashMap(); + CSVRow operationTypeRow = rows.get(0); + List rowValues = operationTypeRow.getListValues(); + for (int j = 1; j < rowValues.size(); j++) { + String operationType = rowValues.get(j); + RoleRights.OPERATION_TYPE ot = RoleRights.OPERATION_TYPE.UNKNOWN; + if (operationType.equalsIgnoreCase("R")) { + ot = RoleRights.OPERATION_TYPE.READ; + } else if (operationType.equalsIgnoreCase("RW")) { + ot = RoleRights.OPERATION_TYPE.READ_WRITE; + } else if (operationType.equalsIgnoreCase("W")) { + ot = RoleRights.OPERATION_TYPE.WRITE; + } + + mapOperationTypes.put(headerKeys.get(j), ot); + } + + LOG.debug("Map of operation types: " + mapOperationTypes); + + // Starting from index 1 (means the second row in the CSV) + for (int i = 1; i < rows.size(); i++) { + LOG.trace(i + " row"); + RoleRights useRights = new RoleRights(); + CSVRow row = rows.get(i); + + // to map properties + rowValues = row.getListValues(); + + LOG.debug("rowValues: " + rowValues); + Map mapUserRolePermissions = new HashMap(); + + GcubeUserRole gCubeUserRole = toGcubeUserRole(rowValues.get(0)); + + if (gCubeUserRole == null) { + LOG.warn("The Role " + rowValues.get(0) + " not found into roleName of: " + GcubeUserRole.values()); + continue; + } + + useRights.setUserRole(gCubeUserRole); + + for (int j = 1; j < rowValues.size(); j++) { + mapUserRolePermissions.put(headerKeys.get(j), rowValues.get(j)); + } + LOG.debug("Role: " + useRights.getUserRole()); + LOG.debug("Permissions read: " + mapUserRolePermissions); + + Map listPermessions = new HashMap(); + + for (ACTION_ON_ITEM value : ACTION_ON_ITEM.values()) { + String yesno = mapUserRolePermissions.get(value.name()); + + if (yesno != null && yesno.equalsIgnoreCase("yes")) { + listPermessions.put(value, mapOperationTypes.get(value.name())); + } + + } + + useRights.setListPermessions(listPermessions); + +// String writeOwn = mapUserRolePermissions.get(WRITE_OWN_CONFIG); +// if (writeOwn != null && writeOwn.equalsIgnoreCase("yes")) { +// useRights.setWriteOwn(true); +// } +// +// String writeAny = mapUserRolePermissions.get(WRITE_ANY_CONFIG); +// if (writeAny != null && writeAny.equalsIgnoreCase("yes")) { +// useRights.setWriteAny(true); +// } + + listUserRights.add(useRights); + + } + LOG.info("Returning user rights config: " + listUserRights); + return listUserRights; + + } catch (Exception e) { + LOG.error("An error occurred on reading the GNA DataEntry config from: " + permissions_for_role, e); + throw new GNAUserRightsConfigException("Error on reading the GNA DataEntry from: " + permissions_for_role); + } finally { + + if (configurationFile != null) { + try { + configurationFile.delete(); + } catch (Exception e) { + // silent + } + } + } + + } + + /** + * Gets the gcube generic query string. + * + * @param secondaryType the secondary type + * @param genericResourceName the generic resource name + * @return the gcube generic query string + */ + public static String getGcubeGenericQueryString(String secondaryType, String genericResourceName) { + + return "for $profile in collection('/db/Profiles/GenericResource')//Resource " + + "where $profile/Profile/SecondaryType/string() eq '" + secondaryType + + "' and $profile/Profile/Name/string() " + " eq '" + genericResourceName + "'" + "return $profile"; + } + + /** + * Gets the secondary type. + * + * @return the secondary type + */ + public String getSecondaryType() { + return SECONDARY_TYPE; + } + + /** + * Gets the scope. + * + * @return the scope + */ + public String getScope() { + return scope; + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java new file mode 100644 index 0000000..bf4a39a --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java @@ -0,0 +1,40 @@ +package org.gcube.application.geoportalcommon.shared; + +import java.io.Serializable; +import java.util.List; + +public class GNADataConfigProfile implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 5152380669677928785L; + private List listItemFields; + + public GNADataConfigProfile() { + + } + + public GNADataConfigProfile(List listItemFields) { + super(); + this.listItemFields = listItemFields; + } + + public List getListItemFields() { + return listItemFields; + } + + public void setListItemFields(List listItemFields) { + this.listItemFields = listItemFields; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GNADataConfigProfile [listItemFields="); + builder.append(listItemFields); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/ItemField.java b/src/main/java/org/gcube/application/geoportalcommon/shared/ItemField.java new file mode 100644 index 0000000..472ea02 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/ItemField.java @@ -0,0 +1,90 @@ +package org.gcube.application.geoportalcommon.shared; + +import java.io.Serializable; +import java.util.List; + +public class ItemField implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1856714668390438433L; + + private String displayName; + private List jsonFields; + private boolean sortable; + private boolean searchable; + private boolean displayIntoTable; + + public ItemField() { + + } + + public ItemField(String displayName, List jsonFields, boolean displayIntoTable, boolean sortable, + boolean searchable) { + super(); + this.displayName = displayName; + this.jsonFields = jsonFields; + this.displayIntoTable = displayIntoTable; + this.sortable = sortable; + this.searchable = searchable; + } + + public String getDisplayName() { + return displayName; + } + + public List getJsonFields() { + return jsonFields; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public void setJsonFields(List jsonFields) { + this.jsonFields = jsonFields; + } + + public boolean isSortable() { + return sortable; + } + + public void setSortable(boolean sortable) { + this.sortable = sortable; + } + + public boolean isSearchable() { + return searchable; + } + + public void setSearchable(boolean searchable) { + this.searchable = searchable; + } + + public boolean isDisplayIntoTable() { + return displayIntoTable; + } + + public void setDisplayIntoTable(boolean displayIntoTable) { + this.displayIntoTable = displayIntoTable; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ItemField [displayName="); + builder.append(displayName); + builder.append(", jsonFields="); + builder.append(jsonFields); + builder.append(", sortable="); + builder.append(sortable); + builder.append(", searchable="); + builder.append(searchable); + builder.append(", displayIntoTable="); + builder.append(displayIntoTable); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/ResultSetPaginatedData.java b/src/main/java/org/gcube/application/geoportalcommon/shared/ResultSetPaginatedData.java new file mode 100644 index 0000000..507aeb3 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/ResultSetPaginatedData.java @@ -0,0 +1,184 @@ +/** + * + */ +package org.gcube.application.geoportalcommon.shared; + +import java.io.Serializable; +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; + +/** + * The Class ResultSetPaginatedData. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Aug 6, 2021 + */ +public class ResultSetPaginatedData implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 6800997954077785719L; + private List data; + private int offset = 0; + private int limit; + private boolean isServerSearchFinished = false; + private long totalItems; + + /** + * Instantiates a new searched folder. + */ + public ResultSetPaginatedData() { + } + + /** + * Instantiates a new result set paginated data. + * + * @param offset the offset + * @param limit the limit + * @param isServerSearchFinished the is server search finished + */ + public ResultSetPaginatedData(int offset, int limit, boolean isServerSearchFinished) { + + this.offset = offset; + this.limit = limit; + this.isServerSearchFinished = isServerSearchFinished; + } + + /** + * Gets the data. + * + * @return the data + */ + public List getData() { + return data; + } + + /** + * Gets the client start index. + * + * @return the client start index + */ + public int getClientStartIndex() { + return offset; + } + + /** + * Gets the limit. + * + * @return the limit + */ + public int getLimit() { + return limit; + } + + /** + * Checks if is server search finished. + * + * @return true, if is server search finished + */ + public boolean isServerSearchFinished() { + return isServerSearchFinished; + } + + /** + * Sets the data. + * + * @param data the new data + */ + public void setData(List data) { + this.data = data; + } + + /** + * Sets the client start index. + * + * @param clientStartIndex the new client start index + */ + public void setClientStartIndex(int clientStartIndex) { + this.offset = clientStartIndex; + } + + /** + * Sets the limit. + * + * @param limit the new limit + */ + public void setLimit(int limit) { + this.limit = limit; + } + + /** + * Sets the server search finished. + * + * @param isServerSearchFinished the new server search finished + */ + public void setServerSearchFinished(boolean isServerSearchFinished) { + this.isServerSearchFinished = isServerSearchFinished; + } + + /** + * Gets the total items. + * + * @return the total items + */ + public long getTotalItems() { + return totalItems; + } + + /** + * Sets the total items. + * + * @param totalItems the new total items + */ + public void setTotalItems(long totalItems) { + this.totalItems = totalItems; + } + + /** + * Gets the serialversionuid. + * + * @return the serialversionuid + */ + public static long getSerialversionuid() { + return serialVersionUID; + } + + /** + * Gets the offset. + * + * @return the offset + */ + public int getOffset() { + return offset; + } + + /** + * Sets the offset. + * + * @param offset the new offset + */ + public void setOffset(int offset) { + this.offset = offset; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ResultSetPaginatedData [data="); + builder.append(data); + builder.append(", offset="); + builder.append(offset); + builder.append(", limit="); + builder.append(limit); + builder.append(", isServerSearchFinished="); + builder.append(isServerSearchFinished); + builder.append(", totalItems="); + builder.append(totalItems); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java b/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java new file mode 100644 index 0000000..d77a568 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java @@ -0,0 +1,156 @@ +package org.gcube.application.geoportalcommon.shared; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * The Class SearchingFilter. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 30, 2021 + */ +public class SearchingFilter implements Serializable { + + /** + * The Enum ORDER. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 30, 2021 + */ + public static enum ORDER { + ASC("ASCENDING"), DESC("DESCENDING"); + + String label; + + /** + * Instantiates a new order. + * + * @param label the label + */ + ORDER(String label) { + this.label = label; + } + + /** + * Gets the label. + * + * @return the label + */ + public String getLabel() { + return label; + } + } + + /** + * + */ + private static final long serialVersionUID = -4004094263090373626L; + + private List orderByFields; + + private ORDER order; + + private Map searchInto; + + /** + * Instantiates a new sort filter. + */ + public SearchingFilter() { + + } + + /** + * Instantiates a new sort filter. + * + * @param orderByFields the order by fields + * @param order the order + */ + public SearchingFilter(List orderByFields, ORDER order) { + this.orderByFields = orderByFields; + this.order = order; + } + + /** + * Instantiates a new sort filter. + * + * @param orderByFields the order by fields + * @param order the order + * @param searchInto the search into + */ + public SearchingFilter(List orderByFields, ORDER order, Map searchInto) { + this.orderByFields = orderByFields; + this.order = order; + this.searchInto = searchInto; + } + + /** + * Sets the search into. + * + * @param searchInto the search into + */ + public void setSearchInto(Map searchInto) { + this.searchInto = searchInto; + } + + /** + * Gets the order by fields. + * + * @return the order by fields + */ + public List getOrderByFields() { + return orderByFields; + } + + /** + * Gets the order. + * + * @return the order + */ + public ORDER getOrder() { + return order; + } + + /** + * Sets the order by fields. + * + * @param orderByFields the new order by fields + */ + public void setOrderByFields(List orderByFields) { + this.orderByFields = orderByFields; + } + + /** + * Sets the order. + * + * @param order the new order + */ + public void setOrder(ORDER order) { + this.order = order; + } + + /** + * Gets the search into. + * + * @return the search into + */ + public Map getSearchInto() { + return searchInto; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SearchingFilter [orderByFields="); + builder.append(orderByFields); + builder.append(", order="); + builder.append(order); + builder.append(", searchInto="); + builder.append(searchInto); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/config/ACTION_ON_ITEM.java b/src/main/java/org/gcube/application/geoportalcommon/shared/config/ACTION_ON_ITEM.java new file mode 100644 index 0000000..7d4562d --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/config/ACTION_ON_ITEM.java @@ -0,0 +1,29 @@ +package org.gcube.application.geoportalcommon.shared.config; + +/** + * The Class ACTION_ON_ITEM. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 24, 2021 + */ +public enum ACTION_ON_ITEM { + + CREATE_NEW_PROJECT("Create New Project"), + VIEW_ON_MAP("View on Map"), + SHOW_METADATA("Show Metadata"), + VIEW_REPORT("View the Report"), + EDIT_PROJECT("Edit the Project"), + DELETE_PROJECT("Delete the Project"); + + String label; + + ACTION_ON_ITEM(String label){ + this.label = label; + } + + public String getLabel() { + return label; + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/config/GNAUserRightsConfigException.java b/src/main/java/org/gcube/application/geoportalcommon/shared/config/GNAUserRightsConfigException.java new file mode 100644 index 0000000..81560c6 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/config/GNAUserRightsConfigException.java @@ -0,0 +1,8 @@ +package org.gcube.application.geoportalcommon.shared.config; + +@SuppressWarnings("serial") +public class GNAUserRightsConfigException extends Exception { + public GNAUserRightsConfigException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/config/GcubeUserRole.java b/src/main/java/org/gcube/application/geoportalcommon/shared/config/GcubeUserRole.java new file mode 100644 index 0000000..a571278 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/config/GcubeUserRole.java @@ -0,0 +1,55 @@ +package org.gcube.application.geoportalcommon.shared.config; + +/** + * The Enum GcubeUserRole. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 25, 2021 + */ +public enum GcubeUserRole { + + DATA_MEMBER("Data-Member", false, false), + DATA_EDITOR("Data-Editor", true, false), + DATA_MANAGER("Data-Manager", true, true); + + private String name; + private boolean writeOwn; + private boolean writeAny; + + /** + * Instantiates a new gcube user role. + * + * @param name the name + */ + private GcubeUserRole(String name, boolean writeOwn, boolean writeAny) { + this.name = name; + this.writeOwn = writeOwn; + this.writeAny = writeAny; + } + + public String getName() { + return name; + } + + public boolean isWriteOwn() { + return writeOwn; + } + + public boolean isWriteAny() { + return writeAny; + } + + public void setName(String name) { + this.name = name; + } + + public void setWriteOwn(boolean writeOwn) { + this.writeOwn = writeOwn; + } + + public void setWriteAny(boolean writeAny) { + this.writeAny = writeAny; + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/config/RoleRights.java b/src/main/java/org/gcube/application/geoportalcommon/shared/config/RoleRights.java new file mode 100644 index 0000000..cd4d1f5 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/config/RoleRights.java @@ -0,0 +1,100 @@ +package org.gcube.application.geoportalcommon.shared.config; + +import java.io.Serializable; +import java.util.Map; + +/** + * The Class RoleRights. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 26, 2021 + */ +public class RoleRights implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -304157165851633221L; + + /** + * The Enum OPERATION_TYPE. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 26, 2021 + */ + public static enum OPERATION_TYPE { + READ, WRITE, READ_WRITE, UNKNOWN + } + + private Map listPermessions; + private GcubeUserRole userRole; + + /** + * Instantiates a new user rights. + */ + public RoleRights() { + super(); + } + + /** + * Instantiates a new role rights. + * + * @param myUsername the my username + * @param listPermessions the list permessions + * @param userRole the user role + */ + public RoleRights(Map listPermessions, GcubeUserRole userRole) { + this.listPermessions = listPermessions; + this.userRole = userRole; + } + + /** + * Gets the list permessions. + * + * @return the list permessions + */ + public Map getListPermessions() { + return listPermessions; + } + + /** + * Gets the user role. + * + * @return the user role + */ + public GcubeUserRole getUserRole() { + return userRole; + } + + /** + * Sets the list permessions. + * + * @param listPermessions the list permessions + */ + public void setListPermessions(Map listPermessions) { + this.listPermessions = listPermessions; + } + + /** + * Sets the user role. + * + * @param userRole the new user role + */ + public void setUserRole(GcubeUserRole userRole) { + this.userRole = userRole; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("RoleRights [listPermessions="); + builder.append(listPermessions); + builder.append(", userRole="); + builder.append(userRole); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java new file mode 100644 index 0000000..c262aa4 --- /dev/null +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -0,0 +1,71 @@ +package org.gcube.application; + +import org.gcube.application.geoportalcommon.GeoportalCommon; +import org.gcube.application.geoportalcommon.MongoServiceCommon; +import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; +import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; +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 TestGNACommon { + + private static String TOKEN = "8e74a17c-92f1-405a-b591-3a6090066248-98187548"; + private static String CONTEXT = "/gcube/devsec/devVRE"; + private static String USERNAME = "francesco.mangiacrapa"; + + @Before + public void init() { + ScopeProvider.instance.set(CONTEXT); + SecurityTokenProvider.instance.set(TOKEN); + } + + //@Test + public GeoNaDataViewerProfile getGeoNaDataViewProfile() throws Exception { + System.out.println("getGeoNaDataViewProfile called"); + + ScopeProvider.instance.set(CONTEXT); + GeoportalCommon gc = new GeoportalCommon(); + GeoNaDataViewerProfile profile = gc.getGeoNaDataViewProfile(null); + System.out.println("Returning profile: " + profile); + return profile; + } + + //@Test + public GeoNaItemRef getLinks() throws Exception { + System.out.println("getGeoNaDataViewProfile called"); + + ScopeProvider.instance.set(CONTEXT); + GeoportalCommon gc = new GeoportalCommon(); + GeoNaItemRef item = new GeoNaItemRef("", "concessione"); + GeoNaItemRef links = gc.getPublicLinksFor(item, true); + return links; + } + + @Test + public void queryConcessioniTest() throws Exception { + try { + + ScopeProvider.instance.set(CONTEXT); + MongoServiceCommon msc = new MongoServiceCommon(); + SearchingFilter filter = new SearchingFilter(); + // filter.setSearchInto(new Se); + ResultSetPaginatedData result = msc.queryOnMongo(30, 0, 30, filter, "concessione"); + + int i = 0; + for (ConcessioneDV concessione : result.getData()) { + System.out.println(++i +") "+concessione); + } + + + } catch (Exception e) { + // TODO: handle exception + } + + } + +} diff --git a/src/test/java/org/gcube/application/TestGeonaReader.java b/src/test/java/org/gcube/application/TestGeonaReader.java deleted file mode 100644 index e5d470b..0000000 --- a/src/test/java/org/gcube/application/TestGeonaReader.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.gcube.application; - -import org.gcube.application.geoportalcommon.GeoportalCommon; -import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; -import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; -import org.gcube.common.scope.api.ScopeProvider; - -public class TestGeonaReader { - - - private static String scope ="/gcube/devsec/devVRE"; - - public static void main(String[] args) throws Exception { - - //System.out.println(getGeoNaDataViewProfile()); - - System.out.println(getLinks()); - - } - - public static GeoNaDataViewerProfile getGeoNaDataViewProfile() throws Exception{ - System.out.println("getGeoNaDataViewProfile called"); - - ScopeProvider.instance.set(scope); - GeoportalCommon gc = new GeoportalCommon(); - GeoNaDataViewerProfile profile = gc.getGeoNaDataViewProfile(null); - System.out.println("Returning profile: "+profile); - return profile; - } - - - - public static GeoNaItemRef getLinks() throws Exception{ - System.out.println("getGeoNaDataViewProfile called"); - - ScopeProvider.instance.set(scope); - GeoportalCommon gc = new GeoportalCommon(); - GeoNaItemRef item = new GeoNaItemRef("", "concessione"); - GeoNaItemRef links = gc.getPublicLinksFor(item,true); - return links; - } - -} -- 2.17.1 From 5d0b45649a7a3acb7f6ccdf5debea7187b5cfa34 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 6 Dec 2021 17:03:01 +0100 Subject: [PATCH 02/12] refactored --- ...r.java => GNADataConfigProfileReader.java} | 15 ++++---- .../config/GNADataEntryConfigs.java | 38 ------------------- .../shared/GNADataConfigProfile.java | 14 ++++++- .../GNAUserRightsConfigException.java | 2 +- .../org/gcube/application/TestGNACommon.java | 16 +++++++- 5 files changed, 37 insertions(+), 48 deletions(-) rename src/main/java/org/gcube/application/geoportalcommon/config/{GNADataEntryConfigsProfileReader.java => GNADataConfigProfileReader.java} (95%) delete mode 100644 src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigs.java rename src/main/java/org/gcube/application/geoportalcommon/shared/{config => exception}/GNAUserRightsConfigException.java (72%) diff --git a/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigsProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/config/GNADataConfigProfileReader.java similarity index 95% rename from src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigsProfileReader.java rename to src/main/java/org/gcube/application/geoportalcommon/config/GNADataConfigProfileReader.java index deac0d2..2537241 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigsProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/config/GNADataConfigProfileReader.java @@ -12,12 +12,13 @@ import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import org.gcube.application.geoportalcommon.shared.GNADataConfigProfile; import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; -import org.gcube.application.geoportalcommon.shared.config.GNAUserRightsConfigException; import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole; 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.GNAUserRightsConfigException; import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.resources.discovery.client.api.DiscoveryClient; @@ -29,13 +30,13 @@ import org.w3c.dom.Document; import org.xml.sax.InputSource; /** - * The Class GNADataEntryConfigsProfileReader. + * The Class GNADataConfigProfileReader. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Dec 2, 2021 */ -public class GNADataEntryConfigsProfileReader { +public class GNADataConfigProfileReader { private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body"; public static final String SECONDARY_TYPE = "ApplicationProfile"; @@ -44,12 +45,12 @@ public class GNADataEntryConfigsProfileReader { private String scope; - private static final Logger LOG = LoggerFactory.getLogger(GNADataEntryConfigsProfileReader.class); + private static final Logger LOG = LoggerFactory.getLogger(GNADataConfigProfileReader.class); /** * Instantiates a new application profile reader. */ - public GNADataEntryConfigsProfileReader() { + public GNADataConfigProfileReader() { } /** @@ -58,7 +59,7 @@ public class GNADataEntryConfigsProfileReader { * @return the map * @throws Exception the exception */ - public GNADataEntryConfigs readProfileFromInfrastrucure() throws Exception { + public GNADataConfigProfile readProfileFromInfrastrucure() throws Exception { LOG.info("called readProfileFromInfrastrucure"); String queryString = getGcubeGenericQueryString(SECONDARY_TYPE, GENERIC_RESOURCE_NAME); LOG.info("Scope " + scope + ", trying to perform query: " + queryString); @@ -67,7 +68,7 @@ public class GNADataEntryConfigsProfileReader { if (scope == null) throw new Exception("Scope is null, set scope into ScopeProvider"); - GNADataEntryConfigs gnDEC = new GNADataEntryConfigs(); + GNADataConfigProfile gnDEC = new GNADataConfigProfile(); String permissions_for_role = ""; try { diff --git a/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigs.java b/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigs.java deleted file mode 100644 index 77d1995..0000000 --- a/src/main/java/org/gcube/application/geoportalcommon/config/GNADataEntryConfigs.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.gcube.application.geoportalcommon.config; - -import java.util.List; - -import org.gcube.application.geoportalcommon.shared.config.RoleRights; - - -public class GNADataEntryConfigs { - - List permissionsForRole = null; - - public GNADataEntryConfigs() { - - } - - public GNADataEntryConfigs(List permissionsForRole) { - super(); - this.permissionsForRole = permissionsForRole; - } - - public List getPermissionsForRole() { - return permissionsForRole; - } - - public void setPermissionsForRole(List permissionsForRole) { - this.permissionsForRole = permissionsForRole; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("GNADataEntryConfigs [permissionsForRole="); - builder.append(permissionsForRole); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java index bf4a39a..2c5172f 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java @@ -3,6 +3,8 @@ package org.gcube.application.geoportalcommon.shared; import java.io.Serializable; import java.util.List; +import org.gcube.application.geoportalcommon.shared.config.RoleRights; + public class GNADataConfigProfile implements Serializable { /** @@ -10,14 +12,16 @@ public class GNADataConfigProfile implements Serializable { */ private static final long serialVersionUID = 5152380669677928785L; private List listItemFields; + private List permissionsForRole; public GNADataConfigProfile() { } - public GNADataConfigProfile(List listItemFields) { + public GNADataConfigProfile(List listItemFields, List permissionsForRole) { super(); this.listItemFields = listItemFields; + this.permissionsForRole = permissionsForRole; } public List getListItemFields() { @@ -28,6 +32,14 @@ public class GNADataConfigProfile implements Serializable { this.listItemFields = listItemFields; } + public List getPermissionsForRole() { + return permissionsForRole; + } + + public void setPermissionsForRole(List permissionsForRole) { + this.permissionsForRole = permissionsForRole; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/config/GNAUserRightsConfigException.java b/src/main/java/org/gcube/application/geoportalcommon/shared/exception/GNAUserRightsConfigException.java similarity index 72% rename from src/main/java/org/gcube/application/geoportalcommon/shared/config/GNAUserRightsConfigException.java rename to src/main/java/org/gcube/application/geoportalcommon/shared/exception/GNAUserRightsConfigException.java index 81560c6..7035781 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/config/GNAUserRightsConfigException.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/exception/GNAUserRightsConfigException.java @@ -1,4 +1,4 @@ -package org.gcube.application.geoportalcommon.shared.config; +package org.gcube.application.geoportalcommon.shared.exception; @SuppressWarnings("serial") public class GNAUserRightsConfigException extends Exception { diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index c262aa4..6b9f2c5 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -2,6 +2,7 @@ package org.gcube.application; import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.MongoServiceCommon; +import org.gcube.application.geoportalcommon.config.GNADataConfigProfileReader; import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; @@ -46,7 +47,7 @@ public class TestGNACommon { return links; } - @Test + //@Test public void queryConcessioniTest() throws Exception { try { @@ -67,5 +68,18 @@ public class TestGNACommon { } } + + @Test + public void readUserRights() throws Exception { + + GNADataConfigProfileReader r = new GNADataConfigProfileReader(); + try { + ScopeProvider.instance.set(CONTEXT); + r.readProfileFromInfrastrucure(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } -- 2.17.1 From 749e6424fd715c4349731a41eee4ea64debad87e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 6 Dec 2021 17:06:39 +0100 Subject: [PATCH 03/12] commented test cases --- src/test/java/org/gcube/application/TestGNACommon.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index 6b9f2c5..cea18d0 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -15,7 +15,7 @@ import org.junit.Test; public class TestGNACommon { - private static String TOKEN = "8e74a17c-92f1-405a-b591-3a6090066248-98187548"; + private static String TOKEN = ""; private static String CONTEXT = "/gcube/devsec/devVRE"; private static String USERNAME = "francesco.mangiacrapa"; @@ -69,7 +69,7 @@ public class TestGNACommon { } - @Test + //@Test public void readUserRights() throws Exception { GNADataConfigProfileReader r = new GNADataConfigProfileReader(); -- 2.17.1 From fa201fb35b1a4133450b6fcb30f01c067d5825c1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 6 Dec 2021 17:12:03 +0100 Subject: [PATCH 04/12] fixed mapping --- .../org/gcube/application/geoportalcommon/GeoportalCommon.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java index c81eb62..ae0d9a2 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java @@ -192,7 +192,7 @@ public class GeoportalCommon { listItemFields.add(new ItemField("Created", Arrays.asList("creationTime"), true, true, false)); listItemFields.add(new ItemField("Created by", Arrays.asList("creationUser"), true, true, true)); - listItemFields.add(new ItemField("Published with", Arrays.asList("recordStatus"), true, true, false)); + listItemFields.add(new ItemField("Published with", Arrays.asList("report.status"), true, true, false)); GNADataConfigProfile gnaDCP = new GNADataConfigProfile(); gnaDCP.setListItemFields(listItemFields); -- 2.17.1 From c9586c85941d47194ff73ec7702707da8ef1c373 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 7 Dec 2021 10:00:38 +0100 Subject: [PATCH 05/12] fixed mapping of ItemFields --- .../org/gcube/application/geoportalcommon/GeoportalCommon.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java index ae0d9a2..6ed0f33 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java @@ -190,7 +190,7 @@ public class GeoportalCommon { listItemFields.add(new ItemField("Project Start/End Date", Arrays.asList("dataInizioProgetto", "dataFineProgetto"), true, false, false)); - listItemFields.add(new ItemField("Created", Arrays.asList("creationTime"), true, true, false)); + listItemFields.add(new ItemField("Created", Arrays.asList("creationTime"), true, false, false)); listItemFields.add(new ItemField("Created by", Arrays.asList("creationUser"), true, true, true)); listItemFields.add(new ItemField("Published with", Arrays.asList("report.status"), true, true, false)); -- 2.17.1 From cca77a169f88f4a0b909fd99738bc34de16771b1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 10 Dec 2021 15:04:45 +0100 Subject: [PATCH 06/12] fixed the OR clause --- .../geoportalcommon/MongoServiceCommon.java | 15 ++++++++++++++- .../java/org/gcube/application/TestGNACommon.java | 11 +++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java b/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java index 24e9c08..25500d3 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java +++ b/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java @@ -23,6 +23,7 @@ import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.mongodb.BasicDBList; import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObjectBuilder; @@ -178,8 +179,20 @@ public class MongoServiceCommon { bs.append("$regex", searchFields.get(key)); bs.append("$options", "i"); builder.append(key, bs); + + } - query = new Document(builder.get().toMap()); + //Building list of Document in OR clause + BasicDBList list = new BasicDBList(); + Map map = builder.get().toMap(); + for (Object key : map.keySet()) { + + BasicDBObject value = (BasicDBObject) map.get(key); + Document doc = new Document((String) key, value); + list.add(doc); + } + query = new Document(); + query.put("$or", list); request.setFilter(query); } diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index cea18d0..edc2e4d 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -1,5 +1,8 @@ package org.gcube.application; +import java.util.HashMap; +import java.util.Map; + import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.MongoServiceCommon; import org.gcube.application.geoportalcommon.config.GNADataConfigProfileReader; @@ -47,14 +50,18 @@ public class TestGNACommon { return links; } - //@Test + @Test public void queryConcessioniTest() throws Exception { try { ScopeProvider.instance.set(CONTEXT); MongoServiceCommon msc = new MongoServiceCommon(); SearchingFilter filter = new SearchingFilter(); - // filter.setSearchInto(new Se); + + Map searchInto = new HashMap(); + //searchInto.put("nome", "mock"); + searchInto.put("authors", "annalisa"); + filter.setSearchInto(searchInto); ResultSetPaginatedData result = msc.queryOnMongo(30, 0, 30, filter, "concessione"); int i = 0; -- 2.17.1 From 07bf55752540e2948a75d9d75a9f4ef642273dea Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 15 Dec 2021 15:42:39 +0100 Subject: [PATCH 07/12] Added WhereClause into SearchingFilter --- .../geoportalcommon/MongoServiceCommon.java | 78 +++++++++------ .../shared/SearchingFilter.java | 66 ++++++++----- .../geoportalcommon/shared/WhereClause.java | 97 +++++++++++++++++++ .../org/gcube/application/TestGNACommon.java | 20 +++- 4 files changed, 206 insertions(+), 55 deletions(-) create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/WhereClause.java diff --git a/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java b/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java index 25500d3..6c1b142 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java +++ b/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java @@ -18,7 +18,9 @@ import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; +import org.gcube.application.geoportalcommon.shared.WhereClause; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -168,38 +170,55 @@ public class MongoServiceCommon { ordering.setFields(orderingFields); request.setOrdering(ordering); - - Document query = null; - if (filter.getSearchInto() != null) { - Map searchFields = filter.getSearchInto(); - BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); - for (String key : searchFields.keySet()) { - // using regex and case-insensitive - BasicDBObject bs = new BasicDBObject(); - bs.append("$regex", searchFields.get(key)); - bs.append("$options", "i"); - builder.append(key, bs); - + + Document query = new Document(); + if(filter.getConditions()!=null) { + for (WhereClause whereClause : filter.getConditions()) { + LOGICAL_OP searchWithOperator = whereClause.getOperator(); + if(searchWithOperator==null) { + searchWithOperator = LOGICAL_OP.OR; + } + + if (whereClause.getSearchInto() != null) { + Map searchFields = whereClause.getSearchInto(); + BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); + for (String key : searchFields.keySet()) { + // using regex and case-insensitive + BasicDBObject bs = new BasicDBObject(); + bs.append("$regex", searchFields.get(key)); + bs.append("$options", "i"); + builder.append(key, bs); + + + } + //Building list of Document in OR clause + BasicDBList list = new BasicDBList(); + Map map = builder.get().toMap(); + for (Object key : map.keySet()) { + + BasicDBObject value = (BasicDBObject) map.get(key); + Document doc = new Document((String) key, value); + list.add(doc); + } + + //query = new Document(); + query.put(searchWithOperator.getOperator(), list); + +// BasicDBObject bs = new BasicDBObject(); +// bs.append("$eq", "PASSED"); +// query.put("report.status", bs); + + } } - //Building list of Document in OR clause - BasicDBList list = new BasicDBList(); - Map map = builder.get().toMap(); - for (Object key : map.keySet()) { - - BasicDBObject value = (BasicDBObject) map.get(key); - Document doc = new Document((String) key, value); - list.add(doc); - } - query = new Document(); - query.put("$or", list); - request.setFilter(query); } - + + request.setFilter(query); + LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex); LOG.info("Direction: " + sDirection); LOG.info("Order by Fields: " + orderingFields); - LOG.info("Search for: " + filter.getSearchInto()); + LOG.info("Search for conditions: " + filter.getConditions()); if (query != null) { LOG.info("Search query to JSON: " + query.toJson()); } @@ -211,7 +230,7 @@ public class MongoServiceCommon { ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); toReturnList.add(concessioneDV); i++; - LOG.trace("converted: " + concessioneDV); + LOG.trace(i+") converted: " + concessioneDV); } LOG.debug("read " + toReturnList + " project/s"); @@ -219,10 +238,11 @@ public class MongoServiceCommon { // TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT // AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE - if (filter.getSearchInto() != null) { + if (filter.getConditions() != null) { searchedData.setTotalItems(toReturnList.size()); + totalItems = toReturnList.size(); } - + if (totalItems == limit || totalItems == 0) { LOG.debug("Page completed returning " + totalItems + " items"); int newOffset = offsetIndex + limitIndex; diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java b/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java index d77a568..b724491 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/SearchingFilter.java @@ -2,7 +2,6 @@ package org.gcube.application.geoportalcommon.shared; import java.io.Serializable; import java.util.List; -import java.util.Map; /** * The Class SearchingFilter. @@ -44,6 +43,37 @@ public class SearchingFilter implements Serializable { } } + /** + * The Enum LOGICAL_OP. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 15, 2021 + */ + public static enum LOGICAL_OP { + AND("$and"), OR("$or"); + + String operator; + + /** + * Instantiates a new order. + * + * @param operator the operator + */ + LOGICAL_OP(String operator) { + this.operator = operator; + } + + /** + * Gets the operator. + * + * @return the operator + */ + public String getOperator() { + return operator; + } + } + /** * */ @@ -51,9 +81,9 @@ public class SearchingFilter implements Serializable { private List orderByFields; - private ORDER order; + private ORDER order = ORDER.ASC; - private Map searchInto; + private List conditions; /** * Instantiates a new sort filter. @@ -80,19 +110,18 @@ public class SearchingFilter implements Serializable { * @param order the order * @param searchInto the search into */ - public SearchingFilter(List orderByFields, ORDER order, Map searchInto) { + public SearchingFilter(List orderByFields, ORDER order, List conditions) { this.orderByFields = orderByFields; this.order = order; - this.searchInto = searchInto; + this.conditions = conditions; } - /** - * Sets the search into. - * - * @param searchInto the search into - */ - public void setSearchInto(Map searchInto) { - this.searchInto = searchInto; + public List getConditions() { + return conditions; + } + + public void setConditions(List conditions) { + this.conditions = conditions; } /** @@ -131,15 +160,6 @@ public class SearchingFilter implements Serializable { this.order = order; } - /** - * Gets the search into. - * - * @return the search into - */ - public Map getSearchInto() { - return searchInto; - } - @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -147,8 +167,8 @@ public class SearchingFilter implements Serializable { builder.append(orderByFields); builder.append(", order="); builder.append(order); - builder.append(", searchInto="); - builder.append(searchInto); + builder.append(", conditions="); + builder.append(conditions); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/WhereClause.java b/src/main/java/org/gcube/application/geoportalcommon/shared/WhereClause.java new file mode 100644 index 0000000..7770f98 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/WhereClause.java @@ -0,0 +1,97 @@ +package org.gcube.application.geoportalcommon.shared; + +import java.io.Serializable; +import java.util.Map; + +import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; + +/** + * The Class WhereClause. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 15, 2021 + */ +public class WhereClause implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -8577885822669878296L; + + private LOGICAL_OP operator = LOGICAL_OP.OR; + + private Map searchInto; + + /** + * Instantiates a new where clause. + */ + public WhereClause() { + + } + + /** + * Instantiates a new where clause. + * + * @param operator the operator + * @param searchInto the search into + */ + public WhereClause(LOGICAL_OP operator, Map searchInto) { + super(); + this.operator = operator; + this.searchInto = searchInto; + } + + /** + * Gets the operator. + * + * @return the operator + */ + public LOGICAL_OP getOperator() { + return operator; + } + + /** + * Gets the search into. + * + * @return the search into + */ + public Map getSearchInto() { + return searchInto; + } + + /** + * Sets the operator. + * + * @param operator the new operator + */ + public void setOperator(LOGICAL_OP operator) { + this.operator = operator; + } + + /** + * Sets the search into. + * + * @param searchInto the search into + */ + public void setSearchInto(Map searchInto) { + this.searchInto = searchInto; + } + + /** + * To string. + * + * @return the string + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("WhereClause [operator="); + builder.append(operator); + builder.append(", searchInto="); + builder.append(searchInto); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index edc2e4d..ed80fb5 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -1,5 +1,6 @@ package org.gcube.application; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -10,6 +11,8 @@ import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.WhereClause; +import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; @@ -59,9 +62,20 @@ public class TestGNACommon { SearchingFilter filter = new SearchingFilter(); Map searchInto = new HashMap(); - //searchInto.put("nome", "mock"); - searchInto.put("authors", "annalisa"); - filter.setSearchInto(searchInto); + searchInto.put("nome", "san"); + searchInto.put("authors", "silvia"); + //searchInto.put("report.status", "PASSED"); + + WhereClause where1 = new WhereClause(LOGICAL_OP.OR, searchInto); + + Map searchInto2 = new HashMap(); + searchInto2.put("report.status", "PASSED"); + WhereClause where2 = new WhereClause(LOGICAL_OP.AND, searchInto2); + + ArrayList list = new ArrayList(); + list.add(where1); + //list.add(where2); + filter.setConditions(list); ResultSetPaginatedData result = msc.queryOnMongo(30, 0, 30, filter, "concessione"); int i = 0; -- 2.17.1 From 69a4f34e880a7a90a34dac3a28cb8a845a4b3f9b Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 21 Dec 2021 11:55:58 +0100 Subject: [PATCH 08/12] refactored and created new class to read configurations from IS --- .../geoportalcommon/GNAConfigsConverter.java | 124 ++++++++++++++++++ ...a => GNADataEntryConfigProfileReader.java} | 64 ++++++--- ... => GNADataViewerConfigProfileReader.java} | 76 ++++++----- .../geoportalcommon/GeoportalCommon.java | 91 ++++++------- .../shared/GNADataConfigProfile.java | 52 -------- .../shared/GNADataEntryConfigProfile.java | 93 +++++++++++++ ...e.java => GNADataViewerConfigProfile.java} | 37 ++++-- .../geoportalcommon/shared/ItemField.java | 92 +++++++++++-- .../shared/config/ItemFieldsConfig.java | 72 ++++++++++ .../org/gcube/application/TestGNACommon.java | 83 ++++++++---- 10 files changed, 588 insertions(+), 196 deletions(-) create mode 100644 src/main/java/org/gcube/application/geoportalcommon/GNAConfigsConverter.java rename src/main/java/org/gcube/application/geoportalcommon/{config/GNADataConfigProfileReader.java => GNADataEntryConfigProfileReader.java} (78%) rename src/main/java/org/gcube/application/geoportalcommon/{GeoNaDataViewerProfileReader.java => GNADataViewerConfigProfileReader.java} (69%) delete mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/GNADataEntryConfigProfile.java rename src/main/java/org/gcube/application/geoportalcommon/shared/{GeoNaDataViewerProfile.java => GNADataViewerConfigProfile.java} (68%) create mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/config/ItemFieldsConfig.java diff --git a/src/main/java/org/gcube/application/geoportalcommon/GNAConfigsConverter.java b/src/main/java/org/gcube/application/geoportalcommon/GNAConfigsConverter.java new file mode 100644 index 0000000..e841a91 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/GNAConfigsConverter.java @@ -0,0 +1,124 @@ +package org.gcube.application.geoportalcommon; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.gcube.application.geoportalcommon.config.CSVFile; +import org.gcube.application.geoportalcommon.config.CSVReader; +import org.gcube.application.geoportalcommon.config.CSVRow; +import org.gcube.application.geoportalcommon.config.FileUtil; +import org.gcube.application.geoportalcommon.shared.ItemField; +import org.gcube.application.geoportalcommon.shared.exception.GNAUserRightsConfigException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class GNAConfigsConverter. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 21, 2021 + */ +public class GNAConfigsConverter { + + private static final Logger LOG = LoggerFactory.getLogger(GNAConfigsConverter.class); + + /** + * Read list items config. + * + * @param contentValue the content value + * @return the list + * @throws GNAUserRightsConfigException the GNA user rights config exception + */ + public static List readListItemsConfig(String contentValue) throws GNAUserRightsConfigException { + LOG.debug("readListItemsConfig called"); + + File configurationFile = null; + List listItemFields = new ArrayList(); + try { + configurationFile = FileUtil.inputStreamToTempFile(contentValue, "GNA_ListItems_Configs"); + + CSVReader reader = new CSVReader(configurationFile); + CSVFile csvFile = reader.getCsvFile(); + + List rows = csvFile.getValueRows(); + + // Starting from index 1 (means the second row in the CSV) + for (int i = 0; i < rows.size(); i++) { + LOG.trace(i + " row"); + ItemField itemField = new ItemField(); + CSVRow row = rows.get(i); + + // mapping to ItemFiel + List rowValues = row.getListValues(); + LOG.debug("rowValues: " + rowValues); + + itemField.setDisplayName(rowValues.get(0)); + + // Reading JSON Fields + String[] jsonFields = rowValues.get(1).split(";"); + List theJsonFields = new ArrayList(jsonFields.length); + for (String jsonField : jsonFields) { + theJsonFields.add(jsonField.trim()); + } + + itemField.setJsonFields(theJsonFields); + + // Display as result + if (checkYesNoValue(rowValues.get(2))) { + itemField.setDisplayAsResult(true); + } + + // Sortable + if (checkYesNoValue(rowValues.get(3))) { + itemField.setSortable(true); + } + + // Searchable + if (checkYesNoValue(rowValues.get(4))) { + itemField.setSearchable(true); + } + + listItemFields.add(itemField); + } + LOG.info("Returning item fields config: " + listItemFields); + return listItemFields; + + } catch (Exception e) { + LOG.error("An error occurred on reading the GNA DataEntry config from: " + contentValue, e); + throw new GNAUserRightsConfigException("Error on reading the GNA DataEntry from: " + contentValue); + } finally { + + if (configurationFile != null) { + try { + configurationFile.delete(); + } catch (Exception e) { + // silent + } + } + } + + } + + /** + * Check yes no value. + * + * @param value the value + * @return true, if successful + */ + public static boolean checkYesNoValue(String value) { + + if (value == null || value.isEmpty()) + return false; + + String lowerValue = value.toLowerCase(); + + if (lowerValue.equals("yes") || lowerValue.equals("true")) { + return true; + } + + return false; + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/config/GNADataConfigProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java similarity index 78% rename from src/main/java/org/gcube/application/geoportalcommon/config/GNADataConfigProfileReader.java rename to src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java index 2537241..3e179f7 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/config/GNADataConfigProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java @@ -1,4 +1,4 @@ -package org.gcube.application.geoportalcommon.config; +package org.gcube.application.geoportalcommon; import static org.gcube.resources.discovery.icclient.ICFactory.client; @@ -12,7 +12,12 @@ import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.gcube.application.geoportalcommon.shared.GNADataConfigProfile; +import org.gcube.application.geoportalcommon.config.CSVFile; +import org.gcube.application.geoportalcommon.config.CSVReader; +import org.gcube.application.geoportalcommon.config.CSVRow; +import org.gcube.application.geoportalcommon.config.FileUtil; +import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; +import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole; import org.gcube.application.geoportalcommon.shared.config.RoleRights; @@ -30,27 +35,29 @@ import org.w3c.dom.Document; import org.xml.sax.InputSource; /** - * The Class GNADataConfigProfileReader. + * The Class GNADataEntryConfigProfileReader. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Dec 2, 2021 + * Dec 21, 2021 */ -public class GNADataConfigProfileReader { +public class GNADataEntryConfigProfileReader { private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body"; public static final String SECONDARY_TYPE = "ApplicationProfile"; public static final String GENERIC_RESOURCE_NAME = "GNA-DataEntry-Configs"; - private static final String TEMP_ROLE_RIGHTS_CONFIG_FILENAME = "GNA_RoleRights_Configurations"; + + 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 String scope; - private static final Logger LOG = LoggerFactory.getLogger(GNADataConfigProfileReader.class); + private static final Logger LOG = LoggerFactory.getLogger(GNADataEntryConfigProfileReader.class); /** * Instantiates a new application profile reader. */ - public GNADataConfigProfileReader() { + public GNADataEntryConfigProfileReader() { } /** @@ -59,7 +66,7 @@ public class GNADataConfigProfileReader { * @return the map * @throws Exception the exception */ - public GNADataConfigProfile readProfileFromInfrastrucure() throws Exception { + protected GNADataEntryConfigProfile readProfileFromInfrastrucure() throws Exception { LOG.info("called readProfileFromInfrastrucure"); String queryString = getGcubeGenericQueryString(SECONDARY_TYPE, GENERIC_RESOURCE_NAME); LOG.info("Scope " + scope + ", trying to perform query: " + queryString); @@ -68,8 +75,9 @@ public class GNADataConfigProfileReader { if (scope == null) throw new Exception("Scope is null, set scope into ScopeProvider"); - GNADataConfigProfile gnDEC = new GNADataConfigProfile(); + GNADataEntryConfigProfile gnDEC = new GNADataEntryConfigProfile(); String permissions_for_role = ""; + String item_fields = ""; try { LOG.info("Trying to fetch GR named: " + GENERIC_RESOURCE_NAME + ", in the scope: " + scope @@ -89,7 +97,8 @@ public class GNADataConfigProfileReader { XPathHelper helper = new XPathHelper(doc.getDocumentElement()); List currValue = null; - String xPathExp = RESOURCE_PROFILE_BODY + "/permssions_for_role/text()"; + + String xPathExp = PATH_TO_PERMISSIONS_PATH + "/text()"; currValue = helper.evaluate(xPathExp); if (currValue != null && currValue.size() > 0) { @@ -97,13 +106,30 @@ public class GNADataConfigProfileReader { } else throw new Exception("I'm not able to read the path: " + xPathExp); - //replacing \n with new_line string - LOG.debug("read permissions_for_role: " + permissions_for_role); - String pfr_with_new_lines = permissions_for_role.replaceAll("\\\\n", System.lineSeparator()); - LOG.debug("permissions_for_role with new lines: " + pfr_with_new_lines); + // replacing \n with new_line string + LOG.debug("read " + PATH_TO_PERMISSIONS_PATH + ": " + permissions_for_role); + String value_with_new_lines = permissions_for_role.replaceAll("\\\\n", System.lineSeparator()); + LOG.debug(PATH_TO_PERMISSIONS_PATH + " with new lines: " + value_with_new_lines); - List listRoleRights = readRoleRightsConfig(pfr_with_new_lines); + List listRoleRights = readRoleRightsConfig(value_with_new_lines); gnDEC.setPermissionsForRole(listRoleRights); + + xPathExp = PATH_TO_ITEM_FIELDS_CONFIG + "/text()"; + currValue = helper.evaluate(xPathExp); + + if (currValue != null && currValue.size() > 0) { + item_fields = currValue.get(0); + } 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); + + List listItemFieldsConfig = GNAConfigsConverter.readListItemsConfig(value_with_new_lines); + gnDEC.setListItemFields(listItemFieldsConfig); + LOG.info("returning: " + gnDEC); return gnDEC; } @@ -124,7 +150,7 @@ public class GNADataConfigProfileReader { * @param name the name * @return the gcube user role */ - public static GcubeUserRole toGcubeUserRole(String name) { + protected static GcubeUserRole toGcubeUserRole(String name) { for (GcubeUserRole gCubeUserRole : GcubeUserRole.values()) { if (gCubeUserRole.getName().equalsIgnoreCase(name)) @@ -148,7 +174,7 @@ public class GNADataConfigProfileReader { File configurationFile = null; List listUserRights = new ArrayList(); try { - configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, TEMP_ROLE_RIGHTS_CONFIG_FILENAME); + configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, "GNA_RoleRights_Configurations"); CSVReader reader = new CSVReader(configurationFile); CSVFile csvFile = reader.getCsvFile(); @@ -208,7 +234,7 @@ public class GNADataConfigProfileReader { for (ACTION_ON_ITEM value : ACTION_ON_ITEM.values()) { String yesno = mapUserRolePermissions.get(value.name()); - if (yesno != null && yesno.equalsIgnoreCase("yes")) { + if (GNAConfigsConverter.checkYesNoValue(yesno)) { listPermessions.put(value, mapOperationTypes.get(value.name())); } diff --git a/src/main/java/org/gcube/application/geoportalcommon/GeoNaDataViewerProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java similarity index 69% rename from src/main/java/org/gcube/application/geoportalcommon/GeoNaDataViewerProfileReader.java rename to src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java index d327092..58fd505 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GeoNaDataViewerProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java @@ -14,7 +14,8 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; -import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; +import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; +import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.LayerItem; import org.gcube.application.geoportalcommon.shared.exception.ApplicationProfileNotFoundException; import org.gcube.common.resources.gcore.utils.XPathHelper; @@ -31,13 +32,13 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; /** - * The Class GeoNaViewerProfileReader. + * The Class GNADataViewerConfigProfileReader. * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Nov 12, 2020 + * Dec 21, 2021 */ -public class GeoNaDataViewerProfileReader { +public class GNADataViewerConfigProfileReader { private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body"; /** @@ -45,8 +46,9 @@ public class GeoNaDataViewerProfileReader { */ public static final String SECONDARY_TYPE = "ApplicationProfile"; public static final String WORKSPACE_EXPLORER_APP_NAME = "GeoNa-Viewer-Profile"; + private static final String PATH_TO_ITEM_FIELDS_CONFIG = RESOURCE_PROFILE_BODY + "/item_fields_config"; - private Logger logger = LoggerFactory.getLogger(GeoNaDataViewerProfileReader.class); + private static Logger LOG = LoggerFactory.getLogger(GNADataViewerConfigProfileReader.class); private String secondaryType; private String scope; private String appID; @@ -56,7 +58,7 @@ public class GeoNaDataViewerProfileReader { * * @param appID the app id */ - public GeoNaDataViewerProfileReader(String appID) { + public GNADataViewerConfigProfileReader(String appID) { this.appID = appID; this.secondaryType = SECONDARY_TYPE; @@ -67,25 +69,27 @@ public class GeoNaDataViewerProfileReader { * Read profile from infrastrucure. * * @return the map + * @throws Exception the exception */ - public GeoNaDataViewerProfile readProfileFromInfrastrucure() throws Exception { + protected GNADataViewerConfigProfile readProfileFromInfrastrucure() throws Exception { String queryString = getGcubeGenericQueryString(secondaryType, appID); - logger.info("Scope " + scope + ", trying to perform query: " + queryString); + LOG.info("Scope " + scope + ", trying to perform query: " + queryString); try { if (scope == null) throw new Exception("Scope is null, set scope into ScopeProvider"); - GeoNaDataViewerProfile profile = new GeoNaDataViewerProfile(); + GNADataViewerConfigProfile profile = new GNADataViewerConfigProfile(); - logger.info("Trying to fetch ApplicationProfile in the scope: " + scope + ", SecondaryType: " + LOG.info("Trying to fetch ApplicationProfile in the scope: " + scope + ", SecondaryType: " + secondaryType + ", AppId: " + appID); Query q = new QueryBox(queryString); DiscoveryClient client = client(); List appProfile = client.submit(q); - + String item_fields = ""; + if (appProfile == null || appProfile.size() == 0) throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appID + " is not registered in the scope: " + scope); @@ -131,12 +135,29 @@ public class GeoNaDataViewerProfileReader { } profile.setMapLayers(mapLayers); - logger.info("returning: " + profile); + + xPathExp = PATH_TO_ITEM_FIELDS_CONFIG + "/text()"; + currValue = helper.evaluate(xPathExp); + + if (currValue != null && currValue.size() > 0) { + item_fields = currValue.get(0); + } 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); + String value_with_new_lines = item_fields.replaceAll("\\\\n", System.lineSeparator()); + LOG.debug(PATH_TO_ITEM_FIELDS_CONFIG + " with new lines: " + value_with_new_lines); + + List listItemFieldsConfig = GNAConfigsConverter.readListItemsConfig(value_with_new_lines); + profile.setListItemFields(listItemFieldsConfig); + + LOG.info("returning: " + profile); return profile; } } catch (Exception e) { - logger.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType " + LOG.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType " + WORKSPACE_EXPLORER_APP_NAME + " from scope " + scope, e); return null; } finally { @@ -179,22 +200,17 @@ public class GeoNaDataViewerProfileReader { @Override public String toString() { - return "GeoNaViewerProfileReader [secondaryType=" + secondaryType + ", scope=" + scope + ", appID=" + appID - + "]"; + StringBuilder builder = new StringBuilder(); + builder.append("GNADataViewerConfigProfileReader [LOG="); + builder.append(LOG); + builder.append(", secondaryType="); + builder.append(secondaryType); + builder.append(", scope="); + builder.append(scope); + builder.append(", appID="); + builder.append(appID); + builder.append("]"); + return builder.toString(); } - /* - * public static void main(String[] args) throws Exception { - * ScopeProvider.instance.set("/gcube/devNext/NextNext"); - * GeoNaDataViewerProfileReader gdvp = new - * GeoNaDataViewerProfileReader("geoportal-data-viewer-app"); - * GeoNaDataViewerProfile profile = gdvp.readProfileFromInfrastrucure(); - * System.out.println(profile.getRestrictedPortletURL()); - * System.out.println(profile.getOpenPortletURL()); - * - * if(profile.getMapLayers()!=null) { for (String type : - * profile.getMapLayers().keySet()) { - * System.out.println("key: "+type+", value: "+profile.getMapLayers().get(type)) - * ; } } } - */ } diff --git a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java index 6ed0f33..5b18dbd 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java @@ -2,33 +2,29 @@ package org.gcube.application.geoportalcommon; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; -import org.gcube.application.geoportalcommon.shared.GNADataConfigProfile; -import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; +import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; +import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; -import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.PublicLink; import org.gcube.portlets.user.urlshortener.UrlShortener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * The Class GeoportalCommon. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Aug 5, 2021 + * Aug 5, 2021 */ public class GeoportalCommon { /** The Constant LOG. */ private static final Logger LOG = LoggerFactory.getLogger(GeoportalCommon.class); - private GeoNaDataViewerProfile geonaDataProfile; + private GNADataViewerConfigProfile geonaDataProfile; /** * Instantiates a new geoportal common. @@ -41,14 +37,14 @@ public class GeoportalCommon { * * @param geonaDataProfile the geona data profile */ - public GeoportalCommon(GeoNaDataViewerProfile geonaDataProfile) { + public GeoportalCommon(GNADataViewerConfigProfile geonaDataProfile) { this.geonaDataProfile = geonaDataProfile; } /** * Gets the public links for. * - * @param item the item + * @param item the item * @param createShortURL creates and returns the short URL also. * @return the public links for * @throws Exception the exception @@ -67,8 +63,8 @@ public class GeoportalCommon { if (item.getItemType() == null) throw new Exception("Bad request, the item type is null"); - if(this.geonaDataProfile==null) - this.geonaDataProfile = getGeoNaDataViewProfile(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP); + if (this.geonaDataProfile == null) + this.geonaDataProfile = readGNADataViewConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP); // Restricted Link String link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(), @@ -77,7 +73,7 @@ public class GeoportalCommon { String shortUrl = link; try { - if(createShortURL) + if (createShortURL) shortUrl = getShortUrl(link); } catch (Exception e) { LOG.warn("Error on shortening the URL: ", e); @@ -107,27 +103,6 @@ public class GeoportalCommon { } } - /** - * Gets the GeoNaData Viewer Profile. - * - * @param appID if null or empty uses the default appID that is - * {@link GeoportalCommonConstants#GEOPORTAL_DATA_VIEWER_APP} - * @return the GeoNaData Viewer Profile - * @throws Exception the exception - */ - public GeoNaDataViewerProfile getGeoNaDataViewProfile(String appID) throws Exception { - LOG.info("getGeoNaDataViewProfile called for: " + appID); - - if (appID == null || appID.isEmpty()) - appID = GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP; - - LOG.info("using AppId: " + appID); - GeoNaDataViewerProfileReader gdvp = new GeoNaDataViewerProfileReader(appID); - GeoNaDataViewerProfile profile = gdvp.readProfileFromInfrastrucure(); - LOG.info("Returning profile: " + profile); - return profile; - } - /** * Gets the short url. * @@ -177,26 +152,42 @@ public class GeoportalCommon { * * @return the geona data profile */ - public GeoNaDataViewerProfile getGeonaDataProfile() { + public GNADataViewerConfigProfile getGeonaDataProfile() { return geonaDataProfile; } - - public GNADataConfigProfile getGNADataConfig(){ - List listItemFields = new ArrayList(); - listItemFields.add(new ItemField("Name", Arrays.asList("nome"), true, true, true)); - listItemFields.add(new ItemField("Introduction", Arrays.asList("introduzione"), true, false, true)); - listItemFields.add(new ItemField("Author/s", Arrays.asList("authors"), true, true, true)); - listItemFields.add(new ItemField("Project Start/End Date", - Arrays.asList("dataInizioProgetto", "dataFineProgetto"), true, false, false)); + /** + * Read GNA data view config. + * + * @param appID the app ID. If null uses the default + * {@link GeoportalCommonConstants#GEOPORTAL_DATA_VIEWER_APP} + * @return the GNA data viewer config profile + * @throws Exception the exception + */ + public GNADataViewerConfigProfile readGNADataViewConfig(String appID) throws Exception { + LOG.info("getGeoNaDataViewProfile called for: " + appID); - listItemFields.add(new ItemField("Created", Arrays.asList("creationTime"), true, false, false)); - listItemFields.add(new ItemField("Created by", Arrays.asList("creationUser"), true, true, true)); - listItemFields.add(new ItemField("Published with", Arrays.asList("report.status"), true, true, false)); - - GNADataConfigProfile gnaDCP = new GNADataConfigProfile(); - gnaDCP.setListItemFields(listItemFields); - return gnaDCP; + if (appID == null || appID.isEmpty()) + appID = GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP; + + LOG.info("using AppId: " + appID); + GNADataViewerConfigProfileReader gdvp = new GNADataViewerConfigProfileReader(appID); + GNADataViewerConfigProfile profile = gdvp.readProfileFromInfrastrucure(); + LOG.info("Returning profile: " + profile); + return profile; + } + + /** + * Gets the GNA data config read from ApplicationProfile stored into IS. + * + * @return the GNA data config + * @throws Exception the exception + */ + public GNADataEntryConfigProfile readGNADataEntryConfig() throws Exception { + + GNADataEntryConfigProfileReader gnaConfigReader = new GNADataEntryConfigProfileReader(); + GNADataEntryConfigProfile config = gnaConfigReader.readProfileFromInfrastrucure(); + return config; } } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java deleted file mode 100644 index 2c5172f..0000000 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataConfigProfile.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.gcube.application.geoportalcommon.shared; - -import java.io.Serializable; -import java.util.List; - -import org.gcube.application.geoportalcommon.shared.config.RoleRights; - -public class GNADataConfigProfile implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 5152380669677928785L; - private List listItemFields; - private List permissionsForRole; - - public GNADataConfigProfile() { - - } - - public GNADataConfigProfile(List listItemFields, List permissionsForRole) { - super(); - this.listItemFields = listItemFields; - this.permissionsForRole = permissionsForRole; - } - - public List getListItemFields() { - return listItemFields; - } - - public void setListItemFields(List listItemFields) { - this.listItemFields = listItemFields; - } - - public List getPermissionsForRole() { - return permissionsForRole; - } - - public void setPermissionsForRole(List permissionsForRole) { - this.permissionsForRole = permissionsForRole; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("GNADataConfigProfile [listItemFields="); - builder.append(listItemFields); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataEntryConfigProfile.java b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataEntryConfigProfile.java new file mode 100644 index 0000000..931fea1 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataEntryConfigProfile.java @@ -0,0 +1,93 @@ +package org.gcube.application.geoportalcommon.shared; + +import java.io.Serializable; +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.config.RoleRights; + +/** + * The Class GNADataEntryConfigProfile. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 21, 2021 + */ +public class GNADataEntryConfigProfile implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 5152380669677928785L; + private List listItemFields; + private List permissionsForRole; + + /** + * Instantiates a new GNA data entry config profile. + */ + public GNADataEntryConfigProfile() { + + } + + /** + * 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; + this.permissionsForRole = permissionsForRole; + } + + /** + * Gets the list item fields. + * + * @return the list item fields + */ + public List getListItemFields() { + return listItemFields; + } + + /** + * Sets the list item fields. + * + * @param listItemFields the new list item fields + */ + public void setListItemFields(List listItemFields) { + this.listItemFields = listItemFields; + } + + /** + * Gets the permissions for role. + * + * @return the permissions for role + */ + public List getPermissionsForRole() { + return permissionsForRole; + } + + /** + * Sets the permissions for role. + * + * @param permissionsForRole the new permissions for role + */ + public void setPermissionsForRole(List permissionsForRole) { + 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("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/GeoNaDataViewerProfile.java b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataViewerConfigProfile.java similarity index 68% rename from src/main/java/org/gcube/application/geoportalcommon/shared/GeoNaDataViewerProfile.java rename to src/main/java/org/gcube/application/geoportalcommon/shared/GNADataViewerConfigProfile.java index 1c0dfcb..de2d1d7 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/GeoNaDataViewerProfile.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/GNADataViewerConfigProfile.java @@ -1,17 +1,17 @@ package org.gcube.application.geoportalcommon.shared; import java.io.Serializable; +import java.util.List; import java.util.Map; - /** - * The Class GeoNaDataViewerProfile. + * The Class GNADataViewerConfigProfile. * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Nov 13, 2020 + * Dec 21, 2021 */ -public class GeoNaDataViewerProfile implements Serializable{ +public class GNADataViewerConfigProfile implements Serializable { /** * @@ -19,13 +19,14 @@ public class GeoNaDataViewerProfile implements Serializable{ private static final long serialVersionUID = 2968334957258327191L; private String restrictedPortletURL; private String openPortletURL; - //the key is the layer type + // the key is the layer type private Map mapLayers; + private List listItemFields; /** * Instantiates a new geo na data viewer profile. */ - public GeoNaDataViewerProfile() { + public GNADataViewerConfigProfile() { } @@ -84,22 +85,36 @@ public class GeoNaDataViewerProfile implements Serializable{ } /** - * To string. + * Gets the list item fields. * - * @return the string + * @return the list item fields */ + public List getListItemFields() { + return listItemFields; + } + + /** + * Sets the list item fields. + * + * @param listItemFields the new list item fields + */ + public void setListItemFields(List listItemFields) { + this.listItemFields = listItemFields; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("GeoNaDataViewerProfile [restrictedPortletURL="); + builder.append("GNADataViewerConfigProfile [restrictedPortletURL="); builder.append(restrictedPortletURL); builder.append(", openPortletURL="); builder.append(openPortletURL); builder.append(", mapLayers="); builder.append(mapLayers); + builder.append(", listItemFields="); + builder.append(listItemFields); builder.append("]"); return builder.toString(); } - } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/ItemField.java b/src/main/java/org/gcube/application/geoportalcommon/shared/ItemField.java index 472ea02..7817b68 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/ItemField.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/ItemField.java @@ -3,6 +3,13 @@ package org.gcube.application.geoportalcommon.shared; import java.io.Serializable; import java.util.List; +/** + * The Class ItemField. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 21, 2021 + */ public class ItemField implements Serializable { /** @@ -14,62 +21,129 @@ public class ItemField implements Serializable { private List jsonFields; private boolean sortable; private boolean searchable; - private boolean displayIntoTable; + private boolean displayAsResult; + /** + * Instantiates a new item field. + */ public ItemField() { } - public ItemField(String displayName, List jsonFields, boolean displayIntoTable, boolean sortable, + /** + * Instantiates a new item field. + * + * @param displayName the display name + * @param jsonFields the json fields + * @param displayAsResult the display as result + * @param sortable the sortable + * @param searchable the searchable + */ + public ItemField(String displayName, List jsonFields, boolean displayAsResult, boolean sortable, boolean searchable) { super(); this.displayName = displayName; this.jsonFields = jsonFields; - this.displayIntoTable = displayIntoTable; + this.displayAsResult = displayAsResult; this.sortable = sortable; this.searchable = searchable; } + /** + * Gets the display name. + * + * @return the display name + */ public String getDisplayName() { return displayName; } + /** + * Gets the json fields. + * + * @return the json fields + */ public List getJsonFields() { return jsonFields; } + /** + * Sets the display name. + * + * @param displayName the new display name + */ public void setDisplayName(String displayName) { this.displayName = displayName; } + /** + * Sets the json fields. + * + * @param jsonFields the new json fields + */ public void setJsonFields(List jsonFields) { this.jsonFields = jsonFields; } + /** + * Checks if is sortable. + * + * @return true, if is sortable + */ public boolean isSortable() { return sortable; } + /** + * Sets the sortable. + * + * @param sortable the new sortable + */ public void setSortable(boolean sortable) { this.sortable = sortable; } + /** + * Checks if is searchable. + * + * @return true, if is searchable + */ public boolean isSearchable() { return searchable; } + /** + * Sets the searchable. + * + * @param searchable the new searchable + */ public void setSearchable(boolean searchable) { this.searchable = searchable; } - public boolean isDisplayIntoTable() { - return displayIntoTable; + /** + * Checks if is display as result. + * + * @return true, if is display as result + */ + public boolean isDisplayAsResult() { + return displayAsResult; } - public void setDisplayIntoTable(boolean displayIntoTable) { - this.displayIntoTable = displayIntoTable; + /** + * Sets the display as result. + * + * @param displayAsResult the new display as result + */ + public void setDisplayAsResult(boolean displayAsResult) { + this.displayAsResult = displayAsResult; } + /** + * To string. + * + * @return the string + */ @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -81,8 +155,8 @@ public class ItemField implements Serializable { builder.append(sortable); builder.append(", searchable="); builder.append(searchable); - builder.append(", displayIntoTable="); - builder.append(displayIntoTable); + builder.append(", displayAsResult="); + builder.append(displayAsResult); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/config/ItemFieldsConfig.java b/src/main/java/org/gcube/application/geoportalcommon/shared/config/ItemFieldsConfig.java new file mode 100644 index 0000000..5a2bdaf --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/config/ItemFieldsConfig.java @@ -0,0 +1,72 @@ +package org.gcube.application.geoportalcommon.shared.config; + +import java.io.Serializable; +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.ItemField; + + +/** + * The Class ItemFieldsConfig. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 20, 2021 + */ +public class ItemFieldsConfig implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 5396430840723300173L; + private List listItemFieldsConfig = null; + + /** + * Instantiates a new item fields config. + */ + public ItemFieldsConfig() { + } + + /** + * Instantiates a new item fields config. + * + * @param listItemFieldsConfig the list item fields config + */ + public ItemFieldsConfig(List listItemFieldsConfig) { + super(); + this.listItemFieldsConfig = listItemFieldsConfig; + } + + /** + * Gets the list item fields config. + * + * @return the list item fields config + */ + public List getListItemFieldsConfig() { + return listItemFieldsConfig; + } + + /** + * Sets the list item fields config. + * + * @param listItemFieldsConfig the new list item fields config + */ + public void setListItemFieldsConfig(List listItemFieldsConfig) { + this.listItemFieldsConfig = listItemFieldsConfig; + } + + /** + * To string. + * + * @return the string + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ItemFieldsConfig [listItemFieldsConfig="); + builder.append(listItemFieldsConfig); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index ed80fb5..d1d2e28 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -5,19 +5,21 @@ import java.util.HashMap; import java.util.Map; import org.gcube.application.geoportalcommon.GeoportalCommon; +import org.gcube.application.geoportalcommon.GeoportalCommonConstants; import org.gcube.application.geoportalcommon.MongoServiceCommon; -import org.gcube.application.geoportalcommon.config.GNADataConfigProfileReader; -import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; +import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; +import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; -import org.gcube.application.geoportalcommon.shared.WhereClause; import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; +import org.gcube.application.geoportalcommon.shared.WhereClause; +import org.gcube.application.geoportalcommon.shared.config.RoleRights; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; 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 TestGNACommon { @@ -31,18 +33,18 @@ public class TestGNACommon { SecurityTokenProvider.instance.set(TOKEN); } - //@Test - public GeoNaDataViewerProfile getGeoNaDataViewProfile() throws Exception { + // @Test + public GNADataViewerConfigProfile getGeoNaDataViewProfile() throws Exception { System.out.println("getGeoNaDataViewProfile called"); ScopeProvider.instance.set(CONTEXT); GeoportalCommon gc = new GeoportalCommon(); - GeoNaDataViewerProfile profile = gc.getGeoNaDataViewProfile(null); + GNADataViewerConfigProfile profile = gc.readGNADataViewConfig(null); System.out.println("Returning profile: " + profile); return profile; } - //@Test + // @Test public GeoNaItemRef getLinks() throws Exception { System.out.println("getGeoNaDataViewProfile called"); @@ -53,52 +55,83 @@ public class TestGNACommon { return links; } - @Test + // @Test public void queryConcessioniTest() throws Exception { try { ScopeProvider.instance.set(CONTEXT); MongoServiceCommon msc = new MongoServiceCommon(); SearchingFilter filter = new SearchingFilter(); - + Map searchInto = new HashMap(); searchInto.put("nome", "san"); searchInto.put("authors", "silvia"); - //searchInto.put("report.status", "PASSED"); - + // searchInto.put("report.status", "PASSED"); + WhereClause where1 = new WhereClause(LOGICAL_OP.OR, searchInto); - + Map searchInto2 = new HashMap(); searchInto2.put("report.status", "PASSED"); WhereClause where2 = new WhereClause(LOGICAL_OP.AND, searchInto2); - + ArrayList list = new ArrayList(); list.add(where1); - //list.add(where2); + // list.add(where2); filter.setConditions(list); ResultSetPaginatedData result = msc.queryOnMongo(30, 0, 30, filter, "concessione"); int i = 0; for (ConcessioneDV concessione : result.getData()) { - System.out.println(++i +") "+concessione); + System.out.println(++i + ") " + concessione); } - } catch (Exception e) { - // TODO: handle exception + e.printStackTrace(); } } - - //@Test - public void readUserRights() throws Exception { - - GNADataConfigProfileReader r = new GNADataConfigProfileReader(); + + // @Test + public void readGNDataEntryConfigsFromIS() throws Exception { + + GeoportalCommon r = new GeoportalCommon(); try { ScopeProvider.instance.set(CONTEXT); - r.readProfileFromInfrastrucure(); + GNADataEntryConfigProfile configurations = r.readGNADataEntryConfig(); + + System.out.println("Permissions are:"); + int i = 0; + for (RoleRights role : configurations.getPermissionsForRole()) { + System.out.println(++i + " " + role); + } + + System.out.println("Item Fields are:"); + i = 0; + for (ItemField item : configurations.getListItemFields()) { + System.out.println(++i + " " + item); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + // @Test + public void readGNDataViewerConfigsFromIS() throws Exception { + + GeoportalCommon r = new GeoportalCommon(); + try { + ScopeProvider.instance.set(CONTEXT); + GNADataViewerConfigProfile configurations = r + .readGNADataViewConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP); + + System.out.println("Map layers are:"); + System.out.println(configurations.getMapLayers()); + System.out.println("Item Fields are:"); + int i = 0; + for (ItemField item : configurations.getListItemFields()) { + System.out.println(++i + " " + item); + } } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } } -- 2.17.1 From 26e801767d2ed995f3263eae37b25cbfdd1fa42d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 21 Dec 2021 12:06:15 +0100 Subject: [PATCH 09/12] improved logs --- .../geoportalcommon/GNADataEntryConfigProfileReader.java | 2 +- .../gcube/application/geoportalcommon/GeoportalCommon.java | 7 ++++--- src/test/java/org/gcube/application/TestGNACommon.java | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java index 3e179f7..9dacfaa 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java @@ -69,8 +69,8 @@ public class GNADataEntryConfigProfileReader { protected GNADataEntryConfigProfile readProfileFromInfrastrucure() throws Exception { LOG.info("called readProfileFromInfrastrucure"); String queryString = getGcubeGenericQueryString(SECONDARY_TYPE, GENERIC_RESOURCE_NAME); - LOG.info("Scope " + scope + ", trying to perform query: " + queryString); this.scope = ScopeProvider.instance.get(); + LOG.info("Scope " + scope + ", trying to perform query: " + queryString); if (scope == null) throw new Exception("Scope is null, set scope into ScopeProvider"); diff --git a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java index 5b18dbd..3571ef7 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java @@ -165,12 +165,13 @@ public class GeoportalCommon { * @throws Exception the exception */ public GNADataViewerConfigProfile readGNADataViewConfig(String appID) throws Exception { - LOG.info("getGeoNaDataViewProfile called for: " + appID); + LOG.info("getGeoNaDataViewProfile called for AppID: " + appID); - if (appID == null || appID.isEmpty()) + if (appID == null || appID.isEmpty()) { + LOG.info("AppID is null, so using DEFAULT: " + appID); appID = GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP; + } - LOG.info("using AppId: " + appID); GNADataViewerConfigProfileReader gdvp = new GNADataViewerConfigProfileReader(appID); GNADataViewerConfigProfile profile = gdvp.readProfileFromInfrastrucure(); LOG.info("Returning profile: " + profile); diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index d1d2e28..32bcf59 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -20,10 +20,11 @@ import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; 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 TestGNACommon { - private static String TOKEN = ""; + private static String TOKEN = "8e74a17c-92f1-405a-b591-3a6090066248-98187548"; private static String CONTEXT = "/gcube/devsec/devVRE"; private static String USERNAME = "francesco.mangiacrapa"; @@ -91,7 +92,7 @@ public class TestGNACommon { } - // @Test + @Test public void readGNDataEntryConfigsFromIS() throws Exception { GeoportalCommon r = new GeoportalCommon(); @@ -115,7 +116,7 @@ public class TestGNACommon { } } - // @Test + //@Test public void readGNDataViewerConfigsFromIS() throws Exception { GeoportalCommon r = new GeoportalCommon(); -- 2.17.1 From 486c40668e26d09b639a5388399c21fac4bb47b3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 21 Dec 2021 15:54:43 +0100 Subject: [PATCH 10/12] improved code --- .../geoportalcommon/GNAConfigsConverter.java | 24 +++++-- .../GNADataEntryConfigProfileReader.java | 14 ++-- .../GNADataViewerConfigProfileReader.java | 5 +- .../geoportalcommon/GeoportalCommon.java | 13 ++-- .../shared/config/ItemFieldsConfig.java | 72 ------------------- ...Exception.java => GNAConfigException.java} | 4 +- .../org/gcube/application/TestGNACommon.java | 23 +++++- 7 files changed, 57 insertions(+), 98 deletions(-) delete mode 100644 src/main/java/org/gcube/application/geoportalcommon/shared/config/ItemFieldsConfig.java rename src/main/java/org/gcube/application/geoportalcommon/shared/exception/{GNAUserRightsConfigException.java => GNAConfigException.java} (50%) diff --git a/src/main/java/org/gcube/application/geoportalcommon/GNAConfigsConverter.java b/src/main/java/org/gcube/application/geoportalcommon/GNAConfigsConverter.java index e841a91..7a355f6 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GNAConfigsConverter.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNAConfigsConverter.java @@ -3,13 +3,14 @@ package org.gcube.application.geoportalcommon; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Random; import org.gcube.application.geoportalcommon.config.CSVFile; import org.gcube.application.geoportalcommon.config.CSVReader; import org.gcube.application.geoportalcommon.config.CSVRow; import org.gcube.application.geoportalcommon.config.FileUtil; import org.gcube.application.geoportalcommon.shared.ItemField; -import org.gcube.application.geoportalcommon.shared.exception.GNAUserRightsConfigException; +import org.gcube.application.geoportalcommon.shared.exception.GNAConfigException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,25 +25,34 @@ public class GNAConfigsConverter { private static final Logger LOG = LoggerFactory.getLogger(GNAConfigsConverter.class); + + public GNAConfigsConverter() { + } /** * Read list items config. * * @param contentValue the content value * @return the list - * @throws GNAUserRightsConfigException the GNA user rights config exception + * @throws GNAConfigException the GNA user rights config exception */ - public static List readListItemsConfig(String contentValue) throws GNAUserRightsConfigException { + public List readListItemsConfig(String contentValue) throws GNAConfigException { LOG.debug("readListItemsConfig called"); File configurationFile = null; List listItemFields = new ArrayList(); try { - configurationFile = FileUtil.inputStreamToTempFile(contentValue, "GNA_ListItems_Configs"); + + configurationFile = FileUtil.inputStreamToTempFile(contentValue, "GNA_ListItems_Configs"+new Random().nextInt()); CSVReader reader = new CSVReader(configurationFile); CSVFile csvFile = reader.getCsvFile(); - + + if(LOG.isTraceEnabled()) { + LOG.trace("CSV Header Row: "+csvFile.getHeaderRow()); + } + List rows = csvFile.getValueRows(); + LOG.debug("CSV Value Row are: "+rows); // Starting from index 1 (means the second row in the CSV) for (int i = 0; i < rows.size(); i++) { @@ -86,8 +96,8 @@ public class GNAConfigsConverter { return listItemFields; } catch (Exception e) { - LOG.error("An error occurred on reading the GNA DataEntry config from: " + contentValue, e); - throw new GNAUserRightsConfigException("Error on reading the GNA DataEntry from: " + contentValue); + LOG.error("An error occurred on reading the GNA config from: " + contentValue, e); + throw new GNAConfigException("Error on reading the GNA config from: " + contentValue); } finally { if (configurationFile != null) { diff --git a/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java index 9dacfaa..195c910 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -23,7 +24,7 @@ import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole; 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.GNAUserRightsConfigException; +import org.gcube.application.geoportalcommon.shared.exception.GNAConfigException; import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.resources.discovery.client.api.DiscoveryClient; @@ -127,7 +128,8 @@ public class GNADataEntryConfigProfileReader { value_with_new_lines = item_fields.replaceAll("\\\\n", System.lineSeparator()); LOG.debug(PATH_TO_ITEM_FIELDS_CONFIG + " with new lines: " + value_with_new_lines); - List listItemFieldsConfig = GNAConfigsConverter.readListItemsConfig(value_with_new_lines); + GNAConfigsConverter gnc = new GNAConfigsConverter(); + List listItemFieldsConfig = gnc.readListItemsConfig(value_with_new_lines); gnDEC.setListItemFields(listItemFieldsConfig); LOG.info("returning: " + gnDEC); @@ -165,16 +167,16 @@ public class GNADataEntryConfigProfileReader { * * @param permissions_for_role the permissions for role * @return the list - * @throws GNAUserRightsConfigException the GNA user rights config not found + * @throws GNAConfigException the GNA user rights config not found * exception */ - public List readRoleRightsConfig(String permissions_for_role) throws GNAUserRightsConfigException { + public List readRoleRightsConfig(String permissions_for_role) throws GNAConfigException { LOG.debug("readRoleRightsConfig called"); File configurationFile = null; List listUserRights = new ArrayList(); try { - configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, "GNA_RoleRights_Configurations"); + configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, "GNA_RoleRights_Configurations"+new Random().nextInt()); CSVReader reader = new CSVReader(configurationFile); CSVFile csvFile = reader.getCsvFile(); @@ -260,7 +262,7 @@ public class GNADataEntryConfigProfileReader { } catch (Exception e) { LOG.error("An error occurred on reading the GNA DataEntry config from: " + permissions_for_role, e); - throw new GNAUserRightsConfigException("Error on reading the GNA DataEntry from: " + permissions_for_role); + throw new GNAConfigException("Error on reading the GNA DataEntry from: " + permissions_for_role); } finally { if (configurationFile != null) { diff --git a/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java index 58fd505..70ea9c5 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java @@ -71,7 +71,7 @@ public class GNADataViewerConfigProfileReader { * @return the map * @throws Exception the exception */ - protected GNADataViewerConfigProfile readProfileFromInfrastrucure() throws Exception { + protected GNADataViewerConfigProfile readProfileFromInfrastructure() throws Exception { String queryString = getGcubeGenericQueryString(secondaryType, appID); LOG.info("Scope " + scope + ", trying to perform query: " + queryString); @@ -149,7 +149,8 @@ public class GNADataViewerConfigProfileReader { String value_with_new_lines = item_fields.replaceAll("\\\\n", System.lineSeparator()); LOG.debug(PATH_TO_ITEM_FIELDS_CONFIG + " with new lines: " + value_with_new_lines); - List listItemFieldsConfig = GNAConfigsConverter.readListItemsConfig(value_with_new_lines); + GNAConfigsConverter gnc = new GNAConfigsConverter(); + List listItemFieldsConfig = gnc.readListItemsConfig(value_with_new_lines); profile.setListItemFields(listItemFieldsConfig); LOG.info("returning: " + profile); diff --git a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java index 3571ef7..a2ded59 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GeoportalCommon.java @@ -64,7 +64,7 @@ public class GeoportalCommon { throw new Exception("Bad request, the item type is null"); if (this.geonaDataProfile == null) - this.geonaDataProfile = readGNADataViewConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP); + this.geonaDataProfile = readGNADataViewerConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP); // Restricted Link String link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(), @@ -157,23 +157,23 @@ public class GeoportalCommon { } /** - * Read GNA data view config. + * Read GNA data viewer config. * * @param appID the app ID. If null uses the default * {@link GeoportalCommonConstants#GEOPORTAL_DATA_VIEWER_APP} * @return the GNA data viewer config profile * @throws Exception the exception */ - public GNADataViewerConfigProfile readGNADataViewConfig(String appID) throws Exception { + public GNADataViewerConfigProfile readGNADataViewerConfig(String appID) throws Exception { LOG.info("getGeoNaDataViewProfile called for AppID: " + appID); if (appID == null || appID.isEmpty()) { - LOG.info("AppID is null, so using DEFAULT: " + appID); appID = GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP; + LOG.info("AppID is null, so using DEFAULT: " + appID); } GNADataViewerConfigProfileReader gdvp = new GNADataViewerConfigProfileReader(appID); - GNADataViewerConfigProfile profile = gdvp.readProfileFromInfrastrucure(); + GNADataViewerConfigProfile profile = gdvp.readProfileFromInfrastructure(); LOG.info("Returning profile: " + profile); return profile; } @@ -185,7 +185,8 @@ public class GeoportalCommon { * @throws Exception the exception */ public GNADataEntryConfigProfile readGNADataEntryConfig() throws Exception { - + LOG.info("readGNADataEntryConfig called"); + GNADataEntryConfigProfileReader gnaConfigReader = new GNADataEntryConfigProfileReader(); GNADataEntryConfigProfile config = gnaConfigReader.readProfileFromInfrastrucure(); return config; diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/config/ItemFieldsConfig.java b/src/main/java/org/gcube/application/geoportalcommon/shared/config/ItemFieldsConfig.java deleted file mode 100644 index 5a2bdaf..0000000 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/config/ItemFieldsConfig.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.gcube.application.geoportalcommon.shared.config; - -import java.io.Serializable; -import java.util.List; - -import org.gcube.application.geoportalcommon.shared.ItemField; - - -/** - * The Class ItemFieldsConfig. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Dec 20, 2021 - */ -public class ItemFieldsConfig implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 5396430840723300173L; - private List listItemFieldsConfig = null; - - /** - * Instantiates a new item fields config. - */ - public ItemFieldsConfig() { - } - - /** - * Instantiates a new item fields config. - * - * @param listItemFieldsConfig the list item fields config - */ - public ItemFieldsConfig(List listItemFieldsConfig) { - super(); - this.listItemFieldsConfig = listItemFieldsConfig; - } - - /** - * Gets the list item fields config. - * - * @return the list item fields config - */ - public List getListItemFieldsConfig() { - return listItemFieldsConfig; - } - - /** - * Sets the list item fields config. - * - * @param listItemFieldsConfig the new list item fields config - */ - public void setListItemFieldsConfig(List listItemFieldsConfig) { - this.listItemFieldsConfig = listItemFieldsConfig; - } - - /** - * To string. - * - * @return the string - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ItemFieldsConfig [listItemFieldsConfig="); - builder.append(listItemFieldsConfig); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/exception/GNAUserRightsConfigException.java b/src/main/java/org/gcube/application/geoportalcommon/shared/exception/GNAConfigException.java similarity index 50% rename from src/main/java/org/gcube/application/geoportalcommon/shared/exception/GNAUserRightsConfigException.java rename to src/main/java/org/gcube/application/geoportalcommon/shared/exception/GNAConfigException.java index 7035781..e739b77 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/exception/GNAUserRightsConfigException.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/exception/GNAConfigException.java @@ -1,8 +1,8 @@ package org.gcube.application.geoportalcommon.shared.exception; @SuppressWarnings("serial") -public class GNAUserRightsConfigException extends Exception { - public GNAUserRightsConfigException(String message) { +public class GNAConfigException extends Exception { + public GNAConfigException(String message) { super(message); } } \ No newline at end of file diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index 32bcf59..c613329 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -24,7 +24,7 @@ import org.junit.Test; public class TestGNACommon { - private static String TOKEN = "8e74a17c-92f1-405a-b591-3a6090066248-98187548"; + private static String TOKEN = ""; private static String CONTEXT = "/gcube/devsec/devVRE"; private static String USERNAME = "francesco.mangiacrapa"; @@ -40,7 +40,7 @@ public class TestGNACommon { ScopeProvider.instance.set(CONTEXT); GeoportalCommon gc = new GeoportalCommon(); - GNADataViewerConfigProfile profile = gc.readGNADataViewConfig(null); + GNADataViewerConfigProfile profile = gc.readGNADataViewerConfig(null); System.out.println("Returning profile: " + profile); return profile; } @@ -94,7 +94,24 @@ public class TestGNACommon { @Test public void readGNDataEntryConfigsFromIS() throws Exception { + + Thread thread = new Thread() { + public void run() { + geoCommon(); + } + }; + Thread thread2 = new Thread() { + public void run() { + geoCommon(); + } + }; + + thread.run(); + thread2.run(); + } + + private void geoCommon() { GeoportalCommon r = new GeoportalCommon(); try { ScopeProvider.instance.set(CONTEXT); @@ -123,7 +140,7 @@ public class TestGNACommon { try { ScopeProvider.instance.set(CONTEXT); GNADataViewerConfigProfile configurations = r - .readGNADataViewConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP); + .readGNADataViewerConfig(null); System.out.println("Map layers are:"); System.out.println(configurations.getMapLayers()); -- 2.17.1 From bd116cbf46a6a490a387efe8108185296500690a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 22 Dec 2021 12:10:43 +0100 Subject: [PATCH 11/12] Renamed GRs to: Geoportal-DataEntry-Configs and Geoportal-DataViewer-Configs --- .../GNADataEntryConfigProfileReader.java | 2 +- .../GNADataViewerConfigProfileReader.java | 4 ++-- .../java/org/gcube/application/TestGNACommon.java | 13 ++++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java index 195c910..a3faaa4 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNADataEntryConfigProfileReader.java @@ -46,7 +46,7 @@ public class GNADataEntryConfigProfileReader { private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body"; public static final String SECONDARY_TYPE = "ApplicationProfile"; - public static final String GENERIC_RESOURCE_NAME = "GNA-DataEntry-Configs"; + 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"; diff --git a/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java b/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java index 70ea9c5..f4b986d 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java +++ b/src/main/java/org/gcube/application/geoportalcommon/GNADataViewerConfigProfileReader.java @@ -45,7 +45,7 @@ public class GNADataViewerConfigProfileReader { * */ public static final String SECONDARY_TYPE = "ApplicationProfile"; - public static final String WORKSPACE_EXPLORER_APP_NAME = "GeoNa-Viewer-Profile"; + public static final String GENERIC_RESOURCE_NAME = "Geoportal-DataViewer-Configs"; private static final String PATH_TO_ITEM_FIELDS_CONFIG = RESOURCE_PROFILE_BODY + "/item_fields_config"; private static Logger LOG = LoggerFactory.getLogger(GNADataViewerConfigProfileReader.class); @@ -159,7 +159,7 @@ public class GNADataViewerConfigProfileReader { } catch (Exception e) { LOG.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType " - + WORKSPACE_EXPLORER_APP_NAME + " from scope " + scope, e); + + GENERIC_RESOURCE_NAME + " from scope " + scope, e); return null; } finally { diff --git a/src/test/java/org/gcube/application/TestGNACommon.java b/src/test/java/org/gcube/application/TestGNACommon.java index c613329..9664dff 100644 --- a/src/test/java/org/gcube/application/TestGNACommon.java +++ b/src/test/java/org/gcube/application/TestGNACommon.java @@ -28,7 +28,7 @@ public class TestGNACommon { private static String CONTEXT = "/gcube/devsec/devVRE"; private static String USERNAME = "francesco.mangiacrapa"; - @Before + //@Before public void init() { ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); @@ -92,9 +92,9 @@ public class TestGNACommon { } - @Test + // @Test public void readGNDataEntryConfigsFromIS() throws Exception { - + Thread thread = new Thread() { public void run() { geoCommon(); @@ -106,11 +106,11 @@ public class TestGNACommon { geoCommon(); } }; - + thread.run(); thread2.run(); } - + private void geoCommon() { GeoportalCommon r = new GeoportalCommon(); try { @@ -139,8 +139,7 @@ public class TestGNACommon { GeoportalCommon r = new GeoportalCommon(); try { ScopeProvider.instance.set(CONTEXT); - GNADataViewerConfigProfile configurations = r - .readGNADataViewerConfig(null); + GNADataViewerConfigProfile configurations = r.readGNADataViewerConfig(null); System.out.println("Map layers are:"); System.out.println(configurations.getMapLayers()); -- 2.17.1 From 672b74e238525fe425c642d5636c302f407a33a3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 13 Jan 2022 16:50:18 +0100 Subject: [PATCH 12/12] updated README --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca98b5c..36c245e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm #### Enhancements -- [#22506] Added classes to read configurations and common classes to GNA DataEntry and Viewer +- [#22506] Added classes to read configurations and common classes from the GNA components: DataEntry and DataViewer ## [v1.2.0] - 2021-09-29 -- 2.17.1