push addional code
[sdc.git] / openecomp-be / lib / openecomp-sdc-enrichment-lib / openecomp-sdc-enrichment-impl / src / main / java / org / openecomp / sdc / enrichment / impl / EnricherHandlerImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.enrichment.impl;
22
23 import org.openecomp.core.enrichment.types.EntityInfo;
24 import org.openecomp.sdc.datatypes.error.ErrorMessage;
25 import org.openecomp.sdc.datatypes.model.AsdcModel;
26 import org.openecomp.sdc.enrichment.EnrichmentInfo;
27 import org.openecomp.sdc.enrichment.impl.external.artifact.ExternalArtifactEnricher;
28 import org.openecomp.sdc.enrichment.impl.tosca.ToscaEnricher;
29 import org.openecomp.sdc.enrichment.inter.Enricher;
30 import org.openecomp.sdc.enrichment.inter.EnricherHandler;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38
39 /**
40  * The type Enricher handler.
41  */
42 public class EnricherHandlerImpl implements EnricherHandler {
43
44   private static Logger logger = LoggerFactory.getLogger(EnricherHandlerImpl.class);
45   private EnrichmentInfo input;
46   private AsdcModel model;
47
48   @Override
49   public List<Enricher> getEnrichers() {
50     List<Enricher> enricherList = new ArrayList<>();
51     enricherList.add(new ToscaEnricher());
52     enricherList.add(new ExternalArtifactEnricher());
53     return enricherList;
54   }
55
56   @Override
57   public Map<String, List<ErrorMessage>> enrich() {
58     Map<String, List<ErrorMessage>> errors = new HashMap<>();
59     Map<String, List<ErrorMessage>> enricherResponse;
60     for (Enricher enricher : getEnrichers()) {
61       enricher.setInput(this.input);
62       enricher.setModel(this.model);
63       enricherResponse = enricher.enrich();
64       errors.putAll(enricherResponse);
65     }
66     return errors;
67   }
68
69   /**
70    * Adds additional input.
71    *
72    * @param key   key
73    * @param input input
74    */
75   public void addAdditionalInput(String key, Object input) {
76     if (!this.input.getAdditionalInfo().containsKey(key)) {
77       this.input.getAdditionalInfo().put(key, new ArrayList<>());
78     }
79     this.input.getAdditionalInfo().get(key).add(input);
80   }
81
82   public void addEntityInfo(String entityId, EntityInfo entityInfo) {
83     this.input.getEntityInfo().put(entityId, entityInfo);
84   }
85
86   public void setModel(AsdcModel model) {
87     this.model = model;
88   }
89 }