Added classes to read configurations and common classes to GNA DataEntry
and Viewer
This commit is contained in:
parent
9e500a23d0
commit
ae1cc32387
|
@ -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
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.application</groupId>
|
||||
<artifactId>geoportal-data-common</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<description>GeoPortal Data Common is common library used by GUI components developed for GeoNA</description>
|
||||
|
||||
<scm>
|
||||
|
|
|
@ -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;
|
||||
|
@ -177,4 +181,22 @@ public class GeoportalCommon {
|
|||
return geonaDataProfile;
|
||||
}
|
||||
|
||||
public GNADataConfigProfile getGNADataConfig(){
|
||||
|
||||
List<ItemField> listItemFields = new ArrayList<ItemField>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Concessione> getListOfConcessioni() throws Exception {
|
||||
LOG.info("called getListOfConcessioni");
|
||||
|
||||
List<Concessione> listOfConcessioni = new ArrayList<Concessione>();
|
||||
LOG.info("Loading list of concessioni from client mongo");
|
||||
MongoConcessioni clientMongo = getInstanceMongoConcessioni();
|
||||
|
||||
Iterator<Concessione> 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<Concessione> 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<ConcessioneDV> toReturnList = new ArrayList<ConcessioneDV>();
|
||||
Direction sDirection = null;
|
||||
List<String> orderingFields = new ArrayList<String>();
|
||||
|
||||
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<ItemField> orderByFields = filter.getOrderByFields();
|
||||
|
||||
if(orderByFields==null) {
|
||||
orderByFields = new ArrayList<ItemField>();
|
||||
}
|
||||
|
||||
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<String, Object> 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<Concessione> 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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<CSVRow> 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<CSVRow> 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<CSVRow>();
|
||||
|
||||
valueRows.add(row);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the value rows.
|
||||
*
|
||||
* @param valueRows the new value rows
|
||||
*/
|
||||
public void setValueRows(List<CSVRow> valueRows) {
|
||||
this.valueRows = valueRows;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value rows.
|
||||
*
|
||||
* @return the valueRows
|
||||
*/
|
||||
public List<CSVRow> 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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<String> 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<String> 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<String> 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<String> parseLine(String cvsLine, char separators, char customQuote) {
|
||||
|
||||
List<String> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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<String> listValues;
|
||||
|
||||
/**
|
||||
* Instantiates a new CSV row.
|
||||
*/
|
||||
public CSVRow(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list values.
|
||||
*
|
||||
* @return the listValues
|
||||
*/
|
||||
public List<String> getListValues() {
|
||||
|
||||
return listValues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param listValues the listValues to set
|
||||
*/
|
||||
public void setListValues(List<String> listValues) {
|
||||
|
||||
this.listValues = listValues;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the value.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public void addValue(String value) {
|
||||
if(listValues==null)
|
||||
listValues = new ArrayList<String>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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<RoleRights> permissionsForRole = null;
|
||||
|
||||
public GNADataEntryConfigs() {
|
||||
|
||||
}
|
||||
|
||||
public GNADataEntryConfigs(List<RoleRights> permissionsForRole) {
|
||||
super();
|
||||
this.permissionsForRole = permissionsForRole;
|
||||
}
|
||||
|
||||
public List<RoleRights> getPermissionsForRole() {
|
||||
return permissionsForRole;
|
||||
}
|
||||
|
||||
public void setPermissionsForRole(List<RoleRights> permissionsForRole) {
|
||||
this.permissionsForRole = permissionsForRole;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("GNADataEntryConfigs [permissionsForRole=");
|
||||
builder.append(permissionsForRole);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String> client = client();
|
||||
List<String> 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<String> 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<RoleRights> 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<RoleRights> readRoleRightsConfig(String permissions_for_role) throws GNAUserRightsConfigException {
|
||||
LOG.debug("readRoleRightsConfig called");
|
||||
|
||||
File configurationFile = null;
|
||||
List<RoleRights> listUserRights = new ArrayList<RoleRights>();
|
||||
try {
|
||||
configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, TEMP_ROLE_RIGHTS_CONFIG_FILENAME);
|
||||
|
||||
CSVReader reader = new CSVReader(configurationFile);
|
||||
CSVFile csvFile = reader.getCsvFile();
|
||||
|
||||
List<String> headerKeys = csvFile.getHeaderRow().getListValues();
|
||||
List<CSVRow> rows = csvFile.getValueRows();
|
||||
|
||||
// MAPPING OPERATION TYPE AS READ, WRITE, etc.
|
||||
Map<String, OPERATION_TYPE> mapOperationTypes = new HashMap<String, RoleRights.OPERATION_TYPE>();
|
||||
CSVRow operationTypeRow = rows.get(0);
|
||||
List<String> 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<String, String> mapUserRolePermissions = new HashMap<String, String>();
|
||||
|
||||
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<ACTION_ON_ITEM, OPERATION_TYPE> listPermessions = new HashMap<ACTION_ON_ITEM, OPERATION_TYPE>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<ItemField> listItemFields;
|
||||
|
||||
public GNADataConfigProfile() {
|
||||
|
||||
}
|
||||
|
||||
public GNADataConfigProfile(List<ItemField> listItemFields) {
|
||||
super();
|
||||
this.listItemFields = listItemFields;
|
||||
}
|
||||
|
||||
public List<ItemField> getListItemFields() {
|
||||
return listItemFields;
|
||||
}
|
||||
|
||||
public void setListItemFields(List<ItemField> listItemFields) {
|
||||
this.listItemFields = listItemFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("GNADataConfigProfile [listItemFields=");
|
||||
builder.append(listItemFields);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String> jsonFields;
|
||||
private boolean sortable;
|
||||
private boolean searchable;
|
||||
private boolean displayIntoTable;
|
||||
|
||||
public ItemField() {
|
||||
|
||||
}
|
||||
|
||||
public ItemField(String displayName, List<String> 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<String> getJsonFields() {
|
||||
return jsonFields;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public void setJsonFields(List<String> 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<ConcessioneDV> 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<ConcessioneDV> 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<ConcessioneDV> 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<ItemField> orderByFields;
|
||||
|
||||
private ORDER order;
|
||||
|
||||
private Map<String, Object> 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<ItemField> 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<ItemField> orderByFields, ORDER order, Map<String, Object> searchInto) {
|
||||
this.orderByFields = orderByFields;
|
||||
this.order = order;
|
||||
this.searchInto = searchInto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the search into.
|
||||
*
|
||||
* @param searchInto the search into
|
||||
*/
|
||||
public void setSearchInto(Map<String, Object> searchInto) {
|
||||
this.searchInto = searchInto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the order by fields.
|
||||
*
|
||||
* @return the order by fields
|
||||
*/
|
||||
public List<ItemField> 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<ItemField> 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<String, Object> 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.application.geoportalcommon.shared.config;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class GNAUserRightsConfigException extends Exception {
|
||||
public GNAUserRightsConfigException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<ACTION_ON_ITEM, OPERATION_TYPE> 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<ACTION_ON_ITEM, OPERATION_TYPE> listPermessions, GcubeUserRole userRole) {
|
||||
this.listPermessions = listPermessions;
|
||||
this.userRole = userRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list permessions.
|
||||
*
|
||||
* @return the list permessions
|
||||
*/
|
||||
public Map<ACTION_ON_ITEM, OPERATION_TYPE> 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<ACTION_ON_ITEM, OPERATION_TYPE> 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue