created GR "GNA-DataEntry-Configs" and using it

feature_22286
Francesco Mangiacrapa 2 years ago
parent deb666d536
commit d19f293930

@ -249,6 +249,11 @@ public class GeonaMainTabPanel extends Composite {
@Override
public void onClick(ClickEvent event) {
alertSearchFor.setText(record_FIELD.getDisplayName());
if(searchField.getText().length() >= MIN_LENGHT_SERCHING_STRING) {
doSearchEvent();
}
}
});
}
@ -315,14 +320,7 @@ public class GeonaMainTabPanel extends Composite {
GWT.log("CHAR CODE: " + event.getCharCode());
if (com.google.gwt.event.dom.client.KeyCodes.KEY_ENTER == event.getCharCode()) {
GWT.log(searchField.getText());
String searchText = searchField.getText();
if (searchText.length() < MIN_LENGHT_SERCHING_STRING) {
Window.alert("Please enter at least "+MIN_LENGHT_SERCHING_STRING+" characters");
return;
}
resetSearch.setVisible(true);
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
doSearchEvent();
}
}
@ -339,6 +337,17 @@ public class GeonaMainTabPanel extends Composite {
});
}
private void doSearchEvent() {
String searchText = searchField.getText();
if (searchText.length() < MIN_LENGHT_SERCHING_STRING) {
Window.alert("Please enter at least "+MIN_LENGHT_SERCHING_STRING+" characters");
return;
}
resetSearch.setVisible(true);
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
}
private String toLabelFilter(RECORD_FIELD orderBy, ORDER direction) {
String labelFilter = orderBy.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name();

@ -35,7 +35,8 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitl
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService;
import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader;
import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigs;
import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigsProfileReader;
import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM;
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
import org.gcube.portlets.user.geoportaldataentry.shared.DisplayField;
@ -552,13 +553,19 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
}
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.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());
}
@ -593,12 +600,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
public List<DisplayField> listDisplayFields() {
List<DisplayField> listDisplayFields = new ArrayList<DisplayField>();
DisplayField df = new DisplayField("Name", Arrays.asList("nome"), true);
// etc
return listDisplayFields;
}
/**
@ -916,12 +920,14 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
try {
PortalContext pContext = PortalContext.getConfiguration();
user = pContext.getCurrentUser(this.getThreadLocalRequest());
List<RoleRights> listUserRightsForRole = GNARoleRitghtsConfigReader.readRoleRightsConfig();
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
GNADataEntryConfigsProfileReader gnaConfigReader = new GNADataEntryConfigsProfileReader();
GNADataEntryConfigs config = gnaConfigReader.readProfileFromInfrastrucure();
List<RoleRights> listUserRightsForRole = config.getPermissionsForRole();
// DEV MODE
if (!SessionUtil.isIntoPortal()) {
LOG.warn("OUT OF PORTAL - DEV MODE detected");
GcubeUserRole myRole = GcubeUserRole.DATA_MANAGER;
GcubeUserRole myRole = GcubeUserRole.DATA_EDITOR;
for (RoleRights roleRight : listUserRightsForRole) {
if (roleRight.getUserRole().equals(myRole)) {

@ -1,5 +1,6 @@
package org.gcube.portlets.user.geoportaldataentry.server.config;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -7,62 +8,93 @@ import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
// TODO: Auto-generated Javadoc
/**
* The Class FileUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Apr 21, 2020
* @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
* @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();
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 {
/**
* 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.portlets.user.geoportaldataentry.server.config;
import java.util.List;
import org.gcube.portlets.user.geoportaldataentry.shared.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.portlets.user.geoportaldataentry.server.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.exception.ApplicationProfileNotFoundException;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM;
import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException;
import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE;
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;
}
}

@ -1,166 +0,0 @@
package org.gcube.portlets.user.geoportaldataentry.server.config;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM;
import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException;
import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.allen_sauer.gwt.log.client.Log;
/**
* The Class GNARoleRitghtsConfigReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 25, 2021
*/
public class GNARoleRitghtsConfigReader {
private static final String USER_RIGHTS_CONFIG_FILENAME = "GNA_RoleRights_Configurations.csv";
private static Logger LOG = LoggerFactory.getLogger(GNARoleRitghtsConfigReader.class);
public static final String WRITE_OWN_CONFIG = "WRITE_OWN";
public static final String WRITE_ANY_CONFIG = "WRITE_ANY";
/**
* Read user rights config.
*
* @return the list
* @throws GNAUserRightsConfigException the GNA user rights config not
* found exception
*/
public static List<RoleRights> readRoleRightsConfig() throws GNAUserRightsConfigException {
LOG.debug("readRoleRightsConfig called");
File configurationFile = null;
try {
InputStream in = (InputStream) GNARoleRitghtsConfigReader.class.getResourceAsStream(USER_RIGHTS_CONFIG_FILENAME);
configurationFile = FileUtil.inputStreamToTempFile(in, USER_RIGHTS_CONFIG_FILENAME);
CSVReader reader = new CSVReader(configurationFile);
CSVFile csvFile = reader.getCsvFile();
List<RoleRights> listUserRights = new ArrayList<RoleRights>();
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 configuration file " + USER_RIGHTS_CONFIG_FILENAME, e);
throw new GNAUserRightsConfigException("Error on reading the configuration file. Is the file '"
+ USER_RIGHTS_CONFIG_FILENAME + "' in the application path?");
} finally {
if (configurationFile != null) {
try {
configurationFile.delete();
} catch (Exception e) {
// silent
}
}
}
}
/**
* 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;
}
}

@ -1,5 +0,0 @@
,CREATE_NEW_PROJECT,VIEW_ON_MAP,VIEW_REPORT,EDIT_PROJECT,DELETE_PROJECT
OPERATION_TYPE,W,R,RW,RW,RW
Data-Member,no,yes,no,no,no
Data-Editor,yes,yes,yes,yes,yes
Data-Manager,yes,yes,yes,yes,yes
1 CREATE_NEW_PROJECT VIEW_ON_MAP VIEW_REPORT EDIT_PROJECT DELETE_PROJECT
2 OPERATION_TYPE W R RW RW RW
3 Data-Member no yes no no no
4 Data-Editor yes yes yes yes yes
5 Data-Manager yes yes yes yes yes

@ -18,8 +18,7 @@ import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedReque
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights;
import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigsProfileReader;
import org.junit.Before;
import org.junit.Test;
@ -39,7 +38,7 @@ public class TestClass {
SecurityTokenProvider.instance.set(TOKEN);
}
//@Test
// @Test
public void getListConcessioniTest() throws Exception {
MongoConcessioni clientMongo = mongoConcessioni().build();
Iterator<Concessione> concessioni = clientMongo.getList();
@ -56,68 +55,61 @@ public class TestClass {
System.out.println(++i + " " + concessione);
}
}
@Test
// @Test
public void queryConcessioniTest() throws Exception {
try {
MongoConcessioni clientMongo = mongoConcessioni().build();
int offsetIndex = 0;
int limitIndex = 25;
Direction sDirection = Direction.ASCENDING;
List<String> orderByFields = Arrays.asList("nome");
Map<String, Object> searchFields = new HashMap<String, Object>();
searchFields.put("nome", "test");
searchFields.put("authors", "fra");
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(orderByFields);
request.setOrdering(ordering);
Document query = null;
if(searchFields!=null) {
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
query = new Document();
for (String key : searchFields.keySet()) {
//builder.append(key, new BasicDBObject("$eq", searchFields.get(key)));
BasicDBObject bs = new BasicDBObject();
bs.append("$regex", searchFields.get(key));
bs.append("$options", "i");
builder.append(key, bs);
//query.put(key, new BasicDBObject("$eq", searchFields.get(key)));
//query = new Document(key, searchFields.get(key));
}
MongoConcessioni clientMongo = mongoConcessioni().build();
int offsetIndex = 0;
int limitIndex = 25;
Direction sDirection = Direction.ASCENDING;
List<String> orderByFields = Arrays.asList("nome");
Map<String, Object> searchFields = new HashMap<String, Object>();
searchFields.put("nome", "test");
searchFields.put("authors", "fra");
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(orderByFields);
request.setOrdering(ordering);
Document query = null;
if (searchFields != null) {
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
query = new Document();
for (String key : searchFields.keySet()) {
// builder.append(key, new BasicDBObject("$eq", searchFields.get(key)));
BasicDBObject bs = new BasicDBObject();
bs.append("$regex", searchFields.get(key));
bs.append("$options", "i");
builder.append(key, bs);
// query.put(key, new BasicDBObject("$eq", searchFields.get(key)));
// query = new Document(key, searchFields.get(key));
}
// query.putAll(builder.get().toMap());
// request.setFilter(query);
BasicDBList list = new BasicDBList();
list.add(builder.get().toMap());
query.put("$or", list);
//or(query);
request.setFilter(query);
//************************************************ AND
BasicDBList list = new BasicDBList();
list.add(builder.get().toMap());
query.put("$or", list);
// or(query);
request.setFilter(query);
// ************************************************ AND
// query = new Document();
// for (String key : searchFields.keySet()) {
// //AND
@ -128,75 +120,74 @@ public class TestClass {
//
// }
// request.setFilter(query);
//******************************************** END AND
}
//OR
/*query = new Document();
BasicDBObject container = new BasicDBObject();
BsonArray bArray = new BsonArray();
for (String key : searchFields.keySet()) {
//AND
BasicDBObject bs = new BasicDBObject();
bs.append("$regex", searchFields.get(key));
bs.append("$options", "i");
query.put(key, bs);
//container.put(key, bs);
// BasicDBObject bs2 = new BasicDBObject();
// bs2.append("$regex", searchFields.get(key));
// bs2.append("$options", "i");
// BsonDocument bsK = new BsonDocument();
// bsK.append(key, new BsonString(bs2.toJson()));
// bArray.add(bsK);
}
// query.put("$or", bArray);
BasicDBList list = new BasicDBList();
list.add(query);
Document orDocument = new Document();
orDocument.put("$or", list);
//
query = orDocument;
request.setFilter(query);*/
System.out.println("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
System.out.println("Direction: " + sDirection);
System.out.println("Order by Fields: " + orderByFields);
System.out.println("Search for: " + query);
System.out.println("Search for Query to JSON: "+query.toJson());
Iterator<Concessione> concessioni = clientMongo.query(request);
if(concessioni.hasNext()) {
System.out.println("Found concessioni, printing them...");
}else
System.out.println("No concessione found");
if (concessioni != null) {
while (concessioni.hasNext()) {
Concessione concessione = (Concessione) concessioni.next();
System.out.println(concessione.getNome());
// ******************************************** END AND
}
// OR
/*
* query = new Document(); BasicDBObject container = new BasicDBObject();
* BsonArray bArray = new BsonArray(); for (String key : searchFields.keySet())
* { //AND BasicDBObject bs = new BasicDBObject(); bs.append("$regex",
* searchFields.get(key)); bs.append("$options", "i"); query.put(key, bs);
*
* //container.put(key, bs);
*
*
* // BasicDBObject bs2 = new BasicDBObject(); // bs2.append("$regex",
* searchFields.get(key)); // bs2.append("$options", "i"); // BsonDocument bsK =
* new BsonDocument(); // bsK.append(key, new BsonString(bs2.toJson())); //
* bArray.add(bsK);
*
* } // query.put("$or", bArray);
*
* BasicDBList list = new BasicDBList(); list.add(query);
*
* Document orDocument = new Document(); orDocument.put("$or", list); // query =
* orDocument; request.setFilter(query);
*/
System.out.println("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
System.out.println("Direction: " + sDirection);
System.out.println("Order by Fields: " + orderByFields);
System.out.println("Search for: " + query);
System.out.println("Search for Query to JSON: " + query.toJson());
Iterator<Concessione> concessioni = clientMongo.query(request);
if (concessioni.hasNext()) {
System.out.println("Found concessioni, printing them...");
} else
System.out.println("No concessione found");
if (concessioni != null) {
while (concessioni.hasNext()) {
Concessione concessione = (Concessione) concessioni.next();
System.out.println(concessione.getNome());
}
}
}
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}
//@Test
// @Test
// public void readUserRights() throws Exception {
// new GNARoleRitghtsConfigReader();
// List<RoleRights> listUserRights = GNARoleRitghtsConfigReader.readRoleRightsConfig();
// System.out.println(listUserRights);
// }
@Test
public void readUserRights() throws Exception {
new GNARoleRitghtsConfigReader();
List<RoleRights> listUserRights = GNARoleRitghtsConfigReader.readRoleRightsConfig();
System.out.println(listUserRights);
GNADataEntryConfigsProfileReader r = new GNADataEntryConfigsProfileReader();
try {
r.readProfileFromInfrastrucure();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Loading…
Cancel
Save