DCAE-D be initial commit
[sdc/dcae-d/dt-be-main.git] / dcaedt_be / src / main / java / org / onap / sdc / dcae / rule / editor / translators / MappingRulesTranslator.java
1 package org.onap.sdc.dcae.rule.editor.translators;
2
3 import java.util.List;
4 import java.util.stream.Collectors;
5
6 import org.onap.sdc.dcae.composition.restmodels.ruleeditor.MappingRules;
7
8 public class MappingRulesTranslator implements IRuleElementTranslator<MappingRules> {
9
10         private static MappingRulesTranslator mappingRulesTranslator = new MappingRulesTranslator();
11
12         public static MappingRulesTranslator getInstance() {
13                 return mappingRulesTranslator;
14         }
15
16         private MappingRulesTranslator() {
17         }
18
19         private RuleTranslator ruleTranslator = RuleTranslator.getInstance();
20
21         public Translation translateToHpJson(MappingRules mappingRules) {
22                 return new MappingRulesTranslation(mappingRules);
23         }
24
25         public Translation translateToHpJson(MappingRules mappingRules, String entryPointPhaseName, String lastPhaseName, String runPhase) {
26                 // 1806 US349308 assign Vfcmt name as rule phaseName
27                 mappingRules.getRules().forEach((k,v) -> v.setPhase(runPhase));
28                 return new MappingRulesTranslation(mappingRules, entryPointPhaseName, lastPhaseName, runPhase);
29         }
30
31         private class MappingRulesTranslation extends Translation {
32
33                 private List<Translation> processing;
34
35                 private MappingRulesTranslation(MappingRules mappingRules) {
36                         processing = mappingRules.getRules().values().stream().map(ruleTranslator::translateToHpJson).collect(Collectors.toList());
37                 }
38
39                 private MappingRulesTranslation(MappingRules mappingRules, String entryPointPhaseName, String lastPhaseName, String runPhase) {
40                         this(mappingRules);
41                         //hardcoded entry point processor
42                         processing.add(0, new RunPhaseRuleTranslation(entryPointPhaseName, runPhase));
43                         //hardcoded map_publish processor
44                         processing.add(new RunPhaseRuleTranslation(runPhase, lastPhaseName));
45                 }
46         }
47
48         private class RunPhaseRuleTranslation extends RuleTranslation {
49
50                 private RunPhaseRuleTranslation(String phaseName, String runPhase) {
51                         phase = phaseName;
52                         if ("snmp_map".equals(phaseName))
53                                 processors.add(new SnmpConvertor());
54                         processors.add(new RunPhaseProcessorsTranslation(runPhase));
55                 }
56         }
57
58         // hardcoded SNMP processor
59         private class SnmpConvertor extends ProcessorTranslation {
60                 private String array = "varbinds";
61                 private String datacolumn = "varbind_value";
62                 private String keycolumn = "varbind_oid";
63
64                 private SnmpConvertor() {
65                         clazz = "SnmpConvertor";
66                 }
67         }
68
69 }