Added check for ssd already present

This commit is contained in:
Giancarlo Panichi 2021-10-15 18:43:22 +02:00
parent fbbfe752e0
commit ec06374a3b
6 changed files with 70 additions and 16 deletions

View File

@ -1,6 +1,7 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=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/java=UTF-8
encoding//src/test/resources=UTF-8 encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8

View File

@ -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 { public static ArrayList<DefinitionItem> retrieveSSD(String category, String scope) throws Exception {
try { try {
logger.debug("Retrieve System Services Definition on IS"); logger.debug("Retrieve System Services Definition on IS");
if (category == null || category.isEmpty())
throw new Exception("Invalid category: " + category);
if (scope == null || scope.isEmpty()) if (scope == null || scope.isEmpty())
throw new Exception("Invalid scope: " + scope); throw new Exception("Invalid scope: " + scope);
@ -133,6 +181,8 @@ public class InformationSystemUtils {
* if (token == null || token.isEmpty()) throw new Exception("Invalid token: " + * if (token == null || token.isEmpty()) throw new Exception("Invalid token: " +
* token); * token);
*/ */
checkSSDPresent(definitionItem, category, scope);
IAMService iamService = retrieveIAMService(scope); IAMService iamService = retrieveIAMService(scope);
@ -217,14 +267,14 @@ public class InformationSystemUtils {
List<ServiceEndpoint> resources = client.submit(query); List<ServiceEndpoint> resources = client.submit(query);
if (resources != null && !resources.isEmpty()) { if (resources != null && !resources.isEmpty()) {
ServiceEndpoint toDelete=resources.get(0); ServiceEndpoint toDelete = resources.get(0);
logger.debug("Requested delete: {}", toDelete); logger.debug("Requested delete: {}", toDelete);
try { try {
RegistryPublisher publisher = RegistryPublisherFactory.create(); RegistryPublisher publisher = RegistryPublisherFactory.create();
publisher.remove(toDelete); publisher.remove(toDelete);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error publishing the ssd on IS: {}", e.getLocalizedMessage(), e); logger.error("Error publishing the ssd on IS: {}", e.getLocalizedMessage(), e);
throw e; throw e;
@ -232,7 +282,7 @@ public class InformationSystemUtils {
logger.debug("Deleted on IS"); logger.debug("Deleted on IS");
} else { } else {
String error="No resources found with name: "+definitionItem.getClientId(); String error = "No resources found with name: " + definitionItem.getClientId();
logger.error(error); logger.error(error);
throw new Exception(error); throw new Exception(error);
} }

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ pageContext.setAttribute("currentUsername", currentUsername);
<script src="<%=renderRequest.getContextPath()%>/js/buttons.html5.min.js"></script> <script src="<%=renderRequest.getContextPath()%>/js/buttons.html5.min.js"></script>
<script src="<%=renderRequest.getContextPath()%>/js/buttons.print.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-session" message="Invalid Session please refresh the page!" />
<liferay-ui:error key="error-create-definition" message="Error creating the definition!" /> <liferay-ui:error key="error-create-definition" message="Error creating the definition!" />