From 7d6aa5f4e9efdafe24a5a72f1012e88a35f07ba6 Mon Sep 17 00:00:00 2001 From: Zdenek Vales Date: Thu, 23 Jan 2020 13:16:51 +0100 Subject: [PATCH] #21: Checker now takes resource instead of collection of capabilities. Implementation of rest api for checker. OSGi service for checker. Checker and restimpl indexer modules added to default modules so that they're included in the build. --- .../crce-api-compatibility-checker/osgi.bnd | 5 ++ .../crce-api-compatibility-checker/pom.xml | 2 + .../crce/apicomp/ApiCompatibilityChecker.java | 25 +++++--- .../ApiCompatibilityCheckerService.java | 11 ---- .../ApiCompatibilityCheckerServiceImpl.java | 32 +++------- .../restimpl/RestApiCompatibilityChecker.java | 34 ++++++---- .../WebservicesCompatibilityChecker.java | 13 ++-- .../kiv/crce/apicomp/internal/Activator.java | 21 +++++-- .../result/CompatibilityCheckResult.java | 13 ++++ .../RestApiCompatibilityCheckerTest.java | 62 +++++++++++-------- modules/crce-default-modules/pom.xml | 15 +++-- .../internal/ws/jersey/ApiCompResJersey.java | 45 +++++++++----- modules/crce-restimpl-indexer/pom.xml | 1 + 13 files changed, 165 insertions(+), 114 deletions(-) create mode 100644 modules/crce-api-compatibility-checker/osgi.bnd diff --git a/modules/crce-api-compatibility-checker/osgi.bnd b/modules/crce-api-compatibility-checker/osgi.bnd new file mode 100644 index 00000000..ed49a253 --- /dev/null +++ b/modules/crce-api-compatibility-checker/osgi.bnd @@ -0,0 +1,5 @@ +#----------------------------------------------------------------- +# Use this file to add customized Bnd instructions for the bundle +#----------------------------------------------------------------- + +Bundle-Activator: ${bundle.namespace}.internal.Activator diff --git a/modules/crce-api-compatibility-checker/pom.xml b/modules/crce-api-compatibility-checker/pom.xml index 82ad8972..e4fadfa0 100644 --- a/modules/crce-api-compatibility-checker/pom.xml +++ b/modules/crce-api-compatibility-checker/pom.xml @@ -12,6 +12,7 @@ crce-api-compatibility-checker 0.0.1-SNAPSHOT + bundle Apicomp - API compatibility checker @@ -27,6 +28,7 @@ ${namespace}.apicomp ${namespace}.apicomp + ${bundle.namespace}.internal.Activator diff --git a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/ApiCompatibilityChecker.java b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/ApiCompatibilityChecker.java index 12ebd314..ac701e6a 100644 --- a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/ApiCompatibilityChecker.java +++ b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/ApiCompatibilityChecker.java @@ -1,36 +1,41 @@ package cz.zcu.kiv.crce.apicomp; import cz.zcu.kiv.crce.apicomp.result.CompatibilityCheckResult; -import cz.zcu.kiv.crce.metadata.Capability; - -import java.util.Set; +import cz.zcu.kiv.crce.metadata.Resource; /** * Interface for compatibility checkers. */ public interface ApiCompatibilityChecker { + /** + * Namespace of the root capability that is expected to hold all metadata relevant to this checker. + * + * @return Capability namespace. + */ + String getRootCapabilityNamespace(); + /** * Verifies that the provided API is supported by this compatibility checker. - * Verification is based on presence of identity capability and it's correct - * namespace and value. + * Verification is based on presence of root capability with namespace equal to + * {@link #getRootCapabilityNamespace()}. * - * @param apiMetadata Set of capabilities which describes the API. + * @param resource Resource that contains API metadata. * @return True if the given API is supported. */ - boolean isApiSupported(Set apiMetadata); + boolean isApiSupported(Resource resource); /** * Compares two APIs using metadata stored in CRCE and returns result in form of * a CompatibilityCheckResult object. * - * @param api1 Set of capabilities containing the metadata for the first API. This might be either single root + * @param api1 Resource with capabilities containing the metadata for the first API. This might be either single root * capability which contains child capabilities with attributes and/or properties with metadata or set of root * capabilities with child capabilities with attributes and/or properties. - * @param api2 Set of capabilities containing the metadata for the second API. This might be either single root + * @param api2 Resource with capabilities containing the metadata for the second API. This might be either single root * capability which contains child capabilities with attributes and/or properties with metadata or set of root * capabilities with child capabilities with attributes and/or properties. * @return Result. */ - CompatibilityCheckResult compareApis(Set api1, Set api2); + CompatibilityCheckResult compareApis(Resource api1, Resource api2); } diff --git a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/ApiCompatibilityCheckerService.java b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/ApiCompatibilityCheckerService.java index b157bf5d..076b1c28 100644 --- a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/ApiCompatibilityCheckerService.java +++ b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/ApiCompatibilityCheckerService.java @@ -1,11 +1,8 @@ package cz.zcu.kiv.crce.apicomp; import cz.zcu.kiv.crce.apicomp.result.CompatibilityCheckResult; -import cz.zcu.kiv.crce.metadata.Capability; import cz.zcu.kiv.crce.metadata.Resource; -import java.util.Set; - /** * A service responsible for calling correct compatibility comparator for * given metadata. @@ -28,12 +25,4 @@ public interface ApiCompatibilityCheckerService { * @return Checker able to compare this resource. */ ApiCompatibilityChecker pickChecker(Resource resource); - - /** - * Returns checker compatible for given set of metadata representing API. - * - * @param apiMetadata API metadata. - * @return Checker able to compare this resource. - */ - ApiCompatibilityChecker pickChecker(Set apiMetadata); } diff --git a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/ApiCompatibilityCheckerServiceImpl.java b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/ApiCompatibilityCheckerServiceImpl.java index 16781015..19aa24d4 100644 --- a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/ApiCompatibilityCheckerServiceImpl.java +++ b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/ApiCompatibilityCheckerServiceImpl.java @@ -5,13 +5,12 @@ import cz.zcu.kiv.crce.apicomp.impl.restimpl.RestApiCompatibilityChecker; import cz.zcu.kiv.crce.apicomp.impl.webservice.WebservicesCompatibilityChecker; import cz.zcu.kiv.crce.apicomp.result.CompatibilityCheckResult; -import cz.zcu.kiv.crce.metadata.Capability; import cz.zcu.kiv.crce.metadata.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; /** * A service responsible for fetching resources' metadata and passing them to @@ -19,6 +18,8 @@ */ public class ApiCompatibilityCheckerServiceImpl implements ApiCompatibilityCheckerService { + private static final Logger logger = LoggerFactory.getLogger(ApiCompatibilityCheckerServiceImpl.class); + private List availableCheckers; public ApiCompatibilityCheckerServiceImpl() { @@ -30,34 +31,21 @@ public ApiCompatibilityCheckerServiceImpl() { @Override public CompatibilityCheckResult compareApis(Resource api1, Resource api2) { - // todo: pass only resource to every layer? - Set metadata1 = new HashSet<>(api1.getCapabilities()); - Set metadata2 = new HashSet<>(api2.getCapabilities()); - - ApiCompatibilityChecker c1 = pickChecker(metadata1), - c2 = pickChecker(metadata2); + ApiCompatibilityChecker c1 = pickChecker(api1), + c2 = pickChecker(api2); - if (c1 == null || c2 == null || !c1.equals(c2)) { - // todo: log error or something + if (c1 == null || !c1.equals(c2)) { + logger.warn("Could not pick right checker or APIs are not comparable."); return null; } - return c1.compareApis(metadata1, metadata2); + return c1.compareApis(api1, api2); } @Override public ApiCompatibilityChecker pickChecker(Resource resource) { - Set metadata = new HashSet<>(resource.getCapabilities()); - return availableCheckers.stream() - .filter(checker -> checker.isApiSupported(metadata)) - .findFirst() - .orElse(null); - } - - @Override - public ApiCompatibilityChecker pickChecker(Set apiMetadata) { return availableCheckers.stream() - .filter(checker -> checker.isApiSupported(apiMetadata)) + .filter(checker -> checker.isApiSupported(resource)) .findFirst() .orElse(null); } diff --git a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/restimpl/RestApiCompatibilityChecker.java b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/restimpl/RestApiCompatibilityChecker.java index dce3791d..a85a6d4b 100644 --- a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/restimpl/RestApiCompatibilityChecker.java +++ b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/restimpl/RestApiCompatibilityChecker.java @@ -9,9 +9,13 @@ import cz.zcu.kiv.crce.compatibility.impl.DefaultDiffImpl; import cz.zcu.kiv.crce.metadata.Attribute; import cz.zcu.kiv.crce.metadata.Capability; +import cz.zcu.kiv.crce.metadata.Resource; import cz.zcu.kiv.crce.metadata.impl.ListAttributeType; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; /** * Compatibility checker for REST API. Expects metadata structure created by @@ -20,28 +24,34 @@ public class RestApiCompatibilityChecker implements ApiCompatibilityChecker { + public RestApiCompatibilityChecker() { + } + + @Override + public String getRootCapabilityNamespace() { + return RestimplIndexerConstants.IDENTITY_CAPABILITY_NAMESPACE; + } + @Override - public boolean isApiSupported(Set apiMetadata) { + public boolean isApiSupported(Resource resource) { // API is supported if it contains capability with namespace 'restimpl.identity' // related constants are in internal package of crce-restimpl-indexer module - return apiMetadata != null && - apiMetadata - .stream() - .anyMatch(capability -> RestimplIndexerConstants.IDENTITY_CAPABILITY_NAMESPACE.equals(capability.getNamespace())); + return resource != null && + !resource.getRootCapabilities(getRootCapabilityNamespace()).isEmpty(); } @Override - public CompatibilityCheckResult compareApis(Set api1, Set api2) { - CompatibilityCheckResult checkResult = new CompatibilityCheckResult(); + public CompatibilityCheckResult compareApis(Resource api1, Resource api2) { + CompatibilityCheckResult checkResult = new CompatibilityCheckResult(api1, api2); // given the structure of metadata created in crce-restimpl-indexer, both // capability sets should contain exactly 1 capability - if (api1.size() != 1 || !isApiSupported(api1)) { + if (!isApiSupported(api1)) { // todo: log error throw new RuntimeException("API 1 is not supported by this checker!"); } - if (api2.size() != 1 || !isApiSupported(api2)) { + if (!isApiSupported(api2)) { // todo: log error throw new RuntimeException("API 2 is not supported by this checker!"); } @@ -49,8 +59,8 @@ public CompatibilityCheckResult compareApis(Set api1, Set apiMetadata) { + public String getRootCapabilityNamespace() { + return null; + } + + @Override + public boolean isApiSupported(Resource resource) { return false; } @Override - public CompatibilityCheckResult compareApis(Set api1, Set api2) { + public CompatibilityCheckResult compareApis(Resource api1, Resource api2) { return null; } } diff --git a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/internal/Activator.java b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/internal/Activator.java index ded9d7bd..426092c0 100644 --- a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/internal/Activator.java +++ b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/internal/Activator.java @@ -6,18 +6,29 @@ import org.apache.felix.dm.DependencyManager; import org.osgi.framework.BundleContext; +import java.util.Hashtable; + /** * Apicomp bundle activator. */ public class Activator extends DependencyActivatorBase { + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + + System.out.println("Start the Apicomp bundle."); + } + @Override public void init(BundleContext context, DependencyManager manager) throws Exception { - System.out.println("Starting the Apicomp bundle."); + System.out.println("Init the Apicomp bundle."); + - manager.add(createComponent() - .setInterface(ApiCompatibilityCheckerService.class.getName(), null) - .setImplementation(ApiCompatibilityCheckerServiceImpl.class) - ); + context.registerService(ApiCompatibilityCheckerService.class, new ApiCompatibilityCheckerServiceImpl(), new Hashtable<>()); +// manager.add(createComponent() +// .setInterface(ApiCompatibilityCheckerService.class.getName(), null) +// .setImplementation(ApiCompatibilityCheckerServiceImpl.class) +// ); } } diff --git a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/result/CompatibilityCheckResult.java b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/result/CompatibilityCheckResult.java index c20bf0f9..cc5786f4 100644 --- a/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/result/CompatibilityCheckResult.java +++ b/modules/crce-api-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/result/CompatibilityCheckResult.java @@ -4,6 +4,7 @@ import cz.zcu.kiv.crce.compatibility.Contract; import cz.zcu.kiv.crce.compatibility.Diff; import cz.zcu.kiv.crce.compatibility.Difference; +import cz.zcu.kiv.crce.metadata.Resource; import cz.zcu.kiv.crce.metadata.type.Version; import javax.annotation.Nonnull; @@ -51,6 +52,18 @@ public CompatibilityCheckResult() { diffDetails = new ArrayList<>(); } + /** + * Diff object of two resources. + * + * @param baseResource Base resource. + * @param resource Resource that is being compared to the base one. + */ + public CompatibilityCheckResult(Resource baseResource, Resource resource) { + this(); + baseResourceName = baseResource.getId(); + resourceName = resource.getId(); + } + @Override public String getId() { return null; diff --git a/modules/crce-api-compatibility-checker/src/test/java/cz/zcu/kiv/crce/apicomp/RestApiCompatibilityCheckerTest.java b/modules/crce-api-compatibility-checker/src/test/java/cz/zcu/kiv/crce/apicomp/RestApiCompatibilityCheckerTest.java index f08bf929..67ab1b42 100644 --- a/modules/crce-api-compatibility-checker/src/test/java/cz/zcu/kiv/crce/apicomp/RestApiCompatibilityCheckerTest.java +++ b/modules/crce-api-compatibility-checker/src/test/java/cz/zcu/kiv/crce/apicomp/RestApiCompatibilityCheckerTest.java @@ -6,14 +6,14 @@ import cz.zcu.kiv.crce.compatibility.Difference; import cz.zcu.kiv.crce.metadata.Capability; import cz.zcu.kiv.crce.metadata.Property; +import cz.zcu.kiv.crce.metadata.Resource; import cz.zcu.kiv.crce.metadata.internal.CapabilityImpl; import cz.zcu.kiv.crce.metadata.internal.PropertyImpl; +import cz.zcu.kiv.crce.metadata.internal.ResourceImpl; import org.junit.Test; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; -import java.util.Set; import static org.junit.Assert.*; @@ -25,28 +25,31 @@ public class RestApiCompatibilityCheckerTest { public void testIsApiSupported() { RestApiCompatibilityChecker checker = new RestApiCompatibilityChecker(); - Capability supportedCapability = new CapabilityImpl("restimpl.identity", ""); - Capability notSupportedCapability = new CapabilityImpl("not.supported", ""); + Resource supportedResource = new ResourceImpl("api"); + supportedResource.addRootCapability(new CapabilityImpl("restimpl.identity", "")); - assertFalse("Empty set should not be supported!",checker.isApiSupported(Collections.emptySet())); + Resource notSupportedResource = new ResourceImpl("api"); + notSupportedResource.addRootCapability(new CapabilityImpl("not.supported", "")); + + assertFalse("Empty set should not be supported!",checker.isApiSupported(new ResourceImpl(""))); assertFalse("Null set should not be supported!",checker.isApiSupported(null)); - assertFalse("Compatibility set with wrong namespace should not be supported", checker.isApiSupported(Collections.singleton(notSupportedCapability))); - assertTrue("Compatibility set with wrong namespace should be supported", checker.isApiSupported(Collections.singleton(supportedCapability))); + assertFalse("Compatibility set with wrong namespace should not be supported", checker.isApiSupported(notSupportedResource)); + assertTrue("Compatibility set with wrong namespace should be supported", checker.isApiSupported(supportedResource)); } @Test(expected = RuntimeException.class) public void testCompareApis_api1notSupported() { - Set api1 = new HashSet<>(); - api1.add(new CapabilityImpl("namespace", "id")); - api1.add(new CapabilityImpl("namespace2", "id2")); + Resource r1 = new ResourceImpl("api1"); + r1.addRootCapability(new CapabilityImpl("namespace", "id")); + r1.addRootCapability(new CapabilityImpl("namespace2", "id2")); - Set api2 = new HashSet<>(); - api1.add(new CapabilityImpl("namespace", "id")); - api1.add(new CapabilityImpl("namespace2", "id2")); + Resource r2 = new ResourceImpl("api2"); + r2.addRootCapability(new CapabilityImpl("namespace", "id")); + r2.addRootCapability(new CapabilityImpl("namespace2", "id2")); RestApiCompatibilityChecker checker = new RestApiCompatibilityChecker(); - checker.compareApis(api1, api2); + checker.compareApis(r1, r2); fail("Not supported exception expected!"); } @@ -56,8 +59,8 @@ public void testCompareApis_api1notSupported() { @Test public void testCompareApis_sameApi() { RestApiCompatibilityChecker checker = new RestApiCompatibilityChecker(); - Set api1 = Collections.singleton(createMockApi1()); - Set api2 = Collections.singleton(createMockApi1()); + Resource api1 = createMockApi1(); + Resource api2 = createMockApi1(); CompatibilityCheckResult result = checker.compareApis(api1, api2); assertEquals("APIs should be same!", Difference.NON, result.getDiffValue()); @@ -66,8 +69,8 @@ public void testCompareApis_sameApi() { @Test public void testCompareApis_differentApi() { RestApiCompatibilityChecker checker = new RestApiCompatibilityChecker(); - Set api1 = Collections.singleton(createMockApi1()); - Set api2 = Collections.singleton(createMockApi2()); + Resource api1 = createMockApi1(); + Resource api2 = createMockApi2(); CompatibilityCheckResult result = checker.compareApis(api1, api2); assertEquals("APIs should not be same!", Difference.MUT, result.getDiffValue()); @@ -80,8 +83,8 @@ public void testCompareApis_differentApi() { @Test public void testCompareApis_shuffled() { RestApiCompatibilityChecker checker = new RestApiCompatibilityChecker(); - Set api1 = Collections.singleton(createMockApi2()); - Set api2 = Collections.singleton(createMockApi2_shuffled()); + Resource api1 = createMockApi2(); + Resource api2 = createMockApi2_shuffled(); CompatibilityCheckResult result = checker.compareApis(api1, api2); assertEquals("APIs should be same!", Difference.NON, result.getDiffValue()); @@ -92,7 +95,7 @@ public void testCompareApis_shuffled() { * * @return */ - private Capability createMockApi1() { + private Resource createMockApi1() { // root capability Capability apiRoot = new CapabilityImpl(RestimplIndexerConstants.IDENTITY_CAPABILITY_NAMESPACE, ""); @@ -112,8 +115,9 @@ private Capability createMockApi1() { responseProperty.setAttribute(RestimplIndexerConstants.ATTR__RESTIMPL_RESPONSE_ID, "cz/kiv/zcu/server/Server.testEndpoint0"); responseProperty.setAttribute(RestimplIndexerConstants.ATTR__RESTIMPL_RESPONSE_STATUS, 200L); - - return apiRoot; + Resource api = new ResourceImpl(""); + api.addRootCapability(apiRoot); + return api; } /** @@ -121,7 +125,7 @@ private Capability createMockApi1() { * * @return */ - private Capability createMockApi2() { + private Resource createMockApi2() { // root capability Capability apiRoot = new CapabilityImpl(RestimplIndexerConstants.IDENTITY_CAPABILITY_NAMESPACE, ""); @@ -142,7 +146,9 @@ private Capability createMockApi2() { responseProperty.setAttribute(RestimplIndexerConstants.ATTR__RESTIMPL_RESPONSE_STATUS, 200L); - return apiRoot; + Resource api = new ResourceImpl(""); + api.addRootCapability(apiRoot); + return api; } /** @@ -150,7 +156,7 @@ private Capability createMockApi2() { * * @return */ - private Capability createMockApi2_shuffled() { + private Resource createMockApi2_shuffled() { // root capability Capability apiRoot = new CapabilityImpl(RestimplIndexerConstants.IDENTITY_CAPABILITY_NAMESPACE, ""); @@ -171,6 +177,8 @@ private Capability createMockApi2_shuffled() { responseProperty.setAttribute(RestimplIndexerConstants.ATTR__RESTIMPL_RESPONSE_STATUS, 200L); - return apiRoot; + Resource api = new ResourceImpl(""); + api.addRootCapability(apiRoot); + return api; } } diff --git a/modules/crce-default-modules/pom.xml b/modules/crce-default-modules/pom.xml index 27c1b441..8c14e0ce 100644 --- a/modules/crce-default-modules/pom.xml +++ b/modules/crce-default-modules/pom.xml @@ -77,11 +77,16 @@ crce-component-versioning 1.0 - - - - - + + ${project.groupId} + crce-restimpl-indexer + 2.1.1-SNAPSHOT + + + ${project.groupId} + crce-api-compatibility-checker + 0.0.1-SNAPSHOT + ${project.groupId} crce-webui-v2 diff --git a/modules/crce-rest-v2/src/main/java/cz/zcu/kiv/crce/rest/v2/internal/ws/jersey/ApiCompResJersey.java b/modules/crce-rest-v2/src/main/java/cz/zcu/kiv/crce/rest/v2/internal/ws/jersey/ApiCompResJersey.java index c5fc37d6..97c28f41 100644 --- a/modules/crce-rest-v2/src/main/java/cz/zcu/kiv/crce/rest/v2/internal/ws/jersey/ApiCompResJersey.java +++ b/modules/crce-rest-v2/src/main/java/cz/zcu/kiv/crce/rest/v2/internal/ws/jersey/ApiCompResJersey.java @@ -6,11 +6,10 @@ import cz.zcu.kiv.crce.repository.Store; import cz.zcu.kiv.crce.rest.v2.internal.Activator; import cz.zcu.kiv.crce.rest.v2.internal.ws.ApiCompRes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import javax.ws.rs.Consumes; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -19,21 +18,33 @@ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public class ApiCompResJersey implements ApiCompRes { + private static final Logger logger = LoggerFactory.getLogger(ApiCompResJersey.class); + @Path("/compare") + @GET @Override public Response compareApis(@QueryParam("id1") String id1, @QueryParam("id2") String id2) { - - // todo: resolve resources by their ids (and return error if needed) - Store store = Activator.instance().getStore(); - Resource api1 = store.getResource(id1, false); - Resource api2 = store.getResource(id2, false); - - - // todo: call compatibility checker service - ApiCompatibilityCheckerService compatibilityCheckerService = Activator.instance().getApiCompatibilityCheckerService(); - CompatibilityCheckResult result = compatibilityCheckerService.compareApis(api1, api2); - - // return result - return Response.ok(result).build(); + logger.info("Comparing APIS with ids: '{}' and '{}'.", id1, id2); + + try { + logger.debug("Getting resources from store."); + Store store = Activator.instance().getStore(); + Resource api1 = store.getResource(id1, true); + Resource api2 = store.getResource(id2, true); + + logger.debug("Calling compatibility checker service."); + ApiCompatibilityCheckerService compatibilityCheckerService = Activator.instance().getApiCompatibilityCheckerService(); + CompatibilityCheckResult result = compatibilityCheckerService.compareApis(api1, api2); + + logger.debug("Done."); + if (result == null) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } + + return Response.ok(result).build(); + } catch (Exception ex) { + logger.error("Unexpected error occurred.", ex); + return Response.serverError().build(); + } } } diff --git a/modules/crce-restimpl-indexer/pom.xml b/modules/crce-restimpl-indexer/pom.xml index 68fc4df4..6285a453 100644 --- a/modules/crce-restimpl-indexer/pom.xml +++ b/modules/crce-restimpl-indexer/pom.xml @@ -66,6 +66,7 @@ org.ow2.asm asm + 7.1