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;
23 import org.openecomp.core.enrichment.api.EnrichmentManager;
24 import org.openecomp.core.enrichment.types.EntityInfo;
25 import org.openecomp.sdc.datatypes.error.ErrorLevel;
26 import org.openecomp.sdc.datatypes.error.ErrorMessage;
27 import org.openecomp.sdc.enrichment.EnrichmentInfo;
28 import org.openecomp.sdc.enrichment.factory.EnricherHandlerFactory;
29 import org.openecomp.sdc.enrichment.inter.Enricher;
30 import org.openecomp.sdc.logging.api.Logger;
31 import org.openecomp.sdc.logging.api.LoggerFactory;
32 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
33 import org.openecomp.sdc.versioning.dao.types.Version;
35 import java.util.Arrays;
36 import java.util.HashMap;
37 import java.util.List;
40 public class EnrichmentManagerImpl implements EnrichmentManager<ToscaServiceModel> {
42 private static Logger logger = (Logger) LoggerFactory.getLogger(EnrichmentManagerImpl.class);
44 private EnrichmentInfo data = null;
45 private ToscaServiceModel model;
49 public Map<String, List<ErrorMessage>> enrich() {
50 Map<String, List<ErrorMessage>> enrichErrors = new HashMap<>();
51 List<Enricher> enricherList =
52 EnricherHandlerFactory.getInstance().createInterface().getEnrichers();
53 for (Enricher enricher : enricherList) {
54 enricher.setData(data);
55 enricher.setModel(model);
57 enrichErrors.putAll(enricher.enrich());
58 } catch (Exception exception) {
59 enrichErrors.put("Enrich", Arrays.asList(new ErrorMessage(ErrorLevel.ERROR, exception
61 logger.error("Exception occurred during enrichment", exception);
68 public void addEntityInfo(String entityKey, EntityInfo entityInfo) {
69 this.data.addEntityInfo(entityKey, entityInfo);
74 public void init(String key, Version version) {
75 data = new EnrichmentInfo();
77 data.setVersion(version);
81 public ToscaServiceModel getModel() {
86 public void setModel(ToscaServiceModel model) {