2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.enrichment.impl.external.artifact;
23 import org.openecomp.core.utilities.file.FileUtils;
24 import org.openecomp.core.utilities.json.JsonUtil;
25 import org.openecomp.sdc.datatypes.error.ErrorMessage;
26 import org.openecomp.sdc.enrichment.inter.Enricher;
27 import org.openecomp.sdc.enrichment.inter.ExternalArtifactEnricherInterface;
28 import org.openecomp.sdc.logging.api.Logger;
29 import org.openecomp.sdc.logging.api.LoggerFactory;
30 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
32 import java.lang.reflect.Constructor;
33 import java.util.Collection;
34 import java.util.HashMap;
35 import java.util.List;
38 public class ExternalArtifactEnricher extends Enricher {
39 private static final String EXTERNAL_ARTIFACT_ENRICH_CONF_FILE = "ExternalArtifactConfiguration"
41 private static Collection<String> implementingClasses =
42 getExternalArtifactEnrichedImplClassesList();
43 private static Logger logger = LoggerFactory.getLogger(ExternalArtifactEnricher.class);
45 private static Collection<String> getExternalArtifactEnrichedImplClassesList() {
46 @SuppressWarnings("unchecked")
47 Map<String, String> confFileAsMap = FileUtils.readViaInputStream(EXTERNAL_ARTIFACT_ENRICH_CONF_FILE,
48 stream -> JsonUtil.json2Object(stream, Map.class));
50 return confFileAsMap.values();
54 public Map<String, List<ErrorMessage>> enrich() {
55 Map<String, List<ErrorMessage>> errors = new HashMap<>();
58 for (String implementingClassName : implementingClasses) {
59 ExternalArtifactEnricherInterface externalArtifactEnricherInstance = getExternalArtifactEnricherInstance(implementingClassName);
60 externalArtifactEnricherInstance.enrich(this.data, (ToscaServiceModel) this.model);
62 } catch (Exception e) {
64 logger.error(e.getMessage());
69 private ExternalArtifactEnricherInterface getExternalArtifactEnricherInstance(
70 String implementingClassName) throws Exception {
71 Class<?> clazz = Class.forName(implementingClassName);
72 Constructor<?> constructor = clazz.getConstructor();
73 return (ExternalArtifactEnricherInterface) constructor.newInstance();