1 package org.onap.sdc.dcae.rule.editor.translators;
4 import java.util.stream.Collectors;
6 import org.onap.sdc.dcae.composition.restmodels.ruleeditor.MappingRules;
8 public class MappingRulesTranslator implements IRuleElementTranslator<MappingRules> {
10 private static MappingRulesTranslator mappingRulesTranslator = new MappingRulesTranslator();
12 public static MappingRulesTranslator getInstance() {
13 return mappingRulesTranslator;
16 private MappingRulesTranslator() {
19 private RuleTranslator ruleTranslator = RuleTranslator.getInstance();
21 public Translation translateToHpJson(MappingRules mappingRules) {
22 return new MappingRulesTranslation(mappingRules);
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);
31 private class MappingRulesTranslation extends Translation {
33 private List<Translation> processing;
35 private MappingRulesTranslation(MappingRules mappingRules) {
36 processing = mappingRules.getRules().values().stream().map(ruleTranslator::translateToHpJson).collect(Collectors.toList());
39 private MappingRulesTranslation(MappingRules mappingRules, String entryPointPhaseName, String lastPhaseName, String runPhase) {
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));
48 private class RunPhaseRuleTranslation extends RuleTranslation {
50 private RunPhaseRuleTranslation(String phaseName, String runPhase) {
52 if ("snmp_map".equals(phaseName))
53 processors.add(new SnmpConvertor());
54 processors.add(new RunPhaseProcessorsTranslation(runPhase));
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";
64 private SnmpConvertor() {
65 clazz = "SnmpConvertor";