summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main')
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/impl/ValidationManagerFactoryImpl.java34
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/impl/ValidationManagerImpl.java69
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationConfiguration.java37
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationConfigurationManager.java74
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationManagerUtil.java65
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidatorConfiguration.java51
6 files changed, 330 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/impl/ValidationManagerFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/impl/ValidationManagerFactoryImpl.java
new file mode 100644
index 0000000000..87d4dd8118
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/impl/ValidationManagerFactoryImpl.java
@@ -0,0 +1,34 @@
+/*-
+ * ============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.validation.impl;
+
+
+import org.openecomp.core.validation.api.ValidationManager;
+import org.openecomp.core.validation.factory.ValidationManagerFactory;
+
+
+public class ValidationManagerFactoryImpl extends ValidationManagerFactory {
+
+ @Override
+ public ValidationManager createInterface() {
+ return new ValidationManagerImpl();
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/impl/ValidationManagerImpl.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/impl/ValidationManagerImpl.java
new file mode 100644
index 0000000000..64c409b463
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/impl/ValidationManagerImpl.java
@@ -0,0 +1,69 @@
+/*-
+ * ============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.validation.impl;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.core.validation.api.ValidationManager;
+import org.openecomp.core.validation.interfaces.Validator;
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.core.validation.types.MessageContainer;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.validation.utils.ValidationConfigurationManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ValidationManagerImpl implements ValidationManager {
+
+ private static Logger logger = LoggerFactory.getLogger(ValidationManagerImpl.class);
+ private GlobalValidationContext globalContext;
+ private List<Validator> validators;
+
+ public ValidationManagerImpl() {
+ globalContext = new GlobalValidationContext();
+ validators = ValidationConfigurationManager.initValidators();
+ }
+
+ @Override
+ public void addFile(String fileName, byte[] fileContent) {
+ globalContext.addFileContext(fileName, fileContent);
+ }
+
+ @Override
+ public Map<String, List<ErrorMessage>> validate() {
+ for (Validator validator : validators) {
+ validator.validate(globalContext);
+ }
+ return convertMessageContainsToErrorMessage(globalContext.getContextMessageContainers());
+ }
+
+ private Map<String, List<ErrorMessage>> convertMessageContainsToErrorMessage(
+ Map<String, MessageContainer> contextMessageContainers) {
+ Map<String, List<ErrorMessage>> errors = new HashMap<>();
+ contextMessageContainers.entrySet().stream()
+ .filter(entry -> CollectionUtils.isNotEmpty(entry.getValue().getErrorMessageList()))
+ .forEach(entry -> errors.put(entry.getKey(), entry.getValue().getErrorMessageList()));
+ return errors;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationConfiguration.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationConfiguration.java
new file mode 100644
index 0000000000..1a74e1cc34
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationConfiguration.java
@@ -0,0 +1,37 @@
+/*-
+ * ============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.validation.utils;
+
+import java.util.Collections;
+import java.util.List;
+
+public class ValidationConfiguration {
+ private List<ValidatorConfiguration> validatorConfigurationList;
+
+ public List<ValidatorConfiguration> getValidatorConfigurationList() {
+ return Collections.unmodifiableList(validatorConfigurationList);
+ }
+
+ public void setValidatorConfigurationList(
+ List<ValidatorConfiguration> validatorConfigurationList) {
+ this.validatorConfigurationList = validatorConfigurationList;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationConfigurationManager.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationConfigurationManager.java
new file mode 100644
index 0000000000..cc921ce985
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationConfigurationManager.java
@@ -0,0 +1,74 @@
+/*-
+ * ============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.validation.utils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.core.validation.interfaces.Validator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class ValidationConfigurationManager {
+
+ private static final String VALIDATION_CONFIGURATION = "validationConfiguration.json";
+ private static final List<Validator> validators = new ArrayList<>();
+ private static Logger logger = LoggerFactory.getLogger(ValidationConfigurationManager.class);
+
+ /**
+ * Init validators list.
+ *
+ * @return the list
+ */
+ public static List<Validator> initValidators() {
+ synchronized (validators) {
+ if (CollectionUtils.isEmpty(validators)) {
+ InputStream validationConfigurationJson =
+ FileUtils.getFileInputStream(VALIDATION_CONFIGURATION);
+ ValidationConfiguration validationConfiguration =
+ JsonUtil.json2Object(validationConfigurationJson, ValidationConfiguration.class);
+ List<ValidatorConfiguration> conf = validationConfiguration.getValidatorConfigurationList();
+ conf.stream().filter(ValidatorConfiguration::isEnableInd).forEachOrdered(
+ validatorConfiguration -> validators.add(validatorInit(validatorConfiguration)));
+ }
+ }
+ return validators;
+ }
+
+ private static Validator validatorInit(ValidatorConfiguration validatorConf) {
+ Validator validator = null;
+ try {
+ validator =
+ CommonMethods.newInstance(validatorConf.getImplementationClass(), Validator.class);
+ } catch (IllegalArgumentException iae) {
+ logger.error("Validator:" + validatorConf.getName() + " Class:"
+ + validatorConf.getImplementationClass() + " failed in initialization. error:"
+ + iae.toString() + " trace:" + Arrays.toString(iae.getStackTrace()));
+ }
+ return validator;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationManagerUtil.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationManagerUtil.java
new file mode 100644
index 0000000000..960bdc2165
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidationManagerUtil.java
@@ -0,0 +1,65 @@
+/*-
+ * ============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.validation.utils;
+
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.validation.api.ValidationManager;
+import org.openecomp.core.validation.errors.Messages;
+import org.openecomp.core.validation.factory.ValidationManagerFactory;
+import org.openecomp.sdc.common.utils.AsdcCommon;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+public class ValidationManagerUtil {
+
+ /**
+ * Handle missing manifest.
+ *
+ * @param fileContentMap the file content map
+ * @param errors the errors
+ */
+ public static void handleMissingManifest(FileContentHandler fileContentMap,
+ Map<String, List<ErrorMessage>> errors) {
+ InputStream manifest = fileContentMap.getFileContent(AsdcCommon.MANIFEST_NAME);
+ if (manifest == null) {
+ ErrorMessage.ErrorMessageUtil.addMessage(AsdcCommon.MANIFEST_NAME, errors)
+ .add(new ErrorMessage(ErrorLevel.ERROR, Messages.MANIFEST_NOT_EXIST.getErrorMessage()));
+ }
+ }
+
+ /**
+ * Init validation manager validation manager.
+ *
+ * @param fileContentMap the file content map
+ * @return the validation manager
+ */
+ public static ValidationManager initValidationManager(FileContentHandler fileContentMap) {
+ ValidationManager validationManager = ValidationManagerFactory.getInstance().createInterface();
+ fileContentMap.getFileList().stream().forEach(fileName -> validationManager
+ .addFile(fileName, FileUtils.toByteArray(fileContentMap.getFileContent(fileName))));
+ return validationManager;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidatorConfiguration.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidatorConfiguration.java
new file mode 100644
index 0000000000..12feb641ae
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/main/java/org/openecomp/sdc/validation/utils/ValidatorConfiguration.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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.validation.utils;
+
+public class ValidatorConfiguration {
+ private String name;
+ private boolean enableInd = true;
+ private String implementationClass;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isEnableInd() {
+ return enableInd;
+ }
+
+ public void setEnableInd(boolean enableInd) {
+ this.enableInd = enableInd;
+ }
+
+ public String getImplementationClass() {
+ return implementationClass;
+ }
+
+ public void setImplementationClass(String implementationClass) {
+ this.implementationClass = implementationClass;
+ }
+}