refactored and created new class to read configurations from IS

This commit is contained in:
Francesco Mangiacrapa 2021-12-21 11:55:58 +01:00
parent 07bf557525
commit 69a4f34e88
10 changed files with 588 additions and 196 deletions

View File

@ -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<ItemField> readListItemsConfig(String contentValue) throws GNAUserRightsConfigException {
LOG.debug("readListItemsConfig called");
File configurationFile = null;
List<ItemField> listItemFields = new ArrayList<ItemField>();
try {
configurationFile = FileUtil.inputStreamToTempFile(contentValue, "GNA_ListItems_Configs");
CSVReader reader = new CSVReader(configurationFile);
CSVFile csvFile = reader.getCsvFile();
List<CSVRow> 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<String> rowValues = row.getListValues();
LOG.debug("rowValues: " + rowValues);
itemField.setDisplayName(rowValues.get(0));
// Reading JSON Fields
String[] jsonFields = rowValues.get(1).split(";");
List<String> theJsonFields = new ArrayList<String>(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;
}
}

View File

@ -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<String> 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<RoleRights> listRoleRights = readRoleRightsConfig(pfr_with_new_lines);
List<RoleRights> 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<ItemField> 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<RoleRights> listUserRights = new ArrayList<RoleRights>();
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()));
}

View File

@ -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<String> client = client();
List<String> 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<ItemField> 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))
* ; } } }
*/
}

View File

@ -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<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));
/**
* 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;
}
}

View File

@ -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<ItemField> listItemFields;
private List<RoleRights> permissionsForRole;
public GNADataConfigProfile() {
}
public GNADataConfigProfile(List<ItemField> listItemFields, List<RoleRights> permissionsForRole) {
super();
this.listItemFields = listItemFields;
this.permissionsForRole = permissionsForRole;
}
public List<ItemField> getListItemFields() {
return listItemFields;
}
public void setListItemFields(List<ItemField> listItemFields) {
this.listItemFields = listItemFields;
}
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("GNADataConfigProfile [listItemFields=");
builder.append(listItemFields);
builder.append("]");
return builder.toString();
}
}

View File

@ -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<ItemField> listItemFields;
private List<RoleRights> 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<ItemField> listItemFields, List<RoleRights> permissionsForRole) {
super();
this.listItemFields = listItemFields;
this.permissionsForRole = permissionsForRole;
}
/**
* Gets the list item fields.
*
* @return the list item fields
*/
public List<ItemField> getListItemFields() {
return listItemFields;
}
/**
* Sets the list item fields.
*
* @param listItemFields the new list item fields
*/
public void setListItemFields(List<ItemField> listItemFields) {
this.listItemFields = listItemFields;
}
/**
* Gets the permissions for role.
*
* @return the permissions for role
*/
public List<RoleRights> getPermissionsForRole() {
return permissionsForRole;
}
/**
* Sets the permissions for role.
*
* @param permissionsForRole the new permissions for role
*/
public void setPermissionsForRole(List<RoleRights> 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();
}
}

View File

@ -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<String, LayerItem> mapLayers;
private List<ItemField> 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<ItemField> getListItemFields() {
return listItemFields;
}
/**
* Sets the list item fields.
*
* @param listItemFields the new list item fields
*/
public void setListItemFields(List<ItemField> 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();
}
}

View File

@ -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<String> 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<String> 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<String> 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<String> 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<String> 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();
}

View File

@ -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<ItemField> 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<ItemField> listItemFieldsConfig) {
super();
this.listItemFieldsConfig = listItemFieldsConfig;
}
/**
* Gets the list item fields config.
*
* @return the list item fields config
*/
public List<ItemField> getListItemFieldsConfig() {
return listItemFieldsConfig;
}
/**
* Sets the list item fields config.
*
* @param listItemFieldsConfig the new list item fields config
*/
public void setListItemFieldsConfig(List<ItemField> 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();
}
}

View File

@ -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<String, Object> searchInto = new HashMap<String, Object>();
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<String, Object> searchInto2 = new HashMap<String, Object>();
searchInto2.put("report.status", "PASSED");
WhereClause where2 = new WhereClause(LOGICAL_OP.AND, searchInto2);
ArrayList<WhereClause> list = new ArrayList<WhereClause>();
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();
}
}