feature_22506 #3
|
@ -3,13 +3,14 @@ package org.gcube.application.geoportalcommon;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.gcube.application.geoportalcommon.config.CSVFile;
|
import org.gcube.application.geoportalcommon.config.CSVFile;
|
||||||
import org.gcube.application.geoportalcommon.config.CSVReader;
|
import org.gcube.application.geoportalcommon.config.CSVReader;
|
||||||
import org.gcube.application.geoportalcommon.config.CSVRow;
|
import org.gcube.application.geoportalcommon.config.CSVRow;
|
||||||
import org.gcube.application.geoportalcommon.config.FileUtil;
|
import org.gcube.application.geoportalcommon.config.FileUtil;
|
||||||
import org.gcube.application.geoportalcommon.shared.ItemField;
|
import org.gcube.application.geoportalcommon.shared.ItemField;
|
||||||
import org.gcube.application.geoportalcommon.shared.exception.GNAUserRightsConfigException;
|
import org.gcube.application.geoportalcommon.shared.exception.GNAConfigException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -24,25 +25,34 @@ public class GNAConfigsConverter {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GNAConfigsConverter.class);
|
private static final Logger LOG = LoggerFactory.getLogger(GNAConfigsConverter.class);
|
||||||
|
|
||||||
|
|
||||||
|
public GNAConfigsConverter() {
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Read list items config.
|
* Read list items config.
|
||||||
*
|
*
|
||||||
* @param contentValue the content value
|
* @param contentValue the content value
|
||||||
* @return the list
|
* @return the list
|
||||||
* @throws GNAUserRightsConfigException the GNA user rights config exception
|
* @throws GNAConfigException the GNA user rights config exception
|
||||||
*/
|
*/
|
||||||
public static List<ItemField> readListItemsConfig(String contentValue) throws GNAUserRightsConfigException {
|
public List<ItemField> readListItemsConfig(String contentValue) throws GNAConfigException {
|
||||||
LOG.debug("readListItemsConfig called");
|
LOG.debug("readListItemsConfig called");
|
||||||
|
|
||||||
File configurationFile = null;
|
File configurationFile = null;
|
||||||
List<ItemField> listItemFields = new ArrayList<ItemField>();
|
List<ItemField> listItemFields = new ArrayList<ItemField>();
|
||||||
try {
|
try {
|
||||||
configurationFile = FileUtil.inputStreamToTempFile(contentValue, "GNA_ListItems_Configs");
|
|
||||||
|
configurationFile = FileUtil.inputStreamToTempFile(contentValue, "GNA_ListItems_Configs"+new Random().nextInt());
|
||||||
|
|
||||||
CSVReader reader = new CSVReader(configurationFile);
|
CSVReader reader = new CSVReader(configurationFile);
|
||||||
CSVFile csvFile = reader.getCsvFile();
|
CSVFile csvFile = reader.getCsvFile();
|
||||||
|
|
||||||
|
if(LOG.isTraceEnabled()) {
|
||||||
|
LOG.trace("CSV Header Row: "+csvFile.getHeaderRow());
|
||||||
|
}
|
||||||
|
|
||||||
List<CSVRow> rows = csvFile.getValueRows();
|
List<CSVRow> rows = csvFile.getValueRows();
|
||||||
|
LOG.debug("CSV Value Row are: "+rows);
|
||||||
|
|
||||||
// Starting from index 1 (means the second row in the CSV)
|
// Starting from index 1 (means the second row in the CSV)
|
||||||
for (int i = 0; i < rows.size(); i++) {
|
for (int i = 0; i < rows.size(); i++) {
|
||||||
|
@ -86,8 +96,8 @@ public class GNAConfigsConverter {
|
||||||
return listItemFields;
|
return listItemFields;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("An error occurred on reading the GNA DataEntry config from: " + contentValue, e);
|
LOG.error("An error occurred on reading the GNA config from: " + contentValue, e);
|
||||||
throw new GNAUserRightsConfigException("Error on reading the GNA DataEntry from: " + contentValue);
|
throw new GNAConfigException("Error on reading the GNA config from: " + contentValue);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
if (configurationFile != null) {
|
if (configurationFile != null) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
@ -23,7 +24,7 @@ import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
|
||||||
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
|
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
|
||||||
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
|
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
|
||||||
import org.gcube.application.geoportalcommon.shared.exception.ApplicationProfileNotFoundException;
|
import org.gcube.application.geoportalcommon.shared.exception.ApplicationProfileNotFoundException;
|
||||||
import org.gcube.application.geoportalcommon.shared.exception.GNAUserRightsConfigException;
|
import org.gcube.application.geoportalcommon.shared.exception.GNAConfigException;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
@ -127,7 +128,8 @@ public class GNADataEntryConfigProfileReader {
|
||||||
value_with_new_lines = item_fields.replaceAll("\\\\n", System.lineSeparator());
|
value_with_new_lines = item_fields.replaceAll("\\\\n", System.lineSeparator());
|
||||||
LOG.debug(PATH_TO_ITEM_FIELDS_CONFIG + " with new lines: " + value_with_new_lines);
|
LOG.debug(PATH_TO_ITEM_FIELDS_CONFIG + " with new lines: " + value_with_new_lines);
|
||||||
|
|
||||||
List<ItemField> listItemFieldsConfig = GNAConfigsConverter.readListItemsConfig(value_with_new_lines);
|
GNAConfigsConverter gnc = new GNAConfigsConverter();
|
||||||
|
List<ItemField> listItemFieldsConfig = gnc.readListItemsConfig(value_with_new_lines);
|
||||||
gnDEC.setListItemFields(listItemFieldsConfig);
|
gnDEC.setListItemFields(listItemFieldsConfig);
|
||||||
|
|
||||||
LOG.info("returning: " + gnDEC);
|
LOG.info("returning: " + gnDEC);
|
||||||
|
@ -165,16 +167,16 @@ public class GNADataEntryConfigProfileReader {
|
||||||
*
|
*
|
||||||
* @param permissions_for_role the permissions for role
|
* @param permissions_for_role the permissions for role
|
||||||
* @return the list
|
* @return the list
|
||||||
* @throws GNAUserRightsConfigException the GNA user rights config not found
|
* @throws GNAConfigException the GNA user rights config not found
|
||||||
* exception
|
* exception
|
||||||
*/
|
*/
|
||||||
public List<RoleRights> readRoleRightsConfig(String permissions_for_role) throws GNAUserRightsConfigException {
|
public List<RoleRights> readRoleRightsConfig(String permissions_for_role) throws GNAConfigException {
|
||||||
LOG.debug("readRoleRightsConfig called");
|
LOG.debug("readRoleRightsConfig called");
|
||||||
|
|
||||||
File configurationFile = null;
|
File configurationFile = null;
|
||||||
List<RoleRights> listUserRights = new ArrayList<RoleRights>();
|
List<RoleRights> listUserRights = new ArrayList<RoleRights>();
|
||||||
try {
|
try {
|
||||||
configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, "GNA_RoleRights_Configurations");
|
configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, "GNA_RoleRights_Configurations"+new Random().nextInt());
|
||||||
|
|
||||||
CSVReader reader = new CSVReader(configurationFile);
|
CSVReader reader = new CSVReader(configurationFile);
|
||||||
CSVFile csvFile = reader.getCsvFile();
|
CSVFile csvFile = reader.getCsvFile();
|
||||||
|
@ -260,7 +262,7 @@ public class GNADataEntryConfigProfileReader {
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("An error occurred on reading the GNA DataEntry config from: " + permissions_for_role, e);
|
LOG.error("An error occurred on reading the GNA DataEntry config from: " + permissions_for_role, e);
|
||||||
throw new GNAUserRightsConfigException("Error on reading the GNA DataEntry from: " + permissions_for_role);
|
throw new GNAConfigException("Error on reading the GNA DataEntry from: " + permissions_for_role);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
if (configurationFile != null) {
|
if (configurationFile != null) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class GNADataViewerConfigProfileReader {
|
||||||
* @return the map
|
* @return the map
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
protected GNADataViewerConfigProfile readProfileFromInfrastrucure() throws Exception {
|
protected GNADataViewerConfigProfile readProfileFromInfrastructure() throws Exception {
|
||||||
|
|
||||||
String queryString = getGcubeGenericQueryString(secondaryType, appID);
|
String queryString = getGcubeGenericQueryString(secondaryType, appID);
|
||||||
LOG.info("Scope " + scope + ", trying to perform query: " + queryString);
|
LOG.info("Scope " + scope + ", trying to perform query: " + queryString);
|
||||||
|
@ -149,7 +149,8 @@ public class GNADataViewerConfigProfileReader {
|
||||||
String value_with_new_lines = item_fields.replaceAll("\\\\n", System.lineSeparator());
|
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);
|
LOG.debug(PATH_TO_ITEM_FIELDS_CONFIG + " with new lines: " + value_with_new_lines);
|
||||||
|
|
||||||
List<ItemField> listItemFieldsConfig = GNAConfigsConverter.readListItemsConfig(value_with_new_lines);
|
GNAConfigsConverter gnc = new GNAConfigsConverter();
|
||||||
|
List<ItemField> listItemFieldsConfig = gnc.readListItemsConfig(value_with_new_lines);
|
||||||
profile.setListItemFields(listItemFieldsConfig);
|
profile.setListItemFields(listItemFieldsConfig);
|
||||||
|
|
||||||
LOG.info("returning: " + profile);
|
LOG.info("returning: " + profile);
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class GeoportalCommon {
|
||||||
throw new Exception("Bad request, the item type is null");
|
throw new Exception("Bad request, the item type is null");
|
||||||
|
|
||||||
if (this.geonaDataProfile == null)
|
if (this.geonaDataProfile == null)
|
||||||
this.geonaDataProfile = readGNADataViewConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP);
|
this.geonaDataProfile = readGNADataViewerConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP);
|
||||||
|
|
||||||
// Restricted Link
|
// Restricted Link
|
||||||
String link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(),
|
String link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(),
|
||||||
|
@ -157,23 +157,23 @@ public class GeoportalCommon {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read GNA data view config.
|
* Read GNA data viewer config.
|
||||||
*
|
*
|
||||||
* @param appID the app ID. If null uses the default
|
* @param appID the app ID. If null uses the default
|
||||||
* {@link GeoportalCommonConstants#GEOPORTAL_DATA_VIEWER_APP}
|
* {@link GeoportalCommonConstants#GEOPORTAL_DATA_VIEWER_APP}
|
||||||
* @return the GNA data viewer config profile
|
* @return the GNA data viewer config profile
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public GNADataViewerConfigProfile readGNADataViewConfig(String appID) throws Exception {
|
public GNADataViewerConfigProfile readGNADataViewerConfig(String appID) throws Exception {
|
||||||
LOG.info("getGeoNaDataViewProfile called for AppID: " + appID);
|
LOG.info("getGeoNaDataViewProfile called for AppID: " + appID);
|
||||||
|
|
||||||
if (appID == null || appID.isEmpty()) {
|
if (appID == null || appID.isEmpty()) {
|
||||||
LOG.info("AppID is null, so using DEFAULT: " + appID);
|
|
||||||
appID = GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP;
|
appID = GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP;
|
||||||
|
LOG.info("AppID is null, so using DEFAULT: " + appID);
|
||||||
}
|
}
|
||||||
|
|
||||||
GNADataViewerConfigProfileReader gdvp = new GNADataViewerConfigProfileReader(appID);
|
GNADataViewerConfigProfileReader gdvp = new GNADataViewerConfigProfileReader(appID);
|
||||||
GNADataViewerConfigProfile profile = gdvp.readProfileFromInfrastrucure();
|
GNADataViewerConfigProfile profile = gdvp.readProfileFromInfrastructure();
|
||||||
LOG.info("Returning profile: " + profile);
|
LOG.info("Returning profile: " + profile);
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
@ -185,6 +185,7 @@ public class GeoportalCommon {
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public GNADataEntryConfigProfile readGNADataEntryConfig() throws Exception {
|
public GNADataEntryConfigProfile readGNADataEntryConfig() throws Exception {
|
||||||
|
LOG.info("readGNADataEntryConfig called");
|
||||||
|
|
||||||
GNADataEntryConfigProfileReader gnaConfigReader = new GNADataEntryConfigProfileReader();
|
GNADataEntryConfigProfileReader gnaConfigReader = new GNADataEntryConfigProfileReader();
|
||||||
GNADataEntryConfigProfile config = gnaConfigReader.readProfileFromInfrastrucure();
|
GNADataEntryConfigProfile config = gnaConfigReader.readProfileFromInfrastrucure();
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
package org.gcube.application.geoportalcommon.shared.config;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.gcube.application.geoportalcommon.shared.ItemField;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Class ItemFieldsConfig.
|
|
||||||
*
|
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
||||||
*
|
|
||||||
* Dec 20, 2021
|
|
||||||
*/
|
|
||||||
public class ItemFieldsConfig implements Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 5396430840723300173L;
|
|
||||||
private List<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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +1,8 @@
|
||||||
package org.gcube.application.geoportalcommon.shared.exception;
|
package org.gcube.application.geoportalcommon.shared.exception;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class GNAUserRightsConfigException extends Exception {
|
public class GNAConfigException extends Exception {
|
||||||
public GNAUserRightsConfigException(String message) {
|
public GNAConfigException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,7 +24,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class TestGNACommon {
|
public class TestGNACommon {
|
||||||
|
|
||||||
private static String TOKEN = "8e74a17c-92f1-405a-b591-3a6090066248-98187548";
|
private static String TOKEN = "";
|
||||||
private static String CONTEXT = "/gcube/devsec/devVRE";
|
private static String CONTEXT = "/gcube/devsec/devVRE";
|
||||||
private static String USERNAME = "francesco.mangiacrapa";
|
private static String USERNAME = "francesco.mangiacrapa";
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class TestGNACommon {
|
||||||
|
|
||||||
ScopeProvider.instance.set(CONTEXT);
|
ScopeProvider.instance.set(CONTEXT);
|
||||||
GeoportalCommon gc = new GeoportalCommon();
|
GeoportalCommon gc = new GeoportalCommon();
|
||||||
GNADataViewerConfigProfile profile = gc.readGNADataViewConfig(null);
|
GNADataViewerConfigProfile profile = gc.readGNADataViewerConfig(null);
|
||||||
System.out.println("Returning profile: " + profile);
|
System.out.println("Returning profile: " + profile);
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,23 @@ public class TestGNACommon {
|
||||||
@Test
|
@Test
|
||||||
public void readGNDataEntryConfigsFromIS() throws Exception {
|
public void readGNDataEntryConfigsFromIS() throws Exception {
|
||||||
|
|
||||||
|
Thread thread = new Thread() {
|
||||||
|
public void run() {
|
||||||
|
geoCommon();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Thread thread2 = new Thread() {
|
||||||
|
public void run() {
|
||||||
|
geoCommon();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
thread.run();
|
||||||
|
thread2.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void geoCommon() {
|
||||||
GeoportalCommon r = new GeoportalCommon();
|
GeoportalCommon r = new GeoportalCommon();
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set(CONTEXT);
|
ScopeProvider.instance.set(CONTEXT);
|
||||||
|
@ -123,7 +140,7 @@ public class TestGNACommon {
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set(CONTEXT);
|
ScopeProvider.instance.set(CONTEXT);
|
||||||
GNADataViewerConfigProfile configurations = r
|
GNADataViewerConfigProfile configurations = r
|
||||||
.readGNADataViewConfig(GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP);
|
.readGNADataViewerConfig(null);
|
||||||
|
|
||||||
System.out.println("Map layers are:");
|
System.out.println("Map layers are:");
|
||||||
System.out.println(configurations.getMapLayers());
|
System.out.println(configurations.getMapLayers());
|
||||||
|
|
Loading…
Reference in New Issue