aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
authorKanagaraj Manickam <kanagaraj.manickam@huawei.com>2022-03-31 03:58:07 +0000
committerGerrit Code Review <gerrit@onap.org>2022-03-31 03:58:07 +0000
commit1bc3036f73039e91ef7a9c91d0901825e3a3b813 (patch)
tree41ad764421ec5a3bb037bd56f76e5b7838634c4c /framework/src
parent4e4f047cf6533f0f01f54d5170a059c5bff5d054 (diff)
parent446ec156336ee41f240bf7276eff4f0dd50b2fa1 (diff)
Merge "Reduced code complexity"
Diffstat (limited to 'framework/src')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java59
1 files changed, 32 insertions, 27 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
index 32ececfa..0d68db1c 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
@@ -263,6 +263,37 @@ public class OnapCommandArtifactStore {
}
}
+ public Artifact setArtifact(Artifact artifact, Artifact existing) throws OnapCommandArtifactNotFound, OnapCommandArtifactContentNotExist, OnapCommandArtifactAlreadyExist, IOException, NoSuchAlgorithmException {
+ if (artifact.getName() == null) {
+ artifact.setName(existing.getName());
+ }
+
+ if (artifact.getDescription() == null) {
+ artifact.setDescription(existing.getDescription());
+ }
+
+ if (artifact.getCategoty() == null) {
+ artifact.setCategoty(existing.getCategoty());
+ }
+
+ if (artifact.getPath()!= null) {
+ if (!new File(artifact.getPath()).exists()) {
+ throw new OnapCommandArtifactContentNotExist(artifact.getPath());
+ }
+ String actual = this.getChecksum(artifact.getPath());
+ if (!existing.getChecksum().equals(actual)) {
+ artifact.setChecksum(actual);
+ artifact.setSize(new File(artifact.getPath()).length() / 1024);
+ }
+ } else {
+ artifact.setPath(existing.getPath());
+ }
+
+ artifact.setCreateAt(existing.getCreateAt());
+ artifact.setLastUpdatedAt(dateFormatter.format(new Date()));
+ return artifact;
+ }
+
public Artifact updateArtifact(String name, String category, Artifact artifact) throws OnapCommandArtifactNotFound, OnapCommandArtifactContentNotExist, OnapCommandArtifactAlreadyExist {
Artifact existing = this.getArtifact(name, category);
String existingStorePath = getArtifactPath(name, category);
@@ -273,33 +304,7 @@ public class OnapCommandArtifactStore {
}
try {
- if (artifact.getName() == null) {
- artifact.setName(existing.getName());
- }
-
- if (artifact.getDescription() == null) {
- artifact.setDescription(existing.getDescription());
- }
-
- if (artifact.getCategoty() == null) {
- artifact.setCategoty(existing.getCategoty());
- }
-
- if (artifact.getPath()!= null) {
- if (!new File(artifact.getPath()).exists()) {
- throw new OnapCommandArtifactContentNotExist(artifact.getPath());
- }
- String actual = this.getChecksum(artifact.getPath());
- if (!existing.getChecksum().equals(actual)) {
- artifact.setChecksum(actual);
- artifact.setSize(new File(artifact.getPath()).length() / 1024);
- }
- } else {
- artifact.setPath(existing.getPath());
- }
-
- artifact.setCreateAt(existing.getCreateAt());
- artifact.setLastUpdatedAt(dateFormatter.format(new Date()));
+ artifact = setArtifact(artifact, existing);
if (artifact.getMetadata().size() > 0) {
//update to existing one
for (Map.Entry<String, String> entry: artifact.getMetadata().entrySet()) {