From c9781ee9541356bbe3d698b2a4c312efeafb6d86 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Fri, 30 Jun 2023 13:48:10 +0200 Subject: [PATCH] Co-authored-by: William Welling <8352733+wwelling@users.noreply.github.com> Co-authored-by: Kevin Day Co-authored-by: Dragan Ivanovic Co-authored-by: chenejac correct context path vs servlet path Refactor Integration Tests to use the full word Test. This allows for the tests to be properly picked up and executed. Merge pull request #281 from kaladay/dynapi-rpc_endpoint_it_to_itest [3678] Refactor Integration Tests to use the full word Test. Merge branch 'sprint-dynapi-2022-feb-staging' of github.com:vivo-project/Vitro into servlet-path Merge pull request #280 from wwelling/servlet-path Correct context path vs servlet path Update of the ontology. Introducing structured parameter types (object and array) rest endpoint corrections and integration tests Updating binding of the ontology to Java classes and n3 test examples.To be in accordance with changes in the ontology. Adding files for primitive types and APIInformation java bean. Adding new line at the end of file and retrieving history of deleted files by using git mv Adding new line at the end of file Merge pull request #283 from chenejac/3653_definition_of_the_ontology 3653 definition of the ontology Merge branch 'sprint-dynapi-2022-feb-staging' of github.com:vivo-project/Vitro into 3667-rest-it --- .../vitro/webapp/dynapi/Initializer.java | 4 +- .../vitro/webapp/dynapi/RESTEndpoint.java | 124 ++-- .../vitro/webapp/dynapi/RPCEndpoint.java | 10 +- .../vitro/webapp/dynapi/ResourceAPIPool.java | 29 + .../vitro/webapp/dynapi/ResourcePool.java | 30 - .../dynapi/components/APIInformation.java | 47 ++ .../webapp/dynapi/components/Action.java | 8 +- .../dynapi/components/CustomRESTAction.java | 4 +- .../dynapi/components/DefaultAction.java | 6 +- .../dynapi/components/DefaultResource.java | 10 - .../dynapi/components/DefaultResourceAPI.java | 5 + .../webapp/dynapi/components/HTTPMethod.java | 2 +- .../dynapi/components/ModelComponent.java | 6 +- .../webapp/dynapi/components/N3Template.java | 2 +- .../dynapi/components/OperationResult.java | 20 +- .../dynapi/components/OperationalStep.java | 8 +- .../webapp/dynapi/components/Parameter.java | 33 +- .../vitro/webapp/dynapi/components/RPC.java | 8 +- .../{Resource.java => ResourceAPI.java} | 12 +- .../{ResourceKey.java => ResourceAPIKey.java} | 13 +- .../webapp/dynapi/components/SPARQLQuery.java | 4 +- .../webapp/dynapi/components/Version.java | 5 + .../components/types/ArrayParameterType.java | 18 + .../components/types/ObjectParameterType.java | 20 + .../components/{ => types}/ParameterType.java | 10 +- .../types/PrimitiveParameterType.java | 4 + .../validators/NumericRangeValidator.java | 4 +- .../RegularExpressionValidator.java | 2 +- .../StringLengthRangeValidator.java | 4 +- .../webapp/dynapi/request/RequestPath.java | 33 +- .../webapp/dynapi/RESTEndpointITest.java | 262 +++++++++ .../vitro/webapp/dynapi/RESTEndpointTest.java | 207 +++---- ...CEndpointIT.java => RPCEndpointITest.java} | 33 +- .../vitro/webapp/dynapi/RPCEndpointTest.java | 11 +- .../webapp/dynapi/ResourceAPIPoolTest.java | 552 ++++++++++++++++++ .../vitro/webapp/dynapi/ResourcePoolTest.java | 552 ------------------ ...ontextIT.java => ServletContextITest.java} | 9 +- .../webapp/dynapi/ServletContextTest.java | 28 +- .../vitro/webapp/dynapi/SolrQueryTest.java | 7 +- .../dynapi/request/RequestPathTest.java | 35 +- .../body/patch/test_collection_resource.json | 1 + .../body/post/test_collection_resource.json | 1 + .../body/put/test_collection_resource.json | 1 + .../delete/test_collection_resource.json | 4 + .../params/get/test_collection_resource.json | 4 + .../patch/test_collection_resource.json | 4 + .../params/post/test_collection_resource.json | 4 + .../params/put/test_collection_resource.json | 4 + .../body/delete/test_collection_resource.json | 1 + .../body/get/test_collection_resource.json | 1 + .../body/patch/test_collection_resource.json | 1 + .../body/post/test_collection_resource.json | 1 + .../body/put/test_collection_resource.json | 1 + .../dynamic-api-individuals-collection.n3 | 67 +-- .../dynamic-api-individuals-concept.n3 | 67 +-- .../dynamic-api-individuals-document.n3 | 68 ++- .../dynamic-api-individuals-organization.n3 | 67 +-- .../dynamic-api-individuals-person.n3 | 67 +-- .../dynamic-api-individuals-person1_1.n3 | 92 +-- .../dynamic-api-individuals-person2.n3 | 89 +-- .../dynamic-api-individuals-person4_3_7.n3 | 90 +-- .../dynamic-api-individuals-process.n3 | 66 +-- .../dynamic-api-individuals-relationship.n3 | 66 +-- .../dynamic-api-individuals-solr-test.n3 | 77 ++- .../dynamic-api-individuals-testing.n3 | 96 ++- .../abox/filegraph/dynamic-api-individuals.n3 | 98 ++-- .../filegraph/dynamic-api-implementation.n3 | 9 +- .../rdf/tbox/filegraph/vitro-dynamic-api.owl | 312 +++++----- 68 files changed, 1946 insertions(+), 1594 deletions(-) create mode 100644 api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourceAPIPool.java delete mode 100644 api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourcePool.java create mode 100644 api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/APIInformation.java delete mode 100644 api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultResource.java create mode 100644 api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultResourceAPI.java rename api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/{Resource.java => ResourceAPI.java} (94%) rename api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/{ResourceKey.java => ResourceAPIKey.java} (82%) create mode 100644 api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ArrayParameterType.java create mode 100644 api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ObjectParameterType.java rename api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/{ => types}/ParameterType.java (63%) create mode 100644 api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/PrimitiveParameterType.java create mode 100644 api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpointITest.java rename api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/{RPCEndpointIT.java => RPCEndpointITest.java} (84%) create mode 100644 api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourceAPIPoolTest.java delete mode 100644 api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourcePoolTest.java rename api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/{ServletContextIT.java => ServletContextITest.java} (81%) create mode 100644 api/src/test/resources/dynapi/mock/rest/request/body/patch/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/request/body/post/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/request/body/put/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/request/params/delete/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/request/params/get/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/request/params/patch/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/request/params/post/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/request/params/put/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/response/body/delete/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/response/body/get/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/response/body/patch/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/response/body/post/test_collection_resource.json create mode 100644 api/src/test/resources/dynapi/mock/rest/response/body/put/test_collection_resource.json diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/Initializer.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/Initializer.java index 43788f85f5..c0a7b29652 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/Initializer.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/Initializer.java @@ -8,8 +8,8 @@ public class Initializer implements ServletContextListener { public Initializer() {} private void initializeResourcePool(ServletContext ctx) { - ResourcePool resourcePool = ResourcePool.getInstance(); - resourcePool.init(ctx); + ResourceAPIPool resourceAPIPool = ResourceAPIPool.getInstance(); + resourceAPIPool.init(ctx); } private void initializeActionPool(ServletContext ctx) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpoint.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpoint.java index 283373fe52..ebcaf571a0 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpoint.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpoint.java @@ -1,6 +1,6 @@ package edu.cornell.mannlib.vitro.webapp.dynapi; -import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.REST_BASE_PATH; +import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.REST_SERVLET_PATH; import static java.lang.String.format; import java.io.IOException; @@ -15,19 +15,20 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.dynapi.components.Action; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.DefaultResourceAPI; import edu.cornell.mannlib.vitro.webapp.dynapi.components.HTTPMethod; import edu.cornell.mannlib.vitro.webapp.dynapi.components.OperationResult; import edu.cornell.mannlib.vitro.webapp.dynapi.components.RPC; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.Resource; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceKey; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceAPI; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceAPIKey; import edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath; -@WebServlet(name = "RESTEndpoint", urlPatterns = { REST_BASE_PATH + "/*" }) +@WebServlet(name = "RESTEndpoint", urlPatterns = { REST_SERVLET_PATH + "/*" }) public class RESTEndpoint extends VitroHttpServlet { private static final Log log = LogFactory.getLog(RESTEndpoint.class); - private ResourcePool resourcePool = ResourcePool.getInstance(); + private ResourceAPIPool resourceAPIPool = ResourceAPIPool.getInstance(); private ActionPool actionPool = ActionPool.getInstance(); @Override @@ -64,66 +65,81 @@ public void doPatch(HttpServletRequest request, HttpServletResponse response) { } private void process(HttpServletRequest request, HttpServletResponse response) { + String method = request.getMethod(); RequestPath requestPath = RequestPath.from(request); - if (requestPath.isValid()) { - ResourceKey resourceKey = ResourceKey.of(requestPath.getResourceName(), requestPath.getResourceVersion()); + if (!requestPath.isValid()) { + log.error(format("Request path %s is not found", request.getPathInfo())); + OperationResult.notFound().prepareResponse(response); + return; + } - if (log.isDebugEnabled()) { - resourcePool.printKeys(); - } - Resource resource = resourcePool.get(resourceKey); - ResourceKey key = resource.getKey(); - String method = request.getMethod(); - - RPC rpc = null; - - if (requestPath.isCustomRestAction()) { - String customRestActionName = requestPath.getActionName(); - try { - rpc = resource.getCustomRestActionRPC(customRestActionName); - } catch (UnsupportedOperationException e) { - log.error(format("Custom REST action %s not implemented for resource %s", customRestActionName, key), e); - OperationResult.notImplemented().prepareResponse(response); - return; - } finally { - resource.removeClient(); - } - } else { - try { - rpc = resource.getRestRPC(method); - } catch (UnsupportedOperationException e) { - log.error(format("Method %s not implemented for resource %s", method, key), e); - OperationResult.notImplemented().prepareResponse(response); - return; - } finally { - resource.removeClient(); - } - } + if (!requestPath.isMethodAllowed(method)) { + log.error(format("Method %s not allowed at path %s", method, request.getPathInfo())); + OperationResult.methodNotAllowed().prepareResponse(response); + return; + } - HTTPMethod rpcMethod = rpc.getHttpMethod(); + ResourceAPIKey resourceAPIKey = ResourceAPIKey.of(requestPath.getResourceName(), requestPath.getResourceVersion()); - if (rpcMethod == null || !rpcMethod.getName().toUpperCase().equals(method)) { - log.error(format("Remote Procedure Call not implemented for resource %s with method %s", key, method)); - OperationResult.notImplemented().prepareResponse(response); - return; - } + if (log.isDebugEnabled()) { + resourceAPIPool.printKeys(); + } + ResourceAPI resourceAPI = resourceAPIPool.get(resourceAPIKey); + + if (resourceAPI instanceof DefaultResourceAPI) { + log.error(format("ResourceAPI %s not found", resourceAPIKey)); + OperationResult.notFound().prepareResponse(response); + return; + } - String actionName = rpc.getName(); + ResourceAPIKey key = resourceAPI.getKey(); - if (log.isDebugEnabled()) { - actionPool.printKeys(); - } - Action action = actionPool.get(actionName); - OperationData input = new OperationData(request); + RPC rpc = null; + + if (requestPath.isCustomRestAction()) { + String customRestActionName = requestPath.getActionName(); try { - OperationResult result = action.run(input); - result.prepareResponse(response); + rpc = resourceAPI.getCustomRestActionRPC(customRestActionName); + } catch (UnsupportedOperationException e) { + log.error(format("Custom REST action %s not implemented for resource %s", customRestActionName, key), e); + OperationResult.methodNotAllowed().prepareResponse(response); + return; } finally { - action.removeClient(); + resourceAPI.removeClient(); } } else { - OperationResult.notFound().prepareResponse(response); + try { + rpc = resourceAPI.getRestRPC(method); + } catch (UnsupportedOperationException e) { + log.error(format("Method %s not implemented for resource %s", method, key), e); + OperationResult.methodNotAllowed().prepareResponse(response); + return; + } finally { + resourceAPI.removeClient(); + } + } + + HTTPMethod rpcMethod = rpc.getHttpMethod(); + + if (rpcMethod == null || !rpcMethod.getName().toUpperCase().equals(method)) { + log.error(format("Remote Procedure Call not implemented for resource %s with method %s", key, method)); + OperationResult.methodNotAllowed().prepareResponse(response); + return; + } + + String actionName = rpc.getName(); + + if (log.isDebugEnabled()) { + actionPool.printKeys(); + } + Action action = actionPool.get(actionName); + OperationData input = new OperationData(request); + try { + OperationResult result = action.run(input); + result.prepareResponse(response); + } finally { + action.removeClient(); } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpoint.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpoint.java index f3ca8b7f31..933d674f99 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpoint.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpoint.java @@ -1,6 +1,6 @@ package edu.cornell.mannlib.vitro.webapp.dynapi; -import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.RPC_BASE_PATH; +import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.RPC_SERVLET_PATH; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; @@ -14,7 +14,7 @@ import edu.cornell.mannlib.vitro.webapp.dynapi.components.OperationResult; import edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath; -@WebServlet(name = "RPCEndpoint", urlPatterns = { RPC_BASE_PATH + "/*" }) +@WebServlet(name = "RPCEndpoint", urlPatterns = { RPC_SERVLET_PATH + "/*" }) public class RPCEndpoint extends VitroHttpServlet { private static final Log log = LogFactory.getLog(RESTEndpoint.class); @@ -23,7 +23,7 @@ public class RPCEndpoint extends VitroHttpServlet { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) { - OperationResult.notImplemented().prepareResponse(response); + OperationResult.methodNotAllowed().prepareResponse(response); } @Override @@ -48,12 +48,12 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) { @Override public void doDelete(HttpServletRequest request, HttpServletResponse response) { - OperationResult.notImplemented().prepareResponse(response); + OperationResult.methodNotAllowed().prepareResponse(response); } @Override public void doPut(HttpServletRequest request, HttpServletResponse response) { - OperationResult.notImplemented().prepareResponse(response); + OperationResult.methodNotAllowed().prepareResponse(response); } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourceAPIPool.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourceAPIPool.java new file mode 100644 index 0000000000..befdbcdda1 --- /dev/null +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourceAPIPool.java @@ -0,0 +1,29 @@ +package edu.cornell.mannlib.vitro.webapp.dynapi; + +import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceAPI; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceAPIKey; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.DefaultResourceAPI; + +public class ResourceAPIPool extends VersionableAbstractPool { + + private static ResourceAPIPool INSTANCE = new ResourceAPIPool(); + + public static ResourceAPIPool getInstance() { + return INSTANCE; + } + + @Override + public ResourceAPIPool getPool() { + return getInstance(); + } + + @Override + public ResourceAPI getDefault() { + return new DefaultResourceAPI(); + } + + @Override + public Class getType() { + return ResourceAPI.class; + } +} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourcePool.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourcePool.java deleted file mode 100644 index ea118b6f78..0000000000 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourcePool.java +++ /dev/null @@ -1,30 +0,0 @@ -package edu.cornell.mannlib.vitro.webapp.dynapi; - -import edu.cornell.mannlib.vitro.webapp.dynapi.components.Resource; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceKey; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.DefaultResource; - -public class ResourcePool extends VersionableAbstractPool { - - private static ResourcePool INSTANCE = new ResourcePool(); - - public static ResourcePool getInstance() { - return INSTANCE; - } - - @Override - public ResourcePool getPool() { - return getInstance(); - } - - @Override - public Resource getDefault() { - return new DefaultResource(); - } - - @Override - public Class getType() { - return Resource.class; - } - -} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/APIInformation.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/APIInformation.java new file mode 100644 index 0000000000..dd7ac2cb5d --- /dev/null +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/APIInformation.java @@ -0,0 +1,47 @@ +package edu.cornell.mannlib.vitro.webapp.dynapi.components; + +import edu.cornell.mannlib.vitro.webapp.dynapi.OperationData; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.validators.Validator; +import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; +import org.apache.jena.datatypes.RDFDatatype; + +import javax.servlet.http.HttpServletResponse; +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +public class APIInformation { + + private String title; + private String description; + private String version; + + public String getTitle() { + return title; + } + + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#title", minOccurs = 1, maxOccurs = 1) + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#description", maxOccurs = 1) + public void setDescription(String description) { + this.description = description; + } + + public String getVersion() { + return version; + } + + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#version", minOccurs = 1, maxOccurs = 1) + public void setVersion(String version) { + this.version = version; + } +} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Action.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Action.java index d0da598ff4..621378b72b 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Action.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Action.java @@ -6,8 +6,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; -import javax.servlet.http.HttpServletResponse; - import edu.cornell.mannlib.vitro.webapp.dynapi.OperationData; import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; @@ -34,17 +32,17 @@ public void dereference() { @Override public OperationResult run(OperationData input) { if (firstStep == null) { - return new OperationResult(HttpServletResponse.SC_NOT_IMPLEMENTED); + return OperationResult.internalServerError(); } return firstStep.run(input); } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#firstStep", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasFirstStep", minOccurs = 1, maxOccurs = 1) public void setStep(OperationalStep step) { this.firstStep = step; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#assignedRPC", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasAssignedRPC", minOccurs = 1, maxOccurs = 1) public void setRPC(RPC rpc) { this.rpc = rpc; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/CustomRESTAction.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/CustomRESTAction.java index 131d215cd8..e37114c99b 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/CustomRESTAction.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/CustomRESTAction.java @@ -17,7 +17,7 @@ public String getName() { return name; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#customRESTActionName", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#name", minOccurs = 1, maxOccurs = 1) public void setName(String name) { this.name = name; } @@ -26,7 +26,7 @@ public RPC getTargetRPC() { return targetRPC; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#forwardTo", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#forwardsTo", minOccurs = 1, maxOccurs = 1) public void setTargetRPC(RPC rpc) { this.targetRPC = rpc; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultAction.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultAction.java index 5ce20913ae..2f07ec9dd3 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultAction.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultAction.java @@ -2,8 +2,6 @@ import java.util.Map; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -19,7 +17,7 @@ public OperationResult run(Map map) { log.debug("param value " + value); } } - OperationResult result = new OperationResult(HttpServletResponse.SC_BAD_REQUEST); - return result; + + return OperationResult.badRequest(); } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultResource.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultResource.java deleted file mode 100644 index 0601d19cf5..0000000000 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultResource.java +++ /dev/null @@ -1,10 +0,0 @@ -package edu.cornell.mannlib.vitro.webapp.dynapi.components; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class DefaultResource extends Resource { - - private static final Log log = LogFactory.getLog(DefaultResource.class); - -} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultResourceAPI.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultResourceAPI.java new file mode 100644 index 0000000000..41a287d8cc --- /dev/null +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/DefaultResourceAPI.java @@ -0,0 +1,5 @@ +package edu.cornell.mannlib.vitro.webapp.dynapi.components; + +public class DefaultResourceAPI extends ResourceAPI { + +} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/HTTPMethod.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/HTTPMethod.java index f2a7dce6c9..109f35e985 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/HTTPMethod.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/HTTPMethod.java @@ -10,7 +10,7 @@ public String getName() { return name; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#methodName", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#name", minOccurs = 1, maxOccurs = 1) public void setName(String name) { this.name = name; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ModelComponent.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ModelComponent.java index 672dc2146c..1108a749b3 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ModelComponent.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ModelComponent.java @@ -7,14 +7,16 @@ public class ModelComponent implements Removable { private String name; - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#modelName", minOccurs = 1, maxOccurs = 1) - public void setModelName(String name) { + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#name", minOccurs = 1, maxOccurs = 1) + public void setName(String name) { this.name = ModelNames.namesMap.get(name); } + @Override public void dereference() { this.name = null; } + public String getName() { return name; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/N3Template.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/N3Template.java index 062407eaad..6680aab10a 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/N3Template.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/N3Template.java @@ -15,7 +15,7 @@ public void addRequiredParameter(Parameter param) { requiredParams.add(param); } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasN3Text", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#n3Text", minOccurs = 1, maxOccurs = 1) public void setN3Text(String n3Text) { this.n3Text = n3Text; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/OperationResult.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/OperationResult.java index f48f88f8d7..7cd5989173 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/OperationResult.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/OperationResult.java @@ -5,16 +5,16 @@ import org.apache.commons.lang3.Range; public class OperationResult { - + private int responseCode; private static Range errors = Range.between(400, 599); public OperationResult(int responseCode) { this.responseCode = responseCode; } - + public boolean hasError() { - if (errors.contains(responseCode) ) { + if (errors.contains(responseCode)) { return true; } return false; @@ -24,12 +24,20 @@ public void prepareResponse(HttpServletResponse response) { response.setStatus(responseCode); } - public static OperationResult notImplemented() { - return new OperationResult(HttpServletResponse.SC_NOT_IMPLEMENTED); + public static OperationResult badRequest() { + return new OperationResult(HttpServletResponse.SC_BAD_REQUEST); } public static OperationResult notFound() { return new OperationResult(HttpServletResponse.SC_NOT_FOUND); } - + + public static OperationResult methodNotAllowed() { + return new OperationResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED); + } + + public static OperationResult internalServerError() { + return new OperationResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/OperationalStep.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/OperationalStep.java index 5cb437cc1d..0fc91b19da 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/OperationalStep.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/OperationalStep.java @@ -31,23 +31,23 @@ public void dereference() { } } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#next", minOccurs = 0, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasNextStep", maxOccurs = 1) public void setNextStep(OperationalStep step) { this.nextStep = step; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasOperation", minOccurs = 0, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasOperation", maxOccurs = 1) public void setOperation(Operation operation) { this.operation = operation; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#isOptional", minOccurs = 0, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#isOptional", maxOccurs = 1) public void setOptional(boolean optional) { this.optional = optional; } public OperationResult run(OperationData data) { - OperationResult result = OperationResult.notImplemented(); + OperationResult result = OperationResult.badRequest(); log.debug("Processing in STEP"); log.debug("Execution step is optional? " + optional); if (operation != null) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Parameter.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Parameter.java index 7ed46c40d6..c5ab98faef 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Parameter.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Parameter.java @@ -1,5 +1,6 @@ package edu.cornell.mannlib.vitro.webapp.dynapi.components; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.types.ParameterType; import org.apache.jena.datatypes.RDFDatatype; import edu.cornell.mannlib.vitro.webapp.dynapi.components.validators.Validator; @@ -7,28 +8,42 @@ public class Parameter implements Removable{ - String name; - Validators validators = new Validators(); - ParameterType type; - + private String name; + private String description; + private Validators validators = new Validators(); + private ParameterType type; + public String getName() { return name; } - + public RDFDatatype getRDFDataType() { return type.getRDFDataType(); } - - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasParameterType", minOccurs = 1, maxOccurs = 1) + + public ParameterType getType() { + return type; + } + + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasType", minOccurs = 1, maxOccurs = 1) public void setParamType(ParameterType type) { this.type = type; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#paramName", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#name", minOccurs = 1, maxOccurs = 1) public void setName(String name) { this.name = name; } - + + public String getDescription() { + return description; + } + + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#description", maxOccurs = 1) + public void setDescription(String description) { + this.description = description; + } + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasValidator") public void addValidator(Validator validator) { validators.add(validator); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/RPC.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/RPC.java index 7f922fec98..f9e009ca79 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/RPC.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/RPC.java @@ -18,7 +18,7 @@ public String getName() { return name; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#rpcName", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#name", minOccurs = 1, maxOccurs = 1) public void setName(String name) { this.name = name; } @@ -27,12 +27,12 @@ public String getMinVersion() { return minVersion; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#rpcAPIVersionMin", minOccurs = 0, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#minAPIVersion", maxOccurs = 1) public void setMinVersion(String minVersion) { this.minVersion = minVersion; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#rpcAPIVersionMax", minOccurs = 0, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#maxAPIVersion", maxOccurs = 1) public void setMaxVersion(String maxVersion) { this.maxVersion = maxVersion; } @@ -45,7 +45,7 @@ public HTTPMethod getHttpMethod() { return httpMethod; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#defaultMethod") + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasDefaultMethod") public void setHttpMethod(HTTPMethod httpMethod) { this.httpMethod = httpMethod; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Resource.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ResourceAPI.java similarity index 94% rename from api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Resource.java rename to api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ResourceAPI.java index 09dd5d11f4..d00e1ff6ea 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Resource.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ResourceAPI.java @@ -9,7 +9,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; -public class Resource implements Versionable { +public class ResourceAPI implements Versionable { private String name; private String versionMin; @@ -34,7 +34,7 @@ public String getVersionMin() { return versionMin; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#restAPIVersionMin", minOccurs = 0, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#minAPIVersion", minOccurs = 0, maxOccurs = 1) public void setVersionMin(String versionMin) { this.versionMin = versionMin; } @@ -44,7 +44,7 @@ public String getVersionMax() { return versionMax; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#restAPIVersionMax", minOccurs = 0, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#maxAPIVersion", maxOccurs = 1) public void setVersionMax(String versionMax) { this.versionMax = versionMax; } @@ -53,14 +53,14 @@ public String getName() { return name; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#resourceName", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#name", minOccurs = 1, maxOccurs = 1) public void setName(String name) { this.name = name; } @Override - public ResourceKey getKey() { - return ResourceKey.of(name, versionMin); + public ResourceAPIKey getKey() { + return ResourceAPIKey.of(name, versionMin); } @Override diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ResourceKey.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ResourceAPIKey.java similarity index 82% rename from api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ResourceKey.java rename to api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ResourceAPIKey.java index b86d940e33..f683170958 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ResourceKey.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ResourceAPIKey.java @@ -2,13 +2,13 @@ import static java.lang.String.format; -public class ResourceKey implements Comparable, Versioned { +public class ResourceAPIKey implements Comparable, Versioned { private final String name; private final Version version; - private ResourceKey(String name, String version) { + private ResourceAPIKey(String name, String version) { this.name = name; this.version = Version.of(version); } @@ -43,7 +43,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - ResourceKey other = (ResourceKey) obj; + ResourceAPIKey other = (ResourceAPIKey) obj; if (name == null) { if (other.name != null) { return false; @@ -62,7 +62,7 @@ public boolean equals(Object obj) { } @Override - public int compareTo(ResourceKey o) { + public int compareTo(ResourceAPIKey o) { int nameCompare = this.name.compareTo(o.name); if (nameCompare == 0) { return this.version.compareTo(o.version); @@ -75,8 +75,7 @@ public String toString() { return format("%s (%s)", name, version.toString()); } - public static ResourceKey of(String name, String version) { - return new ResourceKey(name, version); + public static ResourceAPIKey of(String name, String version) { + return new ResourceAPIKey(name, version); } - } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/SPARQLQuery.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/SPARQLQuery.java index 2d311d4ec0..e01875c233 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/SPARQLQuery.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/SPARQLQuery.java @@ -46,7 +46,7 @@ public void setQueryText(String queryText) { this.queryText = queryText; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasQueryModel", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasModel", minOccurs = 1, maxOccurs = 1) public void setQueryModel(ModelComponent model) { this.modelComponent = model; } @@ -70,7 +70,7 @@ public OperationResult run(OperationData input) { Model queryModel = ModelAccess.on(input.getContext()).getOntModel(modelComponent.getName()); ParameterizedSparqlString pss = new ParameterizedSparqlString(); for (String paramName : requiredParams.getNames()) { - pss.setLiteral(paramName, input.get(paramName)[0],requiredParams.get(paramName).getRDFDataType()); + pss.setLiteral(paramName, input.get(paramName)[0],requiredParams.get(paramName).getRDFDataType()); } pss.setCommandText(queryText); queryModel.enterCriticalSection(Lock.READ); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Version.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Version.java index a13921c841..1b38bcbc27 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Version.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/Version.java @@ -93,6 +93,11 @@ public int compareTo(Version o) { @Override public String toString() { + if (minor == Integer.MAX_VALUE) { + return format("%s", major); + } else if (patch == Integer.MAX_VALUE) { + return format("%s.%s", major, minor); + } return format("%s.%s.%s", major, minor, patch); } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ArrayParameterType.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ArrayParameterType.java new file mode 100644 index 0000000000..3174f03344 --- /dev/null +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ArrayParameterType.java @@ -0,0 +1,18 @@ +package edu.cornell.mannlib.vitro.webapp.dynapi.components.types; + +import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; + +public class ArrayParameterType extends ParameterType { + + private ParameterType elementsType = new PrimitiveParameterType(); + + public ParameterType getElementsType() { + return elementsType; + } + + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasElementsOfType", maxOccurs = 1) + public void setElementsType(ParameterType elementsType) { + this.elementsType = elementsType; + } + +} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ObjectParameterType.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ObjectParameterType.java new file mode 100644 index 0000000000..ca3001d3df --- /dev/null +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ObjectParameterType.java @@ -0,0 +1,20 @@ +package edu.cornell.mannlib.vitro.webapp.dynapi.components.types; + +import edu.cornell.mannlib.vitro.webapp.dynapi.components.Parameter; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.Parameters; +import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; + +public class ObjectParameterType extends ParameterType { + + private Parameters internalElements = new Parameters(); + + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#hasInternalElement") + public void addInternalElement(Parameter param) { + internalElements.add(param); + } + + public Parameters getInternalElements() { + return internalElements; + } + +} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ParameterType.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ParameterType.java similarity index 63% rename from api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ParameterType.java rename to api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ParameterType.java index af21497272..cdff746d25 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/ParameterType.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/ParameterType.java @@ -1,19 +1,20 @@ -package edu.cornell.mannlib.vitro.webapp.dynapi.components; +package edu.cornell.mannlib.vitro.webapp.dynapi.components.types; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.Removable; import org.apache.jena.datatypes.RDFDatatype; import org.apache.jena.datatypes.xsd.XSDDatatype; import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; -public class ParameterType implements Removable { +public abstract class ParameterType implements Removable { - String name; + protected String name; public RDFDatatype getRDFDataType() { return new XSDDatatype(name); } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#typeName", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#name", minOccurs = 1, maxOccurs = 1) public void setName(String name) { this.name = name; } @@ -22,6 +23,5 @@ public void setName(String name) { public void dereference() { // TODO Auto-generated method stub } - } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/PrimitiveParameterType.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/PrimitiveParameterType.java new file mode 100644 index 0000000000..752404f8f8 --- /dev/null +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/types/PrimitiveParameterType.java @@ -0,0 +1,4 @@ +package edu.cornell.mannlib.vitro.webapp.dynapi.components.types; + +public class PrimitiveParameterType extends ParameterType { +} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/NumericRangeValidator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/NumericRangeValidator.java index 9b0f10d1bb..b27f09dba6 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/NumericRangeValidator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/NumericRangeValidator.java @@ -17,7 +17,7 @@ public Float getMinValue() { return minValue; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#validatorMinNumericValue", maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#minNumeric", maxOccurs = 1) public void setMinValue(float minValue) { this.minValue = minValue; } @@ -26,7 +26,7 @@ public Float getMaxValue() { return maxValue; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#validatorMaxNumericValue", maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#maxNumeric", maxOccurs = 1) public void setMaxValue(float maxValue) { this.maxValue = maxValue; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/RegularExpressionValidator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/RegularExpressionValidator.java index 5401c8eae9..3fd91ad673 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/RegularExpressionValidator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/RegularExpressionValidator.java @@ -16,7 +16,7 @@ public String getRegularExpression() { return regularExpression; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#validatorRegularExpressionValue", minOccurs = 1, maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#regularExpression", minOccurs = 1, maxOccurs = 1) public void setRegularExpression (String regularExpression) { this.regularExpression = regularExpression; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/StringLengthRangeValidator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/StringLengthRangeValidator.java index 4b671d30c3..4ee76c905c 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/StringLengthRangeValidator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/components/validators/StringLengthRangeValidator.java @@ -16,7 +16,7 @@ public Integer getMinLength() { return minLength; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#validatorMinLengthValue", maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#minLength", maxOccurs = 1) public void setMinLength(int minLength) { this.minLength = minLength; } @@ -25,7 +25,7 @@ public Integer getMaxLength() { return maxLength; } - @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#validatorMaxLengthValue", maxOccurs = 1) + @Property(uri = "https://vivoweb.org/ontology/vitro-dynamic-api#maxLength", maxOccurs = 1) public void setMaxLength(int maxValue) { this.maxLength = maxValue; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/request/RequestPath.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/request/RequestPath.java index a8b4ef7af8..7e1ac41345 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/request/RequestPath.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dynapi/request/RequestPath.java @@ -11,9 +11,9 @@ public class RequestPath { public static final String RESOURCE_ID_PARAM = "RESOURCE_ID"; - public static final String API_BASE_PATH = "/api"; - public static final String RPC_BASE_PATH = API_BASE_PATH + "/rpc"; - public static final String REST_BASE_PATH = API_BASE_PATH + "/rest"; + public static final String API_SERVLET_PATH = "/api"; + public static final String RPC_SERVLET_PATH = API_SERVLET_PATH + "/rpc"; + public static final String REST_SERVLET_PATH = API_SERVLET_PATH + "/rest"; private final RequestType type; @@ -28,8 +28,8 @@ public class RequestPath { private final String actionName; private RequestPath(HttpServletRequest request) { - String contextPath = request != null && request.getContextPath() != null - ? request.getContextPath() + String servletPath = request != null && request.getServletPath() != null + ? request.getServletPath() : EMPTY; String pathInfo = request != null && request.getPathInfo() != null ? request.getPathInfo() @@ -37,13 +37,13 @@ private RequestPath(HttpServletRequest request) { pathParts = pathInfo.split("/"); - if (contextPath.toLowerCase().contains(RPC_BASE_PATH)) { + if (servletPath.toLowerCase().contains(RPC_SERVLET_PATH)) { type = RequestType.RPC; actionName = pathParts.length > 1 ? pathParts[1] : null; resourceVersion = null; resourceName = null; resourceId = null; - } else if (contextPath.toLowerCase().contains(REST_BASE_PATH)) { + } else if (servletPath.toLowerCase().contains(REST_SERVLET_PATH)) { type = RequestType.REST; resourceVersion = pathParts.length > 1 ? pathParts[1] : null; resourceName = pathParts.length > 2 ? pathParts[2] : null; @@ -124,6 +124,25 @@ public boolean isValid() { return isValid; } + public boolean isMethodAllowed(String method) { + switch (method.toUpperCase()) { + case "POST": + return resourceId == null; + case "PUT": + case "PATCH": + case "DELETE": + return resourceId != null; + case "GET": + return true; + case "HEAD": // this will likely want to be true when supported + case "CONNECT": + case "OPTIONS": + case "TRACE": + default: + } + return false; + } + public boolean isCustomRestAction() { return isNotEmpty(resourceVersion) && isNotEmpty(resourceName) && isNotEmpty(actionName); } diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpointITest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpointITest.java new file mode 100644 index 0000000000..8a7d99d96d --- /dev/null +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpointITest.java @@ -0,0 +1,262 @@ +package edu.cornell.mannlib.vitro.webapp.dynapi; + +import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.REST_SERVLET_PATH; +import static java.lang.String.format; +import static javax.servlet.http.HttpServletResponse.SC_METHOD_NOT_ALLOWED; +import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; +import static javax.servlet.http.HttpServletResponse.SC_OK; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.apache.jena.query.QueryExecution; +import org.apache.jena.query.QueryExecutionFactory; +import org.apache.jena.query.ResultSetFactory; +import org.apache.jena.rdf.model.Model; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; + +@RunWith(Parameterized.class) +public class RESTEndpointITest extends ServletContextITest { + + private final static String BASE_URL = "http://localhost:8080"; + + private final static String MOCK_BASE_PATH = "src/test/resources/dynapi/mock"; + + private final ObjectMapper objectMapper = new ObjectMapper(); + + private RESTEndpoint restEndpoint; + + private ActionPool actionPool; + + private ResourcePool resourcePool; + + @Mock + private QueryExecution queryExecution; + + @Mock + private HttpServletRequest request; + + @Mock + private ServletInputStream requestInputStream; + + @Mock + private HttpServletResponse response; + + @Spy + private ServletOutputStream responseOutputStream; + + private MockedStatic queryExecutionFactoryStatic; + + @Parameter(0) + public String testRequestMethod; + + @Parameter(1) + public String testRequestPath; + + @Parameter(2) + public String testRequestParamsFile; + + @Parameter(3) + public String testRequestBodyFile; + + @Parameter(4) + public String testSparqlResponseFile; + + @Parameter(5) + public Integer testResponseStatus; + + @Parameter(6) + public String testResponseBodyFile; + + @Parameter(7) + public String testMessage; + + @Before + public void beforeEach() throws IOException { + actionPool = ActionPool.getInstance(); + resourcePool = ResourcePool.getInstance(); + + restEndpoint = new RESTEndpoint(); + + loadDefaultModel(); + loadTestModel(); + + actionPool.init(servletContext); + actionPool.reload(); + + resourcePool.init(servletContext); + resourcePool.reload(); + + MockitoAnnotations.openMocks(this); + + when(request.getServletContext()).thenReturn(servletContext); + + queryExecutionFactoryStatic = mockStatic(QueryExecutionFactory.class); + when(QueryExecutionFactory.create(any(String.class), any(Model.class))).thenReturn(queryExecution); + + mockStatus(response); + } + + @After + public void afterEach() { + queryExecutionFactoryStatic.close(); + } + + @Test + public void doTest() throws IOException { + when(request.getMethod()).thenReturn(testRequestMethod); + when(request.getRequestURL()).thenReturn(new StringBuffer(BASE_URL + REST_SERVLET_PATH + testRequestPath)); + when(request.getRequestURI()).thenReturn(BASE_URL + REST_SERVLET_PATH + testRequestPath); + when(request.getServletPath()).thenReturn(REST_SERVLET_PATH); + when(request.getPathInfo()).thenReturn(testRequestPath); + + if (testRequestParamsFile != null) { + String filePath = format("%s/rest/request/params/%s/%s", MOCK_BASE_PATH, testRequestMethod.toLowerCase(), testRequestParamsFile); + Map params = objectMapper.readValue(new File(filePath), new TypeReference>() {}); + when(request.getParameterMap()).thenReturn(params); + } + + if (testRequestBodyFile != null) { + when(request.getInputStream()).thenReturn(requestInputStream); + // mock requestInputStream read with input stream from file + // String filePath = format("%s/rest/request/body/%s/%s", MOCK_BASE_PATH, testRequestMethod.toLowerCase(), testRequestParamsFile); + } + + if (testSparqlResponseFile != null) { + InputStream stream = readMockFileAsInputStream(testSparqlResponseFile); + when(queryExecution.execSelect()).thenReturn(ResultSetFactory.fromJSON(stream)); + } + + if (testResponseBodyFile != null) { + when(response.getOutputStream()).thenReturn(responseOutputStream); + // mock responseOutputStream to a string to compare with file + // String filePath = format("%s/rest/response/body/%s/%s", MOCK_BASE_PATH, testRequestMethod.toLowerCase(), testRequestParamsFile); + } + + run(testRequestMethod); + + if (testResponseStatus != null) { + verify(response, times(1)).setStatus(testResponseStatus); + } else { + verify(response, times(0)).setStatus(anyInt()); + } + + assertEquals("Invalid Status for test: " + testMessage, status, response.getStatus()); + } + + private void run(String method) { + switch (method) { + case "POST": + restEndpoint.doPost(request, response); + break; + case "GET": + restEndpoint.doGet(request, response); + break; + case "PUT": + restEndpoint.doPut(request, response); + break; + case "PATCH": + restEndpoint.doPatch(request, response); + break; + case "DELETE": + restEndpoint.doDelete(request, response); + break; + default: + break; + } + } + + @Parameterized.Parameters + public static Collection requests() { + List requests = new ArrayList<>(Arrays.asList(new Object[][] { + { "POST", "/1/test_not_found", null, null, null, SC_NOT_FOUND, null, "Resource not found" }, + { "GET", "/1/test_not_found", null, null, null, SC_NOT_FOUND, null, "Resource not found" }, + { "PUT", "/1/test_not_found", null, null, null, SC_METHOD_NOT_ALLOWED, null, "Method not allowed before looking for resource" }, + { "PATCH", "/1/test_not_found", null, null, null, SC_METHOD_NOT_ALLOWED, null, "Method not allowed before looking for resource" }, + { "DELETE", "/1/test_not_found", null, null, null, SC_METHOD_NOT_ALLOWED, null, "Method not allowed before looking for resource" } + })); + + // update with applicable individual ids, ideally they would exist in model for integration testing + requests.addAll(requests("test_collection_resource", "https://scholars.institution.edu/individual/n1f9d4ddc", "test_collection_custom_action_name")); + requests.addAll(requests("test_concept_resource", "https://scholars.institution.edu/individual/n1f9d4ddc", "test_concept_custom_action_name")); + requests.addAll(requests("test_document_resource", "https://scholars.institution.edu/individual/n1f9d4ddc", "test_document_custom_action_name")); + requests.addAll(requests("test_organization_resource", "https://scholars.institution.edu/individual/n1f9d4ddc", "test_organization_custom_action_name")); + requests.addAll(requests("test_person_resource", "https://scholars.institution.edu/individual/n1f9d4ddc", "test_person_custom_action_name")); + requests.addAll(requests("test_process_resource", "https://scholars.institution.edu/individual/n1f9d4ddc", "test_process_custom_action_name")); + requests.addAll(requests("test_relationship_resource", "https://scholars.institution.edu/individual/n1f9d4ddc", "test_relationship_custom_action_name")); + + return requests; + } + + public static List requests(String resourceName, String individualUri, String customRestActionName) { + // would be ideal if sparql made actual call during integration tests + String sparqlResFile = "sparql/response/json/sparql-empty-success.json"; + + // TODO: create appropriate request body, request params, and response body files when applicable + // String restReqParamsFile = format("%s.json", resourceName); + // String restReqBodyFile = format("%s.json", resourceName); + // String restResBodyFile = format("%s.json", resourceName); + String restReqParamsFile = "test_collection_resource.json"; + String restReqBodyFile = "test_collection_resource.json"; + String restResBodyFile = "test_collection_resource.json"; + + String resourcePath = format("/1/%s", resourceName); + + String individualResourcePath = format("%s/resource:%s", resourcePath, new String(Base64.getEncoder().encode(individualUri.getBytes()))); + + String customRestActionPath = format("%s/%s", individualResourcePath, customRestActionName); + + return new ArrayList<>(Arrays.asList(new Object[][] { + { "POST", resourcePath, restReqParamsFile, restReqBodyFile, sparqlResFile, SC_OK, restResBodyFile, "Create collection resource" }, + { "GET", resourcePath, restReqParamsFile, null, sparqlResFile, SC_OK, restResBodyFile, "Get collection resources" }, + { "PUT", resourcePath, restReqParamsFile, null, null, SC_METHOD_NOT_ALLOWED, null, "Update not allowed on collection" }, + { "PATCH", resourcePath, restReqParamsFile, null, null, SC_METHOD_NOT_ALLOWED, null, "Patch not allowed on collection" }, + { "DELETE", resourcePath, restReqParamsFile, null, null, SC_METHOD_NOT_ALLOWED, null, "Delete not allowed on collection" }, + + { "POST", individualResourcePath, restReqParamsFile, null, null, SC_METHOD_NOT_ALLOWED, null, "Create not allowed on individualt resource" }, + { "GET", individualResourcePath, restReqParamsFile, null, sparqlResFile, SC_OK, restResBodyFile, "Get individual resource" }, + { "PUT", individualResourcePath, restReqParamsFile, restReqBodyFile, sparqlResFile, SC_OK, restResBodyFile, "Update individual resource" }, + { "PATCH", individualResourcePath, restReqParamsFile, restReqBodyFile, sparqlResFile, SC_OK, restResBodyFile, "Patch individual resource" }, + { "DELETE", individualResourcePath, restReqParamsFile, null, sparqlResFile, SC_OK, restResBodyFile, "Delete individual resource" }, + + { "POST", customRestActionPath, restReqParamsFile, null, null, SC_METHOD_NOT_ALLOWED, null, "Method unsupported by Custom REST action" }, + { "GET", customRestActionPath, restReqParamsFile, null, null, SC_METHOD_NOT_ALLOWED, null, "Method unsupported by Custom REST action" }, + { "PUT", customRestActionPath, restReqParamsFile, restReqBodyFile, sparqlResFile, SC_OK, restResBodyFile, "Run Custom REST action" }, + { "PATCH", customRestActionPath, restReqParamsFile, null, null, SC_METHOD_NOT_ALLOWED, null, "Method unsupported by Custom REST action" }, + { "DELETE", customRestActionPath, restReqParamsFile, null, null, SC_METHOD_NOT_ALLOWED, null, "Method unsupported by Custom REST action" } + })); + } + +} diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpointTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpointTest.java index 9ac562131b..11e101bd18 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpointTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RESTEndpointTest.java @@ -1,7 +1,9 @@ package edu.cornell.mannlib.vitro.webapp.dynapi; -import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.REST_BASE_PATH; -import static org.apache.commons.lang3.StringUtils.EMPTY; +import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.REST_SERVLET_PATH; +import static java.lang.String.format; +import static javax.servlet.http.HttpServletResponse.SC_METHOD_NOT_ALLOWED; +import static javax.servlet.http.HttpServletResponse.SC_OK; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mockStatic; @@ -33,18 +35,17 @@ import edu.cornell.mannlib.vitro.webapp.dynapi.components.HTTPMethod; import edu.cornell.mannlib.vitro.webapp.dynapi.components.OperationResult; import edu.cornell.mannlib.vitro.webapp.dynapi.components.RPC; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.Resource; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceKey; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceAPI; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceAPIKey; @RunWith(Parameterized.class) public class RESTEndpointTest { private final static String PATH_INFO = "/1/test"; - private final static String CONTEXT_PATH = REST_BASE_PATH + PATH_INFO; private Map params = new HashMap<>(); - private MockedStatic resourcePoolStatic; + private MockedStatic resourceAPIPoolStatic; private MockedStatic actionPoolStatic; @@ -52,13 +53,13 @@ public class RESTEndpointTest { private ServletContext context; @Mock - private ResourcePool resourcePool; + private ResourceAPIPool resourceAPIPool; @Mock private ActionPool actionPool; @Mock - private Resource resource; + private ResourceAPI resourceAPI; @Mock private RPC rpc; @@ -81,16 +82,28 @@ public class RESTEndpointTest { public String testMethod; @Parameter(1) - public String testAction; + public String testPathInfo; + + @Parameter(2) + public String testActionName; + + @Parameter(3) + public int[] expectedCounts; + + @Parameter(4) + public int expectedStatus; + + @Parameter(5) + public String testMessage; @Before public void beforeEach() { MockitoAnnotations.openMocks(this); - resourcePoolStatic = mockStatic(ResourcePool.class); + resourceAPIPoolStatic = mockStatic(ResourceAPIPool.class); actionPoolStatic = mockStatic(ActionPool.class); - when(ResourcePool.getInstance()).thenReturn(resourcePool); - when(resourcePool.get(any(ResourceKey.class))).thenReturn(resource); + when(ResourceAPIPool.getInstance()).thenReturn(resourceAPIPool); + when(resourceAPIPool.get(any(ResourceAPIKey.class))).thenReturn(resourceAPI); when(ActionPool.getInstance()).thenReturn(actionPool); when(actionPool.get(any(String.class))).thenReturn(action); @@ -103,50 +116,36 @@ public void beforeEach() { @After public void afterEach() { - resourcePoolStatic.close(); + resourceAPIPoolStatic.close(); actionPoolStatic.close(); } @Test public void doTest() { - prepareMocks(testMethod, testAction); - run(testMethod); - verifyMocksOk(); - } + when(request.getServletPath()).thenReturn(REST_SERVLET_PATH); + when(request.getMethod()).thenReturn(testMethod); + when(request.getPathInfo()).thenReturn(testPathInfo); - @Test - public void doTestNotFound() { - prepareMocksNotFound(testMethod, testAction); - run(testMethod); - verifyMocksNotFound(); - } + when(action.run(any(OperationData.class))) + .thenReturn(new OperationResult(expectedStatus)); - @Test - public void doTestUnsupportedMethod() { - prepareMocksUnsupportedMethod(testMethod, testAction); - run(testMethod); - verifyMocksUnsupportedMethod(); - } + when(httpMethod.getName()).thenReturn(testMethod); - @Test - public void doTestRPCNotImplemented() { - prepareMocksRPCNotImplemented(testMethod, testAction); - run(testMethod); - verifyMocksRPCNotImplemented(); - } + when(rpc.getName()).thenReturn(testActionName); + when(rpc.getHttpMethod()).thenReturn(httpMethod); - @Test - public void doTestCustomAction() { - prepareMocksCustomAction(testMethod, testAction); - run(testMethod); - verifyMocksCustomActionOk(); - } + when(resourceAPI.getRestRPC(testMethod)).thenReturn(rpc); + when(resourceAPI.getCustomRestActionRPC(testActionName)).thenReturn(rpc); + doNothing().when(resourceAPI).removeClient(); - @Test - public void doTestCustomActionUnsupported() { - prepareMocksUnsupportedCustomAction(testMethod, testAction); run(testMethod); - verifyMocksCustomActionUnsupported(); + + verify(resourceAPI, times(expectedCounts[0])).getRestRPC(any()); + verify(resourceAPI, times(expectedCounts[1])).getCustomRestActionRPC(any()); + verify(resourceAPI, times(expectedCounts[2])).removeClient(); + verify(action, times(expectedCounts[3])).run(any()); + verify(action, times(expectedCounts[4])).removeClient(); + verify(response, times(expectedCounts[5])).setStatus(expectedStatus); } private void run(String method) { @@ -171,104 +170,28 @@ private void run(String method) { } } - private void prepareMocks(String method, String actionName) { - when(request.getMethod()).thenReturn(method); - when(request.getContextPath()).thenReturn(CONTEXT_PATH); - when(request.getPathInfo()).thenReturn(PATH_INFO); - - when(action.run(any(OperationData.class))) - .thenReturn(new OperationResult(HttpServletResponse.SC_OK)); - - when(httpMethod.getName()).thenReturn(method); - - when(rpc.getName()).thenReturn(actionName); - when(rpc.getHttpMethod()).thenReturn(httpMethod); - - when(resource.getRestRPC(method)).thenReturn(rpc); - doNothing().when(resource).removeClient(); - } - - private void prepareMocksNotFound(String method, String actionName) { - prepareMocks(method, actionName); - when(request.getPathInfo()).thenReturn(EMPTY); - } - - private void prepareMocksUnsupportedMethod(String method, String actionName) { - prepareMocks(method, actionName); - when(resource.getRestRPC(method)) - .thenThrow(new UnsupportedOperationException("Unsupported method")); - } - - private void prepareMocksRPCNotImplemented(String method, String actionName) { - prepareMocks(method, actionName); - when(httpMethod.getName()).thenReturn("FUBAR"); - } - - private void prepareMocksCustomAction(String method, String actionName) { - when(request.getMethod()).thenReturn(method); - when(request.getContextPath()).thenReturn(CONTEXT_PATH + "/" + actionName); - when(request.getPathInfo()).thenReturn(PATH_INFO + "/" + actionName); - - when(action.run(any(OperationData.class))) - .thenReturn(new OperationResult(HttpServletResponse.SC_OK)); - - when(httpMethod.getName()).thenReturn(method); - - when(rpc.getName()).thenReturn(actionName); - when(rpc.getHttpMethod()).thenReturn(httpMethod); - - when(resource.getCustomRestActionRPC(actionName)).thenReturn(rpc); - doNothing().when(resource).removeClient(); - } - - private void prepareMocksUnsupportedCustomAction(String method, String actionName) { - prepareMocksCustomAction(method, actionName); - when(resource.getCustomRestActionRPC(actionName)) - .thenThrow(new UnsupportedOperationException("Unsupported custom action")); - } - - private void verifyMocksOk() { - verifyMocks(new int[] { 1, 0, 1, 1, 1, 1 }, HttpServletResponse.SC_OK); - } - - private void verifyMocksNotFound() { - verifyMocks(new int[] { 0, 0, 0, 0, 0, 1 }, HttpServletResponse.SC_NOT_FOUND); - } - - private void verifyMocksUnsupportedMethod() { - verifyMocks(new int[] { 1, 0, 1, 0, 0, 1 }, HttpServletResponse.SC_NOT_IMPLEMENTED); - } - - private void verifyMocksRPCNotImplemented() { - verifyMocks(new int[] { 1, 0, 1, 0, 0, 1 }, HttpServletResponse.SC_NOT_IMPLEMENTED); - } - - private void verifyMocksCustomActionOk() { - verifyMocks(new int[] { 0, 1, 1, 1, 1, 1 }, HttpServletResponse.SC_OK); - } - - private void verifyMocksCustomActionUnsupported() { - verifyMocks(new int[] { 0, 1, 1, 0, 0, 1 }, HttpServletResponse.SC_NOT_IMPLEMENTED); - } - - private void verifyMocks(int[] times, int status) { - verify(resource, times(times[0])).getRestRPC(any()); - verify(resource, times(times[1])).getCustomRestActionRPC(any()); - verify(resource, times(times[2])).removeClient(); - verify(action, times(times[3])).run(any()); - verify(action, times(times[4])).removeClient(); - verify(response, times(times[5])).setStatus(status); - } - @Parameterized.Parameters - public static Collection requests() { - return Arrays.asList(new String[][] { - // method action - { "POST", "test" }, - { "GET", "test" }, - { "PUT", "test" }, - { "PATCH", "test" }, - { "DELETE", "test" } + public static Collection requests() { + String actionName = "test"; + String customRestActionPathInfo = format("%s/%s", PATH_INFO, actionName); + + return Arrays.asList(new Object[][] { + // expected counts key + // resource.getRestRPC, resource.getCustomRestActionRPC, resource.removeClient, action.run, action.removeClient, response.setStatus + + // method path info action expected counts expected status + { "POST", PATH_INFO, actionName, new int[] { 1, 0, 1, 1, 1, 1 }, SC_OK, "Create collection resource" }, + { "GET", PATH_INFO, actionName, new int[] { 1, 0, 1, 1, 1, 1 }, SC_OK, "Get collection resources" }, + { "PUT", PATH_INFO, actionName, new int[] { 0, 0, 0, 0, 0, 1 }, SC_METHOD_NOT_ALLOWED, "Cannot put on resource collecion" }, + { "PATCH", PATH_INFO, actionName, new int[] { 0, 0, 0, 0, 0, 1 }, SC_METHOD_NOT_ALLOWED, "Cannot patch on resource collection" }, + { "DELETE", PATH_INFO, actionName, new int[] { 0, 0, 0, 0, 0, 1 }, SC_METHOD_NOT_ALLOWED, "Cannot delete on resource collection" }, + + { "POST", customRestActionPathInfo, actionName, new int[] { 0, 1, 1, 1, 1, 1 }, SC_OK, "Resource found with supported method" }, + { "GET", customRestActionPathInfo, actionName, new int[] { 0, 1, 1, 1, 1, 1 }, SC_METHOD_NOT_ALLOWED, "Resource found with unsupported method" }, + { "PUT", customRestActionPathInfo, actionName, new int[] { 0, 0, 0, 0, 0, 1 }, SC_METHOD_NOT_ALLOWED, "Method unsupported by custom REST action" }, + { "PATCH", customRestActionPathInfo, actionName, new int[] { 0, 0, 0, 0, 0, 1 }, SC_METHOD_NOT_ALLOWED, "Method unsupported by custom REST action" }, + { "DELETE", customRestActionPathInfo, actionName, new int[] { 0, 0, 0, 0, 0, 1 }, SC_METHOD_NOT_ALLOWED, "Method unsupported by custom REST action" } + }); } diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointIT.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointITest.java similarity index 84% rename from api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointIT.java rename to api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointITest.java index 904af9a227..069bbe3dd9 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointIT.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointITest.java @@ -1,8 +1,9 @@ package edu.cornell.mannlib.vitro.webapp.dynapi; +import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.RPC_SERVLET_PATH; import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; -import static javax.servlet.http.HttpServletResponse.SC_NOT_IMPLEMENTED; +import static javax.servlet.http.HttpServletResponse.SC_METHOD_NOT_ALLOWED; import static javax.servlet.http.HttpServletResponse.SC_OK; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -10,7 +11,6 @@ import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.when; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; @@ -34,10 +34,9 @@ import org.mockito.MockedStatic; @RunWith(Parameterized.class) -public class RPCEndpointIT extends ServletContextIT { +public class RPCEndpointITest extends ServletContextITest { - private final static String URI_CONTEXT = "/api/rpc/"; - private final static String URI_BASE = "http://localhost" + URI_CONTEXT; + private final static String URI_BASE = "http://localhost:8080" + RPC_SERVLET_PATH; private RPCEndpoint rpcEndpoint; @@ -92,13 +91,13 @@ public void beforeEach() throws Exception { loadDefaultModel(); when(request.getServletContext()).thenReturn(servletContext); - when(request.getContextPath()).thenReturn(URI_CONTEXT); + when(request.getServletPath()).thenReturn(RPC_SERVLET_PATH); actionPool.init(request.getServletContext()); actionPool.reload(); if (testAction != null) { - StringBuffer buffer = new StringBuffer(URI_BASE + testAction); + StringBuffer buffer = new StringBuffer(URI_BASE + "/" + testAction); when(request.getRequestURL()).thenReturn(buffer); when(request.getPathInfo()).thenReturn("/" + testAction); } @@ -123,8 +122,8 @@ public void afterEach() throws Exception { public void doGetTest() { rpcEndpoint.doGet(request, response); - // For all permutations, this should return HTTP 501. - assertResponseStatus(SC_NOT_IMPLEMENTED); + // For all permutations, this should return HTTP 405. + assertResponseStatus(SC_METHOD_NOT_ALLOWED); } @Test @@ -137,16 +136,16 @@ public void doPostTest() { public void doDeleteTest() { rpcEndpoint.doDelete(request, response); - // For all permutations, this should return HTTP 501. - assertResponseStatus(SC_NOT_IMPLEMENTED); + // For all permutations, this should return HTTP 405. + assertResponseStatus(SC_METHOD_NOT_ALLOWED); } @Test public void doPutTest() { rpcEndpoint.doPut(request, response); - // For all permutations, this should return HTTP 501. - assertResponseStatus(SC_NOT_IMPLEMENTED); + // For all permutations, this should return HTTP 405. + assertResponseStatus(SC_METHOD_NOT_ALLOWED); } private void assertResponseStatus(int status) { @@ -158,8 +157,7 @@ private void assertResponseStatus(int status) { * @throws IOException */ protected void mockSparqlResponseEmptySuccess() throws IOException { - String json = readMockFile("sparql/response/json/sparql-empty-success.json"); - InputStream stream = new ByteArrayInputStream(json.getBytes()); + InputStream stream = readMockFileAsInputStream("sparql/response/json/sparql-empty-success.json"); when(queryExecution.execSelect()).thenReturn(ResultSetFactory.fromJSON(stream)); } @@ -167,7 +165,6 @@ protected void mockSparqlResponseEmptySuccess() throws IOException { public static Collection requests() throws MalformedURLException, NoSuchMethodException, SecurityException { int nf = SC_NOT_FOUND; int se = SC_INTERNAL_SERVER_ERROR; - int ni = SC_NOT_IMPLEMENTED; int ok = SC_OK; String actionIsEmpty = ""; @@ -181,14 +178,14 @@ public static Collection requests() throws MalformedURLException, NoSu String emailIsGood = "example@localhost"; Method[] before = new Method[] { - RPCEndpointIT.class.getDeclaredMethod("mockSparqlResponseEmptySuccess") + RPCEndpointITest.class.getDeclaredMethod("mockSparqlResponseEmptySuccess") }; return Arrays.asList(new Object[][] { // action limit email status before after testMessage { null, null, null, nf, null, null, "NULL Request" }, { actionIsEmpty, null, null, nf, null, null, "Empty Action" }, - { actionIsUnknown, null, null, ni, null, null, "Unknown Action" }, + { actionIsUnknown, null, null, se, null, null, "Unknown Action" }, { actionIsGood, null, null, se, null, null, "NULL Limit" }, { actionIsGood, limitIsEmpty, null, se, null, null, "Empty Limit" }, { actionIsGood, limitIsBad, null, se, null, null, "Bad Limit" }, diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointTest.java index 90346485fd..dc37c9bc10 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/RPCEndpointTest.java @@ -1,6 +1,6 @@ package edu.cornell.mannlib.vitro.webapp.dynapi; -import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.RPC_BASE_PATH; +import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.RPC_SERVLET_PATH; import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mockStatic; @@ -30,7 +30,6 @@ public class RPCEndpointTest { private final static String PATH_INFO = "/test"; - private final static String CONTEXT_PATH = RPC_BASE_PATH + PATH_INFO; private Map params; @@ -73,14 +72,14 @@ public void afterEach() { public void doGetTest() { rpcEndpoint.doGet(request, response); verify(action, times(0)).run(any()); - verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); + verify(response, times(1)).setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } @Test public void doPostTest() { OperationResult result = new OperationResult(HttpServletResponse.SC_OK); - when(request.getContextPath()).thenReturn(CONTEXT_PATH); + when(request.getServletPath()).thenReturn(RPC_SERVLET_PATH); when(request.getPathInfo()).thenReturn(PATH_INFO); when(action.run(any(OperationData.class))).thenReturn(result); @@ -102,13 +101,13 @@ public void doPostTestOnMissing() { public void doDeleteTest() { rpcEndpoint.doDelete(request, response); verify(action, times(0)).run(any()); - verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); + verify(response, times(1)).setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } @Test public void doPutTest() { rpcEndpoint.doPut(request, response); verify(action, times(0)).run(any()); - verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); + verify(response, times(1)).setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } } diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourceAPIPoolTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourceAPIPoolTest.java new file mode 100644 index 0000000000..cd270a507a --- /dev/null +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourceAPIPoolTest.java @@ -0,0 +1,552 @@ +package edu.cornell.mannlib.vitro.webapp.dynapi; + +import static java.lang.String.format; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.concurrent.CompletableFuture; + +import edu.cornell.mannlib.vitro.webapp.dynapi.components.DefaultResourceAPI; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceAPI; +import org.junit.After; +import org.junit.Test; + +import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceAPIKey; +import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException; + +public class ResourceAPIPoolTest extends ServletContextTest { + + protected final static String TEST_PERSON_RESOURCE_URI = "https://vivoweb.org/ontology/vitro-dynamic-api/resourceAPI/testPersonResource1"; + + @After + public void reset() { + setup(); + + ResourceAPIPool resourceAPIPool = ResourceAPIPool.getInstance(); + resourceAPIPool.init(servletContext); + resourceAPIPool.reload(); + + ActionPool actionPool = ActionPool.getInstance(); + actionPool.init(servletContext); + actionPool.reload(); + + assertEquals(0, resourceAPIPool.count()); + assertEquals(0, resourceAPIPool.obsoleteCount()); + + assertEquals(0, actionPool.count()); + assertEquals(0, actionPool.obsoleteCount()); + } + + @Test + public void testGetInstance() { + ResourceAPIPool resourceAPIPool = ResourceAPIPool.getInstance(); + assertNotNull(resourceAPIPool); + assertEquals(resourceAPIPool, ResourceAPIPool.getInstance()); + } + + @Test + public void testGetBeforeInit() { + ResourceAPIPool resourceAPIPool = ResourceAPIPool.getInstance(); + assertTrue(resourceAPIPool.get(TEST_RESOURCE_KEY) instanceof DefaultResourceAPI); + } + + @Test + public void testPrintKeysBeforeInit() { + ResourceAPIPool resourceAPIPool = ResourceAPIPool.getInstance(); + resourceAPIPool.printKeys(); + // nothing to assert + } + + @Test + public void testReloadBeforeInit() throws IOException { + ResourceAPIPool resourceAPIPool = ResourceAPIPool.getInstance(); + resourceAPIPool.reload(); + // not sure what to assert + } + + @Test + public void testInit() throws IOException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + assertEquals(1, resourceAPIPool.count()); + assertEquals(0, resourceAPIPool.obsoleteCount()); + + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(TEST_RESOURCE_KEY)); + } + + @Test + public void testVersioning() throws IOException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + ResourceAPIKey resouce_v0 = ResourceAPIKey.of("test_resource", "0"); + ResourceAPIKey resource_v1 = ResourceAPIKey.of("test_resource", "1"); + + ResourceAPIKey document_v0 = ResourceAPIKey.of("test_document_resource", "0"); + ResourceAPIKey document_v1 = ResourceAPIKey.of("test_document_resource", "1"); + + String testDocumentActionName = "test_document"; + + ResourceAPIKey person_v0 = ResourceAPIKey.of("test_person_resource", "0"); + ResourceAPIKey person_v1 = ResourceAPIKey.of("test_person_resource", "1"); + ResourceAPIKey person_v1_0 = ResourceAPIKey.of("test_person_resource", "1.0"); + ResourceAPIKey person_v1_0_0 = ResourceAPIKey.of("test_person_resource", "1.0.0"); + ResourceAPIKey person_v1_1 = ResourceAPIKey.of("test_person_resource", "1.1"); + ResourceAPIKey person_v1_1_0 = ResourceAPIKey.of("test_person_resource", "1.1.0"); + ResourceAPIKey person_v1_2 = ResourceAPIKey.of("test_person_resource", "1.2"); + ResourceAPIKey person_v2 = ResourceAPIKey.of("test_person_resource", "2"); + ResourceAPIKey person_v3 = ResourceAPIKey.of("test_person_resource", "3"); + ResourceAPIKey person_v4 = ResourceAPIKey.of("test_person_resource", "4"); + ResourceAPIKey person_v4_2 = ResourceAPIKey.of("test_person_resource", "4.2"); + ResourceAPIKey person_v4_3 = ResourceAPIKey.of("test_person_resource", "4.3"); + ResourceAPIKey person_v4_3_6 = ResourceAPIKey.of("test_person_resource", "4.3.6"); + ResourceAPIKey person_v4_3_7 = ResourceAPIKey.of("test_person_resource", "4.3.7"); + ResourceAPIKey person_v4_3_8 = ResourceAPIKey.of("test_person_resource", "4.3.8"); + ResourceAPIKey person_v4_4 = ResourceAPIKey.of("test_person_resource", "4.4"); + ResourceAPIKey person_v5 = ResourceAPIKey.of("test_person_resource", "5"); + + ResourceAPIKey expectedDocument_v1_0_0 = ResourceAPIKey.of("test_document_resource", "1.0.0"); + + ResourceAPIKey expectedPerson_v1_0_0 = TEST_PERSON_RESOURCE_KEY; // "test_person_resource", "1.0.0" + ResourceAPIKey expectedPerson_v1_1_0 = ResourceAPIKey.of("test_person_resource", "1.1.0"); + ResourceAPIKey expectedPerson_v2_0_0 = ResourceAPIKey.of("test_person_resource", "2.0.0"); + ResourceAPIKey expectedPerson_v4_3_7 = ResourceAPIKey.of("test_person_resource", "4.3.7"); + + + // base test for test_resource + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resouce_v0)); + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resource_v1)); + // base test for test_document + assertTrue(resourceAPIPool.get(document_v0) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(document_v1) instanceof DefaultResourceAPI); + // demonstrate no person resources in resource pool + assertTrue(resourceAPIPool.get(person_v0) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v1) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v1_0) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v1_1) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v1_1_0) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v1_2) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v2) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v3) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v4) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v4_2) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v4_3) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v4_3_6) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v4_3_7) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v4_3_8) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v4_4) instanceof DefaultResourceAPI); + assertTrue(resourceAPIPool.get(person_v5) instanceof DefaultResourceAPI); + + loadTestModel(); + resourceAPIPool.reload(); + // base test for test_resource + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resouce_v0)); + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resource_v1)); + // base test for test_document + assertTrue(resourceAPIPool.get(document_v0) instanceof DefaultResourceAPI); + assertResource(expectedDocument_v1_0_0, testDocumentActionName, resourceAPIPool.get(document_v1)); + + // no person version 0 in pool + assertTrue(resourceAPIPool.get(person_v0) instanceof DefaultResourceAPI); + // person resource version 1.0.0 has no max version, any major version request greater than 1 should return version 1.0.0 + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1)); + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v2)); + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v3)); + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v4)); + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v5)); + + + loadPersonVersion1_1Model(); + resourceAPIPool.reload(); + // base test for test_resource + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resouce_v0)); + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resource_v1)); + // base test for test_document + assertTrue(resourceAPIPool.get(document_v0) instanceof DefaultResourceAPI); + assertResource(expectedDocument_v1_0_0, testDocumentActionName, resourceAPIPool.get(document_v1)); + + // no person version 0 in pool + assertTrue(resourceAPIPool.get(person_v0) instanceof DefaultResourceAPI); + // still able to get person version 1.0.0 + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_0)); + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_0_0)); + + // able to get person version 1.1.0 from varying levels of specificity + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1)); + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_1)); + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_1_0)); + + // person version 1 does not have specific minor version 2 + assertTrue(resourceAPIPool.get(person_v1_2) instanceof DefaultResourceAPI); + + // person resource version 1.1.0 has no max version, any major version request greater than 1 should return version 1.1.0 + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v2)); + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v3)); + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v4)); + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v5)); + + + loadPersonVersion2Model(); + resourceAPIPool.reload(); + // base test for test_resource + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resouce_v0)); + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resource_v1)); + // base test for test_document + assertTrue(resourceAPIPool.get(document_v0) instanceof DefaultResourceAPI); + assertResource(expectedDocument_v1_0_0, testDocumentActionName, resourceAPIPool.get(document_v1)); + + // no person version 0 in pool + assertTrue(resourceAPIPool.get(person_v0) instanceof DefaultResourceAPI); + // still able to get person version 1.0.0 + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_0)); + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_0_0)); + + // able to get person version 1.1.0 from varying levels of specificity + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1)); + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_1)); + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_1_0)); + + // person version 1 does not have specific minor version 2 + assertTrue(resourceAPIPool.get(person_v1_2) instanceof DefaultResourceAPI); + + // able to get person version 2.0.0 + assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v2)); + + // person resource version 2.0.0 has no max version, any major version request greater than 2 should return version 2.0.0 + assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v3)); + assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v4)); + assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v5)); + + + loadPersonVersion4_3_7Model(); + resourceAPIPool.reload(); + // base test for test_resource + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resouce_v0)); + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(resource_v1)); + // base test for test_document + assertTrue(resourceAPIPool.get(document_v0) instanceof DefaultResourceAPI); + assertResource(expectedDocument_v1_0_0, testDocumentActionName, resourceAPIPool.get(document_v1)); + + + // no person version 0 in pool + assertTrue(resourceAPIPool.get(person_v0) instanceof DefaultResourceAPI); + // still able to get person version 1.0.0 + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_0)); + assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_0_0)); + + // able to get person version 1.1.0 from varying levels of specificity + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1)); + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_1)); + assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v1_1_0)); + + // person version 1 does not have specific minor version 2 + assertTrue(resourceAPIPool.get(person_v1_2) instanceof DefaultResourceAPI); + + // still able to get person version 2.0.0 + assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v2)); + + // skipped a version from 2.0.0 to 4.3.7 and 2.0.0 has max of 2.0.0 + assertTrue(resourceAPIPool.get(person_v3) instanceof DefaultResourceAPI); + + // no version 4.2 exists + assertTrue(resourceAPIPool.get(person_v4_2) instanceof DefaultResourceAPI); + // version 4.3.6 does not exist + assertTrue(resourceAPIPool.get(person_v4_3_6) instanceof DefaultResourceAPI); + // version 4.3.8 does not exist + assertTrue(resourceAPIPool.get(person_v4_3_8) instanceof DefaultResourceAPI); + + // no version 4.4 exists + assertTrue(resourceAPIPool.get(person_v4_4) instanceof DefaultResourceAPI); + + // able to get person version 4.3.7 at varying levels of specificity + assertResource(expectedPerson_v4_3_7, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v4)); + assertResource(expectedPerson_v4_3_7, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v4_3)); + assertResource(expectedPerson_v4_3_7, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v4_3_7)); + + // person resource version 4.3.7 has no max version, any major version request greater than 4 should return version 2.0.0 + assertResource(expectedPerson_v4_3_7, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(person_v5)); + } + + @Test + public void testPrintKeys() throws IOException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + resourceAPIPool.printKeys(); + // nothing to assert + } + + @Test + public void testAdd() throws IOException, ConfigurationBeanLoaderException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + loadTestModel(); + + ResourceAPI resourceAPI = loader.loadInstance(TEST_PERSON_RESOURCE_URI, ResourceAPI.class); + + resourceAPIPool.add(TEST_PERSON_RESOURCE_URI, resourceAPI); + + assertEquals(0, resourceAPIPool.obsoleteCount()); + + assertResource(TEST_PERSON_RESOURCE_KEY, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY)); + } + + @Test + public void testAddHasClient() throws IOException, ConfigurationBeanLoaderException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + loadTestModel(); + + resourceAPIPool.reload(); + + ResourceAPI resourceAPI = loader.loadInstance(TEST_PERSON_RESOURCE_URI, ResourceAPI.class); + + assertEquals(0, resourceAPIPool.obsoleteCount()); + + ResourceAPI resourceAPIHasClient = resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY); + + resourceAPIPool.add(TEST_PERSON_RESOURCE_URI, resourceAPI); + + assertEquals(1, resourceAPIPool.obsoleteCount()); + + resourceAPIHasClient.removeClient(); + } + + @Test(expected = RuntimeException.class) + public void testAddWithoutModelLoaded() throws IOException, ConfigurationBeanLoaderException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + loadTestModel(); + + ResourceAPI resourceAPI = loader.loadInstance(TEST_PERSON_RESOURCE_URI, ResourceAPI.class); + + reset(); + + assertTrue(resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY) instanceof DefaultResourceAPI); + + resourceAPIPool.add(TEST_PERSON_RESOURCE_URI, resourceAPI); + } + + @Test + public void testRemove() throws IOException, ConfigurationBeanLoaderException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + loadTestModel(); + + resourceAPIPool.reload(); + + ResourceAPI resourceAPI = resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY); + + assertFalse(resourceAPI instanceof DefaultResourceAPI); + + resourceAPI.removeClient(); + + reset(); + + resourceAPIPool.remove(TEST_PERSON_RESOURCE_URI, TEST_PERSON_RESOURCE_KEY); + + assertEquals(0, resourceAPIPool.obsoleteCount()); + + assertTrue(resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY) instanceof DefaultResourceAPI); + } + + @Test + public void testRemoveHasClient() throws IOException, ConfigurationBeanLoaderException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + loadTestModel(); + + resourceAPIPool.reload(); + + ResourceAPI resourceAPIHasClient = resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY); + + assertFalse(resourceAPIHasClient instanceof DefaultResourceAPI); + + setup(); + + resourceAPIPool.init(servletContext); + + resourceAPIPool.remove(TEST_PERSON_RESOURCE_URI, TEST_PERSON_RESOURCE_KEY); + + assertEquals(1, resourceAPIPool.obsoleteCount()); + + assertTrue(resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY) instanceof DefaultResourceAPI); + + resourceAPIHasClient.removeClient(); + } + + @Test(expected = RuntimeException.class) + public void testRemoveWithModelLoaded() throws IOException, ConfigurationBeanLoaderException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + loadTestModel(); + + resourceAPIPool.reload(); + + resourceAPIPool.remove(TEST_PERSON_RESOURCE_URI, TEST_PERSON_RESOURCE_KEY); + } + + @Test + public void testReloadSingle() throws IOException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + loadTestModel(); + + ResourceAPI resourceAPI = resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY); + + assertTrue(resourceAPI instanceof DefaultResourceAPI); + + resourceAPIPool.reload(TEST_PERSON_RESOURCE_URI); + + assertResource(TEST_PERSON_RESOURCE_KEY, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY)); + } + + @Test + public void testReload() throws IOException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(TEST_RESOURCE_KEY)); + + loadTestModel(); + + resourceAPIPool.reload(); + + assertEquals(8, resourceAPIPool.count()); + assertEquals(0, resourceAPIPool.obsoleteCount()); + + assertResource(TEST_PERSON_RESOURCE_KEY, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY)); + } + + @Test + public void testReloadThreadSafety() throws IOException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(TEST_RESOURCE_KEY)); + + loadTestModel(); + + CompletableFuture reloadFuture = CompletableFuture.runAsync(() -> resourceAPIPool.reload()); + + while (!reloadFuture.isDone()) { + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(TEST_RESOURCE_KEY)); + } + + assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourceAPIPool.get(TEST_RESOURCE_KEY)); + + assertResource(TEST_PERSON_RESOURCE_KEY, TEST_PERSON_ACTION_NAME, resourceAPIPool.get(TEST_PERSON_RESOURCE_KEY)); + } + + @Test + public void testRealodOfResourceHasClient() throws IOException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + loadTestModel(); + + ResourceAPI resourceAPI = resourceAPIPool.get(TEST_RESOURCE_KEY); + + CompletableFuture reloadFuture = CompletableFuture.runAsync(() -> resourceAPIPool.reload()); + + while (!reloadFuture.isDone()) { + assertEquals(TEST_RESOURCE_KEY, resourceAPI.getKey()); + } + + resourceAPI.removeClient(); + } + + @Test + public void testClientsManagement() throws IOException, InterruptedException { + ResourceAPIPool resourceAPIPool = initWithDefaultModel(); + + resourceAPIPool.reload(); + + long initalCount = resourceAPIPool.obsoleteCount(); + ResourceAPI resourceAPI = resourceAPIPool.get(TEST_RESOURCE_KEY); + + resourceAPI.removeClient(); + + assertFalse(resourceAPI.hasClients()); + + Thread t1 = getResourceInThread(resourceAPIPool, TEST_RESOURCE_KEY); + + t1.join(); + + assertTrue(resourceAPI.hasClients()); + + resourceAPIPool.reload(); + + assertEquals(initalCount, resourceAPIPool.obsoleteCount()); + } + + private Thread getResourceInThread(ResourceAPIPool resourceAPIPool, ResourceAPIKey resourceAPIKey) { + Runnable client = new Runnable() { + @Override + public void run() { + ResourceAPI resourceAPI = resourceAPIPool.get(resourceAPIKey); + assertEquals(resourceAPIKey, resourceAPI.getKey()); + assertTrue(resourceAPI.hasClients()); + } + }; + Thread thread = new Thread(client); + thread.start(); + return thread; + } + + private ResourceAPIPool initWithDefaultModel() throws IOException { + loadDefaultModel(); + + ResourceAPIPool resourceAPIPool = ResourceAPIPool.getInstance(); + resourceAPIPool.init(servletContext); + + ActionPool actionPool = ActionPool.getInstance(); + actionPool.init(servletContext); + + return resourceAPIPool; + } + + private void loadPersonVersion1_1Model() throws IOException { + // versioning action reuses testSparqlQuery1 from testing action + loadModel( + new RDFFile("N3", "src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person1_1.n3") + ); + } + + private void loadPersonVersion2Model() throws IOException { + // versioning action reuses testSparqlQuery1 from testing action + loadModel( + new RDFFile("N3", "src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person2.n3") + ); + } + + private void loadPersonVersion4_3_7Model() throws IOException { + // versioning action reuses testSparqlQuery1 from testing action + loadModel( + new RDFFile("N3", "src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person4_3_7.n3") + ); + } + + private void assertResource(ResourceAPIKey expctedResourceAPIKey, String expectedActionName, ResourceAPI actualResourceAPI) { + assertNotNull(actualResourceAPI); + assertFalse(format("%s not loaded!", expctedResourceAPIKey), actualResourceAPI instanceof DefaultResourceAPI); + assertEquals(expctedResourceAPIKey, actualResourceAPI.getKey()); + assertTrue(actualResourceAPI.hasClients()); + + assertEquals(expectedActionName, actualResourceAPI.getRpcOnGet().getName()); + assertEquals("GET", actualResourceAPI.getRpcOnGet().getHttpMethod().getName()); + assertEquals(expctedResourceAPIKey.getVersion().toString(), actualResourceAPI.getRpcOnGet().getMinVersion()); + assertEquals(expectedActionName, actualResourceAPI.getRpcOnPost().getName()); + assertEquals("POST", actualResourceAPI.getRpcOnPost().getHttpMethod().getName()); + assertEquals(expctedResourceAPIKey.getVersion().toString(), actualResourceAPI.getRpcOnPost().getMinVersion()); + assertEquals(expectedActionName, actualResourceAPI.getRpcOnDelete().getName()); + assertEquals("DELETE", actualResourceAPI.getRpcOnDelete().getHttpMethod().getName()); + assertEquals(expctedResourceAPIKey.getVersion().toString(), actualResourceAPI.getRpcOnDelete().getMinVersion()); + assertEquals(expectedActionName, actualResourceAPI.getRpcOnPut().getName()); + assertEquals("PUT", actualResourceAPI.getRpcOnPut().getHttpMethod().getName()); + assertEquals(expctedResourceAPIKey.getVersion().toString(), actualResourceAPI.getRpcOnPut().getMinVersion()); + assertEquals(expectedActionName, actualResourceAPI.getRpcOnPatch().getName()); + assertEquals("PATCH", actualResourceAPI.getRpcOnPatch().getHttpMethod().getName()); + assertEquals(expctedResourceAPIKey.getVersion().toString(), actualResourceAPI.getRpcOnPatch().getMinVersion()); + + actualResourceAPI.removeClient(); + } + +} diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourcePoolTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourcePoolTest.java deleted file mode 100644 index 315d53a1a5..0000000000 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ResourcePoolTest.java +++ /dev/null @@ -1,552 +0,0 @@ -package edu.cornell.mannlib.vitro.webapp.dynapi; - -import static java.lang.String.format; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.concurrent.CompletableFuture; - -import org.junit.After; -import org.junit.Test; - -import edu.cornell.mannlib.vitro.webapp.dynapi.components.DefaultResource; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.Resource; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceKey; -import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException; - -public class ResourcePoolTest extends ServletContextTest { - - protected final static String TEST_PERSON_RESOURCE_URI = "https://vivoweb.org/ontology/vitro-dynamic-api/resource/testPersonResource1"; - - @After - public void reset() { - setup(); - - ResourcePool resourcePool = ResourcePool.getInstance(); - resourcePool.init(servletContext); - resourcePool.reload(); - - ActionPool actionPool = ActionPool.getInstance(); - actionPool.init(servletContext); - actionPool.reload(); - - assertEquals(0, resourcePool.count()); - assertEquals(0, resourcePool.obsoleteCount()); - - assertEquals(0, actionPool.count()); - assertEquals(0, actionPool.obsoleteCount()); - } - - @Test - public void testGetInstance() { - ResourcePool resourcePool = ResourcePool.getInstance(); - assertNotNull(resourcePool); - assertEquals(resourcePool, ResourcePool.getInstance()); - } - - @Test - public void testGetBeforeInit() { - ResourcePool resourcePool = ResourcePool.getInstance(); - assertTrue(resourcePool.get(TEST_RESOURCE_KEY) instanceof DefaultResource); - } - - @Test - public void testPrintKeysBeforeInit() { - ResourcePool resourcePool = ResourcePool.getInstance(); - resourcePool.printKeys(); - // nothing to assert - } - - @Test - public void testReloadBeforeInit() throws IOException { - ResourcePool resourcePool = ResourcePool.getInstance(); - resourcePool.reload(); - // not sure what to assert - } - - @Test - public void testInit() throws IOException { - ResourcePool resourcePool = initWithDefaultModel(); - assertEquals(1, resourcePool.count()); - assertEquals(0, resourcePool.obsoleteCount()); - - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(TEST_RESOURCE_KEY)); - } - - @Test - public void testVersioning() throws IOException { - ResourcePool resourcePool = initWithDefaultModel(); - - ResourceKey resouce_v0 = ResourceKey.of("test_resource", "0"); - ResourceKey resource_v1 = ResourceKey.of("test_resource", "1"); - - ResourceKey document_v0 = ResourceKey.of("test_document_resource", "0"); - ResourceKey document_v1 = ResourceKey.of("test_document_resource", "1"); - - String testDocumentActionName = "test_document"; - - ResourceKey person_v0 = ResourceKey.of("test_person_resource", "0"); - ResourceKey person_v1 = ResourceKey.of("test_person_resource", "1"); - ResourceKey person_v1_0 = ResourceKey.of("test_person_resource", "1.0"); - ResourceKey person_v1_0_0 = ResourceKey.of("test_person_resource", "1.0.0"); - ResourceKey person_v1_1 = ResourceKey.of("test_person_resource", "1.1"); - ResourceKey person_v1_1_0 = ResourceKey.of("test_person_resource", "1.1.0"); - ResourceKey person_v1_2 = ResourceKey.of("test_person_resource", "1.2"); - ResourceKey person_v2 = ResourceKey.of("test_person_resource", "2"); - ResourceKey person_v3 = ResourceKey.of("test_person_resource", "3"); - ResourceKey person_v4 = ResourceKey.of("test_person_resource", "4"); - ResourceKey person_v4_2 = ResourceKey.of("test_person_resource", "4.2"); - ResourceKey person_v4_3 = ResourceKey.of("test_person_resource", "4.3"); - ResourceKey person_v4_3_6 = ResourceKey.of("test_person_resource", "4.3.6"); - ResourceKey person_v4_3_7 = ResourceKey.of("test_person_resource", "4.3.7"); - ResourceKey person_v4_3_8 = ResourceKey.of("test_person_resource", "4.3.8"); - ResourceKey person_v4_4 = ResourceKey.of("test_person_resource", "4.4"); - ResourceKey person_v5 = ResourceKey.of("test_person_resource", "5"); - - ResourceKey expectedDocument_v1_0_0 = ResourceKey.of("test_document_resource", "1.0.0"); - - ResourceKey expectedPerson_v1_0_0 = TEST_PERSON_RESOURCE_KEY; // "test_person_resource", "1.0.0" - ResourceKey expectedPerson_v1_1_0 = ResourceKey.of("test_person_resource", "1.1.0"); - ResourceKey expectedPerson_v2_0_0 = ResourceKey.of("test_person_resource", "2.0.0"); - ResourceKey expectedPerson_v4_3_7 = ResourceKey.of("test_person_resource", "4.3.7"); - - - // base test for test_resource - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resouce_v0)); - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resource_v1)); - // base test for test_document - assertTrue(resourcePool.get(document_v0) instanceof DefaultResource); - assertTrue(resourcePool.get(document_v1) instanceof DefaultResource); - // demonstrate no person resources in resource pool - assertTrue(resourcePool.get(person_v0) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v1) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v1_0) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v1_1) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v1_1_0) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v1_2) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v2) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v3) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v4) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v4_2) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v4_3) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v4_3_6) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v4_3_7) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v4_3_8) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v4_4) instanceof DefaultResource); - assertTrue(resourcePool.get(person_v5) instanceof DefaultResource); - - loadTestModel(); - resourcePool.reload(); - // base test for test_resource - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resouce_v0)); - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resource_v1)); - // base test for test_document - assertTrue(resourcePool.get(document_v0) instanceof DefaultResource); - assertResource(expectedDocument_v1_0_0, testDocumentActionName, resourcePool.get(document_v1)); - - // no person version 0 in pool - assertTrue(resourcePool.get(person_v0) instanceof DefaultResource); - // person resource version 1.0.0 has no max version, any major version request greater than 1 should return version 1.0.0 - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1)); - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v2)); - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v3)); - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v4)); - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v5)); - - - loadPersonVersion1_1Model(); - resourcePool.reload(); - // base test for test_resource - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resouce_v0)); - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resource_v1)); - // base test for test_document - assertTrue(resourcePool.get(document_v0) instanceof DefaultResource); - assertResource(expectedDocument_v1_0_0, testDocumentActionName, resourcePool.get(document_v1)); - - // no person version 0 in pool - assertTrue(resourcePool.get(person_v0) instanceof DefaultResource); - // still able to get person version 1.0.0 - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_0)); - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_0_0)); - - // able to get person version 1.1.0 from varying levels of specificity - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1)); - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_1)); - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_1_0)); - - // person version 1 does not have specific minor version 2 - assertTrue(resourcePool.get(person_v1_2) instanceof DefaultResource); - - // person resource version 1.1.0 has no max version, any major version request greater than 1 should return version 1.1.0 - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v2)); - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v3)); - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v4)); - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v5)); - - - loadPersonVersion2Model(); - resourcePool.reload(); - // base test for test_resource - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resouce_v0)); - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resource_v1)); - // base test for test_document - assertTrue(resourcePool.get(document_v0) instanceof DefaultResource); - assertResource(expectedDocument_v1_0_0, testDocumentActionName, resourcePool.get(document_v1)); - - // no person version 0 in pool - assertTrue(resourcePool.get(person_v0) instanceof DefaultResource); - // still able to get person version 1.0.0 - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_0)); - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_0_0)); - - // able to get person version 1.1.0 from varying levels of specificity - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1)); - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_1)); - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_1_0)); - - // person version 1 does not have specific minor version 2 - assertTrue(resourcePool.get(person_v1_2) instanceof DefaultResource); - - // able to get person version 2.0.0 - assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v2)); - - // person resource version 2.0.0 has no max version, any major version request greater than 2 should return version 2.0.0 - assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v3)); - assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v4)); - assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v5)); - - - loadPersonVersion4_3_7Model(); - resourcePool.reload(); - // base test for test_resource - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resouce_v0)); - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(resource_v1)); - // base test for test_document - assertTrue(resourcePool.get(document_v0) instanceof DefaultResource); - assertResource(expectedDocument_v1_0_0, testDocumentActionName, resourcePool.get(document_v1)); - - - // no person version 0 in pool - assertTrue(resourcePool.get(person_v0) instanceof DefaultResource); - // still able to get person version 1.0.0 - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_0)); - assertResource(expectedPerson_v1_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_0_0)); - - // able to get person version 1.1.0 from varying levels of specificity - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1)); - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_1)); - assertResource(expectedPerson_v1_1_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v1_1_0)); - - // person version 1 does not have specific minor version 2 - assertTrue(resourcePool.get(person_v1_2) instanceof DefaultResource); - - // still able to get person version 2.0.0 - assertResource(expectedPerson_v2_0_0, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v2)); - - // skipped a version from 2.0.0 to 4.3.7 and 2.0.0 has max of 2.0.0 - assertTrue(resourcePool.get(person_v3) instanceof DefaultResource); - - // no version 4.2 exists - assertTrue(resourcePool.get(person_v4_2) instanceof DefaultResource); - // version 4.3.6 does not exist - assertTrue(resourcePool.get(person_v4_3_6) instanceof DefaultResource); - // version 4.3.8 does not exist - assertTrue(resourcePool.get(person_v4_3_8) instanceof DefaultResource); - - // no version 4.4 exists - assertTrue(resourcePool.get(person_v4_4) instanceof DefaultResource); - - // able to get person version 4.3.7 at varying levels of specificity - assertResource(expectedPerson_v4_3_7, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v4)); - assertResource(expectedPerson_v4_3_7, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v4_3)); - assertResource(expectedPerson_v4_3_7, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v4_3_7)); - - // person resource version 4.3.7 has no max version, any major version request greater than 4 should return version 2.0.0 - assertResource(expectedPerson_v4_3_7, TEST_PERSON_ACTION_NAME, resourcePool.get(person_v5)); - } - - @Test - public void testPrintKeys() throws IOException { - ResourcePool resourcePool = initWithDefaultModel(); - - resourcePool.printKeys(); - // nothing to assert - } - - @Test - public void testAdd() throws IOException, ConfigurationBeanLoaderException { - ResourcePool resourcePool = initWithDefaultModel(); - - loadTestModel(); - - Resource resource = loader.loadInstance(TEST_PERSON_RESOURCE_URI, Resource.class); - - resourcePool.add(TEST_PERSON_RESOURCE_URI, resource); - - assertEquals(0, resourcePool.obsoleteCount()); - - assertResource(TEST_PERSON_RESOURCE_KEY, TEST_PERSON_ACTION_NAME, resourcePool.get(TEST_PERSON_RESOURCE_KEY)); - } - - @Test - public void testAddHasClient() throws IOException, ConfigurationBeanLoaderException { - ResourcePool resourcePool = initWithDefaultModel(); - - loadTestModel(); - - resourcePool.reload(); - - Resource resource = loader.loadInstance(TEST_PERSON_RESOURCE_URI, Resource.class); - - assertEquals(0, resourcePool.obsoleteCount()); - - Resource resourceHasClient = resourcePool.get(TEST_PERSON_RESOURCE_KEY); - - resourcePool.add(TEST_PERSON_RESOURCE_URI, resource); - - assertEquals(1, resourcePool.obsoleteCount()); - - resourceHasClient.removeClient(); - } - - @Test(expected = RuntimeException.class) - public void testAddWithoutModelLoaded() throws IOException, ConfigurationBeanLoaderException { - ResourcePool resourcePool = initWithDefaultModel(); - - loadTestModel(); - - Resource resource = loader.loadInstance(TEST_PERSON_RESOURCE_URI, Resource.class); - - reset(); - - assertTrue(resourcePool.get(TEST_PERSON_RESOURCE_KEY) instanceof DefaultResource); - - resourcePool.add(TEST_PERSON_RESOURCE_URI, resource); - } - - @Test - public void testRemove() throws IOException, ConfigurationBeanLoaderException { - ResourcePool resourcePool = initWithDefaultModel(); - - loadTestModel(); - - resourcePool.reload(); - - Resource resource = resourcePool.get(TEST_PERSON_RESOURCE_KEY); - - assertFalse(resource instanceof DefaultResource); - - resource.removeClient(); - - reset(); - - resourcePool.remove(TEST_PERSON_RESOURCE_URI, TEST_PERSON_RESOURCE_KEY); - - assertEquals(0, resourcePool.obsoleteCount()); - - assertTrue(resourcePool.get(TEST_PERSON_RESOURCE_KEY) instanceof DefaultResource); - } - - @Test - public void testRemoveHasClient() throws IOException, ConfigurationBeanLoaderException { - ResourcePool resourcePool = initWithDefaultModel(); - - loadTestModel(); - - resourcePool.reload(); - - Resource resourceHasClient = resourcePool.get(TEST_PERSON_RESOURCE_KEY); - - assertFalse(resourceHasClient instanceof DefaultResource); - - setup(); - - resourcePool.init(servletContext); - - resourcePool.remove(TEST_PERSON_RESOURCE_URI, TEST_PERSON_RESOURCE_KEY); - - assertEquals(1, resourcePool.obsoleteCount()); - - assertTrue(resourcePool.get(TEST_PERSON_RESOURCE_KEY) instanceof DefaultResource); - - resourceHasClient.removeClient(); - } - - @Test(expected = RuntimeException.class) - public void testRemoveWithModelLoaded() throws IOException, ConfigurationBeanLoaderException { - ResourcePool resourcePool = initWithDefaultModel(); - - loadTestModel(); - - resourcePool.reload(); - - resourcePool.remove(TEST_PERSON_RESOURCE_URI, TEST_PERSON_RESOURCE_KEY); - } - - @Test - public void testReloadSingle() throws IOException { - ResourcePool resourcePool = initWithDefaultModel(); - - loadTestModel(); - - Resource resource = resourcePool.get(TEST_PERSON_RESOURCE_KEY); - - assertTrue(resource instanceof DefaultResource); - - resourcePool.reload(TEST_PERSON_RESOURCE_URI); - - assertResource(TEST_PERSON_RESOURCE_KEY, TEST_PERSON_ACTION_NAME, resourcePool.get(TEST_PERSON_RESOURCE_KEY)); - } - - @Test - public void testReload() throws IOException { - ResourcePool resourcePool = initWithDefaultModel(); - - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(TEST_RESOURCE_KEY)); - - loadTestModel(); - - resourcePool.reload(); - - assertEquals(8, resourcePool.count()); - assertEquals(0, resourcePool.obsoleteCount()); - - assertResource(TEST_PERSON_RESOURCE_KEY, TEST_PERSON_ACTION_NAME, resourcePool.get(TEST_PERSON_RESOURCE_KEY)); - } - - @Test - public void testReloadThreadSafety() throws IOException { - ResourcePool resourcePool = initWithDefaultModel(); - - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(TEST_RESOURCE_KEY)); - - loadTestModel(); - - CompletableFuture reloadFuture = CompletableFuture.runAsync(() -> resourcePool.reload()); - - while (!reloadFuture.isDone()) { - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(TEST_RESOURCE_KEY)); - } - - assertResource(TEST_RESOURCE_KEY, TEST_ACTION_NAME, resourcePool.get(TEST_RESOURCE_KEY)); - - assertResource(TEST_PERSON_RESOURCE_KEY, TEST_PERSON_ACTION_NAME, resourcePool.get(TEST_PERSON_RESOURCE_KEY)); - } - - @Test - public void testRealodOfResourceHasClient() throws IOException { - ResourcePool resourcePool = initWithDefaultModel(); - - loadTestModel(); - - Resource resource = resourcePool.get(TEST_RESOURCE_KEY); - - CompletableFuture reloadFuture = CompletableFuture.runAsync(() -> resourcePool.reload()); - - while (!reloadFuture.isDone()) { - assertEquals(TEST_RESOURCE_KEY, resource.getKey()); - } - - resource.removeClient(); - } - - @Test - public void testClientsManagement() throws IOException, InterruptedException { - ResourcePool resourcePool = initWithDefaultModel(); - - resourcePool.reload(); - - long initalCount = resourcePool.obsoleteCount(); - Resource resource = resourcePool.get(TEST_RESOURCE_KEY); - - resource.removeClient(); - - assertFalse(resource.hasClients()); - - Thread t1 = getResourceInThread(resourcePool, TEST_RESOURCE_KEY); - - t1.join(); - - assertTrue(resource.hasClients()); - - resourcePool.reload(); - - assertEquals(initalCount, resourcePool.obsoleteCount()); - } - - private Thread getResourceInThread(ResourcePool resourcePool, ResourceKey resourceKey) { - Runnable client = new Runnable() { - @Override - public void run() { - Resource resource = resourcePool.get(resourceKey); - assertEquals(resourceKey, resource.getKey()); - assertTrue(resource.hasClients()); - } - }; - Thread thread = new Thread(client); - thread.start(); - return thread; - } - - private ResourcePool initWithDefaultModel() throws IOException { - loadDefaultModel(); - - ResourcePool resourcePool = ResourcePool.getInstance(); - resourcePool.init(servletContext); - - ActionPool actionPool = ActionPool.getInstance(); - actionPool.init(servletContext); - - return resourcePool; - } - - private void loadPersonVersion1_1Model() throws IOException { - // versioning action reuses testSparqlQuery1 from testing action - loadModel( - new RDFFile("N3", "src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person1_1.n3") - ); - } - - private void loadPersonVersion2Model() throws IOException { - // versioning action reuses testSparqlQuery1 from testing action - loadModel( - new RDFFile("N3", "src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person2.n3") - ); - } - - private void loadPersonVersion4_3_7Model() throws IOException { - // versioning action reuses testSparqlQuery1 from testing action - loadModel( - new RDFFile("N3", "src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person4_3_7.n3") - ); - } - - private void assertResource(ResourceKey expctedResourceKey, String expectedActionName, Resource actualResource) { - assertNotNull(actualResource); - assertFalse(format("%s not loaded!", expctedResourceKey), actualResource instanceof DefaultResource); - assertEquals(expctedResourceKey, actualResource.getKey()); - assertTrue(actualResource.hasClients()); - - assertEquals(expectedActionName, actualResource.getRpcOnGet().getName()); - assertEquals("GET", actualResource.getRpcOnGet().getHttpMethod().getName()); - assertEquals(expctedResourceKey.getVersion().toString(), actualResource.getRpcOnGet().getMinVersion()); - assertEquals(expectedActionName, actualResource.getRpcOnPost().getName()); - assertEquals("POST", actualResource.getRpcOnPost().getHttpMethod().getName()); - assertEquals(expctedResourceKey.getVersion().toString(), actualResource.getRpcOnPost().getMinVersion()); - assertEquals(expectedActionName, actualResource.getRpcOnDelete().getName()); - assertEquals("DELETE", actualResource.getRpcOnDelete().getHttpMethod().getName()); - assertEquals(expctedResourceKey.getVersion().toString(), actualResource.getRpcOnDelete().getMinVersion()); - assertEquals(expectedActionName, actualResource.getRpcOnPut().getName()); - assertEquals("PUT", actualResource.getRpcOnPut().getHttpMethod().getName()); - assertEquals(expctedResourceKey.getVersion().toString(), actualResource.getRpcOnPut().getMinVersion()); - assertEquals(expectedActionName, actualResource.getRpcOnPatch().getName()); - assertEquals("PATCH", actualResource.getRpcOnPatch().getHttpMethod().getName()); - assertEquals(expctedResourceKey.getVersion().toString(), actualResource.getRpcOnPatch().getMinVersion()); - - actualResource.removeClient(); - } - -} diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextIT.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextITest.java similarity index 81% rename from api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextIT.java rename to api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextITest.java index 2f021153b9..b7d0f53a2b 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextIT.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextITest.java @@ -5,6 +5,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; @@ -12,7 +13,7 @@ import javax.servlet.http.HttpServletResponse; -public abstract class ServletContextIT extends ServletContextTest { +public abstract class ServletContextITest extends ServletContextTest { protected Map parameterMap; @@ -27,7 +28,11 @@ public void setup() { } protected String readMockFile(String path) throws IOException { - return super.readFile("src/test/resources/dynapi/mock/" + path); + return readFile("src/test/resources/dynapi/mock/" + path); + } + + protected InputStream readMockFileAsInputStream(String path) throws IOException { + return readFileAsInputStream("src/test/resources/dynapi/mock/" + path); } protected void mockParameterIntoMap(String name, String value) { diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextTest.java index e54287849d..3293e506e3 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/ServletContextTest.java @@ -3,7 +3,9 @@ import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.FULL_UNION; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.StringReader; import java.nio.file.Files; import java.nio.file.Path; @@ -12,7 +14,7 @@ import org.apache.jena.rdf.model.ModelFactory; import org.junit.Before; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceKey; +import edu.cornell.mannlib.vitro.webapp.dynapi.components.ResourceAPIKey; import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoader; import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccessStub; import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub; @@ -21,10 +23,10 @@ public abstract class ServletContextTest { protected final static String TEST_ACTION_NAME = "test_action"; - protected final static ResourceKey TEST_RESOURCE_KEY = ResourceKey.of("test_resource", "0.1.0"); + protected final static ResourceAPIKey TEST_RESOURCE_KEY = ResourceAPIKey.of("test_resource", "0.1.0"); protected final static String TEST_PERSON_ACTION_NAME = "test_person"; - protected final static ResourceKey TEST_PERSON_RESOURCE_KEY = ResourceKey.of("test_person_resource", "1.0.0"); + protected final static ResourceAPIKey TEST_PERSON_RESOURCE_KEY = ResourceAPIKey.of("test_person_resource", "1.0.0"); protected ServletContextStub servletContext; protected ModelAccessFactoryStub modelAccessFactory; @@ -47,14 +49,6 @@ public void setup() { loader = new ConfigurationBeanLoader(ontModel, servletContext); } - protected void loadModelsFromN3(String fileFormat, String... paths) throws IOException { - for(String path : paths){ - loadModel( - new RDFFile(fileFormat, path) - ); - } - } - protected void loadTestModel() throws IOException { // all actions reuse testSparqlQuery1 from testing action loadModel( @@ -83,12 +77,24 @@ protected void loadModel(RDFFile... rdfFiles) throws IOException { } } + protected void loadModels(String fileFormat, String... paths) throws IOException { + for (String path : paths) { + loadModel(new RDFFile(fileFormat, path)); + } + } + protected String readFile(String path) throws IOException { Path p = new File(path).toPath(); return new String(Files.readAllBytes(p)); } + protected InputStream readFileAsInputStream(String path) throws IOException { + File file = new File(path); + + return new FileInputStream(file); + } + protected class RDFFile { private final String format; private final String path; diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/SolrQueryTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/SolrQueryTest.java index dfed1a7b14..521cf59713 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/SolrQueryTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/SolrQueryTest.java @@ -7,7 +7,6 @@ import edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl; import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; -import edu.cornell.mannlib.vitro.webapp.dynapi.components.Action; import edu.cornell.mannlib.vitro.webapp.dynapi.components.Parameter; import edu.cornell.mannlib.vitro.webapp.dynapi.components.SolrQuery; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; @@ -28,11 +27,11 @@ public class SolrQueryTest extends ServletContextTest{ private final static String TEST_DATA_PATH="src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-solr-test.n3"; private final static String TEST_SOLR_QUERY_URI="https://vivoweb.org/ontology/vitro-dynamic-api/solrQuery/genericSolrTextQuery"; + private static MockedStatic applicationUtils; + @Spy private SolrQuery solrQuery; - private static MockedStatic applicationUtils; - @Mock ApplicationImpl application; @@ -69,7 +68,7 @@ public void setupQuery(){ @Test public void testLoadingAndPropertiesSetup() throws IOException, ConfigurationBeanLoaderException { loadDefaultModel(); - loadModelsFromN3(TEST_DATA_PATH.split("\\.")[1],TEST_DATA_PATH); + loadModels(TEST_DATA_PATH.split("\\.")[1], TEST_DATA_PATH); SolrQuery query = loader.loadInstance(TEST_SOLR_QUERY_URI, SolrQuery.class); assertNotNull(query); diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/request/RequestPathTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/request/RequestPathTest.java index db9f48383f..29cc0d6f26 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/request/RequestPathTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/dynapi/request/RequestPathTest.java @@ -1,5 +1,8 @@ package edu.cornell.mannlib.vitro.webapp.dynapi.request; +import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.REST_SERVLET_PATH; +import static edu.cornell.mannlib.vitro.webapp.dynapi.request.RequestPath.RPC_SERVLET_PATH; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -27,7 +30,7 @@ public class RequestPathTest { @Test public void testRpc() { - when(request.getContextPath()).thenReturn("/api/rpc/create"); + when(request.getServletPath()).thenReturn(RPC_SERVLET_PATH); when(request.getPathInfo()).thenReturn("/create"); RequestPath requestPath = RequestPath.from(request); @@ -41,25 +44,25 @@ public void testRpc() { assertEquals(null, requestPath.getResourceId()); - when(request.getContextPath()).thenReturn("/api/rpc/"); + when(request.getServletPath()).thenReturn(RPC_SERVLET_PATH); when(request.getPathInfo()).thenReturn("/"); assertFalse(RequestPath.from(request).isValid()); - when(request.getContextPath()).thenReturn(null); + when(request.getServletPath()).thenReturn(null); when(request.getPathInfo()).thenReturn("/create"); assertFalse(RequestPath.from(request).isValid()); - when(request.getContextPath()).thenReturn("/api/rpc"); + when(request.getServletPath()).thenReturn(RPC_SERVLET_PATH); when(request.getPathInfo()).thenReturn(null); assertFalse(RequestPath.from(request).isValid()); - when(request.getContextPath()).thenReturn(null); + when(request.getServletPath()).thenReturn(null); when(request.getPathInfo()).thenReturn(null); assertFalse(RequestPath.from(request).isValid()); @@ -67,7 +70,7 @@ public void testRpc() { @Test public void testRestCollection() { - when(request.getContextPath()).thenReturn("/api/rest/1/persons"); + when(request.getServletPath()).thenReturn(REST_SERVLET_PATH); when(request.getPathInfo()).thenReturn("/1/persons"); RequestPath requestPath = RequestPath.from(request); @@ -81,25 +84,25 @@ public void testRestCollection() { assertEquals(null, requestPath.getActionName()); - when(request.getContextPath()).thenReturn("/api/rest/"); + when(request.getServletPath()).thenReturn(REST_SERVLET_PATH); when(request.getPathInfo()).thenReturn("/"); assertFalse(RequestPath.from(request).isValid()); - when(request.getContextPath()).thenReturn(null); + when(request.getServletPath()).thenReturn(null); when(request.getPathInfo()).thenReturn("/1/persons"); assertFalse(RequestPath.from(request).isValid()); - when(request.getContextPath()).thenReturn("/api/rest"); + when(request.getServletPath()).thenReturn(REST_SERVLET_PATH); when(request.getPathInfo()).thenReturn(null); assertFalse(RequestPath.from(request).isValid()); - when(request.getContextPath()).thenReturn(null); + when(request.getServletPath()).thenReturn(null); when(request.getPathInfo()).thenReturn(null); assertFalse(RequestPath.from(request).isValid()); @@ -107,7 +110,7 @@ public void testRestCollection() { @Test public void testRestCustomAction() { - when(request.getContextPath()).thenReturn("/api/rest/1/persons/dedupe"); + when(request.getServletPath()).thenReturn(REST_SERVLET_PATH); when(request.getPathInfo()).thenReturn("/1/persons/dedupe"); RequestPath requestPath = RequestPath.from(request); @@ -123,7 +126,7 @@ public void testRestCustomAction() { @Test public void testRestIndividual() { - when(request.getContextPath()).thenReturn("/api/rest/1/persons/resource:" + encodedResourceId); + when(request.getServletPath()).thenReturn(REST_SERVLET_PATH); when(request.getPathInfo()).thenReturn("/1/persons/resource:" + encodedResourceId); RequestPath requestPath = RequestPath.from(request); @@ -139,7 +142,7 @@ public void testRestIndividual() { @Test public void testRestIndividualCustomAction() { - when(request.getContextPath()).thenReturn("/api/rest/1/persons/resource:" + encodedResourceId + "/patch"); + when(request.getServletPath()).thenReturn(REST_SERVLET_PATH); when(request.getPathInfo()).thenReturn("/1/persons/resource:" + encodedResourceId + "/patch"); RequestPath requestPath = RequestPath.from(request); @@ -155,17 +158,17 @@ public void testRestIndividualCustomAction() { @Test public void testNotFound() { - when(request.getContextPath()).thenReturn("/api/rest/1/persons/resource:" + encodedResourceId + "/patch/foo"); + when(request.getServletPath()).thenReturn(REST_SERVLET_PATH); when(request.getPathInfo()).thenReturn("/1/persons/resource:" + encodedResourceId + "/patch/foo"); assertFalse(RequestPath.from(request).isValid()); - when(request.getContextPath()).thenReturn("/api/bar/1/persons"); + when(request.getServletPath()).thenReturn("/api/bar"); when(request.getPathInfo()).thenReturn("/1/persons"); assertFalse(RequestPath.from(request).isValid()); - when(request.getContextPath()).thenReturn("/some/random/path"); + when(request.getServletPath()).thenReturn("/some/random/path"); when(request.getPathInfo()).thenReturn("/3/2/1"); assertFalse(RequestPath.from(request).isValid()); diff --git a/api/src/test/resources/dynapi/mock/rest/request/body/patch/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/request/body/patch/test_collection_resource.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/request/body/patch/test_collection_resource.json @@ -0,0 +1 @@ +{} diff --git a/api/src/test/resources/dynapi/mock/rest/request/body/post/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/request/body/post/test_collection_resource.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/request/body/post/test_collection_resource.json @@ -0,0 +1 @@ +{} diff --git a/api/src/test/resources/dynapi/mock/rest/request/body/put/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/request/body/put/test_collection_resource.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/request/body/put/test_collection_resource.json @@ -0,0 +1 @@ +{} diff --git a/api/src/test/resources/dynapi/mock/rest/request/params/delete/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/request/params/delete/test_collection_resource.json new file mode 100644 index 0000000000..01c0e214fc --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/request/params/delete/test_collection_resource.json @@ -0,0 +1,4 @@ +{ + "email": ["example@localhost"], + "limit": ["10"] +} diff --git a/api/src/test/resources/dynapi/mock/rest/request/params/get/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/request/params/get/test_collection_resource.json new file mode 100644 index 0000000000..01c0e214fc --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/request/params/get/test_collection_resource.json @@ -0,0 +1,4 @@ +{ + "email": ["example@localhost"], + "limit": ["10"] +} diff --git a/api/src/test/resources/dynapi/mock/rest/request/params/patch/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/request/params/patch/test_collection_resource.json new file mode 100644 index 0000000000..01c0e214fc --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/request/params/patch/test_collection_resource.json @@ -0,0 +1,4 @@ +{ + "email": ["example@localhost"], + "limit": ["10"] +} diff --git a/api/src/test/resources/dynapi/mock/rest/request/params/post/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/request/params/post/test_collection_resource.json new file mode 100644 index 0000000000..01c0e214fc --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/request/params/post/test_collection_resource.json @@ -0,0 +1,4 @@ +{ + "email": ["example@localhost"], + "limit": ["10"] +} diff --git a/api/src/test/resources/dynapi/mock/rest/request/params/put/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/request/params/put/test_collection_resource.json new file mode 100644 index 0000000000..01c0e214fc --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/request/params/put/test_collection_resource.json @@ -0,0 +1,4 @@ +{ + "email": ["example@localhost"], + "limit": ["10"] +} diff --git a/api/src/test/resources/dynapi/mock/rest/response/body/delete/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/response/body/delete/test_collection_resource.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/response/body/delete/test_collection_resource.json @@ -0,0 +1 @@ +{} diff --git a/api/src/test/resources/dynapi/mock/rest/response/body/get/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/response/body/get/test_collection_resource.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/response/body/get/test_collection_resource.json @@ -0,0 +1 @@ +{} diff --git a/api/src/test/resources/dynapi/mock/rest/response/body/patch/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/response/body/patch/test_collection_resource.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/response/body/patch/test_collection_resource.json @@ -0,0 +1 @@ +{} diff --git a/api/src/test/resources/dynapi/mock/rest/response/body/post/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/response/body/post/test_collection_resource.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/response/body/post/test_collection_resource.json @@ -0,0 +1 @@ +{} diff --git a/api/src/test/resources/dynapi/mock/rest/response/body/put/test_collection_resource.json b/api/src/test/resources/dynapi/mock/rest/response/body/put/test_collection_resource.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/api/src/test/resources/dynapi/mock/rest/response/body/put/test_collection_resource.json @@ -0,0 +1 @@ +{} diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-collection.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-collection.n3 index 5867a07496..896ae4b39b 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-collection.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-collection.n3 @@ -5,12 +5,11 @@ @prefix dynapi: . @prefix xsd: . - a dynapi:action ; rdfs:label "Test collection action 1"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -19,56 +18,54 @@ a dynapi:rpc ; - dynapi:resourceName "Test rpc create collection 1" ; - dynapi:rpcName "test_collection"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc create collection 1"@en-US ; + dynapi:name "test_collection" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get collection 1" ; - dynapi:rpcName "test_collection"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc get collection 1"@en-US ; + dynapi:name "test_collection" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update collection 1" ; - dynapi:rpcName "test_collection"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc update collection 1"@en-US ; + dynapi:name "test_collection" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch collection 1" ; - dynapi:rpcName "test_collection"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc patch collection 1"@en-US ; + dynapi:name "test_collection" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete collection 1" ; - dynapi:rpcName "test_collection"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc delete collection 1"@en-US ; + dynapi:name "test_collection" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test collection custom action 1" ; - dynapi:customRESTActionName "test_collection_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test collection custom action 1"@en-US ; + dynapi:name "test_collection_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . - - a dynapi:resource ; - dynapi:resourceName "test_collection_resource" ; - rdfs:label "Test collection resource 1"@en-US ; + + a dynapi:resourceAPI ; + rdfs:label "Test collection resourceAPI 1"@en-US ; + dynapi:name "test_collection_resource" ; + dynapi:minAPIVersion "1.0.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "1.0.0" . - + dynapi:hasCustomRESTAction . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-concept.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-concept.n3 index d7a698ea7b..7fbbee4c10 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-concept.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-concept.n3 @@ -5,12 +5,11 @@ @prefix dynapi: . @prefix xsd: . - a dynapi:action ; rdfs:label "Test concept action 1"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -19,56 +18,54 @@ a dynapi:rpc ; - dynapi:resourceName "Test rpc create concept 1" ; - dynapi:rpcName "test_concept"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc create concept 1"@en-US ; + dynapi:name "test_concept" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get concept 1" ; - dynapi:rpcName "test_concept"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc get concept 1"@en-US ; + dynapi:name "test_concept" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update concept 1" ; - dynapi:rpcName "test_concept"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc update concept 1"@en-US ; + dynapi:name "test_concept" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch concept 1" ; - dynapi:rpcName "test_concept"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc patch concept 1"@en-US ; + dynapi:name "test_concept" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete concept 1" ; - dynapi:rpcName "test_concept"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc delete concept 1"@en-US ; + dynapi:name "test_concept" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test concept custom action 1" ; - dynapi:customRESTActionName "test_concept_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test concept custom action 1"@en-US ; + dynapi:name "test_concept_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . - - a dynapi:resource ; - dynapi:resourceName "test_concept_resource" ; - rdfs:label "Test concept resource 1"@en-US ; + + a dynapi:resourceAPI ; + rdfs:label "Test concept resourceAPI 1"@en-US ; + dynapi:name "test_concept_resource" ; + dynapi:minAPIVersion "1.0.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "1.0.0" . - + dynapi:hasCustomRESTAction . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-document.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-document.n3 index f93ee8fac7..735917764d 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-document.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-document.n3 @@ -5,12 +5,11 @@ @prefix dynapi: . @prefix xsd: . - a dynapi:action ; rdfs:label "Test document action 1"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -19,56 +18,55 @@ a dynapi:rpc ; - dynapi:resourceName "Test rpc create document 1" ; - dynapi:rpcName "test_document"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc create document 1"@en-US ; + dynapi:name "test_document" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get document 1" ; - dynapi:rpcName "test_document"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc get document 1"@en-US ; + dynapi:name "test_document" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update document 1" ; - dynapi:rpcName "test_document"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc update document 1"@en-US ; + dynapi:name "test_document" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch document 1" ; - dynapi:rpcName "test_document"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc patch document 1"@en-US ; + dynapi:name "test_document" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete document 1" ; - dynapi:rpcName "test_document"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc delete document 1"@en-US ; + dynapi:name "test_document" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test document custom action 1" ; - dynapi:customRESTActionName "test_document_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test document custom action 1"@en-US ; + dynapi:name "test_document_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . + - - a dynapi:resource ; - dynapi:resourceName "test_document_resource" ; - rdfs:label "Test document resource 1"@en-US ; + + a dynapi:resourceAPI ; + rdfs:label "Test document resourceAPI 1"@en-US ; + dynapi:name "test_document_resource" ; + dynapi:minAPIVersion "1.0.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "1.0.0" . - + dynapi:hasCustomRESTAction . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-organization.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-organization.n3 index ae98e452e1..394b6a71ea 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-organization.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-organization.n3 @@ -5,12 +5,11 @@ @prefix dynapi: . @prefix xsd: . - a dynapi:action ; rdfs:label "Test organization action 1"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -19,56 +18,54 @@ a dynapi:rpc ; - dynapi:resourceName "Test rpc create organization 1" ; - dynapi:rpcName "test_organization"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc create organization 1"@en-US ; + dynapi:name "test_organization" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get organization 1" ; - dynapi:rpcName "test_organization"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc get organization 1"@en-US ; + dynapi:name "test_organization" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update organization 1" ; - dynapi:rpcName "test_organization"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc update organization 1"@en-US ; + dynapi:name "test_organization" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch organization 1" ; - dynapi:rpcName "test_organization"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc patch organization 1"@en-US ; + dynapi:name "test_organization" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete organization 1" ; - dynapi:rpcName "test_organization"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc delete organization 1"@en-US ; + dynapi:name "test_organization" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test organization custom action 1" ; - dynapi:customRESTActionName "test_organization_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test organization custom action 1"@en-US ; + dynapi:name "test_organization_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . - - a dynapi:resource ; - dynapi:resourceName "test_organization_resource" ; - rdfs:label "Test organization resource 1"@en-US ; + + a dynapi:resourceAPI ; + rdfs:label "Test organization resourceAPI 1"@en-US ; + dynapi:name "test_organization_resource" ; + dynapi:minAPIVersion "1.0.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "1.0.0" . - + dynapi:hasCustomRESTAction . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person.n3 index b558b17ef9..29ca00c90f 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person.n3 @@ -5,12 +5,11 @@ @prefix dynapi: . @prefix xsd: . - a dynapi:action ; rdfs:label "Test person action 1"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -19,56 +18,54 @@ a dynapi:rpc ; - dynapi:resourceName "Test rpc create person 1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc create person 1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get person 1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc get person 1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update person 1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc update person 1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch person 1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc patch person 1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete person 1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc delete person 1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test person custom action 1" ; - dynapi:customRESTActionName "test_person_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test person custom action 1"@en-US ; + dynapi:name "test_person_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . - - a dynapi:resource ; - dynapi:resourceName "test_person_resource" ; - rdfs:label "Test person resource 1"@en-US ; + + a dynapi:resourceAPI ; + rdfs:label "Test person resourceAPI 1"@en-US ; + dynapi:name "test_person_resource" ; + dynapi:minAPIVersion "1.0.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "1.0.0" . - + dynapi:hasCustomRESTAction . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person1_1.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person1_1.n3 index 902db64c6a..e750490266 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person1_1.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person1_1.n3 @@ -5,88 +5,88 @@ @prefix dynapi: . @prefix xsd: . - a dynapi:action ; rdfs:label "Test person action 1.1"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; - rdfs:label "Test person operational step 1.1"@en-US ; + rdfs:label "Test person operational step 1"@en-US ; dynapi:hasOperation . a dynapi:rpc ; - dynapi:resourceName "Test rpc create person 1.1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.1.0" . + rdfs:label "Test rpc create person 1.1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.1.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get person 1.1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.1.0" . + rdfs:label "Test rpc get person 1.1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.1.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update person 1.1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.1.0" . + rdfs:label "Test rpc update person 1.1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.1.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch person 1.1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.1.0" . + rdfs:label "Test rpc patch person 1.1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.1.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete person 1" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.1.0" . + rdfs:label "Test rpc delete person 1.1"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.1.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test person custom action 1.1" ; - dynapi:customRESTActionName "test_person_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.1.0" . - - - a dynapi:resource ; - dynapi:resourceName "test_person_resource" ; - rdfs:label "Test person resource 1.1"@en-US ; + rdfs:label "Test person custom action 1.1"@en-US ; + dynapi:name "test_person_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . + + + a dynapi:resourceAPI ; + rdfs:label "Test person resourceAPI 1.1"@en-US ; + dynapi:name "test_person_resource" ; + dynapi:minAPIVersion "1.1.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "1.1.0" . - + dynapi:hasCustomRESTAction . - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.0.0" . + - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.0.0" . + - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.0.0" . + - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.0.0" . + - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.0.0" . - dynapi:rpcAPIVersionMax "1.1.0" . - - - dynapi:restAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.0.0" . + + dynapi:maxAPIVersion "1.0.0" . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person2.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person2.n3 index 7bb2f73e7e..bfa327da70 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person2.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person2.n3 @@ -9,8 +9,8 @@ a dynapi:action ; rdfs:label "Test person action 2"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -19,73 +19,76 @@ a dynapi:rpc ; - dynapi:resourceName "Test rpc create person 2" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "2.0.0" . + rdfs:label "Test rpc create person 2"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "2.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get person 2" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "2.0.0" . + rdfs:label "Test rpc get person 2"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "2.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update person 2" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "2.0.0" . + rdfs:label "Test rpc update person 2"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "2.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch person 2" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "2.0.0" . + rdfs:label "Test rpc patch person 2"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "2.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete person 2" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "2.0.0" . + rdfs:label "Test rpc delete person 2"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "2.0.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test person custom action 2" ; - dynapi:customRESTActionName "test_person_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "2.0.0" . - - - a dynapi:resource ; - dynapi:resourceName "test_person_resource" ; - rdfs:label "Test person resource 2"@en-US ; + rdfs:label "Test person custom action 2"@en-US ; + dynapi:name "test_person_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . + + + a dynapi:resourceAPI ; + rdfs:label "Test person resourceAPI 2"@en-US ; + dynapi:name "test_person_resource" ; + dynapi:minAPIVersion "2.0.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "2.0.0" . + dynapi:hasCustomRESTAction . + - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.1.0" . + - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.1.0" . + - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.1.0" . + - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.1.0" . + - dynapi:rpcAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.1.0" . - dynapi:rpcAPIVersionMax "1.1.0" . - - - dynapi:restAPIVersionMax "1.1.0" . + dynapi:maxAPIVersion "1.1.0" . + + dynapi:maxAPIVersion "1.1.0" . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person4_3_7.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person4_3_7.n3 index ae8b961142..a93779fe57 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person4_3_7.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-person4_3_7.n3 @@ -5,12 +5,11 @@ @prefix dynapi: . @prefix xsd: . - a dynapi:action ; rdfs:label "Test person action 4"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -19,73 +18,76 @@ a dynapi:rpc ; - dynapi:resourceName "Test rpc create person 4" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "4.3.7" . + rdfs:label "Test rpc create person 4"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "4.3.7" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get person 4" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "4.3.7" . + rdfs:label "Test rpc get person 4"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "4.3.7" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update person 4" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "4.3.7" . + rdfs:label "Test rpc update person 4"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "4.3.7" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch person 4" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "4.3.7" . + rdfs:label "Test rpc patch person 4"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "4.3.7" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete person 4" ; - dynapi:rpcName "test_person"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "4.3.7" . + rdfs:label "Test rpc delete person 4"@en-US ; + dynapi:name "test_person" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "4.3.7" . a dynapi:customRESTAction ; - dynapi:resourceName "Test person custom action 4" ; - dynapi:customRESTActionName "test_person_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "4.3.7" . - - - a dynapi:resource ; - dynapi:resourceName "test_person_resource" ; - rdfs:label "Test person resource 4"@en-US ; + rdfs:label "Test person custom action 4"@en-US ; + dynapi:name "test_person_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . + + + a dynapi:resourceAPI ; + rdfs:label "Test person resourceAPI 4.3.7"@en-US ; + dynapi:name "test_person_resource" ; + dynapi:minAPIVersion "4.3.7" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "4.3.7" . + dynapi:hasCustomRESTAction . + - dynapi:rpcAPIVersionMax "2.0.0" . + dynapi:maxAPIVersion "2.0.0" . + - dynapi:rpcAPIVersionMax "2.0.0" . + dynapi:maxAPIVersion "2.0.0" . + - dynapi:rpcAPIVersionMax "2.0.0" . + dynapi:maxAPIVersion "2.0.0" . + - dynapi:rpcAPIVersionMax "2.0.0" . + dynapi:maxAPIVersion "2.0.0" . + - dynapi:rpcAPIVersionMax "2.0.0" . + dynapi:maxAPIVersion "2.0.0" . - dynapi:rpcAPIVersionMax "2.0.0" . - - - dynapi:restAPIVersionMax "2.0.0" . + dynapi:maxAPIVersion "2.0.0" . + + dynapi:maxAPIVersion "2.0.0" . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-process.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-process.n3 index 3c3a29599b..11eaf31578 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-process.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-process.n3 @@ -9,8 +9,8 @@ a dynapi:action ; rdfs:label "Test process action 1"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -19,56 +19,54 @@ a dynapi:rpc ; - dynapi:resourceName "Test rpc create process 1" ; - dynapi:rpcName "test_process"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc create process 1"@en-US ; + dynapi:name "test_process" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get process 1" ; - dynapi:rpcName "test_process"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc get process 1"@en-US ; + dynapi:name "test_process" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update process 1" ; - dynapi:rpcName "test_process"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc update process 1"@en-US ; + dynapi:name "test_process" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch process 1" ; - dynapi:rpcName "test_process"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc patch process 1"@en-US ; + dynapi:name "test_process" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete process 1" ; - dynapi:rpcName "test_process"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc delete process 1"@en-US ; + dynapi:name "test_process" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test process custom action 1" ; - dynapi:customRESTActionName "test_process_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test process custom action 1"@en-US ; + dynapi:name "test_process_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . - - a dynapi:resource ; - dynapi:resourceName "test_process_resource" ; - rdfs:label "Test process resource 1"@en-US ; + + a dynapi:resourceAPI ; + rdfs:label "Test process resourceAPI 1"@en-US ; + dynapi:name "test_process_resource" ; + dynapi:minAPIVersion "1.0.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "1.0.0" . - + dynapi:hasCustomRESTAction . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-relationship.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-relationship.n3 index 72628d7a1d..422423f14c 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-relationship.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-relationship.n3 @@ -9,8 +9,8 @@ a dynapi:action ; rdfs:label "Test relationship action 1"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -19,56 +19,54 @@ a dynapi:rpc ; - dynapi:resourceName "Test rpc create relationship 1" ; - dynapi:rpcName "test_relationship"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc create relationship 1"@en-US ; + dynapi:name "test_relationship" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get relationship 1" ; - dynapi:rpcName "test_relationship"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc get relationship 1"@en-US ; + dynapi:name "test_relationship" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update relationship 1" ; - dynapi:rpcName "test_relationship"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc update relationship 1"@en-US ; + dynapi:name "test_relationship" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch relationship 1" ; - dynapi:rpcName "test_relationship"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc patch relationship 1"@en-US ; + dynapi:name "test_relationship" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete relationship 1" ; - dynapi:rpcName "test_relationship"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test rpc delete relationship 1"@en-US ; + dynapi:name "test_relationship" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "1.0.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test relationship custom action 1" ; - dynapi:customRESTActionName "test_relationship_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "1.0.0" . + rdfs:label "Test relationship custom action 1"@en-US ; + dynapi:name "test_relationship_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . - - a dynapi:resource ; - dynapi:resourceName "test_relationship_resource" ; - rdfs:label "Test relationship resource 1"@en-US ; + + a dynapi:resourceAPI ; + rdfs:label "Test relationship resourceAPI 1"@en-US ; + dynapi:name "test_relationship_resource" ; + dynapi:minAPIVersion "1.0.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "1.0.0" . - + dynapi:hasCustomRESTAction . diff --git a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-solr-test.n3 b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-solr-test.n3 index 263db492ca..8585a83215 100644 --- a/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-solr-test.n3 +++ b/api/src/test/resources/rdf/abox/filegraph/dynamic-api-individuals-solr-test.n3 @@ -5,52 +5,51 @@ @prefix dynapi: . @prefix xsd: . + + a dynapi:action ; + rdfs:label "Solr test action"@en-US ; + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . + + + a dynapi:step, dynapi:operationalStep ; + rdfs:label "Solr Test operational step 1"@en-US ; + dynapi:hasOperation . - a dynapi:operation, dynapi:solrQuery ; - rdfs:label "Test solr query 1"@en-US ; - dynapi:requiresParameter ; - dynapi:solrQueryText "http" ; - dynapi:solrField "Field1" , "Field2" ; - dynapi:solrFilter "Field2:?textSearchParam" , "ALTTEXT:get" ; - dynapi:solrOffset "3" ; - dynapi:solrLimit "10" ; - dynapi:solrSort "testField ASC" , "?sortFieldParam ?sortFieldDirection" ; - dynapi:solrFacet "ALLTEXT" . - + a dynapi:operation, dynapi:solrQuery ; + rdfs:label "Test solr query 1"@en-US ; + dynapi:requiresParameter ; + dynapi:solrQueryText "http" ; + dynapi:solrField "Field1" , "Field2" ; + dynapi:solrFilter "Field2:?textSearchParam" , "ALTTEXT:get" ; + dynapi:solrOffset "3" ; + dynapi:solrLimit "10" ; + dynapi:solrSort "testField ASC" , "?sortFieldParam ?sortFieldDirection" ; + dynapi:solrFacet "ALLTEXT" . + - a dynapi:parameter; - dynapi:paramName "searchText"; - dynapi:hasParameterType ; - rdfs:label "Search text for solr query 1"@en-US . - + a dynapi:parameter ; + rdfs:label "Search text for solr query 1"@en-US ; + dynapi:name "searchText" ; + dynapi:hasType . + - a dynapi:parameter; - dynapi:paramName "fildForSorting"; - dynapi:hasParameterType ; - rdfs:label "Choose document field for sorting"@en-US . + a dynapi:parameter ; + rdfs:label "Choose document field for sorting"@en-US ; + dynapi:name "fildForSorting" ; + dynapi:hasType . - a dynapi:parameter; - dynapi:paramName "sordDirection"; - dynapi:hasParameterType ; - rdfs:label "Choose sort direction"@en-US . - - - a dynapi:action ; - rdfs:label "Solr test action"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + a dynapi:parameter ; + rdfs:label "Choose sort direction"@en-US ; + dynapi:paramName "sordDirection" ; + dynapi:hasParameterType . - a dynapi:rpc ; - dynapi:resourceName "Solr Test rpc individual" ; - dynapi:rpcName "solr_test_action"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "0.1.0" . + a dynapi:rpc ; + dynapi:name "solr_test_action"@en-US ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersionMin "0.1.0" . - - a dynapi:step, dynapi:operationalStep ; - rdfs:label "Solr Test operational step 1"@en-US ; - dynapi:hasOperation . diff --git a/home/src/main/resources/rdf/abox/filegraph/dynamic-api-individuals-testing.n3 b/home/src/main/resources/rdf/abox/filegraph/dynamic-api-individuals-testing.n3 index d5172a8bb5..a7bbb059bd 100644 --- a/home/src/main/resources/rdf/abox/filegraph/dynamic-api-individuals-testing.n3 +++ b/home/src/main/resources/rdf/abox/filegraph/dynamic-api-individuals-testing.n3 @@ -10,8 +10,8 @@ a dynapi:action ; rdfs:label "Test action"@en-US ; - dynapi:assignedRPC ; - dynapi:firstStep . + dynapi:hasAssignedRPC ; + dynapi:hasFirstStep . a dynapi:step, dynapi:operationalStep ; @@ -21,94 +21,92 @@ a dynapi:operation, dynapi:sparqlQuery ; rdfs:label "Test sparql query 1"@en-US ; - dynapi:hasQueryModel ; + dynapi:hasModel ; dynapi:requiresParameter , ; dynapi:sparqlQueryText "SELECT ?geoLocation ?label\nWHERE\n{\n ?geoLocation \n OPTIONAL { ?geoLocation ?label } \n}\nLIMIT ?limit" . a dynapi:parameter ; - dynapi:paramName "limit" ; - dynapi:hasParameterType ; + rdfs:label "Test parameter 1 for query 1"@en-US ; + dynapi:name "limit" ; + dynapi:hasType ; dynapi:hasValidator , - ; - rdfs:label "Test parameter 1 for query 1"@en-US . + . a dynapi:parameter ; - dynapi:paramName "email" ; - dynapi:hasParameterType ; + rdfs:label "Test parameter 2 for query 1"@en-US ; + dynapi:name "email" ; + dynapi:hasType ; dynapi:hasValidator , - ; - rdfs:label "Test parameter 2 for query 1"@en-US . + . a dynapi:validator , dynapi_java:validators.Validator , dynapi_java:validators.NumericRangeValidator ; - dynapi:validatorMinNumericValue 10 ; - dynapi:validatorMaxNumericValue 30.5 ; - rdfs:label "Test range validator for parameter 1"@en-US . + rdfs:label "Test range validator for parameter 1"@en-US ; + dynapi:minValue 10 ; + dynapi:maxValue 30.5 . a dynapi:validator , dynapi_java:validators.Validator , dynapi_java:validators.StringLengthRangeValidator ; - dynapi:validatorMinLengthValue 5 ; - rdfs:label "Test string length range validator for parameter 2"@en-US . + rdfs:label "Test string length range validator for parameter 2"@en-US ; + dynapi:minLength 5 . a dynapi:rpc ; - dynapi:resourceName "Test rpc create individual" ; - dynapi:rpcName "test_action"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "0.1.0" . + rdfs:label "Test rpc create individual"@en-US ; + dynapi:name "test_action" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "0.1.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc get individual" ; - dynapi:rpcName "test_action"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "0.1.0" . + rdfs:label "Test rpc get individual"@en-US ; + dynapi:name "test_action" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "0.1.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc update individual" ; - dynapi:rpcName "test_action"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "0.1.0" . + rdfs:label "Test rpc update individual"@en-US ; + dynapi:name "test_action" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "0.1.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc patch individual" ; - dynapi:rpcName "test_action"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "0.1.0" . + rdfs:label "Test rpc patch individual"@en-US ; + dynapi:name "test_action" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "0.1.0" . a dynapi:rpc ; - dynapi:resourceName "Test rpc delete individual" ; - dynapi:rpcName "test_action"@en-US ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "0.1.0" . + rdfs:label "Test rpc delete individual"@en-US ; + dynapi:name "test_action" ; + dynapi:hasDefaultMethod ; + dynapi:minAPIVersion "0.1.0" . a dynapi:customRESTAction ; - dynapi:resourceName "Test custom action" ; - dynapi:customRESTActionName "test_custom_action_name" ; - dynapi:forwardTo ; - dynapi:defaultMethod ; - dynapi:rpcAPIVersionMin "0.1.0" . - - - a dynapi:resource ; - dynapi:resourceName "test_resource" ; - rdfs:label "Test resource 1"@en-US ; + rdfs:label "Test custom action"@en-US ; + dynapi:name "test_custom_action_name" ; + dynapi:hasDefaultMethod ; + dynapi:forwardsTo . + + + a dynapi:resourceAPI ; + rdfs:label "Test resourceAPI 1"@en-US ; + dynapi:name "test_resource" ; + dynapi:minAPIVersion "0.1.0" ; dynapi:onPost ; dynapi:onGet ; dynapi:onPut ; dynapi:onPatch ; dynapi:onDelete ; - dynapi:hasCustomRESTAction ; - dynapi:restAPIVersionMin "0.1.0" . - + dynapi:hasCustomRESTAction . diff --git a/home/src/main/resources/rdf/abox/filegraph/dynamic-api-individuals.n3 b/home/src/main/resources/rdf/abox/filegraph/dynamic-api-individuals.n3 index aeae4029c5..af13fb485b 100644 --- a/home/src/main/resources/rdf/abox/filegraph/dynamic-api-individuals.n3 +++ b/home/src/main/resources/rdf/abox/filegraph/dynamic-api-individuals.n3 @@ -25,12 +25,12 @@ vitro:mostSpecificType dynapi:validator . - a dynapi:validator , - dynapi_java:validators.Validator , - dynapi_java:validators.RegularExpressionValidator ; - dynapi:validatorRegularExpressionValue "^(.+)@(\\S+)$" ; - rdfs:label "Is email"@en-US ; - vitro:mostSpecificType dynapi:validator . + a dynapi:validator , + dynapi_java:validators.Validator , + dynapi_java:validators.RegularExpressionValidator ; + dynapi:regularExpression "^(.+)@(\\S+)$" ; + rdfs:label "Is email"@en-US ; + vitro:mostSpecificType dynapi:validator . #------------------------------------------------------------------------------- # @@ -39,45 +39,57 @@ a dynapi:parameterType , - dynapi_java:ParameterType ; - dynapi:typeName "boolean" ; + dynapi:primitiveParameterType , + dynapi_java:types.ParameterType , + dynapi_java:types.PrimitiveParameterType ; + dynapi:name "boolean" ; rdfs:label "Boolean type"@en-US ; - vitro:mostSpecificType dynapi:parameterType . + vitro:mostSpecificType dynapi:primitiveParameterType . a dynapi:parameterType , - dynapi_java:ParameterType ; - dynapi:typeName "decimal" ; + dynapi:primitiveParameterType , + dynapi_java:types.ParameterType , + dynapi_java:types.PrimitiveParameterType ; + dynapi:name "decimal" ; rdfs:label "Decimal type"@en-US ; - vitro:mostSpecificType dynapi:parameterType . + vitro:mostSpecificType dynapi:primitiveParameterType . a dynapi:parameterType , - dynapi_java:ParameterType ; - dynapi:typeName "integer" ; + dynapi:primitiveParameterType , + dynapi_java:types.ParameterType , + dynapi_java:types.PrimitiveParameterType ; + dynapi:name "integer" ; rdfs:label "Integer type"@en-US ; - vitro:mostSpecificType dynapi:parameterType . + vitro:mostSpecificType dynapi:primitiveParameterType . - + a dynapi:parameterType , - dynapi_java:ParameterType ; - dynapi:typeName "individual" ; - rdfs:label "Individual type"@en-US ; - vitro:mostSpecificType dynapi:parameterType . - - + dynapi:objectParameterType , + dynapi_java:types.ParameterType , + dynapi_java:types.ObjectParameterType ; + dynapi:name "object" ; + rdfs:label "Object type"@en-US ; + vitro:mostSpecificType dynapi:objectParameterType . + + a dynapi:parameterType , - dynapi_java:ParameterType ; - dynapi:typeName "list" ; - rdfs:label "List type"@en-US ; - vitro:mostSpecificType dynapi:parameterType . + dynapi:arrayParameterType , + dynapi_java:types.ParameterType , + dynapi_java:types.ArrayParameterType ; + dynapi:name "array" ; + rdfs:label "Array type"@en-US ; + vitro:mostSpecificType dynapi:arrayParameterType . a dynapi:parameterType , - dynapi_java:ParameterType ; - dynapi:typeName "string" ; + dynapi:primitiveParameterType , + dynapi_java:types.ParameterType , + dynapi_java:types.PrimitiveParameterType ; + dynapi:name "string" ; rdfs:label "String type"@en-US ; - vitro:mostSpecificType dynapi:parameterType . + vitro:mostSpecificType dynapi:primitiveParameterType . #------------------------------------------------------------------------------- # @@ -86,43 +98,43 @@ a dynapi:model ; - dynapi:modelName "TBOX_ASSERTIONS" ; + dynapi:name "TBOX_ASSERTIONS" ; rdfs:label "tbox assertions model"@en-US ; vitro:mostSpecificType dynapi:model . a dynapi:model ; - dynapi:modelName "ABOX_ASSERTIONS" ; + dynapi:name "ABOX_ASSERTIONS" ; rdfs:label "abox assertions model"@en-US ; vitro:mostSpecificType dynapi:model . a dynapi:model ; - dynapi:modelName "ABOX_UNION" ; + dynapi:name "ABOX_UNION" ; rdfs:label "abox union model"@en-US ; vitro:mostSpecificType dynapi:model . a dynapi:model ; - dynapi:modelName "TBOX_UNION" ; + dynapi:name "TBOX_UNION" ; rdfs:label "tbox union model"@en-US ; vitro:mostSpecificType dynapi:model . a dynapi:model ; - dynapi:modelName "FULL_UNION" ; + dynapi:name "FULL_UNION" ; rdfs:label "full union model"@en-US ; vitro:mostSpecificType dynapi:model . a dynapi:model ; - dynapi:modelName "APPLICATION_METADATA" ; + dynapi:name "APPLICATION_METADATA" ; rdfs:label "application metadata model"@en-US ; vitro:mostSpecificType dynapi:model . a dynapi:model ; - dynapi:modelName "USER_ACCOUNTS" ; + dynapi:name "USER_ACCOUNTS" ; rdfs:label "user accounts model"@en-US ; vitro:mostSpecificType dynapi:model . @@ -133,36 +145,36 @@ a dynapi:httpMethod ; - dynapi:methodName "GET" ; + dynapi:name "GET" ; rdfs:label "HTTP GET method"@en-US ; vitro:mostSpecificType dynapi:httpMethod . a dynapi:httpMethod ; - dynapi:methodName "POST" ; + dynapi:name "POST" ; rdfs:label "HTTP POST method"@en-US ; vitro:mostSpecificType dynapi:httpMethod . a dynapi:httpMethod ; - dynapi:methodName "PUT" ; + dynapi:name "PUT" ; rdfs:label "HTTP PUT method"@en-US ; vitro:mostSpecificType dynapi:httpMethod . a dynapi:httpMethod ; - dynapi:methodName "PATCH" ; + dynapi:name "PATCH" ; rdfs:label "HTTP PATCH method"@en-US ; vitro:mostSpecificType dynapi:httpMethod . a dynapi:httpMethod ; - dynapi:methodName "DELETE" ; + dynapi:name "DELETE" ; rdfs:label "HTTP DELETE method"@en-US ; vitro:mostSpecificType dynapi:httpMethod . a dynapi:httpMethod ; - dynapi:methodName "OPTIONS" ; + dynapi:name "OPTIONS" ; rdfs:label "HTTP OPTIONS method"@en-US ; - vitro:mostSpecificType dynapi:httpMethod . + vitro:mostSpecificType dynapi:httpMethod . \ No newline at end of file diff --git a/home/src/main/resources/rdf/tbox/filegraph/dynamic-api-implementation.n3 b/home/src/main/resources/rdf/tbox/filegraph/dynamic-api-implementation.n3 index 27fa6d7726..4de13f63a3 100644 --- a/home/src/main/resources/rdf/tbox/filegraph/dynamic-api-implementation.n3 +++ b/home/src/main/resources/rdf/tbox/filegraph/dynamic-api-implementation.n3 @@ -21,9 +21,13 @@ dynapi:model rdfs:subClassOf dynapi_java:ModelComponent . dynapi:parameter rdfs:subClassOf dynapi_java:Parameter . -dynapi:parameterType rdfs:subClassOf dynapi_java:ParameterType . +dynapi:primitiveParameterType rdfs:subClassOf dynapi_java:types.PrimitiveParameterType, dynapi_java:types.ParameterType . -dynapi:resource rdfs:subClassOf dynapi_java:Resource . +dynapi:arrayParameterType rdfs:subClassOf dynapi_java:types.ArrayParameterType, dynapi_java:types.ParameterType . + +dynapi:objectParameterType rdfs:subClassOf dynapi_java:types.ObjectParameterType, dynapi_java:types.ParameterType . + +dynapi:resourceAPI rdfs:subClassOf dynapi_java:ResourceAPI . dynapi:rpc rdfs:subClassOf dynapi_java:RPC . @@ -31,3 +35,4 @@ dynapi:httpMethod rdfs:subClassOf dynapi_java:HTTPMethod . dynapi:customRESTAction rdfs:subClassOf dynapi_java:CustomRESTAction . +dynapi:api rdfs:subClassOf dynapi_java:APIInformation . diff --git a/home/src/main/resources/rdf/tbox/filegraph/vitro-dynamic-api.owl b/home/src/main/resources/rdf/tbox/filegraph/vitro-dynamic-api.owl index adaebace0f..469dc5479c 100644 --- a/home/src/main/resources/rdf/tbox/filegraph/vitro-dynamic-api.owl +++ b/home/src/main/resources/rdf/tbox/filegraph/vitro-dynamic-api.owl @@ -7,10 +7,10 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> - - - - - + @@ -31,7 +29,7 @@ has operation - + @@ -42,48 +40,48 @@ has validator - - - + + + first step - - - + + + next - - - + + + next step if condition fails - - - + + + next step if condition is met - + @@ -94,7 +92,7 @@ provides parameter - + @@ -105,7 +103,7 @@ requires access - + @@ -116,84 +114,87 @@ requires parameter - - - + + + + has query model - + - + + - - - has template model + + + has type - - - - + - - + - has parameter type + type of elements in an array + + + + + + has internal element - - + on GET - + - + on POST - + - + on DELETE - + - + on PUT - - + + - + on PATCH @@ -203,15 +204,15 @@ - + has custom action - + - + @@ -221,9 +222,9 @@ - + - + @@ -231,17 +232,19 @@ - + - + + default http method - - - - - + - has n3 text + n3 text - + @@ -272,8 +273,8 @@ SPARQL query text - - + + @@ -283,27 +284,27 @@ solr query text - + - + solr query fields to be returned - + - + solr query filter - + - + @@ -311,9 +312,9 @@ solr query limit parameter - + - + @@ -321,36 +322,36 @@ solr query offset parameter - + - + solr query sort parameter - + - + solr query facet parameter - + - + - has question + question - + @@ -361,123 +362,95 @@ is optional - - - - - - rpc name - - - + + - - model name - - - - - + + + + - parameter name + name - + validator min value - + validator max value - + - validator min length value + validator min length - + - validator max length value + validator max length - + - validator regular expression value + validator regular expression - - - - - type name - - - + - - - resource name - - - - - - - REST API minimum version - - - - - + + - REST API maximum version - + API minimum version + - + + - RPC API minimum version - + API maximum version + - + - + - RPC API maximum version - + title + - + - + + + - http method name - + description + - + - + - custom action name - - - - - @@ -495,7 +466,7 @@ Action - + @@ -504,7 +475,7 @@ Conditional step - + @@ -520,8 +491,21 @@ Parameter type - + + Primitive parameter type + + + + + Object parameter type + + + + + Array parameter type + + @@ -529,7 +513,7 @@ Role - + @@ -550,7 +534,7 @@ sparql Query - + @@ -561,7 +545,7 @@ SolrQuery - + @@ -575,7 +559,7 @@ Operational step - + @@ -591,7 +575,7 @@ Template - + @@ -633,18 +617,17 @@ Model - - + - - Resource + + Resource API - + - RPC + RPC @@ -660,9 +643,12 @@ Custom REST action + + API description + + -