aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-common-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-common-lib')
-rw-r--r--openecomp-be/lib/openecomp-common-lib/pom.xml29
-rw-r--r--openecomp-be/lib/openecomp-common-lib/pom.xml.versionsBackup44
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCategory.java12
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCode.java13
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCodeAndMessage.java1
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/GeneralErrorBuilder.java8
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/JsonMappingErrorBuilder.java8
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java146
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ValidationErrorBuilder.java11
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java106
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java (renamed from openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/AsdcCommon.java)8
11 files changed, 328 insertions, 58 deletions
diff --git a/openecomp-be/lib/openecomp-common-lib/pom.xml b/openecomp-be/lib/openecomp-common-lib/pom.xml
index a5f1987708..06e8152af7 100644
--- a/openecomp-be/lib/openecomp-common-lib/pom.xml
+++ b/openecomp-be/lib/openecomp-common-lib/pom.xml
@@ -2,45 +2,38 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+ <groupId>org.openecomp.core</groupId>
+ <name>openecomp-common-lib</name>
+ <artifactId>openecomp-common-lib</artifactId>
+
<parent>
<artifactId>openecomp-sdc-lib</artifactId>
<groupId>org.openecomp.sdc</groupId>
<version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
</parent>
- <artifactId>openecomp-common-lib</artifactId>
-
- <name>openecomp-common-lib</name>
-
<dependencies>
<dependency>
- <groupId>org.openecomp.sdc</groupId>
+ <groupId>org.openecomp.core</groupId>
<artifactId>openecomp-utilities-lib</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>${project.version}</version>
</dependency>
-
<dependency>
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-datatypes-lib</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
- <version>${ws.rs.version}</version>
+ <version>2.1-m05</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
- <version>1.1.2</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>1.1.2</version>
+ <version>${logback.version}</version>
</dependency>
</dependencies>
-
-
-</project> \ No newline at end of file
+</project>
diff --git a/openecomp-be/lib/openecomp-common-lib/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-common-lib/pom.xml.versionsBackup
new file mode 100644
index 0000000000..e2333b5ae3
--- /dev/null
+++ b/openecomp-be/lib/openecomp-common-lib/pom.xml.versionsBackup
@@ -0,0 +1,44 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.openecomp.core</groupId>
+ <name>openecomp-common-lib</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-utilities-lib</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-datatypes-lib</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>2.0-m10</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-utilities-lib</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <artifactId>openecomp-common-lib</artifactId>
+
+ <parent>
+ <artifactId>openecomp-sdc-lib</artifactId>
+ <groupId>org.openecomp.sdc</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+
+</project> \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCategory.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCategory.java
index d24ee62124..00f8d74fb7 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCategory.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCategory.java
@@ -44,21 +44,21 @@ public enum ErrorCategory {
VALIDATION,
/**
- * Problems caused by attempt of a user to perform certain operations which contradict the
- * system rules. Mostly applicable to UI-driven flows in presentation tier.
+ * Problems caused by attempt of a user to perform certain operations which contradict the system
+ * rules. Mostly applicable to UI-driven flows in presentation tier.
*/
USER,
/**
* Improper values set in the system configuration (negative numbers, missing or inconsistent
* definitions, mismatch with valid values list etc).
- * */
+ */
CONFIGURATION,
/**
- * Security constraint violations (failed login attempts, lack of permissions to perform
- * operation and so on). Any problems related to authentication/authorization should use the
- * special category for system auditing purposes.
+ * Security constraint violations (failed login attempts, lack of permissions to perform operation
+ * and so on). Any problems related to authentication/authorization should use the special
+ * category for system auditing purposes.
*/
SECURITY
}
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCode.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCode.java
index aa0b123d4a..6a9990dcf1 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCode.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCode.java
@@ -32,6 +32,14 @@ public class ErrorCode implements Serializable {
protected ErrorCode() {
}
+ /*
+ For backward compatibility only - will be removed soon
+ */
+
+ @Override
+ public String toString() {
+ return message;
+ }
public String id() {
return id;
@@ -60,11 +68,6 @@ public class ErrorCode implements Serializable {
this.category = category;
}
- @Override
- public String toString() {
- return message;
- }
-
public static class ErrorCodeBuilder {
private String id;
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCodeAndMessage.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCodeAndMessage.java
index 672397f53c..58f073935a 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCodeAndMessage.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCodeAndMessage.java
@@ -26,7 +26,6 @@ import javax.ws.rs.core.Response;
/**
* This class represents an error object to be returned in failed REST instead of just returning one
* of HTTP fail statuses.
- *
*/
public class ErrorCodeAndMessage {
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/GeneralErrorBuilder.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/GeneralErrorBuilder.java
index 155d020396..7ded61e2dc 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/GeneralErrorBuilder.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/GeneralErrorBuilder.java
@@ -20,9 +20,6 @@
package org.openecomp.sdc.common.errors;
-/**
- * The type General error builder.
- */
public class GeneralErrorBuilder {
private static final String GENERAL_ERROR_REST_ID = "GENERAL_ERROR_REST_ID";
@@ -41,11 +38,6 @@ public class GeneralErrorBuilder {
builder.withMessage(String.format(GENERAL_ERROR_REST_MSG, detailedError));
}
- /**
- * Build error code.
- *
- * @return the error code
- */
public ErrorCode build() {
return builder.build();
}
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/JsonMappingErrorBuilder.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/JsonMappingErrorBuilder.java
index 2a916dbf90..8c5b1cd2ad 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/JsonMappingErrorBuilder.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/JsonMappingErrorBuilder.java
@@ -20,9 +20,6 @@
package org.openecomp.sdc.common.errors;
-/**
- * The type Json mapping error builder.
- */
public class JsonMappingErrorBuilder {
private static final String JSON_MAPPING_ERROR_ERR_ID = "JSON_MAPPING_ERROR_ERR_ID";
@@ -41,11 +38,6 @@ public class JsonMappingErrorBuilder {
builder.withMessage(String.format(JSON_MAPPING_ERROR_ERR_ERR_MSG));
}
- /**
- * Build error code.
- *
- * @return the error code
- */
public ErrorCode build() {
return builder.build();
}
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
new file mode 100644
index 0000000000..0be6a55df6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
@@ -0,0 +1,146 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.errors;
+
+
+public enum Messages {
+ CANT_LOAD_CLASS("Can't load class %s. Error: %s"),
+
+ VERSION_UPGRADE("Item %s is of old version. A check out was made in order to get new " +
+ "functionalities"),
+
+ INVALID_ZIP_FILE("Invalid zip file"),
+ FAILED_TO_TRANSLATE_ZIP_FILE("Failed to translate zip file"),
+ ZIP_NOT_EXIST("Zip file doesn't exist"),
+
+ ZIP_SHOULD_NOT_CONTAIN_FOLDERS("Zip file should not contain folders"),
+ MANIFEST_NOT_EXIST("Manifest doesn't exist"),
+ FILE_TYPE_NOT_LEGAL("File type not legal as data for other file"),
+ MODULE_IN_MANIFEST_NO_YAML("Module '%s', has no yaml file reference"),
+ NO_MODULES_IN_MANIFEST("At least on Base/Module must be defined \n"),
+ MODULE_IN_MANIFEST_VOL_ENV_NO_VOL("Module '%s', has volume Env. reference with no Volume " +
+ "reference"),
+ ILLEGAL_MANIFEST("Illegal Manifest"),
+ NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST("no zip file was uploaded or zip file doesn't exist"),
+ MAPPING_OBJECTS_FAILURE("Failed to map object %s to %s. Exception message: %s"),
+ MORE_THEN_ONE_VOL_FOR_HEAT("heat contains more then one vol. selecting only first vol"),
+ ZIP_CONTENT_MAP("failed to load zip content"),
+ CREATE_MANIFEST_FROM_ZIP("cannot create manifest from the attached zip file"),
+ CANDIDATE_PROCESS_FAILED("Candidate zip file process failed"),
+ FOUND_UNASSIGNED_FILES("cannot process zip since it has unassigned files"),
+
+
+ /* manifest errors*/
+ MISSING_FILE_IN_ZIP("Missing file in zip"),
+ MISSING_FILE_IN_MANIFEST("Missing file in manifest"),
+ MISSING_FILE_NAME_IN_MANIFEST("Missing file name in manifest - %s"),
+ MISSING_NESTED_FILE("Missing nested file - %s"),
+ MISSING_ARTIFACT("Missing artifact - %s"),
+ WRONG_HEAT_FILE_EXTENSION("Wrong HEAT file extension - %s"),
+ WRONG_ENV_FILE_EXTENSION("Wrong ENV file extension - %s"),
+ INVALID_MANIFEST_FILE("invalid manifest file"),
+ INVALID_FILE_TYPE("Missing or Unknown file type in Manifest"),
+ ENV_NOT_ASSOCIATED_TO_HEAT("ENV file must be associated to a HEAT file"),
+
+ /* content errors*/
+ INVALID_YAML_FORMAT("Invalid YAML format - %s"),
+ INVALID_YAML_FORMAT_REASON("Invalid YAML format Problem - [%s]"),
+ EMPTY_YAML_FILE("empty yaml"),
+ GENERAL_YAML_PARSER_ERROR("general parser error"),
+ GENERAL_HEAT_PARSER_ERROR("general parser error"),
+ INVALID_HEAT_FORMAT_REASON("Invalid HEAT format problem - [%s]"),
+ MISSING_RESOURCE_IN_DEPENDS_ON("a Missing resource in depend On, Missing Resource ID [%s]"),
+ REFERENCED_PARAMETER_NOT_FOUND("Referenced parameter - %s - not found, used in resource [%s]"),
+ GET_ATTR_NOT_FOUND("get_attr attribute not found, Attribute name [%s], Resource ID [%s]"),
+ MISSING_PARAMETER_IN_NESTED(
+ "Referenced parameter not found in nested file - %s, parameter name [%s], Resource ID [%s]"),
+ NESTED_LOOP("Nested files loop - %s"),
+ MORE_THAN_ONE_BIND_FROM_NOVA_TO_PORT("Resource Port %s exceed allowed relations from NovaServer"),
+ SERVER_NOT_DEFINED_FROM_NOVA("Missing server group definition - %s, %s"),
+ WRONG_POLICY_IN_SERVER_GROUP("Wrong policy in server group - %s"),
+ MISSING_IMAGE_AND_FLAVOR("Missing both Image and Flavor in NOVA Server, Resource ID [%s]"),
+ ENV_INCLUDES_PARAMETER_NOT_IN_HEAT("Env file %s includes a parameter not in HEAT - %s"),
+ PARAMETER_ENV_VALUE_NOT_ALIGN_WITH_TYPE("Parameter env value %s not align with type"),
+ PARAMETER_DEFAULT_VALUE_NOT_ALIGN_WITH_TYPE(
+ "Parameter - %s default value not align with type %s"),
+ INVALID_RESOURCE_TYPE("A resource has an invalid or unsupported type - %s, Resource ID [%s]"),
+ ARTIFACT_FILE_NOT_REFERENCED("Artifact file is not referenced."),
+ RESOURCE_NOT_IN_USE("%s not in use, Resource Id [%s]"),
+ PORT_NO_BIND_TO_ANY_NOVA_SERVER("Port not bind to any NOVA Server, Resource Id [%s]"),
+ INVALID_GET_RESOURCE_SYNTAX(
+ "invalid get_resource syntax is in use - %s , get_resource"
+ + " function should get the resource id of the referenced resource"),
+ INVALID_RESOURCE_GROUP_TYPE(
+ "OS::Heat::ResourceGroup resource with resource_def which is not pointing to "
+ + "nested heat file is not supported, Resource ID [%s], resource_def type [%s]"),
+ WRONG_VALUE_TYPE_ASSIGNED_NESTED_INPUT(
+ "Wrong value type assigned to a nested input parameter, nested resource [%s],"
+ + " property name [%s], nested file [%s]"),
+ NOVA_NAME_IMAGE_FLAVOR_NOT_CONSISTENT(
+ "Nova Server naming convention in image, flavor and name properties is not "
+ + "consistent, Resource ID [%s]"),
+ RESOURCE_GROUP_INVALID_INDEX_VAR(
+ "Wrong value assigned to a ResourceGroup index_var property (functions are not allowed"
+ + " but only strings), Resource ID [%s]"),
+ CONTRAIL_2_IN_USE("Contrail 2.x deprecated resource is in use, Resource ID [%s]"),
+
+ /* warnings */
+ REFERENCED_RESOURCE_NOT_FOUND("Referenced resource - %s not found"),
+ MISSING_GET_PARAM("Missing get_param in %s, Resource Id [%s]"),
+
+ /*OPENECOMP Guide lines*/
+ MISSING_NOVA_SERVER_METADATA("Missing Nova Server Metadata property, Resource ID [%s]"),
+ MISSING_NOVA_SERVER_VNF_ID("Missing VNF_ID in Metadata property, Resource ID [%s]"),
+ MISSING_NOVA_SERVER_VF_MODULE_ID("Missing VF_MODULE_ID in Metadata property, Resource id [%s]"),
+ NETWORK_PARAM_NOT_ALIGNED_WITH_GUIDE_LINE(
+ "Network Parameter Name not aligned with Guidelines, Parameter Name [%s] Resource ID [%s]"),
+ MISSIN_BASE_HEAT_FILE(
+ "Missing Base HEAT. Pay attention that without Base HEAT, there will be no shared resources"),
+ MULTI_BASE_HEAT_FILE("Multi Base HEAT. Expected only one. Files %s."),
+ RESOURCE_NOT_DEFINED_IN_OUTPUT(
+ "Resource is not defined as output and thus cannot be Shared, Resource ID [%s]"),
+ RESOURCE_CONNECTED_TO_TWO_EXTERNAL_NETWORKS_WITH_SAME_ROLE(
+ "A resource is connected twice to the same network role, Network Role [%s],"
+ + " Resource ID [%s]"),
+ VOLUME_HEAT_NOT_EXPOSED("Volume is not defined as output and thus cannot be attached %s"),
+ FORBIDDEN_RESOURCE_IN_USE("%s is in use, Resource ID [%s]"),
+ PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES(
+ "%s '%s' Parameter Name not aligned with Guidelines, Parameter Name [%s], Resource ID [%s]."
+ + " As a result, VF/VFC Profile may miss this information"),
+ /* Contrail validator messages*/
+ MERGE_OF_CONTRAIL2_AND_CONTRAIL3_RESOURCES(
+ "HEAT Package includes both Contrail 2 and Contrail 3 resources. "
+ + "Contrail 2 resources can be found in %s. Contrail 3 resources can be found in %s"),
+ CONTRAIL_VM_TYPE_NAME_NOT_ALIGNED_WITH_NAMING_CONVENSION(
+ "Service Template naming convention in Image and Flavor "
+ + "properties is not consistent in Resource, Resource ID %s");
+
+ private String errorMessage;
+
+ Messages(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ValidationErrorBuilder.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ValidationErrorBuilder.java
index eb60a63a4b..129abf3ab7 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ValidationErrorBuilder.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ValidationErrorBuilder.java
@@ -20,14 +20,8 @@
package org.openecomp.sdc.common.errors;
-/**
- * The type Validation error builder.
- */
public class ValidationErrorBuilder {
- /**
- * The constant FIELD_VALIDATION_ERROR_ERR_ID.
- */
public static final String FIELD_VALIDATION_ERROR_ERR_ID = "FIELD_VALIDATION_ERROR_ERR_ID";
private static final String FIELD_VALIDATION_ERROR_ERR_MSG =
"Field does not conform to predefined criteria : %s : %s";
@@ -56,11 +50,6 @@ public class ValidationErrorBuilder {
}
}
- /**
- * Build error code.
- *
- * @return the error code
- */
public ErrorCode build() {
return builder.build();
}
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
new file mode 100644
index 0000000000..8ffddc48d7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.utils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.logging.types.LoggerConstants;
+import org.openecomp.sdc.logging.types.LoggerErrorDescription;
+import org.openecomp.sdc.common.errors.Messages;
+import org.slf4j.MDC;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class CommonUtil {
+
+ public static String getMethodName() {
+ return Thread.currentThread().getStackTrace()[2].getMethodName();
+ }
+
+ public static FileContentHandler loadUploadFileContent(byte[] uploadedFileData)
+ throws IOException {
+ return getFileContentMapFromOrchestrationCandidateZip(uploadedFileData);
+ }
+
+ public static FileContentHandler getFileContentMapFromOrchestrationCandidateZip(byte[] uploadFileData)
+ throws IOException {
+ ZipEntry zipEntry;
+ List<String> folderList = new ArrayList<>();
+ FileContentHandler mapFileContent = new FileContentHandler();
+ try {
+ ZipInputStream inputZipStream;
+
+ byte[] fileByteContent;
+ String currentEntryName;
+ inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData));
+
+ while ((zipEntry = inputZipStream.getNextEntry()) != null) {
+ currentEntryName = zipEntry.getName();
+ // else, get the file content (as byte array) and save it in a map.
+ fileByteContent = FileUtils.toByteArray(inputZipStream);
+
+ int index = lastIndexFileSeparatorIndex(currentEntryName);
+ if (index != -1) { //todo ?
+ folderList.add(currentEntryName);
+ } else {
+ mapFileContent.addFile(currentEntryName, fileByteContent);
+ }
+
+ }
+
+ } catch (RuntimeException exception) {
+ throw new IOException(exception);
+ }
+
+ if (CollectionUtils.isNotEmpty(folderList)) {
+ MDC.put(LoggerConstants.ERROR_DESCRIPTION, LoggerErrorDescription.INVALID_ZIP);
+ throw new CoreException((new ErrorCode.ErrorCodeBuilder())
+ .withMessage(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
+ .withId(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
+ .withCategory(ErrorCategory.APPLICATION).build());
+ }
+
+ return mapFileContent;
+ }
+
+ private static int lastIndexFileSeparatorIndex(String filePath) {
+ int length = filePath.length() - 1;
+
+ for (int i = length; i >= 0; i--) {
+ char currChar = filePath.charAt(i);
+ if (currChar == '/' || currChar == File.separatorChar || currChar == File.pathSeparatorChar) {
+ return i;
+ }
+ }
+ // if we've reached to the start of the string and didn't find file separator - return -1
+ return -1;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/AsdcCommon.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java
index d3806ff34e..156a86c841 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/AsdcCommon.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java
@@ -20,12 +20,18 @@
package org.openecomp.sdc.common.utils;
-public class AsdcCommon {
+public class SdcCommon {
public static final String MANIFEST_NAME = "MANIFEST.json";
public static final String UPLOAD_FILE = "uploadFile";
+ public static final String PROCESS_FILE = "Process File";
+ public static final String ILLEGAL_MANIFEST = "Illegal manifest";
public static final String HEAT_TO_TOSCA_MAPPING_CONF = "heatToToscaMapping.json";
public static final String HEAT_META = "HEAT.meta";
public static final String PARENT = "parent";
+
+ public static final String VSP_ID = "vspId";
+ public static final String VERSION = "version";
+ public static final String USER = "user";
}