Copy model picture when federating 21/3921/2
authorAndrew Gauld <agauld@att.com>
Thu, 7 Mar 2019 19:26:05 +0000 (19:26 +0000)
committerAndrew Gauld <agauld@att.com>
Thu, 7 Mar 2019 19:51:06 +0000 (19:51 +0000)
Change-Id: If6af8ae18c5bc5beafe30f5243c2ec5dfcd8fae2
Issue-ID: ACUMOS-2570
Signed-off-by: Andrew Gauld <agauld@att.com>
13 files changed:
docs/release-notes.rst
gateway/pom.xml
gateway/src/main/java/org/acumos/federation/gateway/adapter/PeerGateway.java
gateway/src/main/java/org/acumos/federation/gateway/cds/Solution.java
gateway/src/main/java/org/acumos/federation/gateway/cds/SolutionBuilder.java
gateway/src/main/java/org/acumos/federation/gateway/config/CDMSClientConfiguration.java
gateway/src/main/java/org/acumos/federation/gateway/config/NexusConfiguration.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/CatalogServiceImpl.java
gateway/src/test/java/org/acumos/federation/gateway/test/CatalogServiceTest.java
gateway/src/test/java/org/acumos/federation/gateway/test/PeerGatewayTest.java
gateway/src/test/resources/mockCDSSolutionPicResponse.tgz [new file with mode: 0644]
gateway/src/test/resources/mockCDSsaveSolutionPicResponse.json [new file with mode: 0644]
gateway/src/test/resources/mockPeerSolutionResponse.json

index d981143..4498860 100644 (file)
@@ -23,6 +23,10 @@ Federation Gateway Release Notes
 This server is available as a Docker image in a Docker registry at the Linux Foundation.
 The image name is "federation-gateway" and the tag is a version string as shown below. 
 
+Version 2.1.1, 2019-03-07
+-------------------------
+* Solution picture should be copied (`ACUMOS-2570 <https://jira.acumos.org/browse/ACUMOS-2570>`_)
+
 Version 2.1.0, 2019-03-05
 -------------------------
 * Update to CDS 2.1.2
index 2e389ef..2bc4f48 100644 (file)
@@ -25,7 +25,7 @@
        <modelVersion>4.0.0</modelVersion>
        <groupId>org.acumos.federation</groupId>
        <artifactId>gateway</artifactId>
-       <version>2.1.0-SNAPSHOT</version>
+       <version>2.1.1-SNAPSHOT</version>
        <name>Federation Gateway</name>
        <description>Federated Acumos Interface for inter-acumos and ONAP communication</description>
 
index 37b15d2..4bb6444 100644 (file)
@@ -23,6 +23,7 @@ package org.acumos.federation.gateway.adapter;
 import java.io.Closeable;
 import java.lang.invoke.MethodHandles;
 import java.time.Instant;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -376,6 +377,7 @@ public class PeerGateway {
                                                                .withModified(TimestampedEntity.ORIGIN)
                                                                .withUser(getUserId(this.sub))
                                                                .withSource(this.peer.getPeerId())
+                                                               .withPicture(thePeerSolution.getPicture())
                                                                .resetStats()
                                                                .build();
                }
@@ -405,6 +407,7 @@ public class PeerGateway {
                                }
                        }
 
+                       theLocalSolution.setPicture(thePeerSolution.getPicture());
                        //tags, keep only the delta
                        Set<MLPTag> tags = thePeerSolution.getTags();
                        tags.removeAll(theLocalSolution.getTags());
@@ -414,6 +417,9 @@ public class PeerGateway {
                }
 
                private boolean hasChanged(Solution thePeerSolution, Solution theLocalSolution) {
+                       if (!Arrays.equals(theLocalSolution.getPicture(), thePeerSolution.getPicture())) {
+                               return true;
+                       }
                        if (!theLocalSolution.getTags().containsAll(thePeerSolution.getTags()))
                                return false;
 
@@ -656,7 +662,7 @@ public class PeerGateway {
                                                Resource documentContent = null;
                                                try {
                                                        documentContent = thePeerClient.getDocumentContent(
-                                                               peerSolution.getSolutionId(), localRevision.getRevisionId(), peerDocument.getDocumentId());
+                                                               peerSolution.getSolutionId(), peerRevision.getRevisionId(), peerDocument.getDocumentId());
                                                        log.info("Received {} bytes of document content", documentContent.contentLength()); 
                                                }
                                                catch (FederationException x) {
index b515c1b..790c969 100644 (file)
@@ -51,6 +51,7 @@ public class Solution extends MLPSolution {
        };
 
        private List<? extends MLPSolutionRevision>             revisions;
+       private byte[] picture;
 
        public Solution() {
        }
@@ -66,6 +67,14 @@ public class Solution extends MLPSolution {
        public List<? extends MLPSolutionRevision>      getRevisions() {
                return this.revisions;
        }
+
+       public void setPicture(byte[] picture) {
+               this.picture = picture;
+       }
+
+       public byte[] getPicture() {
+               return this.picture;
+       }
        
        public static SolutionBuilder build() {
                return new SolutionBuilder(new Solution());
index 515f765..5a2e101 100644 (file)
@@ -123,6 +123,11 @@ public class SolutionBuilder {
                this.solution.setFeatured(false);
                return this;
        }
+
+       public SolutionBuilder withPicture(byte[] thePicture) {
+               this.solution.setPicture(thePicture);
+               return this;
+       }
 }
 
 
index 642ca49..5b7dcd6 100644 (file)
@@ -32,6 +32,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.web.client.RestTemplateBuilder;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.http.converter.ByteArrayHttpMessageConverter;
 import org.springframework.stereotype.Component;
 
 /**
@@ -112,7 +113,7 @@ public class CDMSClientConfiguration {
                                        () -> new HttpComponentsClientHttpRequestFactory(this.localIfConfig.buildClient()))
                                //.rootUri(env.getProperty("cdms.client.url"))
                                        .basicAuthorization(this.username, this.password)
-                                       .messageConverters(cdsMessageConverter);
+                                       .messageConverters(new ByteArrayHttpMessageConverter(), cdsMessageConverter);
 
                return new CommonDataServiceRestClientImpl(this.url, builder.build());
        }
index adbe69f..61a1d23 100644 (file)
@@ -115,7 +115,7 @@ public class NexusConfiguration {
                return this.groupId;
        }
 
-       public void setNameSperator(String theNameSeparator) {
+       public void setNameSeparator(String theNameSeparator) {
                this.nameSeparator = theNameSeparator;
        }
 
index 5861966..9f01fe1 100644 (file)
@@ -168,6 +168,7 @@ public class CatalogServiceImpl extends AbstractServiceImpl
                                return null;
 
                        solution.setRevisions(revisions);
+                       solution.setPicture(cdsClient.getSolutionPicture(theSolutionId));
                        return solution;
                }
                catch (HttpStatusCodeException restx) {
@@ -195,6 +196,7 @@ public class CatalogServiceImpl extends AbstractServiceImpl
                        else {
                                cdsClient.updateSolution(theSolution);
                        }
+                       cdsClient.saveSolutionPicture(theSolution.getSolutionId(), theSolution.getPicture());
                }
                catch (HttpStatusCodeException scx) {
                        log.error("CDS solution call failed. CDS says " + scx.getResponseBodyAsString(), scx);
index c17470d..2f4a799 100644 (file)
@@ -100,6 +100,7 @@ public class CatalogServiceTest extends ServiceTest {
                registerMockResponse("GET /ccds/solution/search/date?atc=PB&inst=1531747662000&active=true&page=1&size=100", MockResponse.success("mockCDSDateSolutionsResponsePage1.json"));
                registerMockResponse("GET /ccds/solution/10101010-1010-1010-1010-101010101010", MockResponse.success("mockCDSSolutionResponse.json"));
                registerMockResponse("GET /ccds/solution/10101010-1010-1010-1010-101010101010/revision", MockResponse.success("mockCDSSolutionRevisionsResponse.json"));
+               registerMockResponse("GET /ccds/solution/10101010-1010-1010-1010-101010101010/pic", MockResponse.success("mockCDSSolutionPicResponse.tgz"));
                registerMockResponse("GET /ccds/revision/a0a0a0a0-a0a0-a0a0-a0a0-a0a0a0a0a0a0/artifact", MockResponse.success("mockCDSSolutionRevisionArtifactsResponse.json"));
                registerMockResponse("GET /ccds/solution/f0f0f0f0-f0f0-f0f0-f0f0-f0f0f0f0f0f0", new MockResponse(400, "Error", "mockCDSNoEntryWithIDResponse.json"));
                registerMockResponse("GET /ccds/solution/f0f0f0f0-f0f0-f0f0-f0f0-f0f0f0f0f0f0/revision", new MockResponse(400, "Error", "mockCDSNoEntryWithIDResponse.json"));
index fd52af5..577e57f 100644 (file)
@@ -110,7 +110,7 @@ public class PeerGatewayTest {
        private MockAnswer peerAnswer = new MockAnswer();       
        private MockAnswer cdsAnswer = new MockAnswer();        
        //initialize with the number of checkpoints
-       private CountDownLatch stepLatch = new CountDownLatch(4);
+       private CountDownLatch stepLatch = new CountDownLatch(5);
 
        @Before
        public void initTest() throws IOException {
@@ -126,6 +126,7 @@ public class PeerGatewayTest {
                                .mockResponse(info -> info.getPath().equals("/ccds/peer/sub/1"), MockResponse.success("mockCDSPeerSubscriptionResponse.json")) //this works for GET and PUT ..
                                .mockResponse(info -> info.getMethod().equals("GET") && info.getPath().equals("/ccds/solution/6793411f-c7a1-4e93-85bc-f91d267541d8"), MockResponse.success("mockCDSNoSuchSolutionResponse.json"))
                                .mockResponse(info -> info.getMethod().equals("POST") && info.getPath().equals("/ccds/solution"), MockResponse.success("mockCDSCreateSolutionResponse.json", stepTrack))
+                               .mockResponse(info -> info.getMethod().equals("PUT") && info.getPath().equals("/ccds/solution/6793411f-c7a1-4e93-85bc-f91d267541d8/pic"), MockResponse.success("mockCDSsaveSolutionPicResponse.json", stepTrack))
                                .mockResponse(info -> info.getMethod().equals("GET") && info.getPath().equals("/ccds/solution/6793411f-c7a1-4e93-85bc-f91d267541d8/revision"), MockResponse.success("mockCDSNoSuchSolutionRevisionsResponse.json"))
                                .mockResponse(info -> info.getMethod().equals("POST") && info.getPath().equals("/ccds/solution/6793411f-c7a1-4e93-85bc-f91d267541d8/revision"), MockResponse.success("mockCDSCreateSolutionRevisionResponse.json", stepTrack))
                                .mockResponse(info -> info.getMethod().equals("POST") && info.getPath().equals("/ccds/artifact"), MockResponse.success("mockCDSCreateArtifactResponse.json", stepTrack))
diff --git a/gateway/src/test/resources/mockCDSSolutionPicResponse.tgz b/gateway/src/test/resources/mockCDSSolutionPicResponse.tgz
new file mode 100644 (file)
index 0000000..3b18e51
--- /dev/null
@@ -0,0 +1 @@
+hello world
diff --git a/gateway/src/test/resources/mockCDSsaveSolutionPicResponse.json b/gateway/src/test/resources/mockCDSsaveSolutionPicResponse.json
new file mode 100644 (file)
index 0000000..2c63c08
--- /dev/null
@@ -0,0 +1,2 @@
+{
+}
index b0340a1..96da6bd 100644 (file)
@@ -9,8 +9,9 @@
   "modelTypeCode":"CL",
   "toolkitTypeCode":"",
   "metadata":"acumosa",
-  "created":"1550012925",
-  "modified":"1550012925",
+  "created":"2019-02-12T23:08:45Z",
+  "modified":"2019-02-12T23:08:45Z",
+  "picture":"9999aGVsbG8gd29ybGQK",
        "revisions":[{
          "revisionId":"2c7e4481-6e6f-47d9-b7a4-c4e674d2b341",
        "solutionId":"6793411f-c7a1-4e93-85bc-f91d267541d8",
@@ -18,7 +19,7 @@
          "metadata":"acumosa",
          "userId":"admin",
          "accessTypeCode": "PB",
-               "created":"1550012925",
-               "modified":"1550012925"}]
+               "created":"2019-02-12T23:08:45Z",
+               "modified":"2019-02-12T23:08:45Z"}]
  }
 }