use of alien4cloud.tosca.parser.MappingTarget in project alien4cloud by alien4cloud.
the class AbstractMapper method quickMap.
/**
* Map a field to be parsed as a scalar and mapped to a tosca field that use the same name based on LOWER_CASE_WITH_UNDERSCORES rather than CAMEL_CASE.
*
* @param fieldName The name of the field.
*/
public void quickMap(String fieldName) {
int pathSeparatorLastIndex = fieldName.lastIndexOf(".");
pathSeparatorLastIndex++;
pathSeparatorLastIndex = pathSeparatorLastIndex > 0 ? pathSeparatorLastIndex : 0;
String yamlFieldCamelCase = fieldName.substring(pathSeparatorLastIndex);
String yamlField = ((PropertyNamingStrategyBase) PropertyNamingStrategy.SNAKE_CASE).translate(yamlFieldCamelCase);
log.trace("Mapping yaml field {} to {} using basic ScalarParser", yamlField, fieldName);
instance.getYamlToObjectMapping().put(yamlField, new MappingTarget(fieldName, scalarParser));
}
use of alien4cloud.tosca.parser.MappingTarget in project alien4cloud by alien4cloud.
the class AbstractMapper method quickMap.
/**
* Map a field to be parsed with the given parser and mapped to a tosca field that use the same name based on LOWER_CASE_WITH_UNDERSCORES rather than
* CAMEL_CASE.
*
* @param parser The parser to use to parse the field.
* @param fieldName The name of the field to parse.
*/
public void quickMap(INodeParser<?> parser, String fieldName) {
int pathSeparatorLastIndex = fieldName.lastIndexOf(".");
pathSeparatorLastIndex++;
pathSeparatorLastIndex = pathSeparatorLastIndex > 0 ? pathSeparatorLastIndex : 0;
String yamlFieldCamelCase = fieldName.substring(pathSeparatorLastIndex);
String yamlField = ((PropertyNamingStrategyBase) PropertyNamingStrategy.SNAKE_CASE).translate(yamlFieldCamelCase);
log.info("Mapping yaml field {} to {} using basic ScalarParser", yamlField, fieldName);
instance.getYamlToObjectMapping().put(yamlField, new MappingTarget(fieldName, parser));
}
use of alien4cloud.tosca.parser.MappingTarget in project alien4cloud by alien4cloud.
the class DiscriminatorMappingBuilder method buildMapping.
@Override
public MappingTarget buildMapping(MappingNode mappingNode, ParsingContextExecution context) {
String mappingTarget = "";
Map<String, INodeParser<?>> parsersByKey = Maps.newHashMap();
INodeParser<?> fallbackParser = null;
for (NodeTuple tuple : mappingNode.getValue()) {
String tupleKey = ParserUtils.getScalar(tuple.getKeyNode(), context);
if (DISCRIMINATOR.equals(tupleKey)) {
mappingTarget = ParserUtils.getScalar(tuple.getValueNode(), context);
} else if (KEYS.equals(tupleKey)) {
MappingNode keys = (MappingNode) tuple.getValueNode();
for (NodeTuple keyMappingTuple : keys.getValue()) {
parsersByKey.put(ParserUtils.getScalar(keyMappingTuple.getKeyNode(), context), baseParserFactory.getReferencedParser(ParserUtils.getScalar(keyMappingTuple.getValueNode(), context)));
}
} else if (DEFAULT.equals(tupleKey)) {
fallbackParser = baseParserFactory.getReferencedParser(ParserUtils.getScalar(tuple.getValueNode(), context));
}
}
return new MappingTarget(mappingTarget, baseParserFactory.getKeyDiscriminatorParser(parsersByKey, fallbackParser));
}
use of alien4cloud.tosca.parser.MappingTarget in project alien4cloud by alien4cloud.
the class MapMappingBuilder method buildMapping.
@Override
public MappingTarget buildMapping(MappingNode mappingNode, ParsingContextExecution context) {
Map<String, String> map = ParserUtils.parseStringMap(mappingNode, context);
if (map.containsKey(TYPE) && map.containsKey(LIST_TYPE)) {
log.warn("Both field [ {} ] and [ {} ] exist in your mapping. If it's defined [ {} ] will override the [ {} ].", TYPE, LIST_TYPE, LIST_TYPE, TYPE);
}
// default mapping for simple type or for a list_type if defined
MappingTarget mappingTarget = new MappingTarget(map.get(MAP), baseParserFactory.getMapParser(baseParserFactory.getReferencedParser(map.get(TYPE)), "map of " + map.get(TYPE), map.get(KEY)));
if (map.containsKey(LIST_TYPE) && !map.get(LIST_TYPE).isEmpty()) {
mappingTarget = new MappingTarget(map.get(MAP), baseParserFactory.getMapParser(baseParserFactory.getListParser(baseParserFactory.getReferencedParser(map.get(TYPE)), "list of " + map.get(LIST_TYPE), map.get(KEY)), "map of " + map.get(LIST_TYPE), map.get(KEY)));
}
return mappingTarget;
}
use of alien4cloud.tosca.parser.MappingTarget in project alien4cloud by alien4cloud.
the class ReferenceMappingBuilder method buildMapping.
@Override
public MappingTarget buildMapping(MappingNode mappingNode, ParsingContextExecution context) {
Map<String, String> map = Maps.newHashMap();
for (NodeTuple tuple : mappingNode.getValue()) {
String key = ParserUtils.getScalar(tuple.getKeyNode(), context);
String value = ParserUtils.getScalar(tuple.getValueNode(), context);
map.put(key, value);
}
return new MappingTarget(map.get(REFERENCE_KEY), baseParserFactory.getReferencedParser(map.get(TYPE)));
}
Aggregations