From 76710be619c3d089bcaa77b85c00808390c4bd24 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 7 May 2024 12:24:23 +0200 Subject: [PATCH] - Rewritten calledMethod to allow aggregation [#26707] --- geoportal-service/CHANGELOG.md | 3 +- .../service/rest/ProfiledDocuments.java | 60 +++++++++++++++++-- .../service/rest/UseCaseDescriptors.java | 16 +++++ 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/geoportal-service/CHANGELOG.md b/geoportal-service/CHANGELOG.md index 8e6a43e..55e4481 100644 --- a/geoportal-service/CHANGELOG.md +++ b/geoportal-service/CHANGELOG.md @@ -2,8 +2,9 @@ ## [v1.2.0-SNAPSHOT] - 2024-04-08 -- Integrated the EventManager of the cms-plugin-framework +- Integrated the EventManager of the cms-plugin-framework [#26321] - Added optional message when performing lifecycle step [#27192] +- Rewritten calledMethod to allow aggregation [#26707] ## [v1.1.1] - 2023-09-06 diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java index ecbf0c9..0b08063 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java @@ -1,10 +1,5 @@ package org.gcube.application.geoportal.service.rest; -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.DefaultValue; @@ -33,10 +28,11 @@ import org.gcube.application.geoportal.common.model.document.accounting.Accounti import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation; import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation.Status; import org.gcube.application.geoportal.common.model.rest.ConfigurationException; +import org.gcube.application.geoportal.common.model.rest.PerformStepRequest; import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; -import org.gcube.application.geoportal.common.model.rest.PerformStepRequest; import org.gcube.application.geoportal.common.rest.InterfaceConstants; +import org.gcube.application.geoportal.service.accounting.CalledMethodHandler; import org.gcube.application.geoportal.service.engine.mongo.ProfiledMongoManager; import org.gcube.application.geoportal.service.engine.providers.ConfigurationCache; import org.gcube.application.geoportal.service.engine.providers.ProjectAccessImpl; @@ -113,6 +109,9 @@ public class ProfiledDocuments { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Project createNew(Document d) { + + CalledMethodHandler.setCalledMethod("POST /createNew/{" + InterfaceConstants.Parameters.PROJECT_ID + "}"); + Project theNewProject = new GuardedMethod() { @Override protected Project run() throws Exception, WebApplicationException { @@ -155,6 +154,9 @@ public class ProfiledDocuments { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Project update(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String documentId, Document d) { + + CalledMethodHandler.setCalledMethod("PUT /update/{" + InterfaceConstants.Parameters.PROJECT_ID + "}"); + Project theUpdatedProject = new GuardedMethod() { @Override protected Project run() throws Exception, WebApplicationException { @@ -195,6 +197,8 @@ public class ProfiledDocuments { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Project patch(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String documentId, Document d) { + CalledMethodHandler.setCalledMethod("PATCH /patch/{" + InterfaceConstants.Parameters.PROJECT_ID + "}"); + return new GuardedMethod() { @Override protected Project run() throws Exception, WebApplicationException { @@ -217,6 +221,9 @@ public class ProfiledDocuments { @Path("{" + InterfaceConstants.Parameters.PROJECT_ID + "}") public Boolean delete(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, @DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force) { + + CalledMethodHandler.setCalledMethod("POST /delete/{" + InterfaceConstants.Parameters.PROJECT_ID + "}"); + Boolean deleted = new GuardedMethod() { @Override protected Boolean run() throws Exception, WebApplicationException { @@ -261,6 +268,10 @@ public class ProfiledDocuments { @Path("/" + InterfaceConstants.Methods.REGISTER_FILES_PATH + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}") public Project registerFileSet(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, RegisterFileSetRequest request) { + + CalledMethodHandler.setCalledMethod("POST /" + InterfaceConstants.Methods.REGISTER_FILES_PATH + "/{" + + InterfaceConstants.Parameters.PROJECT_ID + "}"); + return new GuardedMethod() { @Override protected Project run() throws Exception, WebApplicationException { @@ -291,6 +302,10 @@ public class ProfiledDocuments { @DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force, @DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.IGNORE_ERRORS) Boolean ignore_errors, String path) { + + CalledMethodHandler.setCalledMethod("POST /" + InterfaceConstants.Methods.DELETE_FILES_PATH + "/{" + + InterfaceConstants.Parameters.PROJECT_ID + "}"); + return new GuardedMethod() { @Override protected Project run() throws Exception, WebApplicationException { @@ -314,6 +329,10 @@ public class ProfiledDocuments { @Path("/" + InterfaceConstants.Methods.STEP + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}") public Project performStep(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, PerformStepRequest performStepRequest) { + + CalledMethodHandler.setCalledMethod( + "POST /" + InterfaceConstants.Methods.STEP + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}"); + Project theProject = new GuardedMethod() { @Override protected Project run() throws Exception, WebApplicationException { @@ -354,6 +373,10 @@ public class ProfiledDocuments { @Produces(MediaType.APPLICATION_JSON) @Path("/" + InterfaceConstants.Methods.FORCE_UNLOCK + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}") public Project forceUnlock(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) { + + CalledMethodHandler.setCalledMethod("PUT /" + InterfaceConstants.Methods.FORCE_UNLOCK + "/{" + + InterfaceConstants.Parameters.PROJECT_ID + "}"); + return new GuardedMethod() { @Override @@ -377,6 +400,10 @@ public class ProfiledDocuments { @Path("/" + InterfaceConstants.Methods.SET_PROJECT_ACCESS_POLICY + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}") public Project setAccessPolicy(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, Access toSet) { + + CalledMethodHandler.setCalledMethod("PUT /" + InterfaceConstants.Methods.SET_PROJECT_ACCESS_POLICY + "/{" + + InterfaceConstants.Parameters.PROJECT_ID + "}"); + return new GuardedMethod() { @Override @@ -415,6 +442,9 @@ public class ProfiledDocuments { @Produces(MediaType.APPLICATION_JSON) @Path("{" + InterfaceConstants.Parameters.PROJECT_ID + "}") public Project getById(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) { + + CalledMethodHandler.setCalledMethod("GET /getById/{" + InterfaceConstants.Parameters.PROJECT_ID + "}"); + return new GuardedMethod() { @Override protected Project run() throws Exception, WebApplicationException { @@ -434,6 +464,9 @@ public class ProfiledDocuments { @Produces(MediaType.APPLICATION_JSON) @Path("/" + InterfaceConstants.Methods.SEARCH_PATH) public String search(String filter) { + + CalledMethodHandler.setCalledMethod("POST /search"); + return new GuardedMethod() { @Override protected String run() throws Exception, WebApplicationException { @@ -480,6 +513,11 @@ public class ProfiledDocuments { public String getRelationshipChain(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, @PathParam(InterfaceConstants.Parameters.RELATIONSHIP_ID) String relationshipId, @DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.DEEP) Boolean deep) { + + CalledMethodHandler.setCalledMethod("GET /getRelationshipChain/{" + "{" + + InterfaceConstants.Methods.RELATIONSHIP + "}/{" + InterfaceConstants.Parameters.PROJECT_ID + "}" + + "/{" + InterfaceConstants.Parameters.RELATIONSHIP_ID + "}"); + return new GuardedMethod() { @Override protected String run() throws Exception, WebApplicationException { @@ -506,6 +544,11 @@ public class ProfiledDocuments { @PathParam(InterfaceConstants.Parameters.RELATIONSHIP_ID) String relationshipId, @QueryParam(InterfaceConstants.Parameters.TARGET_ID) String targetId, @QueryParam(InterfaceConstants.Parameters.TARGET_UCD) String targetUCD) { + + CalledMethodHandler.setCalledMethod("PUT /setRelation/{" + InterfaceConstants.Methods.RELATIONSHIP + "}/{" + + InterfaceConstants.Parameters.PROJECT_ID + "}" + "/{" + InterfaceConstants.Parameters.RELATIONSHIP_ID + + "}"); + return new GuardedMethod() { @Override protected Project run() throws Exception, WebApplicationException { @@ -539,6 +582,11 @@ public class ProfiledDocuments { @PathParam(InterfaceConstants.Parameters.RELATIONSHIP_ID) String relationshipId, @QueryParam(InterfaceConstants.Parameters.TARGET_ID) String targetId, @QueryParam(InterfaceConstants.Parameters.TARGET_UCD) String targetUCD) { + + CalledMethodHandler.setCalledMethod("PUT /deleteRelation/{" + InterfaceConstants.Methods.RELATIONSHIP + "}/{" + + InterfaceConstants.Parameters.PROJECT_ID + "}" + "/{" + InterfaceConstants.Parameters.RELATIONSHIP_ID + + "}"); + return new GuardedMethod() { @Override protected Project run() throws Exception, WebApplicationException { diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/UseCaseDescriptors.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/UseCaseDescriptors.java index a7fe1f0..012aeff 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/UseCaseDescriptors.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/UseCaseDescriptors.java @@ -18,6 +18,7 @@ import org.gcube.application.cms.implementations.ImplementationProvider; import org.gcube.application.cms.serialization.Serialization; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.gcube.application.geoportal.common.rest.InterfaceConstants; +import org.gcube.application.geoportal.service.accounting.CalledMethodHandler; import org.gcube.application.geoportal.service.engine.mongo.UCDManagerI; import com.webcohesion.enunciate.metadata.rs.RequestHeader; @@ -50,6 +51,9 @@ public class UseCaseDescriptors { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public UseCaseDescriptor createNew(UseCaseDescriptor toCreate) { + + CalledMethodHandler.setCalledMethod("@POST /createNew"); + return new GuardedMethod() { @Override protected UseCaseDescriptor run() throws Exception, WebApplicationException { @@ -71,6 +75,9 @@ public class UseCaseDescriptors { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public UseCaseDescriptor update(@PathParam(InterfaceConstants.Parameters.UCID) String profileId, UseCaseDescriptor d) { + + CalledMethodHandler.setCalledMethod("PUT /update/" + "{" + InterfaceConstants.Parameters.UCID + "\"}"); + return new GuardedMethod() { @Override protected UseCaseDescriptor run() throws Exception, WebApplicationException { @@ -88,6 +95,9 @@ public class UseCaseDescriptors { public Boolean delete(@PathParam(InterfaceConstants.Parameters.UCID) String id, @DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force) { + + CalledMethodHandler.setCalledMethod("DELETE /delete/" + "{" + InterfaceConstants.Parameters.UCID + "\"}"); + return new GuardedMethod() { @Override protected Boolean run() throws Exception, WebApplicationException { @@ -104,6 +114,9 @@ public class UseCaseDescriptors { @Produces(MediaType.APPLICATION_JSON) @Path("{"+InterfaceConstants.Parameters.UCID +"}") public UseCaseDescriptor getById(@PathParam(InterfaceConstants.Parameters.UCID) String id) { + + CalledMethodHandler.setCalledMethod("GET /getById/" + "{" + InterfaceConstants.Parameters.UCID + "\"}"); + return new GuardedMethod() { @Override protected UseCaseDescriptor run() throws Exception, WebApplicationException { @@ -119,6 +132,9 @@ public class UseCaseDescriptors { @Produces(MediaType.APPLICATION_JSON) @Path("/"+InterfaceConstants.Methods.QUERY_PATH) public Iterable query(String queryString){ + + CalledMethodHandler.setCalledMethod("@POST /" + InterfaceConstants.Methods.QUERY_PATH); + return new GuardedMethod>() { @Override protected Iterable run() throws Exception, WebApplicationException {