Added delete operation
This commit is contained in:
parent
8fb3eb9a9d
commit
e7a98ef0aa
54
pom.xml
54
pom.xml
|
@ -17,12 +17,27 @@
|
|||
<description>
|
||||
Requesting Party Token Portlet
|
||||
</description>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
||||
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Giancarlo Panichi</name>
|
||||
<email>g.panichi@isti.cnr.it</email>
|
||||
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
|
||||
<roles>
|
||||
<role>architect</role>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
@ -147,38 +162,22 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope-maps</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.gcube.resourcemanagement</groupId>
|
||||
<artifactId>resourcemanager-client</artifactId>
|
||||
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency> -->
|
||||
<!-- <dependency> <groupId>org.gcube.resourcemanagement</groupId> <artifactId>resourcemanager-client</artifactId>
|
||||
<version>[1.0.0, 2.0.0-SNAPSHOT)</version> <scope>compile</scope> </dependency> -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>registry-publisher</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.gcube.resourcemanagement</groupId>
|
||||
<artifactId>ghn-manager-client</artifactId>
|
||||
<version>[1.1.0, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency> -->
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>common-gcore-resources</artifactId>
|
||||
</dependency> -->
|
||||
<!-- <dependency> <groupId>org.gcube.resourcemanagement</groupId> <artifactId>ghn-manager-client</artifactId>
|
||||
<version>[1.1.0, 2.0.0-SNAPSHOT)</version> <scope>compile</scope> </dependency> -->
|
||||
<!-- <dependency> <groupId>org.gcube.resources</groupId> <artifactId>common-gcore-resources</artifactId>
|
||||
</dependency> -->
|
||||
|
||||
<!-- Common Encryption -->
|
||||
<dependency>
|
||||
|
@ -232,7 +231,7 @@
|
|||
</dependency>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>com.liferay.maven.plugins</groupId>
|
||||
<artifactId>liferay-maven-plugin</artifactId>
|
||||
|
@ -254,7 +253,7 @@
|
|||
<pluginType>portlet</pluginType>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
|
@ -263,13 +262,16 @@
|
|||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!--
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<configuration>
|
||||
<encoding>${project.build.resources.encoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugin> -->
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -20,7 +20,7 @@ import org.gcube.portlets.admin.systemservicedefinition.definition.DefClientIdCo
|
|||
import org.gcube.portlets.admin.systemservicedefinition.definition.DefDescriptionComparator;
|
||||
import org.gcube.portlets.admin.systemservicedefinition.definition.DefinitionItem;
|
||||
import org.gcube.portlets.admin.systemservicedefinition.event.CreateSSDEvent;
|
||||
import org.gcube.portlets.admin.systemservicedefinition.event.CreateSSDEventPublisher;
|
||||
import org.gcube.portlets.admin.systemservicedefinition.event.DeleteSSDEvent;
|
||||
import org.gcube.portlets.admin.systemservicedefinition.is.InformationSystemUtils;
|
||||
import org.gcube.portlets.admin.systemservicedefinition.shared.Constants;
|
||||
import org.gcube.portlets.admin.systemservicedefinition.util.UserCredentials;
|
||||
|
@ -209,7 +209,7 @@ public class SystemServiceDefinition extends MVCPortlet {
|
|||
*/
|
||||
try {
|
||||
itemsList = InformationSystemUtils.retrieveSSD(Constants.SYSTEM_SERVICE_CATEGORY,
|
||||
userCredentials.getCurrentScope(), userCredentials.getAccessToken());
|
||||
userCredentials.getCurrentScope());
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving System Services from IS. {}", e.getLocalizedMessage(), e);
|
||||
throw new PortletException("Error retrieving System Services from IS. " + e.getLocalizedMessage(), e);
|
||||
|
@ -364,8 +364,8 @@ public class SystemServiceDefinition extends MVCPortlet {
|
|||
String secret = UUID.randomUUID().toString();
|
||||
DefinitionItem definitionItem = new DefinitionItem(clientId, description, username, secret);
|
||||
InformationSystemUtils.publishSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
|
||||
userCredentials.getCurrentScope(), userCredentials.getAccessToken());
|
||||
// publishCreateSSDEvent(definitionItem);
|
||||
userCredentials.getCurrentScope());
|
||||
publishCreateSSDEvent(definitionItem);
|
||||
SessionMessages.add(actionRequest, "success-definition-created");
|
||||
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
||||
} catch (Exception e) {
|
||||
|
@ -393,17 +393,7 @@ public class SystemServiceDefinition extends MVCPortlet {
|
|||
|
||||
}
|
||||
|
||||
private void publishCreateSSDEvent(DefinitionItem definitionItem) {
|
||||
logger.debug("Trying to send the event to create System Service");
|
||||
CreateSSDEvent toSend = new CreateSSDEvent(definitionItem);
|
||||
new CreateSSDEventPublisher().publish(toSend);
|
||||
logger.info("Done send event " + toSend.getName() + " for " + toSend.getUser());
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void editDefinition(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -465,33 +455,64 @@ public class SystemServiceDefinition extends MVCPortlet {
|
|||
}
|
||||
|
||||
paramsInfo(actionRequest);
|
||||
|
||||
|
||||
logger.debug("Delete Request");
|
||||
String clientId = ParamUtil.getString(actionRequest, "clientId");
|
||||
if (clientId == null || clientId.isEmpty()) {
|
||||
logger.error("Invalid client id: " + clientId);
|
||||
SessionErrors.add(actionRequest, "error-invalid-clientId");
|
||||
SessionMessages.add(actionRequest,
|
||||
PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
|
||||
PortalUtil.copyRequestParameters(actionRequest, actionResponse);
|
||||
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
DefinitionItem definitionItem=new DefinitionItem(clientId);
|
||||
InformationSystemUtils.deleteSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
|
||||
userCredentials.getCurrentScope());
|
||||
publishDeleteSSDEvent(definitionItem);
|
||||
SessionMessages.add(actionRequest, "success-definition-deleted");
|
||||
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
||||
|
||||
SessionMessages.add(actionRequest, "success-definition-deleted");
|
||||
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
||||
|
||||
/*
|
||||
* SessionErrors.add(actionRequest, "error-delete-definition");
|
||||
* SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) +
|
||||
* SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
|
||||
* actionResponse.setRenderParameter("jspPage",
|
||||
* "/html/systemservicedefinition/view.jsp");
|
||||
*/
|
||||
|
||||
/*
|
||||
* String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
|
||||
* ThemeDisplay themeDisplay =
|
||||
* (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
|
||||
*
|
||||
* PortletURL redirectURL =
|
||||
* PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
|
||||
* portletName,themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
|
||||
* redirectURL.setParameter("jspPage", "/registration.jsp");
|
||||
* SessionErrors.add(actionRequest, "WRONG_FIRST_NAME_ERROR");
|
||||
* actionResponse.sendRedirect(redirectURL.toString());
|
||||
*/
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(),e);
|
||||
SessionErrors.add(actionRequest, "error-delete-definition");
|
||||
SessionMessages.add(actionRequest,
|
||||
PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
|
||||
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void publishCreateSSDEvent(DefinitionItem definitionItem) {
|
||||
logger.debug("Trying to send the event to create System Service");
|
||||
CreateSSDEvent toCreate = new CreateSSDEvent(definitionItem);
|
||||
toCreate.publisher.publish(toCreate);
|
||||
logger.info("Done send create event " + toCreate.getName() + " for " + toCreate.getUser());
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void publishDeleteSSDEvent(DefinitionItem definitionItem) {
|
||||
logger.debug("Trying to send the event to delete System Service");
|
||||
DeleteSSDEvent toDelete = new DeleteSSDEvent(definitionItem);
|
||||
toDelete.publisher.publish(toDelete);
|
||||
logger.info("Done send delete event " + toDelete.getName() + " for " + toDelete.getUser());
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* private void createDefinition(ResourceRequest resourceRequest,
|
||||
* ResourceResponse resourceResponse, UserCredentials userCredentials) throws
|
||||
|
|
|
@ -16,6 +16,10 @@ public class DefinitionItem implements Serializable {
|
|||
private String username;
|
||||
private String secret;
|
||||
|
||||
public DefinitionItem(String clientId) {
|
||||
super();
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public DefinitionItem(String clientId, String description, String username, String secret) {
|
||||
super();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.portlets.admin.systemservicedefinition.event;
|
||||
|
||||
import org.gcube.portal.event.publisher.lr62.AbstractLR62EventPublisher;
|
||||
import org.gcube.portal.event.publisher.lr62.PortalEvent;
|
||||
import org.gcube.portlets.admin.systemservicedefinition.definition.DefinitionItem;
|
||||
|
||||
|
@ -12,6 +13,14 @@ public class CreateSSDEvent extends PortalEvent {
|
|||
|
||||
private static final long serialVersionUID = 1499288552188273747L;
|
||||
|
||||
public class CreateSSDEventPublisher extends AbstractLR62EventPublisher {
|
||||
public CreateSSDEventPublisher() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
public CreateSSDEventPublisher publisher;
|
||||
|
||||
public static final String NAME = "create_system_service";
|
||||
public static final String CLIENT_ID_ENTRY = "client_id";
|
||||
public static final String DESCRIPTION_ENTRY = "description";
|
||||
|
@ -19,6 +28,7 @@ public class CreateSSDEvent extends PortalEvent {
|
|||
|
||||
public CreateSSDEvent(DefinitionItem definitionItem) {
|
||||
super(NAME);
|
||||
publisher = new CreateSSDEventPublisher();
|
||||
setClientId(definitionItem.getClientId());
|
||||
setDescription(definitionItem.getDescription());
|
||||
setClientSecret(definitionItem.getSecret());
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package org.gcube.portlets.admin.systemservicedefinition.event;
|
||||
|
||||
import org.gcube.portal.event.publisher.lr62.AbstractLR62EventPublisher;
|
||||
|
||||
public class CreateSSDEventPublisher extends AbstractLR62EventPublisher {
|
||||
public CreateSSDEventPublisher() {
|
||||
super();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package org.gcube.portlets.admin.systemservicedefinition.event;
|
||||
|
||||
import org.gcube.portal.event.publisher.lr62.AbstractLR62EventPublisher;
|
||||
import org.gcube.portal.event.publisher.lr62.PortalEvent;
|
||||
import org.gcube.portlets.admin.systemservicedefinition.definition.DefinitionItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi
|
||||
*
|
||||
*/
|
||||
public class DeleteSSDEvent extends PortalEvent {
|
||||
|
||||
private static final long serialVersionUID = 1499288552188273747L;
|
||||
|
||||
public class DeleteSSDEventPublisher extends AbstractLR62EventPublisher {
|
||||
public DeleteSSDEventPublisher() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
public DeleteSSDEventPublisher publisher;
|
||||
|
||||
public static final String NAME = "delete_system_service";
|
||||
public static final String CLIENT_ID_ENTRY = "client_id";
|
||||
|
||||
public DeleteSSDEvent(DefinitionItem definitionItem) {
|
||||
super(NAME);
|
||||
publisher = new DeleteSSDEventPublisher();
|
||||
setClientId(definitionItem.getClientId());
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
set(CLIENT_ID_ENTRY, clientId);
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return (String) get(CLIENT_ID_ENTRY);
|
||||
}
|
||||
|
||||
}
|
|
@ -26,8 +26,7 @@ public class InformationSystemUtils {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class);
|
||||
|
||||
|
||||
public static IAMService retrieveIAMService(String scope, String token) throws Exception {
|
||||
public static IAMService retrieveIAMService(String scope) throws Exception {
|
||||
|
||||
try {
|
||||
logger.debug("Retrieve IAM Service on IS");
|
||||
|
@ -35,8 +34,10 @@ public class InformationSystemUtils {
|
|||
if (scope == null || scope.isEmpty())
|
||||
throw new Exception("Invalid scope: " + scope);
|
||||
|
||||
if (token == null || token.isEmpty())
|
||||
throw new Exception("Invalid token: " + scope);
|
||||
/*
|
||||
* if (token == null || token.isEmpty()) throw new Exception("Invalid token: " +
|
||||
* scope);
|
||||
*/
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
// AccessTokenProvider.instance.set(token);
|
||||
|
@ -45,19 +46,19 @@ public class InformationSystemUtils {
|
|||
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
|
||||
query.addCondition("$resource/Profile/Category/text() eq '" + Constants.IAM_SERVICE_CATEGORY + "'")
|
||||
.addCondition("$resource/Profile/Name/text() eq '" + Constants.IAM_SERVICE_NAME + "'");
|
||||
|
||||
|
||||
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
||||
|
||||
List<ServiceEndpoint> resources = client.submit(query);
|
||||
|
||||
IAMService iamService=null;
|
||||
|
||||
if(resources!=null&&!resources.isEmpty()) {
|
||||
ServiceEndpoint iams=resources.get(0);
|
||||
iamService=new IAMService(iams.profile().runtime().hostedOn());
|
||||
IAMService iamService = null;
|
||||
|
||||
if (resources != null && !resources.isEmpty()) {
|
||||
ServiceEndpoint iams = resources.get(0);
|
||||
iamService = new IAMService(iams.profile().runtime().hostedOn());
|
||||
}
|
||||
|
||||
logger.debug("IAM Services retrieved: {}",iamService);
|
||||
|
||||
logger.debug("IAM Services retrieved: {}", iamService);
|
||||
return iamService;
|
||||
|
||||
} catch (Throwable e) {
|
||||
|
@ -67,7 +68,7 @@ public class InformationSystemUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static ArrayList<DefinitionItem> retrieveSSD(String category, String scope, String token) throws Exception {
|
||||
public static ArrayList<DefinitionItem> retrieveSSD(String category, String scope) throws Exception {
|
||||
|
||||
try {
|
||||
logger.debug("Retrieve System Services Definition on IS");
|
||||
|
@ -75,8 +76,10 @@ public class InformationSystemUtils {
|
|||
if (scope == null || scope.isEmpty())
|
||||
throw new Exception("Invalid scope: " + scope);
|
||||
|
||||
if (token == null || token.isEmpty())
|
||||
throw new Exception("Invalid token: " + scope);
|
||||
/*
|
||||
* if (token == null || token.isEmpty()) throw new Exception("Invalid token: " +
|
||||
* scope);
|
||||
*/
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
// AccessTokenProvider.instance.set(token);
|
||||
|
@ -116,8 +119,7 @@ public class InformationSystemUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void publishSSD(DefinitionItem definitionItem, String category, String scope, String token)
|
||||
throws Exception {
|
||||
public static void publishSSD(DefinitionItem definitionItem, String category, String scope) throws Exception {
|
||||
if (definitionItem == null)
|
||||
throw new Exception("Invalid definition: " + definitionItem);
|
||||
|
||||
|
@ -127,56 +129,56 @@ public class InformationSystemUtils {
|
|||
if (scope == null || scope.isEmpty())
|
||||
throw new Exception("Invalid scope: " + scope);
|
||||
|
||||
if (token == null || token.isEmpty())
|
||||
throw new Exception("Invalid token: " + token);
|
||||
/*
|
||||
* if (token == null || token.isEmpty()) throw new Exception("Invalid token: " +
|
||||
* token);
|
||||
*/
|
||||
|
||||
IAMService iamService = retrieveIAMService(scope);
|
||||
|
||||
|
||||
IAMService iamService=retrieveIAMService(scope, token);
|
||||
|
||||
ServiceEndpoint toPublish = new ServiceEndpoint();
|
||||
logger.debug("Resource Type: {}",toPublish.type());
|
||||
logger.debug("Resource Type: {}", toPublish.type());
|
||||
/*
|
||||
* List<String> scopes = new ArrayList<String>(); scopes.add(scope);
|
||||
* Collection<String> col = toPublish.scopes().asCollection();
|
||||
* col.addAll(scopes);
|
||||
*/
|
||||
|
||||
|
||||
toPublish.newProfile();
|
||||
toPublish.profile().name(definitionItem.getClientId());
|
||||
toPublish.profile().description(definitionItem.getDescription());
|
||||
toPublish.profile().category(category);
|
||||
toPublish.profile().version("1.0.0");
|
||||
|
||||
|
||||
toPublish.profile().newRuntime();
|
||||
toPublish.profile().runtime().ghnId("");
|
||||
toPublish.profile().runtime().status("READY");
|
||||
toPublish.profile().runtime().hostedOn("d4science.org");
|
||||
|
||||
|
||||
toPublish.profile().newPlatform();
|
||||
toPublish.profile().platform().name("d4science");
|
||||
toPublish.profile().platform().version((short) 0);
|
||||
toPublish.profile().platform().minorVersion((short) 0);
|
||||
toPublish.profile().platform().revisionVersion((short) 0);
|
||||
toPublish.profile().platform().buildVersion((short) 0);
|
||||
|
||||
|
||||
|
||||
AccessPoint accessPoint = new AccessPoint();
|
||||
|
||||
// String encryptedPassword =
|
||||
// StringEncrypter.getEncrypter().encrypt(definitionItem.getSecret());
|
||||
String encryptedPassword = StringEncrypter.getEncrypter().encrypt(definitionItem.getSecret());
|
||||
accessPoint.name(definitionItem.getClientId());
|
||||
accessPoint.description("Keycloak client credentials");
|
||||
accessPoint.address(iamService.getAddress());
|
||||
accessPoint.credentials(definitionItem.getSecret(), definitionItem.getUsername());
|
||||
accessPoint.credentials(encryptedPassword, definitionItem.getUsername());
|
||||
toPublish.profile().accessPoints().add(accessPoint);
|
||||
|
||||
|
||||
logger.debug("Request publish: {}", toPublish);
|
||||
|
||||
try {
|
||||
|
||||
|
||||
// AccessTokenProvider.instance.set(token);
|
||||
//SecurityTokenProvider.instance.set(token);
|
||||
// SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
|
||||
RegistryPublisher publisher = RegistryPublisherFactory.create();
|
||||
|
||||
String id = publisher.create(toPublish).id();
|
||||
|
@ -191,6 +193,49 @@ public class InformationSystemUtils {
|
|||
logger.debug("Published on IS");
|
||||
|
||||
}
|
||||
|
||||
public static void deleteSSD(DefinitionItem definitionItem, String category, String scope) throws Exception {
|
||||
if (definitionItem == null)
|
||||
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);
|
||||
|
||||
if (resources != null && !resources.isEmpty()) {
|
||||
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;
|
||||
}
|
||||
|
||||
logger.debug("Deleted on IS");
|
||||
} else {
|
||||
String error="No resources found with name: "+definitionItem.getClientId();
|
||||
logger.error(error);
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ public class Constants {
|
|||
public static final String DEFAULT_SCOPE = "/gcube";
|
||||
public static final String DEFAULT_TOKEN = "";
|
||||
|
||||
|
||||
public static final String DEFAULT_ROLE = "OrganizationMember";
|
||||
|
||||
// Session
|
||||
|
|
|
@ -24,8 +24,7 @@ public class ISTest {
|
|||
public void findSSD() {
|
||||
|
||||
try {
|
||||
InformationSystemUtils.retrieveSSD(Constants.SYSTEM_SERVICE_CATEGORY, Constants.DEFAULT_SCOPE,
|
||||
Constants.DEFAULT_TOKEN);
|
||||
InformationSystemUtils.retrieveSSD(Constants.SYSTEM_SERVICE_CATEGORY, Constants.DEFAULT_SCOPE);
|
||||
assertTrue(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -34,15 +33,15 @@ public class ISTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Ignore
|
||||
public void publishSSD() {
|
||||
|
||||
try {
|
||||
DefinitionItem definitionItem=new DefinitionItem("sample-client-name", "sample-client-description",
|
||||
DefinitionItem definitionItem = new DefinitionItem("sample-client-name", "sample-client-description",
|
||||
"sample-client-description", "xxxxx-xxxx-xxx-xxxx");
|
||||
InformationSystemUtils.publishSSD(definitionItem,Constants.SYSTEM_SERVICE_CATEGORY, Constants.DEFAULT_SCOPE,
|
||||
Constants.DEFAULT_TOKEN);
|
||||
InformationSystemUtils.publishSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
|
||||
Constants.DEFAULT_SCOPE);
|
||||
assertTrue(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -52,4 +51,23 @@ public class ISTest {
|
|||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void deleteSSD() {
|
||||
|
||||
try {
|
||||
DefinitionItem definitionItem = new DefinitionItem("sample-client-name", "sample-client-description",
|
||||
"sample-client-description", "xxxxx-xxxx-xxx-xxxx");
|
||||
InformationSystemUtils.deleteSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
|
||||
Constants.DEFAULT_SCOPE);
|
||||
assertTrue(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
assertTrue("Error deleting the resource!", false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -7,3 +7,4 @@
|
|||
/howto.txt
|
||||
/log4j.properties
|
||||
/symm.key
|
||||
/.~lock.symm.key#
|
||||
|
|
Loading…
Reference in New Issue