Browse Source

Added check for ssd already present

master
Giancarlo Panichi 1 month ago
parent
commit
ec06374a3b
  1. 1
      .settings/org.eclipse.core.resources.prefs
  2. 58
      src/main/java/org/gcube/portlets/admin/systemservicedefinition/is/InformationSystemUtils.java
  3. 1
      src/main/java/org/gcube/portlets/admin/systemservicedefinition/shared/Constants.java
  4. 8
      src/main/webapp/html/systemservicedefinition/simpleProgressBar.jsp
  5. 16
      src/main/webapp/html/systemservicedefinition/ssd_create.jsp
  6. 2
      src/main/webapp/html/systemservicedefinition/view.jsp

1
.settings/org.eclipse.core.resources.prefs

@ -1,6 +1,7 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/main/webapp/html/systemservicedefinition/view.jsp=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

58
src/main/java/org/gcube/portlets/admin/systemservicedefinition/is/InformationSystemUtils.java

@ -68,10 +68,58 @@ public class InformationSystemUtils {
}
}
public static void checkSSDPresent(DefinitionItem definitionItem, String category, String scope)
throws Exception {
try {
if (definitionItem == null || definitionItem.getClientId() == null
|| definitionItem.getClientId().isEmpty())
throw new Exception("Invalid definition: " + definitionItem);
if (category == null || category.isEmpty())
throw new Exception("Invalid category: " + category);
if (scope == null || scope.isEmpty())
throw new Exception("Invalid scope: " + scope);
ScopeProvider.instance.set(scope);
// AccessTokenProvider.instance.set(token);
// SecurityTokenProvider.instance.set(token);
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq '" + category + "'")
.addCondition("$resource/Profile/Name/text() eq '" + definitionItem.getClientId() + "'");
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
for(ServiceEndpoint ssd: resources) {
if (definitionItem.getClientId().compareTo(ssd.profile().name()) == 0) {
StringBuilder error=new StringBuilder();
error.append("System Service ");
error.append(definitionItem.getClientId());
error.append(" already present in the scope: ");
error.append(scope);
logger.error(error.toString());
throw new Exception(error.toString());
}
}
logger.debug("System Service not already present on IS in scope: "+scope);
return ;
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
throw e;
}
}
public static ArrayList<DefinitionItem> retrieveSSD(String category, String scope) throws Exception {
try {
logger.debug("Retrieve System Services Definition on IS");
if (category == null || category.isEmpty())
throw new Exception("Invalid category: " + category);
if (scope == null || scope.isEmpty())
throw new Exception("Invalid scope: " + scope);
@ -133,6 +181,8 @@ public class InformationSystemUtils {
* if (token == null || token.isEmpty()) throw new Exception("Invalid token: " +
* token);
*/
checkSSDPresent(definitionItem, category, scope);
IAMService iamService = retrieveIAMService(scope);
@ -217,14 +267,14 @@ public class InformationSystemUtils {
List<ServiceEndpoint> resources = client.submit(query);
if (resources != null && !resources.isEmpty()) {
ServiceEndpoint toDelete=resources.get(0);
ServiceEndpoint toDelete = resources.get(0);
logger.debug("Requested delete: {}", toDelete);
try {
RegistryPublisher publisher = RegistryPublisherFactory.create();
publisher.remove(toDelete);
} catch (Exception e) {
logger.error("Error publishing the ssd on IS: {}", e.getLocalizedMessage(), e);
throw e;
@ -232,7 +282,7 @@ public class InformationSystemUtils {
logger.debug("Deleted on IS");
} else {
String error="No resources found with name: "+definitionItem.getClientId();
String error = "No resources found with name: " + definitionItem.getClientId();
logger.error(error);
throw new Exception(error);
}

1
src/main/java/org/gcube/portlets/admin/systemservicedefinition/shared/Constants.java

@ -11,7 +11,6 @@ public class Constants {
public static final String DEFAULT_USER = "giancarlo.panichi";
public static final String DEFAULT_SCOPE = "/gcube";
public static final String DEFAULT_TOKEN = "";
public static final String DEFAULT_ROLE = "OrganizationMember";
// Session

8
src/main/webapp/html/systemservicedefinition/simpleProgressBar.jsp

@ -45,13 +45,9 @@ function move() {
id=setInterval(frame, 10);
}
function sendRequest(formName, elem){
console.log("Send Request");
elem.disabled=true;
function loadingActive(){
console.log("Loading...");
move();
let frm=document.getElementById(formName);
document.getElementById("act").value="submit";
frm.submit();
}
</script>

16
src/main/webapp/html/systemservicedefinition/ssd_create.jsp

@ -2,11 +2,11 @@
<portlet:actionURL name="createDefinition" var="createDefinitionURL" />
<liferay-ui:error key="error-invalid-clientId"
message="Invalid client id!" />
message="Invalid Client Id!" />
<liferay-ui:error key="error-invalid-clientId-space"
message="Invalid client id! Space characters are not allowed." />
message="Invalid Client Id! Space characters are not allowed." />
<liferay-ui:error key="error-invalid-description"
message="Invalid description!" />
message="Invalid Description!" />
<form id="createDefinitionForm"
@ -25,7 +25,7 @@
<input type="hidden" id="act" name="act" value="">
<div>
<button class="btn btn-primary"
onclick="sendRequest('createDefinitionForm', this)">Save</button>
onclick="createDefinition(this)">Save</button>
<button class="btn btn-default"
onclick="cancel()">Cancel</button>
</div>
@ -38,6 +38,14 @@ function cancel(){
location.href = '<%=createDefinitionURL.toString()%>';
}
function createDefinition(elem){
elem.disabled=true;
document.getElementById("act").value="submit";
let frm=document.getElementById("createDefinitionForm");
frm.submit();
loadingActive();
}
</script>
<%@include file="simpleProgressBar.jsp" %>

2
src/main/webapp/html/systemservicedefinition/view.jsp

@ -37,7 +37,7 @@ pageContext.setAttribute("currentUsername", currentUsername);
<script src="<%=renderRequest.getContextPath()%>/js/buttons.html5.min.js"></script>
<script src="<%=renderRequest.getContextPath()%>/js/buttons.print.min.js"></script>
<p>Use this portlet to automatically create or delete System Services.</p>
<p>Use this portlet to automatically create or delete system services, our internal services that carry out "system" operations with the need to be authorised to access other services with every active contexts of the infrastructure.</p>
<liferay-ui:error key="error-session" message="Invalid Session please refresh the page!" />
<liferay-ui:error key="error-create-definition" message="Error creating the definition!" />

Loading…
Cancel
Save