summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-06-19 17:27:03 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-07-05 07:59:06 +0000
commit0bea1a6770a361820e7332766e10683a86687698 (patch)
tree6fa5e7ec20a6bdc3fc466cb80a25c6db2f33b1ad
parente4092fe48f6dd74c778a03d84df00835d6ca0a3d (diff)
Fix sonar issues
Fix sonar/checkstyle issues in sdc code Issue-ID: SDC-3158 Signed-off-by: sebdet <sebastien.determe@intl.att.com> Change-Id: I0ae188c5f0e2d96fd94de66fe0dcd0c47bcd9af5
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java38
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java84
2 files changed, 56 insertions, 66 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java
index 27ef49ac15..aaafdd2367 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java
@@ -7,9 +7,9 @@
* Licensed 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
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,13 +20,12 @@
package org.openecomp.sdc.asdctool.impl;
+import java.util.Properties;
import org.apache.http.HttpStatus;
import org.openecomp.sdc.common.http.client.api.HttpRequest;
import org.openecomp.sdc.common.http.client.api.HttpResponse;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.Properties;
-
/**
* Created by mlando on 2/23/2016.
*/
@@ -34,31 +33,26 @@ public class RestUtils {
static final String DELETE_PRODUCT = "http://%s:%s/sdc2/rest/v1/catalog/products/%s";
- private static Logger log = Logger.getLogger(RestUtils.class.getName());
+ private static Logger log = Logger.getLogger(RestUtils.class.getName());
- public RestUtils() {
- }
+ public Integer deleteProduct(String productUid, String beHost, String bePort, String adminUser) {
+ String url = String.format(DELETE_PRODUCT, beHost, bePort, productUid);
- public Integer deleteProduct(String productUid, String beHost, String bePort, String adminUser) {
- String url = String.format(DELETE_PRODUCT, beHost, bePort, productUid);
-
- Properties headers = new Properties();
- headers.put("USER_ID", adminUser);
- try {
- HttpResponse<String> httpResponse = HttpRequest.delete(url, headers);
+ Properties headers = new Properties();
+ headers.put("USER_ID", adminUser);
+ try {
+ HttpResponse<String> httpResponse = HttpRequest.delete(url, headers);
int status = httpResponse.getStatusCode();
if (status == HttpStatus.SC_OK) {
log.debug("Product uid:{} successfully deleted", productUid);
- }
- else {
+ } else {
log.error("Product uid:{} delete failed status {}", productUid, status);
}
return status;
- }
- catch(Exception e) {
- log.error("Product uid:{} delete failed with exception",productUid, e);
- }
- return null;
- }
+ } catch (Exception e) {
+ log.error("Product uid:{} delete failed with exception", productUid, e);
+ }
+ return null;
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
index 3794343ee4..697d6faecb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
@@ -7,9 +7,9 @@
* Licensed 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
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,10 +20,29 @@
package org.openecomp.sdc.be.components.csar;
+import static org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.FAILED_UPLOAD_ARTIFACT_TO_COMPONENT;
+import static org.openecomp.sdc.be.tosca.CsarUtils.ARTIFACTS_PATH;
+
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.OptionalInt;
+import java.util.Scanner;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@@ -44,6 +63,7 @@ import org.openecomp.sdc.be.config.Configuration.VfModuleProperty;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -79,35 +99,11 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.OptionalInt;
-import java.util.Scanner;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import static org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.FAILED_UPLOAD_ARTIFACT_TO_COMPONENT;
-import static org.openecomp.sdc.be.tosca.CsarUtils.ARTIFACTS_PATH;
-
-
@org.springframework.stereotype.Component("csarArtifactsAndGroupsBusinessLogic")
public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private static final Logger log = Logger.getLogger(CsarArtifactsAndGroupsBusinessLogic.class.getName());
- private static final String ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME = "Artifact file is not in expected formatr, fileName {}";
private static final String ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME = "Artifact file is not in expected format, fileName {}";
- private static final String ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME1 = "Artifact file is not in expected formatr, fileName ";
- private static final String ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME1 = "Artifact file is not in expected format, fileName ";
private static final String ARTIFACT_INTERNALS_ARE_INVALID = "Artifact internals are invalid";
private static final String ARTIFACT_WITH_NAME_AND_TYPE_ALREADY_EXIST_WITH_TYPE = "Artifact with name {} and type {} already exist with type {}";
private final Gson gson = new Gson();
@@ -186,8 +182,8 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
List<ArtifactTemplateInfo> artifactsWithoutGroups = parsedArtifactsMap.remove(ArtifactTemplateInfo.CSAR_ARTIFACT);
Collection<List<ArtifactTemplateInfo>> parsedArifactsCollection = parsedArtifactsMap.values();
- Either<Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>>, ResponseFormat> parsedArtifactsPerGroupEither = createArtifactsTemplateCollection(csarInfo, updatedResource, createdNewArtifacts, shouldLock, inTransaction,
- createdDeploymentArtifactsAfterDelete, labelCounter, parsedArifactsCollection);
+ Either<Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>>, ResponseFormat> parsedArtifactsPerGroupEither = createArtifactsTemplateCollection(csarInfo, updatedResource, createdNewArtifacts,
+ createdDeploymentArtifactsAfterDelete, labelCounter, parsedArifactsCollection);
if(parsedArtifactsPerGroupEither.isRight()){
log.error("Failed to parse artifacts. Status is {} ", parsedArtifactsPerGroupEither.right().value());
return Either.right(parsedArtifactsPerGroupEither.right().value());
@@ -240,7 +236,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
createdDeploymentArtifactsAfterDelete = deploymentArtifact.values().stream()
.collect(Collectors.toList());
-
+
// update vfModule names
Set<GroupDefinition> groupForAssociateWithMembers = mergedgroup.keySet();
Either<Resource, ResponseFormat> validateUpdateVfGroupNamesRes = updateVfModuleNames(createdNewArtifacts,
@@ -361,7 +357,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
artifactsGroup.addAll(updatedGroupDef.getArtifacts());
associateMembersToArtifacts(createdNewArtifacts, createdDeploymentArtifactsAfterDelete, heatGroups,
artifactsGroup, members);
-
+
updatedGroupDef.setMembers(members);
}
}
@@ -405,7 +401,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
List<GroupDefinition> listToDelete = groups.stream()
.filter(g -> g.getType().equals(groupType))
.collect(Collectors.toList());
-
+
groupBusinessLogic.deleteGroups(resource, listToDelete);
}
}
@@ -448,10 +444,10 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
if (op.isPresent() && !op.get().getArtifactType().equalsIgnoreCase(template.getType())) {
artifactsToDelete.add(op.get());
}
- }
+ }
}
}
-
+
return artifactsToDelete;
}
@@ -479,8 +475,9 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
}
- private Either<Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>>, ResponseFormat> createArtifactsTemplateCollection(CsarInfo csarInfo, Resource resource,
- List<ArtifactDefinition> createdNewArtifacts, boolean shouldLock, boolean inTransaction,
+ private Either<Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>>, ResponseFormat> createArtifactsTemplateCollection(
+ CsarInfo csarInfo, Resource resource,
+ List<ArtifactDefinition> createdNewArtifacts,
List<ArtifactDefinition> createdDeploymentArtifactsAfterDelete, int labelCounter,
Collection<List<ArtifactTemplateInfo>> parsedArifactsCollection) {
@@ -646,7 +643,8 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
if (resStatus.isRight()) {
return resStatus;
}
- Map<String, ArtifactDefinition> createdArtifactsMap = createdArtifacts.stream().collect(Collectors.toMap(artifact -> artifact.getArtifactLabel(), artifact -> artifact));
+ Map<String, ArtifactDefinition> createdArtifactsMap = createdArtifacts.stream().collect(Collectors.toMap(
+ ArtifactDataDefinition::getArtifactLabel, artifact -> artifact));
resource.setDeploymentArtifacts(createdArtifactsMap);
if (groupName != null && !groupName.isEmpty()) {
@@ -658,7 +656,8 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
needToCreate.add(groupDefinitionEither.left().value());
}
}
- Map<String, ArtifactDefinition> createdArtifactsMap = createdArtifacts.stream().collect(Collectors.toMap(artifact -> artifact.getArtifactLabel(), artifact -> artifact));
+ Map<String, ArtifactDefinition> createdArtifactsMap = createdArtifacts.stream().collect(Collectors.toMap(
+ ArtifactDataDefinition::getArtifactLabel, artifact -> artifact));
resource.setDeploymentArtifacts(createdArtifactsMap);
Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic
@@ -1193,15 +1192,12 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
&& artifactType.equalsIgnoreCase(template.getType())) {
isNeedToDeleteArtifact = false;
break;
-
} else {
-
- if (generatedFromArt != null) {
- if (generatedFromArt.getArtifactName().equalsIgnoreCase(template.getFileName())
- && generatedFromArt.getArtifactType().equalsIgnoreCase(template.getType())) {
+ if (generatedFromArt != null
+ && generatedFromArt.getArtifactName().equalsIgnoreCase(template.getFileName())
+ && generatedFromArt.getArtifactType().equalsIgnoreCase(template.getType())) {
isNeedToDeleteArtifact = false;
break;
- }
}
}
}
@@ -1774,7 +1770,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
.map(rf -> componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(rf), component))
.left()
.map (c -> (Resource) c);
-
+
}