Adjust the artifact uri building process. 22/3122/1
authorSerban Jora <sj2381@att.com>
Wed, 10 Oct 2018 05:03:42 +0000 (01:03 -0400)
committerSerban Jora <sj2381@att.com>
Wed, 10 Oct 2018 05:04:50 +0000 (01:04 -0400)
Change-Id: I8b64968e322ac2b95d53c2f9bea4499a6bca62ec
Issue-ID: ACUMOS-1780
Signed-off-by: Serban Jora <sj2381@att.com>
gateway/src/main/java/org/acumos/federation/gateway/cds/Artifact.java
gateway/src/main/java/org/acumos/federation/gateway/cds/Document.java
gateway/src/main/java/org/acumos/federation/gateway/cds/Reference.java
gateway/src/main/java/org/acumos/federation/gateway/controller/CatalogController.java

index ecf9891..3af4cf1 100644 (file)
@@ -33,7 +33,6 @@ public class Artifact extends MLPArtifact
 
        public Artifact(MLPArtifact theCDSArtifact) {
                super(theCDSArtifact);
-               setFilename(getUriFilename());
        }
        
        public Artifact(Artifact theArtifact) {
@@ -45,7 +44,7 @@ public class Artifact extends MLPArtifact
                return new ArtifactBuilder(new Artifact());
        }
 
-       public static ArtifactBuilder buildFrom(MLPArtifact theArtifact) {
+       public static ArtifactBuilder buildFrom(Artifact theArtifact) {
                return new ArtifactBuilder(new Artifact(theArtifact));
        }
 
index 122b05b..a8b4889 100644 (file)
@@ -39,14 +39,13 @@ public class Document extends MLPDocument
        
        public Document(Document theDocument) {
                super(theDocument);
-               this.filename = theDocument.getFilename();
        }
 
        public static DocumentBuilder build() {
                return new DocumentBuilder(new Document());
        }
 
-       public static DocumentBuilder buildFrom(MLPDocument theDocument) {
+       public static DocumentBuilder buildFrom(Document theDocument) {
                return new DocumentBuilder(new Document(theDocument));
        }
 
index 70a1ae5..390d5f0 100644 (file)
@@ -35,6 +35,10 @@ public interface Reference {
 
        public void setUri(String theUri);
 
+       public String getVersion();
+
+       public void setVersion(String theVersion);
+
        @JsonIgnore
        public default String getUriFilename() {
                String curi = getUri();
@@ -50,5 +54,19 @@ public interface Reference {
                }
        }
 
+       @JsonIgnore
+       public default String getCanonicalFilename() {
+               
+               String filename = getUriFilename(),
+                                        basename = FilenameUtils.getBaseName(filename),
+                                        extension = FilenameUtils.getExtension(filename);
+
+               if (basename.endsWith("-" + getVersion())) {
+                       return basename.substring(0, basename.lastIndexOf('-')) + "." + extension;
+               }
+               else {
+                       return filename;
+               }
+       }
 }
 
index 5254e71..1edf20c 100644 (file)
@@ -496,7 +496,7 @@ public class CatalogController extends AbstractController {
                String artifactUri = theArtifact.getUri();
 
                //remember the artifact filename before redirecting
-               theArtifact.setFilename(theArtifact.getUriFilename());
+               theArtifact.setFilename(theArtifact.getCanonicalFilename());
 
                //redirect              
                {
@@ -525,7 +525,7 @@ public class CatalogController extends AbstractController {
                String artifactUri = theDocument.getUri();
 
                //remember the document filename before redirecting
-               theDocument.setFilename(theDocument.getUriFilename());
+               theDocument.setFilename(theDocument.getCanonicalFilename());
 
                //redirect              
                {