From 26f9460cf37ea7aa5e296065cae618e1ced42088 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Fri, 17 Feb 2023 15:30:35 +0100 Subject: [PATCH] add separated method for consuming json --- .../resources/ServiceEndpointResource.java | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/icproxy/resources/ServiceEndpointResource.java b/src/main/java/org/gcube/informationsystem/icproxy/resources/ServiceEndpointResource.java index 106ddae..01bf157 100644 --- a/src/main/java/org/gcube/informationsystem/icproxy/resources/ServiceEndpointResource.java +++ b/src/main/java/org/gcube/informationsystem/icproxy/resources/ServiceEndpointResource.java @@ -88,20 +88,10 @@ public class ServiceEndpointResource { @POST @Produces(MediaType.APPLICATION_XML) - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Consumes(MediaType.APPLICATION_XML) public ServiceEndpoint create(ServiceEndpoint resourceProfile) { log.debug("Try to create new serviceEndpoint profile {} in {}",resourceProfile, ScopeProvider.instance.get()); if (Objects.nonNull(resourceProfile) && isRoleEnabled()){ -// ServiceEndpoint newResource= new ServiceEndpoint(); -// ServiceEndpoint.Profile profile=newResource.newProfile().category(resourceProfile.getCategory()).name(resourceProfile.getName()); -// ServiceEndpoint. platform=profile.newPlatform().name(resourceProfile.getPlatform()).version(1).minorVersion(0).platformVersion(0).revisionVersion(0).buildVersion(0); -// ServiceEndpoint.AccessPoint ap=new ServiceEndpoint.AccessPoint(); -// ap.name(resourceProfile.getAccessPointName()); -// ap.address(resourceProfile.getAccessPointAddress()); -// ap.credentials(resourceProfile.getAccessPointPass(), resourceProfile.getAccessPointUsername()); -// profile.accessPoints().add(ap); -// registerSE(newResource); -// return newResource; log.debug("going to encrypt and push"); registerSE(encryptResource(resourceProfile)); log.debug("pushed on IS"); @@ -112,6 +102,30 @@ public class ServiceEndpointResource { } + @POST + @Produces(MediaType.APPLICATION_XML) + @Consumes(MediaType.APPLICATION_JSON) + public ServiceEndpoint create(ServiceEndpointProfile resourceProfile) { + log.debug("Try to create new serviceEndpoint profile {} in {}",resourceProfile, ScopeProvider.instance.get()); + if (Objects.nonNull(resourceProfile) && isRoleEnabled()){ + ServiceEndpoint newResource= new ServiceEndpoint(); + ServiceEndpoint.Profile profile=newResource.newProfile().category(resourceProfile.getCategory()).name(resourceProfile.getName()); + profile.newPlatform().name(resourceProfile.getPlatform()).version(1).minorVersion(0).platformVersion(0).revisionVersion(0).buildVersion(0); + ServiceEndpoint.AccessPoint ap=new ServiceEndpoint.AccessPoint(); + ap.name(resourceProfile.getAccessPointName()); + ap.address(resourceProfile.getAccessPointAddress()); + ap.credentials(resourceProfile.getAccessPointPass(), resourceProfile.getAccessPointUsername()); + profile.accessPoints().add(ap); + log.debug("going to encrypt and push"); + registerSE(encryptResource(newResource)); + log.debug("pushed on IS"); + return newResource; + }else{ + throw new RuntimeException("ServiceEndpoint profile is null or user not enabled"); + } + + } + private SimpleQuery getQuery(String resourceName, String resourceCategory){ SimpleQuery query = queryFor(ServiceEndpoint.class); query.addCondition(String.format("$resource/Profile/Name/text() eq '%s'",resourceName));