Integrated roles into ActionDefinition by reading from the Handler
"LifecycleManagement"
This commit is contained in:
parent
c998a39f11
commit
564afb38e8
|
@ -7,6 +7,7 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -23,6 +24,7 @@ import org.gcube.application.geoportal.common.model.document.lifecycle.Lifecycle
|
|||
import org.gcube.application.geoportal.common.model.document.relationships.Relationship;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.gcube.application.geoportalcommon.geoportal.GeoportalConfigUtil;
|
||||
import org.gcube.application.geoportalcommon.geoportal.config.ActionDefinition;
|
||||
import org.gcube.application.geoportalcommon.geoportal.config.FilePath;
|
||||
import org.gcube.application.geoportalcommon.geoportal.config.GcubeProfile;
|
||||
|
@ -106,7 +108,7 @@ public class ConvertToDataValueObjectModel {
|
|||
|
||||
List<HandlerDeclarationDV> listHandlersDV = new ArrayList<HandlerDeclarationDV>();
|
||||
if (handlersIds != null) {
|
||||
LOG.info("List of input handlersIds is "+handlersIds+", converting it");
|
||||
LOG.info("List of input handlersIds is " + handlersIds + ", converting it");
|
||||
Map<String, List<HandlerDeclaration>> handlersMapByID = ucd.getHandlersMapByID();
|
||||
|
||||
if (handlersMapByID != null) {
|
||||
|
@ -114,7 +116,7 @@ public class ConvertToDataValueObjectModel {
|
|||
List<HandlerDeclaration> listHandlerDeclaration = handlersMapByID.get(handlersId);
|
||||
for (HandlerDeclaration handlerDeclaration : listHandlerDeclaration) {
|
||||
LOG.debug("converting handler {}", handlerDeclaration);
|
||||
HandlerDeclarationDV hdDV = toHandlerDeclarationDV(handlerDeclaration, ucd.getName());
|
||||
HandlerDeclarationDV hdDV = toHandlerDeclarationDV(handlerDeclaration, ucd);
|
||||
if (hdDV != null) {
|
||||
LOG.debug("handler converted to {}", hdDV);
|
||||
listHandlersDV.add(hdDV);
|
||||
|
@ -131,7 +133,7 @@ public class ConvertToDataValueObjectModel {
|
|||
List<HandlerDeclaration> listHandlerDeclaration = ucd.getHandlers();
|
||||
for (HandlerDeclaration handlerDeclaration : listHandlerDeclaration) {
|
||||
LOG.debug("converting handler {}", handlerDeclaration);
|
||||
HandlerDeclarationDV hdDV = toHandlerDeclarationDV(handlerDeclaration, ucd.getName());
|
||||
HandlerDeclarationDV hdDV = toHandlerDeclarationDV(handlerDeclaration, ucd);
|
||||
if (hdDV != null) {
|
||||
LOG.debug("handler converted to {}", hdDV);
|
||||
listHandlersDV.add(hdDV);
|
||||
|
@ -177,10 +179,12 @@ public class ConvertToDataValueObjectModel {
|
|||
* @return the handler declaration DV
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static HandlerDeclarationDV toHandlerDeclarationDV(HandlerDeclaration handlerDeclaration, String profileName,
|
||||
GEOPORTAL_CONFIGURATION_TYPE... readConfigs) throws Exception {
|
||||
LOG.debug("toHandlerDeclarationDV called [handlerDeclaration: "+handlerDeclaration+"], [profileName: "+profileName+"], [readConfigs: "+readConfigs+"]");
|
||||
|
||||
public static HandlerDeclarationDV toHandlerDeclarationDV(HandlerDeclaration handlerDeclaration,
|
||||
UseCaseDescriptor ucd, GEOPORTAL_CONFIGURATION_TYPE... readConfigs) throws Exception {
|
||||
String profileName = ucd.getName();
|
||||
LOG.debug("toHandlerDeclarationDV called [handlerDeclaration: " + handlerDeclaration + "], [profileName: "
|
||||
+ profileName + "], [readConfigs: " + readConfigs + "]");
|
||||
|
||||
if (handlerDeclaration == null) {
|
||||
LOG.warn(HandlerDeclaration.class.getSimpleName() + " is null");
|
||||
return null;
|
||||
|
@ -252,7 +256,6 @@ public class ConvertToDataValueObjectModel {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (jsonConfigurations == null) {
|
||||
String error = "No managed configurations as '"
|
||||
+ Arrays.asList(GEOPORTAL_CONFIGURATION_TYPE.values()).toString() + "' found in the handler "
|
||||
|
@ -260,9 +263,9 @@ public class ConvertToDataValueObjectModel {
|
|||
LOG.warn(error);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
for (GEOPORTAL_CONFIGURATION_TYPE geoportalConfigType : listGeoportalConfigType) {
|
||||
|
||||
|
||||
switch (geoportalConfigType) {
|
||||
case gcube_profiles: {
|
||||
|
||||
|
@ -271,8 +274,8 @@ public class ConvertToDataValueObjectModel {
|
|||
int i = 0;
|
||||
for (String asJSONString : jsonConfigurations) {
|
||||
LOG.debug(++i + ") the gCubeProfile is: " + asJSONString);
|
||||
GcubeProfile profile = org.gcube.application.geoportal.client.utils.Serialization.read(asJSONString,
|
||||
GcubeProfile.class);
|
||||
GcubeProfile profile = org.gcube.application.geoportal.client.utils.Serialization
|
||||
.read(asJSONString, GcubeProfile.class);
|
||||
listGcubeProfiles.add(toGcubeProfileDV(profile));
|
||||
}
|
||||
|
||||
|
@ -291,8 +294,8 @@ public class ConvertToDataValueObjectModel {
|
|||
int i = 0;
|
||||
for (String asJSONString : jsonConfigurations) {
|
||||
LOG.debug(++i + ") the itemField is: " + asJSONString);
|
||||
ItemField itemField = org.gcube.application.geoportal.client.utils.Serialization.read(asJSONString,
|
||||
ItemField.class);
|
||||
ItemField itemField = org.gcube.application.geoportal.client.utils.Serialization
|
||||
.read(asJSONString, ItemField.class);
|
||||
listItemFields.add(toItemFieldDV(itemField));
|
||||
}
|
||||
|
||||
|
@ -306,17 +309,39 @@ public class ConvertToDataValueObjectModel {
|
|||
|
||||
case actions_definition: {
|
||||
|
||||
List<ActionDefinitionDV> listActionsDef = new ArrayList<ActionDefinitionDV>(jsonConfigurations.size());
|
||||
List<ActionDefinitionDV> listActionsDef = new ArrayList<ActionDefinitionDV>(
|
||||
jsonConfigurations.size());
|
||||
|
||||
LOG.trace("Into " + GEOPORTAL_CONFIGURATION_TYPE.actions_definition + " handlers are: {}", ucd.getHandlers());
|
||||
|
||||
List<HandlerDeclaration> listHandlersLC = ucd
|
||||
.getHandlersByType(GEOPORTAL_DATA_HANDLER.gna_concessioni_lc.getType());
|
||||
|
||||
HandlerDeclaration handlerLC = null;
|
||||
if (listHandlersLC != null && listHandlersLC.size() > 0) {
|
||||
handlerLC = listHandlersLC.get(0);
|
||||
}
|
||||
LOG.debug("Into " + GEOPORTAL_CONFIGURATION_TYPE.actions_definition + " the handler "
|
||||
+ GEOPORTAL_DATA_HANDLER.gna_concessioni_lc + " is: {}", handlerLC);
|
||||
|
||||
int i = 0;
|
||||
for (String asJSONString : jsonConfigurations) {
|
||||
LOG.debug(++i + ") the ActionDefinition is: " + asJSONString);
|
||||
ActionDefinition actionDef = org.gcube.application.geoportal.client.utils.Serialization
|
||||
.read(asJSONString, ActionDefinition.class);
|
||||
listActionsDef.add(toActionDefinition(actionDef));
|
||||
|
||||
Set<String> roles = new HashSet<String>();
|
||||
if (handlerLC != null) {
|
||||
for (String stepID : actionDef.getCall_STEPS()) {
|
||||
List<String> listRoles = GeoportalConfigUtil.readRolesForSTEPId(handlerLC, stepID);
|
||||
roles.addAll(listRoles);
|
||||
}
|
||||
}
|
||||
listActionsDef.add(toActionDefinition(actionDef, roles));
|
||||
}
|
||||
|
||||
ConfigurationDV<List<ActionDefinitionDV>> dDV = new ConfigurationDV<List<ActionDefinitionDV>>(listActionsDef);
|
||||
ConfigurationDV<List<ActionDefinitionDV>> dDV = new ConfigurationDV<List<ActionDefinitionDV>>(
|
||||
listActionsDef);
|
||||
dDV.setConfiguration(listActionsDef);
|
||||
dDV.setConfigurationType(geoportalConfigType); // -> GEOPORTAL_CONFIGURATION_TYPE.actions_definition
|
||||
hdDV.setConfiguration(dDV);
|
||||
|
@ -406,9 +431,10 @@ public class ConvertToDataValueObjectModel {
|
|||
* To action definition.
|
||||
*
|
||||
* @param actionDefinition the action definition
|
||||
* @param roles the roles required to perform the callable STEPS
|
||||
* @return the action definition DV
|
||||
*/
|
||||
public static ActionDefinitionDV toActionDefinition(ActionDefinition actionDefinition) {
|
||||
public static ActionDefinitionDV toActionDefinition(ActionDefinition actionDefinition, Set<String> roles) {
|
||||
LOG.trace("toActionDefinition called");
|
||||
|
||||
if (actionDefinition == null) {
|
||||
|
@ -422,6 +448,7 @@ public class ConvertToDataValueObjectModel {
|
|||
actDef.setDescription(actionDefinition.getDescription());
|
||||
actDef.setDisplayOnPhase(actionDefinition.getDisplay_on_phase());
|
||||
actDef.setTitle(actionDefinition.getTitle());
|
||||
actDef.setRoles(roles);
|
||||
|
||||
LOG.info("returning: " + actionDefinition);
|
||||
return actDef;
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package org.gcube.application.geoportalcommon.geoportal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
|
||||
|
||||
/**
|
||||
* The Class GeoportalConfigUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Sep 15, 2022
|
||||
*/
|
||||
public class GeoportalConfigUtil {
|
||||
private static Logger LOG = LoggerFactory.getLogger(GeoportalConfigUtil.class);
|
||||
|
||||
/**
|
||||
* Read roles for STEP id.
|
||||
*
|
||||
* @param handler the handler
|
||||
* @param stepID the step ID
|
||||
* @return the list
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static List<String> readRolesForSTEPId(HandlerDeclaration handler, String stepID) throws Exception {
|
||||
LOG.debug("readRolesForSTEPId called for stepID {}, handler {}", stepID, handler);
|
||||
|
||||
List<String> roles = new ArrayList<String>();
|
||||
try {
|
||||
|
||||
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
|
||||
.jsonProvider(new JsonOrgJsonProvider()).build();
|
||||
|
||||
String toJSON = handler.getConfiguration().toJson();
|
||||
LOG.debug("Handler to JSON: " + toJSON);
|
||||
JSONObject jObject = new JSONObject(toJSON);
|
||||
JsonPath jsonPath = JsonPath.compile("$.step_access[?(@.STEP == '" + stepID + "' )].roles");
|
||||
LOG.trace("jsonPath: " + jsonPath.getPath());
|
||||
// $..book[?(@.price <= $['expensive'])]
|
||||
JSONArray data = jsonPath.read(jObject, configuration);
|
||||
LOG.debug("jsonPath matching data lenght: " + data.length());
|
||||
HashSet<String> listdata = new HashSet<String>(data.length());
|
||||
|
||||
if(data.length()>0) {
|
||||
LOG.debug("stepID found");
|
||||
try {
|
||||
JSONArray arrayRoles = new JSONArray(data.get(0).toString());
|
||||
for (int i = 0; i < arrayRoles.length(); i++) {
|
||||
String role = arrayRoles.get(i).toString();
|
||||
LOG.info("for STEP_ID {} read role {}", stepID, role);
|
||||
listdata.add(role);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
LOG.warn("Error on reading array roles for STEP_ID: "+stepID, e);
|
||||
}
|
||||
}
|
||||
|
||||
roles = listdata.stream().collect(Collectors.toList());
|
||||
LOG.info("for STEP_ID {} returning Roles {} ", stepID, roles);
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Error occurred on reading roles into handler {} returning no role", handler);
|
||||
|
||||
}
|
||||
|
||||
return roles;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package org.gcube.application.geoportalcommon.shared.geoportal.config;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
public class ActionDefinitionDV implements GeoportalConfigurationID, Serializable {
|
||||
|
||||
|
@ -17,6 +18,8 @@ public class ActionDefinitionDV implements GeoportalConfigurationID, Serializabl
|
|||
|
||||
private String configID;
|
||||
|
||||
public Set<String> roles;
|
||||
|
||||
public ActionDefinitionDV() {
|
||||
|
||||
}
|
||||
|
@ -81,6 +84,14 @@ public class ActionDefinitionDV implements GeoportalConfigurationID, Serializabl
|
|||
this.configID = configID;
|
||||
}
|
||||
|
||||
public Set<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Set<String> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -96,6 +107,8 @@ public class ActionDefinitionDV implements GeoportalConfigurationID, Serializabl
|
|||
builder.append(Arrays.toString(displayOnPhase));
|
||||
builder.append(", configID=");
|
||||
builder.append(configID);
|
||||
builder.append(", roles=");
|
||||
builder.append(roles);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ public enum GEOPORTAL_DATA_HANDLER {
|
|||
geoportal_data_list("org.gcube.portlets.user.geoportal-data-list", "DATA_LIST_GUI"),
|
||||
geoportal_data_entry("org.gcube.portlets.user.geoportal-data-entry-app", "DATA_ENTRY_GUI"),
|
||||
geoportal_workflow_action_list("org.gcube.portlets.user.geoportal-workflow-action-list","WORKFLOW_ACTION_LIST_GUI"),
|
||||
gna_concessionio_lc("GNA-CONCESSIONI-LC", "LifecycleManagement");
|
||||
gna_concessioni_lc("GNA-CONCESSIONI-LC", "LifecycleManagement");
|
||||
|
||||
String id;
|
||||
String type;
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
|
||||
|
@ -43,7 +44,7 @@ public class UCD_Tests {
|
|||
// private static String TOKEN = ""; //preVRE
|
||||
|
||||
private static String CONTEXT = "/gcube/devsec/devVRE";
|
||||
private static String TOKEN = ""; // devVRE
|
||||
private static String TOKEN = "c41a00c0-7897-48d2-a67a-05190d6ce5e6-98187548"; // devVRE
|
||||
|
||||
private static String PROFILE_ID = "profiledConcessioni";
|
||||
|
||||
|
@ -117,7 +118,7 @@ public class UCD_Tests {
|
|||
* @return the UCD for data entry handler ids
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
// @Test
|
||||
//@Test
|
||||
public void getUCDFor_DataEntry_HandlerIds() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
@ -207,7 +208,7 @@ public class UCD_Tests {
|
|||
try {
|
||||
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
|
||||
ucd = client.getUCDForId(PROFILE_ID);
|
||||
handlers = client.getHandlersByType(PROFILE_ID, GEOPORTAL_DATA_HANDLER.gna_concessionio_lc.getType());
|
||||
handlers = client.getHandlersByType(PROFILE_ID, GEOPORTAL_DATA_HANDLER.gna_concessioni_lc.getType());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -226,7 +227,7 @@ public class UCD_Tests {
|
|||
* @return the roles for STEP id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
//@Test
|
||||
public void getRolesForSTEPId() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
@ -238,8 +239,8 @@ public class UCD_Tests {
|
|||
|
||||
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
|
||||
ucd = client.getUCDForId(PROFILE_ID);
|
||||
handlers = client.getHandlersByType(PROFILE_ID, GEOPORTAL_DATA_HANDLER.gna_concessionio_lc.getType());
|
||||
|
||||
handlers = client.getHandlersByType(PROFILE_ID, GEOPORTAL_DATA_HANDLER.gna_concessioni_lc.getType());
|
||||
|
||||
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
|
||||
.jsonProvider(new JsonOrgJsonProvider()).build();
|
||||
|
||||
|
@ -275,7 +276,7 @@ public class UCD_Tests {
|
|||
* @return the configurations for UC D data handlers
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public void getConfigurations_ForUCD_Data_Handlers() throws Exception {
|
||||
ScopeProvider.instance.set(CONTEXT);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
|
|
Loading…
Reference in New Issue