Simplified catalog solutions lookup 30/2730/1
authorSerban Jora <sj2381@att.com>
Wed, 5 Sep 2018 18:42:25 +0000 (14:42 -0400)
committerSerban Jora <sj2381@att.com>
Wed, 5 Sep 2018 18:43:55 +0000 (14:43 -0400)
Fix missing 'self' peer handling

Change-Id: I1b57ace65b52e9be9abf661e8816a6ce1546be94
Signed-off-by: Serban Jora <sj2381@att.com>
Issue-ID: ACUMOS-1694

docs/release-notes.rst
gateway/pom.xml
gateway/src/main/java/org/acumos/federation/gateway/cds/AccessType.java [new file with mode: 0644]
gateway/src/main/java/org/acumos/federation/gateway/security/AuthenticationConfiguration.java
gateway/src/main/java/org/acumos/federation/gateway/service/CatalogServiceConfiguration.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/CatalogServiceImpl.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/ServiceImpl.java
gateway/src/test/java/org/acumos/federation/gateway/test/CatalogServiceTest.java

index d2ac3ee..917174d 100644 (file)
@@ -22,6 +22,12 @@ Federated Gateway Release Notes
 
 The Federated Gateway server is available as a Docker image in a Docker registry.
 
+Version 1.18.1, 2018-09-05
+-------------------------
+
+* Simplified catalog solutions lookup
+* Fix 'self' peer not found (ACUMS-1694)
+
 Version 1.18.0, 2018-09-05
 -------------------------
 
index 4c7ae05..8f9654d 100644 (file)
@@ -24,7 +24,7 @@ limitations under the License.
        <modelVersion>4.0.0</modelVersion>
        <groupId>org.acumos.federation</groupId>
        <artifactId>gateway</artifactId>
-       <version>1.18.0-SNAPSHOT</version>
+       <version>1.18.1-SNAPSHOT</version>
        <name>Federation Gateway</name>
        <description>Federated Acumos Interface for inter-acumos and ONAP communication</description>
 
diff --git a/gateway/src/main/java/org/acumos/federation/gateway/cds/AccessType.java b/gateway/src/main/java/org/acumos/federation/gateway/cds/AccessType.java
new file mode 100644 (file)
index 0000000..acc1932
--- /dev/null
@@ -0,0 +1,59 @@
+/*-
+ * ===============LICENSE_START=======================================================
+ * Acumos
+ * ===================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
+ * ===================================================================================
+ * This Acumos software file is distributed by AT&T and Tech Mahindra
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *  
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ * This file is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ===============LICENSE_END=========================================================
+ */
+package org.acumos.federation.gateway.cds;
+
+import java.util.EnumSet;
+
+/**
+ * Supplements the CDS representation of a solution revision access type information.
+ */
+public enum AccessType {
+
+       Organization("OR"), //
+       Public("PB"), //
+       Private("PR"), //
+       Restricted("RS")//
+       ;
+
+       private String                                                  code;
+       //private MLPAccessTypeCode     mlp;
+
+       private AccessType(String theCode) {
+               this.code = theCode;
+       }
+
+       public String code() {
+               return this.code;
+       }
+
+       //public MLPAccessType mlp() {
+       //      return this.mlp;
+       //}
+
+       public static AccessType forCode(final String theCode) {
+               return EnumSet.allOf(AccessType.class)
+                                               .stream()
+                                               .filter(status -> status.code().equals(theCode))
+                                               .findFirst()
+                                               .orElse(null);
+       }
+}
+
+
index 239f42f..8791b4b 100644 (file)
@@ -33,6 +33,7 @@ import org.acumos.federation.gateway.service.PeerService;
 import org.acumos.federation.gateway.util.Utils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.BeanCreationException;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Lazy;
@@ -114,7 +115,10 @@ public class AuthenticationConfiguration extends WebSecurityConfigurerAdapter {
        @Bean
        @Lazy
        public Peer self() {
-               return new Peer(peerService.getSelf(), Role.SELF.priviledges());
+               MLPPeer self = peerService.getSelf();
+               if (self == null)
+                       throw new BeanCreationException("Unable to find 'self' peer");
+               return new Peer(self, Role.SELF.priviledges());
        }
 
        /** */
index 6c4a6dc..2f78362 100644 (file)
@@ -69,6 +69,8 @@ public class CatalogServiceConfiguration {
                this.solutionsSelector.put(Solution.Fields.active, true);
                // Fetch only Public models
                this.solutionsSelector.put(Solution.Fields.accessTypeCode, AccessTypeCode.PB.toString());
+               // Fetch solutions last updated since the beggining of times
+               this.solutionsSelector.put(Solution.Fields.modified, new Long(1));
 
                this.solutionRevisionsSelector = new HashMap<String, Object>();
                // Fetch only for Public revisions
index 419a2db..45e0fce 100644 (file)
@@ -24,6 +24,7 @@
 package org.acumos.federation.gateway.service.impl;
 
 import java.lang.invoke.MethodHandles;
+import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -47,6 +48,8 @@ import org.acumos.federation.gateway.cds.Document;
 import org.acumos.federation.gateway.cds.Artifact;
 import org.acumos.federation.gateway.cds.Solution;
 import org.acumos.federation.gateway.cds.SolutionRevision;
+import org.acumos.federation.gateway.cds.AccessType;
+import org.acumos.federation.gateway.cds.ValidationStatus;
 import org.acumos.federation.gateway.config.EELFLoggerDelegate;
 import org.acumos.federation.gateway.service.CatalogService;
 import org.acumos.federation.gateway.service.CatalogServiceConfiguration;
@@ -95,54 +98,24 @@ public class CatalogServiceImpl extends AbstractServiceImpl
                try {
                        do {
                                log.debug(EELFLoggerDelegate.debugLogger, "getSolutions page {}", pageResponse);
-                               if (selector.containsKey(Solution.Fields.modified)) {
-                                       //Use the dedicated api: this is a 'deep' application of the 'modified' criteria as it will look into revisions
-                                       //and artifacts for related information modified since.
-                                       pageResponse =
-                                               cdsClient.findSolutionsByDate(
-                                                       (Boolean)selector.getOrDefault(Solution.Fields.active, Boolean.TRUE),
-                                                       selector.containsKey(Solution.Fields.accessTypeCode) ?
-                                                               new String[] {selector.get(Solution.Fields.accessTypeCode).toString()} :
-                                                               null,
-                                                       selector.containsKey(Solution.Fields.validationStatusCode) ?
-                                                               new String[] {selector.get(Solution.Fields.validationStatusCode).toString()} :
-                                                               null,
-                                                       new Date((Long)selector.get(Solution.Fields.modified)),
-                                                       pageRequest);
+                               pageResponse =
+                                       cdsClient.findSolutionsByDate(
+                                               (Boolean)selector.getOrDefault(Solution.Fields.active, Boolean.TRUE),
+                                               selector.containsKey(Solution.Fields.accessTypeCode) ?
+                                                       new String[] {selector.get(Solution.Fields.accessTypeCode).toString()} :
+                                                       Arrays.stream(AccessType.values()).map(at -> at.code()).toArray(String[]::new),
+                                               selector.containsKey(Solution.Fields.validationStatusCode) ?
+                                                       new String[] {selector.get(Solution.Fields.validationStatusCode).toString()} :
+                                                       Arrays.stream(ValidationStatus.values()).map(vs -> vs.code()).toArray(String[]::new),
+                                               new Date((Long)selector.get(Solution.Fields.modified)),
+                                               pageRequest);
                        
-                                       //we need to post-process all other selection criteria
-                                       pageSolutions = pageResponse.getContent().stream()
-                                                                                                               .filter(solution -> ServiceImpl.isSelectable(solution, theSelector))
-                                                                                                               .collect(Collectors.toList());
-                               }
-                               else {
-                                       pageResponse =
-                                               cdsClient.findPortalSolutions(selector.containsKey(Solution.Fields.name) ?
-                                                                                                                                                                               new String[] {selector.get(Solution.Fields.name).toString()} :
-                                                                                                                                                                               null,
-                                                                                                                                                                       selector.containsKey(Solution.Fields.description) ?
-                                                                                                                                                                               new String[] {selector.get(Solution.Fields.description).toString()} :
-                                                                                                                                                                               null,
-                                                                                                                                                                       (Boolean)selector.getOrDefault(Solution.Fields.active, Boolean.TRUE),
-                                                                                                                                                                       null, //user ids
-                                                                                                                                                                       selector.containsKey(Solution.Fields.accessTypeCode) ?
-                                                                                                                                                                               new String[] {selector.get(Solution.Fields.accessTypeCode).toString()} :
-                                                                                                                                                                               null,
-                                                                                                                                                                       selector.containsKey(Solution.Fields.modelTypeCode) ?
-                                                                                                                                                                               new String[] {selector.get(Solution.Fields.modelTypeCode).toString()} :
-                                                                                                                                                                               null,
-                                                                                                                                                                       selector.containsKey(Solution.Fields.validationStatusCode) ?
-                                                                                                                                                                               new String[] {selector.get(Solution.Fields.validationStatusCode).toString()} :
-                                                                                                                                                                               null,
-                                                                                                                                                                       selector.containsKey(Solution.Fields.tags) ?
-                                                                                                                                                                               new String[] {selector.get(Solution.Fields.tags).toString()} :
-                                                                                                                                                                               null,
-                                                                                                                                                                       null,   //authorKeywords
-                                                                                                                                                                       null, //publisherKeywords
-                                                                                                                                                                       pageRequest);
-                                       pageSolutions = pageResponse.getContent();
-                               }
                                log.debug(EELFLoggerDelegate.debugLogger, "getSolutions page response {}", pageResponse);
+                               //we need to post-process all other selection criteria
+                               pageSolutions = pageResponse.getContent().stream()
+                                                                                                       .filter(solution -> ServiceImpl.isSelectable(solution, selector))
+                                                                                                       .collect(Collectors.toList());
+                               log.debug(EELFLoggerDelegate.debugLogger, "getSolutions page selection {}", pageSolutions);
                
                                pageRequest.setPage(pageResponse.getNumber() + 1);
                                solutions.addAll(pageSolutions);
index 5a45b79..a9353d6 100644 (file)
 
 package org.acumos.federation.gateway.service.impl;
 
+import java.lang.invoke.MethodHandles;
+
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.acumos.cds.domain.MLPSolution;
+import org.acumos.cds.domain.MLPTag;
+
+import org.acumos.federation.gateway.config.EELFLoggerDelegate;
 
 /**
  * Some basic tooling for service implementation.
  * Common functionality to be re-used across service implementations.
  */
-public interface ServiceImpl {
+public abstract class ServiceImpl {
+
+       private static final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(MethodHandles.lookup().lookupClass());
+
+       private ServiceImpl() {
+       }
 
        /**
         * Bit of a primitive implementation
@@ -48,8 +59,9 @@ public interface ServiceImpl {
                        else if (modelTypeCode instanceof List) {
                                res &= ((List)modelTypeCode).contains(theSolution.getModelTypeCode());
                        }
-                       else
-                               res = false;
+                       else {
+                               log.debug(EELFLoggerDelegate.debugLogger, "unknown modelTypeCode criteria representation {}", modelTypeCode.getClass().getName());
+                       }
                }
 
                Object toolkitTypeCode = theSelector.get("toolkitTypeCode");
@@ -60,8 +72,39 @@ public interface ServiceImpl {
                        else if (toolkitTypeCode instanceof List) {
                                res &= ((List)toolkitTypeCode).contains(theSolution.getToolkitTypeCode());
                        }
-                       else
+                       else {
+                               log.debug(EELFLoggerDelegate.debugLogger, "unknown toolkitTypeCode criteria representation {}", toolkitTypeCode.getClass().getName());
+                       }
+               }
+
+               Object tags = theSelector.get("tags");
+               if (tags != null) {
+                       Set<MLPTag> solutionTags = theSolution.getTags();
+                       if (tags instanceof String) {
+                               res &= solutionTags.stream().filter(solutionTag -> tags.equals(solutionTag.getTag())).findAny().isPresent();
+                       }
+                       else if (tags instanceof List) {
+                               res &= solutionTags.stream().filter(solutionTag -> ((List)tags).contains(solutionTag.getTag())).findAny().isPresent();
+                       }
+                       else {
+                               log.debug(EELFLoggerDelegate.debugLogger, "unknown tags criteria representation {}", tags.getClass().getName());
+                       }
+               }
+
+               Object name = theSelector.get("name");
+               if (name != null) {
+                       res &= theSolution.getName().contains(name.toString());
+               }
+
+               Object desc = theSelector.get("description");
+               if (desc != null) {
+                       String solutionDesc = theSolution.getDescription();
+                       if (solutionDesc == null) {
                                res = false;
+                       }
+                       else {
+                               res &= solutionDesc.contains(desc.toString());
+                       }
                }
 
                return res;
index b40ebb8..0b2fb96 100644 (file)
@@ -82,7 +82,7 @@ public class CatalogServiceTest extends ServiceTest {
 
        protected void initMockResponses() {
 
-               registerMockResponse("GET /ccds/solution/search/portal?atc=PB&active=true&page=0&size=100", MockResponse.success("mockCDSPortalSolutionsResponse.json"));
+               registerMockResponse("GET /ccds/solution/search/date?atc=PB&datems=1&vsc=PS&vsc=NV&active=true&page=0&size=100", MockResponse.success("mockCDSPortalSolutionsResponse.json"));
                registerMockResponse("GET /ccds/solution/search/date?atc=PB&datems=1531747662&vsc=PS&active=true&page=0&size=100", MockResponse.success("mockCDSDateSolutionsResponsePage0.json"));
                registerMockResponse("GET /ccds/solution/search/date?atc=PB&datems=1531747662&vsc=PS&active=true&page=1&size=100", MockResponse.success("mockCDSDateSolutionsResponsePage1.json"));
                registerMockResponse("GET /ccds/solution/10101010-1010-1010-1010-101010101010", MockResponse.success("mockCDSSolutionResponse.json"));