Fix content uri handling 06/3106/2
authorSerban Jora <sj2381@att.com>
Tue, 9 Oct 2018 06:13:15 +0000 (02:13 -0400)
committerSerban Jora <sj2381@att.com>
Tue, 9 Oct 2018 06:31:00 +0000 (02:31 -0400)
Change-Id: Icc8f41cbe74858991c458c8ef9de63c4de40af61
Issue-ID: ACUMOS-1780
Signed-off-by: Serban Jora <sj2381@att.com>
15 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/Artifact.java
gateway/src/main/java/org/acumos/federation/gateway/cds/ArtifactBuilder.java
gateway/src/main/java/org/acumos/federation/gateway/cds/Document.java
gateway/src/main/java/org/acumos/federation/gateway/cds/DocumentBuilder.java
gateway/src/main/java/org/acumos/federation/gateway/cds/Mapper.java
gateway/src/main/java/org/acumos/federation/gateway/cds/PeerSubscription.java [new file with mode: 0644]
gateway/src/main/java/org/acumos/federation/gateway/cds/Reference.java [new file with mode: 0644]
gateway/src/main/java/org/acumos/federation/gateway/controller/PeerSubscriptionController.java
gateway/src/main/java/org/acumos/federation/gateway/service/PeerSubscriptionService.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/PeerServiceLocalImpl.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/PeerSubscriptionServiceImpl.java
gateway/src/main/java/org/acumos/federation/gateway/task/PeerSubscriptionTask.java

index 568bf95..da71d9f 100644 (file)
@@ -22,6 +22,13 @@ Federation Gateway Release Notes
 
 This server is available as a Docker image in a Docker registry at the Linux Foundation.
 
+--------------------------
+Version 1.18.6, 2018-10-08
+--------------------------
+
+* Fix for the handling of mis-represented content uris (`ACUMOS-1780 <https://jira.acumos.org/browse/ACUMOS-1780>`_)
+* Adds subscription option directing the handling of error in content retrieval with respect to catalog updates
+
 --------------------------
 Version 1.18.5, 2018-10-02
 --------------------------
index 5e24839..091dbfe 100644 (file)
@@ -17,7 +17,7 @@
        <modelVersion>4.0.0</modelVersion>
        <groupId>org.acumos.federation</groupId>
        <artifactId>gateway</artifactId>
-       <version>1.18.5-SNAPSHOT</version>
+       <version>1.18.6-SNAPSHOT</version>
        <name>Federation Gateway</name>
        <description>Federated Acumos Interface for inter-acumos and ONAP communication</description>
 
index 8e81bb1..5edc1b8 100644 (file)
@@ -45,6 +45,7 @@ import org.acumos.federation.gateway.cds.Document;
 import org.acumos.federation.gateway.cds.Solution;
 import org.acumos.federation.gateway.cds.SolutionRevision;
 import org.acumos.federation.gateway.cds.SubscriptionScope;
+import org.acumos.federation.gateway.cds.PeerSubscription;
 import org.acumos.federation.gateway.common.Clients;
 import org.acumos.federation.gateway.common.FederationClient;
 import org.acumos.federation.gateway.config.EELFLoggerDelegate;
@@ -139,12 +140,12 @@ public class PeerGateway {
        public class PeerGatewayUpdateTask implements Runnable {
 
                private MLPPeer peer;
-               private MLPPeerSubscription sub;
+               private PeerSubscription sub;
                private List<MLPSolution> solutions;
 
                public PeerGatewayUpdateTask(MLPPeer thePeer, MLPPeerSubscription theSub, List<MLPSolution> theSolutions) {
                        this.peer = thePeer;
-                       this.sub = theSub;
+                       this.sub = new PeerSubscription(theSub);
                        this.solutions = theSolutions;
                }
 
@@ -173,67 +174,88 @@ public class PeerGateway {
                        //return (ICommonDataServiceRestClient)theContext.getAttribute(AbstractServiceImpl.Attributes.cdsClient);
                }
 
-               private Artifact createArtifact(String theSolutionId, String theRevisionId, Artifact peerArtifact,
-                               ServiceContext theContext) throws Exception {
-
-                       Artifact artifact = Artifact.buildFrom(peerArtifact)
-                                                                                                               .withUser(getUserId(this.sub))
-                                                                                                               .build();
-                       try {
-                               getCDSClient(theContext).createArtifact(artifact);
-                               getCDSClient(theContext).addSolutionRevisionArtifact(theSolutionId, theRevisionId, artifact.getArtifactId());
-                       }
-                       catch (HttpStatusCodeException restx) {
-                               log.error(EELFLoggerDelegate.errorLogger,
-                                               "createArtifact CDS call failed. CDS message is " + restx.getResponseBodyAsString(), restx);
-                               return null;
-                       }
-                       catch (Exception x) {
-                               log.error(EELFLoggerDelegate.errorLogger, "createArtifact unexpected failure", x);
-                               throw x;
-                       }
-                       return artifact;
+               private Artifact copyArtifact(Artifact peerArtifact) {
+                       return Artifact.buildFrom(peerArtifact)
+                                                               .withUser(getUserId(this.sub))
+                                                               .withCreated(0)
+                                                               .withModified(0)
+                                                               .build();
                }
 
                /* we create a new one as nothing is preserved. assumes matching ids. */
                private Artifact copyArtifact(Artifact peerArtifact, Artifact localArtifact) {
-
                        return Artifact.buildFrom(peerArtifact)
                                                                .withId(localArtifact.getArtifactId())
                                                                .withUser(getUserId(this.sub))
                                                                .build();
                }
 
-               private Document createDocument(String theSolutionId, String theRevisionId, Document peerDocument,
-                               ServiceContext theContext) {
+               private void putArtifact(String theSolutionId, String theRevisionId, Artifact theArtifact,
+                               ServiceContext theContext) throws ServiceException {
 
-                       Document document = Document.buildFrom(peerDocument)
-                                                                                                               .withUser(getUserId(this.sub))
-                                                                                                               .build();
                        try {
-                               getCDSClient(theContext).createDocument(document);
-                               getCDSClient(theContext).addSolutionRevisionDocument(theRevisionId, AccessTypeCode.PB.name(), document.getDocumentId());
-                               return document;
+                               if (theArtifact.getCreated().getTime() == 0) {
+                                       getCDSClient(theContext).createArtifact(theArtifact);
+                                       getCDSClient(theContext).addSolutionRevisionArtifact(theSolutionId, theRevisionId, theArtifact.getArtifactId());
+                                       log.info(EELFLoggerDelegate.debugLogger, "Local artifact created: {}", theArtifact);
+                               }
+                               else {
+                                       getCDSClient(theContext).updateArtifact(theArtifact);
+                                       log.info(EELFLoggerDelegate.debugLogger, "Local artifact updated: {}", theArtifact);
+                               }
+       
                        }
                        catch (HttpStatusCodeException restx) {
                                log.error(EELFLoggerDelegate.errorLogger,
-                                               "createDocument CDS call failed. CDS message is " + restx.getResponseBodyAsString(), restx);
-                               return null;
+                                               "Artifact CDS call failed. CDS message is " + restx.getResponseBodyAsString(), restx);
+                               throw new ServiceException("Artifact CDS call failed.", restx);
                        }
                        catch (Exception x) {
-                               log.error(EELFLoggerDelegate.errorLogger, "createDocument unexpected failure", x);
-                               return null;
+                               log.error(EELFLoggerDelegate.errorLogger, "Artifact unexpected failure", x);
+                               throw new ServiceException("Artifact CDS call failed.", x);
                        }
                }
 
-               private Document copyDocument(Document peerDocument, Document localDocument) {
+               private Document copyDocument(Document peerDocument) {
+                       return Document.buildFrom(peerDocument)
+                                                               .withUser(getUserId(this.sub))
+                                                               .withCreated(0)
+                                                               .withModified(0)
+                                                               .build();
+               }
 
+               private Document copyDocument(Document peerDocument, Document localDocument) {
                        return Document.buildFrom(peerDocument)
                                                                .withId(localDocument.getDocumentId())
                                                                .withUser(getUserId(this.sub))
                                                                .build();
                }
 
+               private void putDocument(String theSolutionId, String theRevisionId, Document theDocument,
+                               ServiceContext theContext) throws ServiceException {
+
+                       try {
+                               if (theDocument.getCreated().getTime() == 0) {
+                                       getCDSClient(theContext).createDocument(theDocument);
+                                       getCDSClient(theContext).addSolutionRevisionDocument(theRevisionId, AccessTypeCode.PB.name(), theDocument.getDocumentId());
+                                       log.info(EELFLoggerDelegate.debugLogger, "Local document created: {}", theDocument);
+                               }
+                               else {
+                                       getCDSClient(theContext).updateDocument(theDocument);
+                                       log.info(EELFLoggerDelegate.debugLogger, "Local document updated: {}", theDocument);
+                               }
+                       }
+                       catch (HttpStatusCodeException restx) {
+                               log.error(EELFLoggerDelegate.errorLogger,
+                                               "Document CDS call failed. CDS message is " + restx.getResponseBodyAsString(), restx);
+                               throw new ServiceException("Document CDS call failed.", restx);
+                       }
+                       catch (Exception x) {
+                               log.error(EELFLoggerDelegate.errorLogger, "Document handling unexpected failure", x);
+                               throw new ServiceException("Document handling unexpected failure", x);
+                       }
+               }
+
 
                /**
                 * Here comes the core process of updating a local solution's related
@@ -251,8 +273,8 @@ public class PeerGateway {
 
                        FederationClient fedClient = clients.getFederationClient(this.peer.getApiUrl());
 
-                       Solution localSolution,
-                                                        peerSolution;
+                       Solution localSolution = null,
+                                                        peerSolution = null;
 
                        //retrieve the full representation from the peer
                        peerSolution = (Solution)fedClient.getSolution(theSolution.getSolutionId()).getContent();
@@ -341,26 +363,23 @@ public class PeerGateway {
                                for (Map.Entry<Artifact, Artifact> artifactEntry : peerToLocalArtifacts.entrySet()) {
                                        Artifact peerArtifact = artifactEntry.getKey(),
                                                                         localArtifact = artifactEntry.getValue();
-                                       boolean doUpdate = false;
-                                       boolean doContent = (peerArtifact.getUri() != null) &&
-                                                                                                                       (SubscriptionScope.Full == SubscriptionScope.forCode(this.sub.getScopeType()));
+                                       boolean doCatalog = false;
 
                                        if (localArtifact == null) {
-                                               localArtifact = createArtifact(localSolution.getSolutionId(), localRevision.getRevisionId(),
-                                                               peerArtifact, theContext);
+                                               localArtifact = copyArtifact(peerArtifact);
+                                               doCatalog = true;
                                        }
                                        else {
                                                if (!peerArtifact.getVersion().equals(localArtifact.getVersion())) {
                                                        // update local artifact
                                                        localArtifact = copyArtifact(peerArtifact, localArtifact);
-                                                       doUpdate = true;
-                                               }
-                                               else {
-                                                       //if no changes, do not go after the content
-                                                       doContent = false;
+                                                       doCatalog = true;
                                                }
                                        }
 
+                                       boolean doContent = doCatalog &&
+                                                                                                                       (peerArtifact.getUri() != null) &&
+                                                                                                                       (SubscriptionScope.Full == SubscriptionScope.forCode(this.sub.getScopeType()));
                                        if (doContent) {
                                                log.info(EELFLoggerDelegate.debugLogger, "Processing content for artifact {}", peerArtifact); 
                                                // TODO: we are trying to access the artifact by its identifier which
@@ -374,17 +393,19 @@ public class PeerGateway {
                                                }
                                                catch (Exception x) {
                                                        log.error(EELFLoggerDelegate.errorLogger, "Failed to retrieve acumos artifact content", x);
+                                                       doCatalog = this.sub.getSubscriptionOptions().alwaysUpdateCatalog();
                                                }
 
                                                if (artifactContent != null) {
                                                        try {
                                                                content.putArtifactContent(
                                                                        localSolution.getSolutionId(), localRevision.getRevisionId(), localArtifact, artifactContent);
-                                                               doUpdate = true;
+                                                               doCatalog = true;
                                                        }
                                                        catch (ServiceException sx) {
                                                                log.error(EELFLoggerDelegate.errorLogger,
                                                                                        "Failed to store artifact content to local repo", sx);
+                                                               doCatalog = this.sub.getSubscriptionOptions().alwaysUpdateCatalog();
                                                        }
                                                        finally {
                                                                if (artifactContent instanceof Closeable) {
@@ -394,15 +415,12 @@ public class PeerGateway {
                                                }
                                        }
 
-                                       if (doUpdate) {
+                                       if (doCatalog) {
                                                try {
-                                                       getCDSClient(theContext).updateArtifact(localArtifact);
-                                                       log.info(EELFLoggerDelegate.debugLogger, "Local artifact updated with local content reference: {}", localArtifact); 
+                                                       putArtifact(localSolution.getSolutionId(), localRevision.getRevisionId(), localArtifact, theContext);
                                                }
-                                               catch (HttpStatusCodeException restx) {
-                                                       log.error(EELFLoggerDelegate.errorLogger,
-                                                                       "updateArtifact CDS call failed. CDS message is " + restx.getResponseBodyAsString(),
-                                                                       restx);
+                                               catch (ServiceException sx) {
+                                                       log.error(EELFLoggerDelegate.errorLogger, "Artifact processing failed.", sx);
                                                }
                                        }
                                } //end map artifacts loop
@@ -419,13 +437,11 @@ public class PeerGateway {
                                for (Map.Entry<Document, Document> documentEntry : peerToLocalDocuments.entrySet()) {
                                        Document peerDocument = documentEntry.getKey(),
                                                                         localDocument = documentEntry.getValue();
-                                       boolean doUpdate = false;
-                                       boolean doContent = (peerDocument.getUri() != null) &&
-                                                                                                                       (SubscriptionScope.Full == SubscriptionScope.forCode(this.sub.getScopeType()));
+                                       boolean doCatalog = false;
 
                                        if (localDocument == null) {
-                                               localDocument = createDocument(localSolution.getSolutionId(), localRevision.getRevisionId(),
-                                                               peerDocument, theContext);
+                                               localDocument = copyDocument(peerDocument);
+                                               doCatalog = true;
                                        }
                                        else {
                                                //version strings are not standard so comparing them is not necessarly safe
@@ -433,14 +449,13 @@ public class PeerGateway {
                                                                !peerDocument.getVersion().equals(localDocument.getVersion())) {
                                                        // update local doc
                                                        localDocument = copyDocument(peerDocument, localDocument);
-                                                       doUpdate = true;
-                                               }
-                                               else {
-                                                       //if no changes, do not go after the content
-                                                       doContent = false;
+                                                       doCatalog = true;
                                                }
                                        }
 
+                                       boolean doContent = doCatalog &&
+                                                                                                                       (peerDocument.getUri() != null) &&
+                                                                                                                       (SubscriptionScope.Full == SubscriptionScope.forCode(this.sub.getScopeType()));
                                        if (doContent) {
                                                log.info(EELFLoggerDelegate.debugLogger, "Processing content for document {}", peerDocument); 
                                                // TODO: we are trying to access the document by its identifier which
@@ -454,30 +469,29 @@ public class PeerGateway {
                                                }
                                                catch (Exception x) {
                                                        log.error(EELFLoggerDelegate.errorLogger, "Failed to retrieve acumos document content", x);
+                                                       doCatalog = this.sub.getSubscriptionOptions().alwaysUpdateCatalog();
                                                }
 
                                                if (documentContent != null) {
                                                        try {
                                                                content.putDocumentContent(
                                                                        localSolution.getSolutionId(), localRevision.getRevisionId(), localDocument, documentContent);
-                                                               doUpdate = true;
+                                                               doCatalog = true;
                                                        }
                                                        catch (ServiceException sx) {
                                                                log.error(EELFLoggerDelegate.errorLogger,
                                                                                        "Failed to store document content to local repo", sx);
+                                                               doCatalog = this.sub.getSubscriptionOptions().alwaysUpdateCatalog();
                                                        }
                                                }
                                        }
 
-                                       if (doUpdate) {
+                                       if (doCatalog) {
                                                try {
-                                                       getCDSClient(theContext).updateDocument(localDocument);
-                                                       log.info(EELFLoggerDelegate.debugLogger, "Local document updated with local content reference: {}", localDocument); 
+                                                       putDocument(localSolution.getSolutionId(), localRevision.getRevisionId(), localDocument, theContext);
                                                }
-                                               catch (HttpStatusCodeException restx) {
-                                                       log.error(EELFLoggerDelegate.errorLogger,
-                                                                       "updateDocument CDS call failed. CDS message is " + restx.getResponseBodyAsString(),
-                                                                       restx);
+                                               catch (ServiceException sx) {
+                                                       log.error(EELFLoggerDelegate.errorLogger,       "Document processing failed",   sx);
                                                }
                                        }
        
index 11abcd1..ecf9891 100644 (file)
  */
 package org.acumos.federation.gateway.cds;
 
-import java.net.URI;
-import java.net.URISyntaxException;
-
 import org.acumos.cds.domain.MLPArtifact;
 
-import org.apache.commons.io.FilenameUtils;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
 /**
  */
-public class Artifact extends MLPArtifact {
+public class Artifact extends MLPArtifact
+                                                                                       implements Reference {
 
        private String filename;
 
@@ -63,15 +57,5 @@ public class Artifact extends MLPArtifact {
                return this.filename;
        }
 
-       @JsonIgnore
-       public String getUriFilename() {
-               try {
-                       return FilenameUtils.getName(new URI(getUri()).getPath());
-               }
-               catch (URISyntaxException urisx) {
-                       throw new IllegalStateException("Invalid artifact uri", urisx);
-               }
-       }
-
 }
 
index fee3c74..931038d 100644 (file)
@@ -40,11 +40,21 @@ public class ArtifactBuilder {
                return this;
        }
 
+       public ArtifactBuilder withCreated(long theDate) {
+               this.artifact.setCreated(new Date(theDate));
+               return this;
+       }
+
        public ArtifactBuilder withModifiedDate(Date theDate) {
                this.artifact.setModified(theDate);
                return this;
        }
 
+       public ArtifactBuilder withModified(long theDate) {
+               this.artifact.setModified(new Date(theDate));
+               return this;
+       }
+
        public ArtifactBuilder withId(String theArtifactId) {
                this.artifact.setArtifactId(theArtifactId);
                return this;
index bb9d6a6..122b05b 100644 (file)
  */
 package org.acumos.federation.gateway.cds;
 
-import java.net.URI;
-import java.net.URISyntaxException;
-
 import org.acumos.cds.domain.MLPDocument;
 
-import org.apache.commons.io.FilenameUtils;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
 
 /**
  */
-public class Document extends MLPDocument {
+public class Document extends MLPDocument 
+                                                                                       implements Reference {
 
        private String filename;
 
@@ -63,17 +58,6 @@ public class Document extends MLPDocument {
                return this.filename;
        }
 
-       @JsonIgnore
-       public String getUriFilename() {
-               try {
-                       return FilenameUtils.getName(new URI(getUri()).getPath());
-               }
-               catch (URISyntaxException urisx) {
-                       throw new IllegalStateException("Invalid document uri", urisx);
-               }
-       }
-
-
 }
 
 
index 6c01c7f..55d8ca3 100644 (file)
@@ -40,11 +40,21 @@ public class DocumentBuilder {
                return this;
        }
 
+       public DocumentBuilder withCreated(long theDate) {
+               this.document.setCreated(new Date(theDate));
+               return this;
+       }
+
        public DocumentBuilder withModifiedDate(Date theDate) {
                this.document.setModified(theDate);
                return this;
        }
 
+       public DocumentBuilder withModified(long theDate) {
+               this.document.setModified(new Date(theDate));
+               return this;
+       }
+
        public DocumentBuilder withId(String theDocumentId) {
                this.document.setDocumentId(theDocumentId);
                return this;
index deb3537..aa6596f 100644 (file)
@@ -25,10 +25,12 @@ import org.acumos.cds.domain.MLPArtifact;
 import org.acumos.cds.domain.MLPDocument;
 import org.acumos.cds.domain.MLPSolution;
 import org.acumos.cds.domain.MLPSolutionRevision;
+import org.acumos.cds.domain.MLPPeerSubscription;
 
 import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.JavaType;
 import com.fasterxml.jackson.databind.DeserializationContext;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
@@ -41,28 +43,29 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
  */
 public class Mapper {
 
-
        public static ObjectMapper build() {
                ObjectMapper mapper = new ObjectMapper();
 
                SimpleModule fedModule =
       new SimpleModule("CDSModule",
-          new Version(1, 17, 0, null));
+          new Version(1, 18, 0, null));
     fedModule.addDeserializer(MLPSolution.class, new SolutionDeserializer());
     fedModule.addDeserializer(MLPSolutionRevision.class, new SolutionRevisionDeserializer());
     fedModule.addDeserializer(MLPArtifact.class, new ArtifactDeserializer());
     fedModule.addDeserializer(MLPDocument.class, new DocumentDeserializer());
+    fedModule.addDeserializer(MLPPeerSubscription.class, new PeerSubscriptionDeserializer());
+
                mapper.registerModule(fedModule);
 
                return mapper;
        }
-       
+
        private static class SolutionDeserializer extends StdDeserializer<MLPSolution> {
+
                public SolutionDeserializer() {
                        super(MLPSolution.class);
                }
+
                @Override
        public MLPSolution deserialize(JsonParser theParser, DeserializationContext theCtx) 
                                                                                                                                                                                                throws IOException, JsonProcessingException {
@@ -113,6 +116,19 @@ public class Mapper {
        }
        }
 
+       private static class PeerSubscriptionDeserializer extends StdDeserializer<MLPPeerSubscription> {
+               public PeerSubscriptionDeserializer() {
+                       super(MLPPeerSubscription.class);
+               }
+               @Override
+       public MLPPeerSubscription deserialize(JsonParser theParser, DeserializationContext theCtx) 
+                                                                                                                                                                                               throws IOException, JsonProcessingException {
+         ObjectMapper mapper = (ObjectMapper) theParser.getCodec();
+       return mapper.readValue(theParser, PeerSubscription.class);
+       }
+       }
 
 }
 
diff --git a/gateway/src/main/java/org/acumos/federation/gateway/cds/PeerSubscription.java b/gateway/src/main/java/org/acumos/federation/gateway/cds/PeerSubscription.java
new file mode 100644 (file)
index 0000000..36ff585
--- /dev/null
@@ -0,0 +1,100 @@
+/*-
+ * ===============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 org.acumos.cds.domain.MLPPeerSubscription;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+/**
+ */
+public class PeerSubscription extends MLPPeerSubscription {
+
+       private static final SubscriptionOptions defaultOptions = new SubscriptionOptions();
+       private static final ObjectMapper mapper = new ObjectMapper();
+
+       private SubscriptionOptions opts;
+
+       public PeerSubscription() {
+       }
+
+       public PeerSubscription(MLPPeerSubscription theCDSPeerSub) {
+               super(theCDSPeerSub);
+               //base class does through property assignments ..
+               setOptions(theCDSPeerSub.getOptions());
+       }
+       
+       public PeerSubscription(PeerSubscription thePeerSub) {
+               super(thePeerSub);
+               this.opts = thePeerSub.getSubscriptionOptions();
+       }
+
+       @Override
+       public void setOptions(String theOptions) {
+               super.setOptions(theOptions);
+               if (theOptions == null || theOptions.length() == 0) {
+                       //should we make the difference between unspecified and defaulted ?
+                       this.opts = defaultOptions;
+               }
+               else {
+                       try {
+                               this.opts = mapper.readValue(theOptions, SubscriptionOptions.class);
+                       }
+                       catch (Exception x) {
+                               throw new IllegalArgumentException("Falied to read options value " + theOptions, x);
+                       }
+               }               
+       }
+
+       @JsonIgnore
+       public SubscriptionOptions getSubscriptionOptions() {
+               return opts;
+       }
+
+       @JsonIgnore
+       public void setSubscriptionOptions(SubscriptionOptions theOptions) {
+               this.opts = theOptions;
+               try {
+                       super.setOptions(theOptions == null ? null
+                                                                                                                                                                       : mapper.writeValueAsString(theOptions));
+               }
+               catch(JsonProcessingException jpx) {
+                       throw new IllegalArgumentException("Cannot serialize", jpx);
+               }
+       }
+
+       public static class SubscriptionOptions {
+       
+               public CatalogUpdateOptions catalogUpdate = CatalogUpdateOptions.onSuccess;
+
+               public boolean alwaysUpdateCatalog() {
+                       return this.catalogUpdate.equals(CatalogUpdateOptions.always);
+               }
+       }
+
+       public static enum CatalogUpdateOptions {
+               onSuccess,
+               always
+       }
+
+}
+
diff --git a/gateway/src/main/java/org/acumos/federation/gateway/cds/Reference.java b/gateway/src/main/java/org/acumos/federation/gateway/cds/Reference.java
new file mode 100644 (file)
index 0000000..70a1ae5
--- /dev/null
@@ -0,0 +1,54 @@
+/*-
+ * ===============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.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.commons.io.FilenameUtils;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+/**
+ * Capable of pointing to some (external) content. Contains the content location as an uri.
+ */
+public interface Reference {
+
+       public String getUri();
+
+       public void setUri(String theUri);
+
+       @JsonIgnore
+       public default String getUriFilename() {
+               String curi = getUri();
+               if (curi == null)
+                       return null;
+               try {
+                       return FilenameUtils.getName(new URI(curi).getPath());
+               }
+               catch (URISyntaxException urisx) {
+                       //let's do our worst; this works in a UX env because it employs the same path separator
+                       //as uris.
+                       return FilenameUtils.getName(curi);
+               }
+       }
+
+}
+
index 401a43a..99dd8f3 100644 (file)
@@ -28,6 +28,7 @@ import org.acumos.cds.domain.MLPPeer;
 import org.acumos.cds.domain.MLPPeerSubscription;
 import org.acumos.federation.gateway.common.API;
 import org.acumos.federation.gateway.common.JsonResponse;
+import org.acumos.federation.gateway.cds.PeerSubscription;
 import org.acumos.federation.gateway.config.EELFLoggerDelegate;
 import org.acumos.federation.gateway.service.PeerService;
 import org.acumos.federation.gateway.service.PeerSubscriptionService;
@@ -80,7 +81,7 @@ public class PeerSubscriptionController extends AbstractController {
                        log.debug(EELFLoggerDelegate.debugLogger, "trigger");
        
                        MLPPeer peer = this.peerService.getPeerById(thePeerId);
-                       MLPPeerSubscription subscription = this.peerSubscriptionService.getPeerSubscription(theSubscriptionId);
+                       PeerSubscription subscription = this.peerSubscriptionService.getPeerSubscription(theSubscriptionId);
                        //coherence check
                        //subscription.getPeerId().equals(thePeerId);
 
index 4e43981..9e3f613 100644 (file)
@@ -24,6 +24,8 @@ import java.util.List;
 
 import org.acumos.cds.domain.MLPPeerSubscription;
 
+import org.acumos.federation.gateway.cds.PeerSubscription;
+
 /**
  * 
  *
@@ -42,7 +44,7 @@ public interface PeerSubscriptionService {
         *            Peer subscription ID
         * @return Peer Subscription based on the configured Subject Name
         */
-       MLPPeerSubscription getPeerSubscription(Long subId);
+       PeerSubscription getPeerSubscription(Long subId);
 
        /**
         * @param mlpPeerSubscription
index e04455d..011321a 100644 (file)
@@ -32,6 +32,7 @@ import javax.annotation.PreDestroy;
 
 import org.acumos.cds.domain.MLPPeer;
 import org.acumos.cds.domain.MLPPeerSubscription;
+import org.acumos.federation.gateway.cds.PeerSubscription;
 import org.acumos.federation.gateway.config.EELFLoggerDelegate;
 import org.acumos.federation.gateway.service.PeerService;
 import org.acumos.federation.gateway.service.PeerSubscriptionService;
@@ -159,14 +160,14 @@ public class PeerServiceLocalImpl extends AbstractServiceLocalImpl implements Pe
                                .orElse(null);
                log.info(EELFLoggerDelegate.debugLogger,
                                "Peer " + thePeerId + " subs:" + (peer == null ? "none" : peer.getSubscriptions()));
-               return peer == null ? Collections.EMPTY_LIST : peer.getSubscriptions();
+               return peer == null ? Collections.EMPTY_LIST : (List)peer.getSubscriptions();
        }
 
        /** */
        @Override
-       public MLPPeerSubscription getPeerSubscription(Long theSubId) {
+       public PeerSubscription getPeerSubscription(Long theSubId) {
                for (FLPPeer peer : this.peers) {
-                       for (MLPPeerSubscription peerSub : peer.getSubscriptions()) {
+                       for (PeerSubscription peerSub : peer.getSubscriptions()) {
                                if (peerSub.getSubId().equals(theSubId))
                                        return peerSub;
                        }
@@ -179,10 +180,10 @@ public class PeerServiceLocalImpl extends AbstractServiceLocalImpl implements Pe
        public void updatePeerSubscription(MLPPeerSubscription theSub) throws ServiceException {
                for (FLPPeer peer : this.peers) {
                        for (int i = 0; i < peer.getSubscriptions().size(); i++) {
-                               MLPPeerSubscription peerSub = peer.getSubscriptions().get(i);
+                               PeerSubscription peerSub = peer.getSubscriptions().get(i);
                                if (theSub.getSubId().equals(peerSub.getSubId()) &&
                                                theSub.getPeerId().equals(peerSub.getPeerId())) {
-                                       peer.getSubscriptions().set(i, theSub);
+                                       peer.getSubscriptions().set(i, new PeerSubscription(theSub));
                                        return;
                                }
                        }
@@ -194,7 +195,7 @@ public class PeerServiceLocalImpl extends AbstractServiceLocalImpl implements Pe
        public static class FLPPeer extends MLPPeer {
 
                @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
-               private List<MLPPeerSubscription> subscriptions;
+               private List<PeerSubscription> subscriptions;
 
                public FLPPeer() {
                }
@@ -204,11 +205,11 @@ public class PeerServiceLocalImpl extends AbstractServiceLocalImpl implements Pe
                }
 
                // @JsonIgnore
-               public List<MLPPeerSubscription> getSubscriptions() {
+               public List<PeerSubscription> getSubscriptions() {
                        return this.subscriptions;
                }
 
-               public void setSubscriptions(List<MLPPeerSubscription> theSubscriptions) {
+               public void setSubscriptions(List<PeerSubscription> theSubscriptions) {
                        this.subscriptions = theSubscriptions;
                }
 
index 5a9c4d4..61904bb 100644 (file)
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.acumos.cds.client.ICommonDataServiceRestClient;
 import org.acumos.cds.domain.MLPPeerSubscription;
+import org.acumos.federation.gateway.cds.PeerSubscription;
 import org.acumos.federation.gateway.config.EELFLoggerDelegate;
 import org.acumos.federation.gateway.service.PeerSubscriptionService;
 import org.acumos.federation.gateway.service.ServiceException;
@@ -54,9 +55,9 @@ public class PeerSubscriptionServiceImpl extends AbstractServiceImpl implements
        }
 
        @Override
-       public MLPPeerSubscription getPeerSubscription(Long theSubId) {
+       public PeerSubscription getPeerSubscription(Long theSubId) {
                log.debug(EELFLoggerDelegate.debugLogger, "getPeerSubscription:{}", theSubId);
-               MLPPeerSubscription peerSubscription = getClient().getPeerSubscription(theSubId);
+               PeerSubscription peerSubscription = (PeerSubscription)getClient().getPeerSubscription(theSubId);
                log.debug(EELFLoggerDelegate.debugLogger, "getPeerSubscription :{}", peerSubscription);
                return peerSubscription;
        }
index 58ccb49..c20a11a 100644 (file)
@@ -117,7 +117,7 @@ public class PeerSubscriptionTask implements Runnable {
                        this.peerSubscriptionService.updatePeerSubscription(this.subscription);
                }
                catch (Exception x) {
-                       log.error(EELFLoggerDelegate.errorLogger, "Peer task failed for " + peer.getName() + ", " + peer.getApiUrl() + ", " + subscription.getSelector(), x);
+                       log.error(EELFLoggerDelegate.errorLogger, "Peer task failed for " + peer.getName() + ", " + peer.getApiUrl() + ", " + subscription, x);
                }
        }
 }