Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.regnosys.rosetta.translate.IngesterGenerator Maven / Gradle / Ivy
package com.regnosys.rosetta.translate;
import com.codahale.metrics.MetricRegistry;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
import com.regnosys.rosetta.common.util.UrlUtils;
import com.regnosys.rosetta.generator.java.RosettaJavaPackages;
import com.regnosys.rosetta.generator.java.enums.EnumHelper;
import com.regnosys.rosetta.generator.java.types.JavaTypeTranslator;
import com.regnosys.rosetta.generator.java.types.JavaTypeUtil;
import com.regnosys.rosetta.generator.object.ExpandedAttribute;
import com.regnosys.rosetta.generator.object.ExpandedType;
import com.regnosys.rosetta.generator.util.IterableUtil;
import com.regnosys.rosetta.generator.util.RosettaAttributeExtensions;
import com.regnosys.rosetta.interpreter.RosettaValue;
import com.regnosys.rosetta.rosetta.Import;
import com.regnosys.rosetta.rosetta.RosettaAttributeReference;
import com.regnosys.rosetta.rosetta.RosettaAttributeReferenceSegment;
import com.regnosys.rosetta.rosetta.RosettaBuiltinType;
import com.regnosys.rosetta.rosetta.RosettaDataReference;
import com.regnosys.rosetta.rosetta.RosettaEnumValueReference;
import com.regnosys.rosetta.rosetta.RosettaEnumeration;
import com.regnosys.rosetta.rosetta.RosettaExternalSynonymSource;
import com.regnosys.rosetta.rosetta.RosettaMapTestExpression;
import com.regnosys.rosetta.rosetta.RosettaMergeSynonymValue;
import com.regnosys.rosetta.rosetta.RosettaModel;
import com.regnosys.rosetta.rosetta.RosettaRootElement;
import com.regnosys.rosetta.rosetta.RosettaSynonymSource;
import com.regnosys.rosetta.rosetta.RosettaType;
import com.regnosys.rosetta.rosetta.RosettaTypeAlias;
import com.regnosys.rosetta.rosetta.TypeCall;
import com.regnosys.rosetta.rosetta.expression.RosettaBooleanLiteral;
import com.regnosys.rosetta.rosetta.expression.RosettaIntLiteral;
import com.regnosys.rosetta.rosetta.expression.RosettaLiteral;
import com.regnosys.rosetta.rosetta.expression.RosettaNumberLiteral;
import com.regnosys.rosetta.rosetta.expression.RosettaStringLiteral;
import com.regnosys.rosetta.translate.CustomDeserialise;
import com.regnosys.rosetta.translate.datamodel.Cardinality;
import com.regnosys.rosetta.translate.datamodel.ModelParser;
import com.regnosys.rosetta.translate.datamodel.Schema;
import com.regnosys.rosetta.translate.datamodel.SchemaDeserialise;
import com.regnosys.rosetta.translate.datamodel.SchemaSerialise;
import com.regnosys.rosetta.translate.datamodel.json.JsonSchemaParser;
import com.regnosys.rosetta.translate.datamodel.xsd.BeansXsdParser;
import com.regnosys.rosetta.translate.synonymmap.AttributeGroup;
import com.regnosys.rosetta.translate.synonymmap.AttributeGroupMapping;
import com.regnosys.rosetta.translate.synonymmap.CardinalityChecker;
import com.regnosys.rosetta.translate.synonymmap.Element;
import com.regnosys.rosetta.translate.synonymmap.ModelCombiner;
import com.regnosys.rosetta.translate.synonymmap.SynonymAbsentTest;
import com.regnosys.rosetta.translate.synonymmap.SynonymBinaryTest;
import com.regnosys.rosetta.translate.synonymmap.SynonymCondition;
import com.regnosys.rosetta.translate.synonymmap.SynonymConditionFuncTest;
import com.regnosys.rosetta.translate.synonymmap.SynonymExistsTest;
import com.regnosys.rosetta.translate.synonymmap.SynonymGroup;
import com.regnosys.rosetta.translate.synonymmap.SynonymMap;
import com.regnosys.rosetta.translate.synonymmap.SynonymMapBuilder;
import com.regnosys.rosetta.translate.synonymmap.SynonymPathTest;
import com.regnosys.rosetta.translate.synonymmap.SynonymRosettaPathTest;
import com.regnosys.rosetta.translate.synonymmap.SynonymTest;
import com.regnosys.rosetta.translate.synonymmap.SynonymValue;
import com.regnosys.rosetta.types.RType;
import com.regnosys.rosetta.types.builtin.RBuiltinTypeService;
import com.rosetta.model.lib.RosettaModelObject;
import com.rosetta.util.DottedPath;
import com.rosetta.util.types.JavaClass;
import com.rosetta.util.types.generated.GeneratedJavaClass;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtend.lib.annotations.Data;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtend2.lib.StringConcatenationClient;
import org.eclipse.xtext.xbase.lib.CollectionExtensions;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.Pair;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure2;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
@SuppressWarnings("all")
public class IngesterGenerator {
@Data
public static class GeneratedIngesters {
private final GeneratedNameAndSource generatedFactory;
private final List generatedHandlers;
private final List errors;
public Map classNameToDef() {
final HashMap classes = CollectionLiterals.newHashMap();
classes.put(this.generatedFactory.getClassName(), this.generatedFactory.getSource());
final Consumer _function = (GeneratedNameAndSource it) -> {
classes.put(it.getClassName(), it.getSource());
};
this.generatedHandlers.forEach(_function);
return classes;
}
public GeneratedIngesters(final GeneratedNameAndSource generatedFactory, final List generatedHandlers, final List errors) {
super();
this.generatedFactory = generatedFactory;
this.generatedHandlers = generatedHandlers;
this.errors = errors;
}
@Override
@Pure
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.generatedFactory== null) ? 0 : this.generatedFactory.hashCode());
result = prime * result + ((this.generatedHandlers== null) ? 0 : this.generatedHandlers.hashCode());
return prime * result + ((this.errors== null) ? 0 : this.errors.hashCode());
}
@Override
@Pure
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
IngesterGenerator.GeneratedIngesters other = (IngesterGenerator.GeneratedIngesters) obj;
if (this.generatedFactory == null) {
if (other.generatedFactory != null)
return false;
} else if (!this.generatedFactory.equals(other.generatedFactory))
return false;
if (this.generatedHandlers == null) {
if (other.generatedHandlers != null)
return false;
} else if (!this.generatedHandlers.equals(other.generatedHandlers))
return false;
if (this.errors == null) {
if (other.errors != null)
return false;
} else if (!this.errors.equals(other.errors))
return false;
return true;
}
@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("generatedFactory", this.generatedFactory);
b.add("generatedHandlers", this.generatedHandlers);
b.add("errors", this.errors);
return b.toString();
}
@Pure
public GeneratedNameAndSource getGeneratedFactory() {
return this.generatedFactory;
}
@Pure
public List getGeneratedHandlers() {
return this.generatedHandlers;
}
@Pure
public List getErrors() {
return this.errors;
}
}
@Data
public static class ParseHandlersAndMappingErrors {
private final List parseHandlers;
private final List errors;
public ParseHandlersAndMappingErrors(final List parseHandlers, final List errors) {
super();
this.parseHandlers = parseHandlers;
this.errors = errors;
}
@Override
@Pure
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.parseHandlers== null) ? 0 : this.parseHandlers.hashCode());
return prime * result + ((this.errors== null) ? 0 : this.errors.hashCode());
}
@Override
@Pure
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
IngesterGenerator.ParseHandlersAndMappingErrors other = (IngesterGenerator.ParseHandlersAndMappingErrors) obj;
if (this.parseHandlers == null) {
if (other.parseHandlers != null)
return false;
} else if (!this.parseHandlers.equals(other.parseHandlers))
return false;
if (this.errors == null) {
if (other.errors != null)
return false;
} else if (!this.errors.equals(other.errors))
return false;
return true;
}
@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("parseHandlers", this.parseHandlers);
b.add("errors", this.errors);
return b.toString();
}
@Pure
public List getParseHandlers() {
return this.parseHandlers;
}
@Pure
public List getErrors() {
return this.errors;
}
}
public static class UniqueFilter implements Predicate {
private Set seen = CollectionLiterals.newHashSet();
private Function propExtract;
public UniqueFilter(final Function propExt) {
this.propExtract = propExt;
}
@Override
public boolean test(final T t) {
return this.seen.add(this.propExtract.apply(t));
}
}
private static final Logger LOGGER = Logger.getLogger(IngesterGenerator.class);
public static final MetricRegistry GENERATOR_METRICS = new MetricRegistry();
@Inject
@Extension
private JavaTypeTranslator typeTranslator;
@Inject
private JsonSchemaParser jsonSchemaParser;
@Inject
private RBuiltinTypeService builtins;
public IngesterGenerator.GeneratedIngesters generateXml(final String envName, final String factoryName, final List generatorParamsList) {
BeansXsdParser _beansXsdParser = new BeansXsdParser();
final IngesterGenerator.ParseHandlersAndMappingErrors handlersAndErrors = this.parseHandlersAndMappingErrors(_beansXsdParser, generatorParamsList);
final String factory = this.generateXmlFactory(envName, factoryName, generatorParamsList);
GenerationResult _generationResult = new GenerationResult(false, factory);
GeneratedNameAndSource _generatedNameAndSource = new GeneratedNameAndSource(((envName + ".") + factoryName), _generationResult);
return new IngesterGenerator.GeneratedIngesters(_generatedNameAndSource,
handlersAndErrors.parseHandlers,
handlersAndErrors.errors);
}
public IngesterGenerator.GeneratedIngesters generateJson(final String envName, final String factoryName, final List generatorParamsList) {
String _simpleName = this.jsonSchemaParser.getClass().getSimpleName();
String _plus = ("JSON model parser " + _simpleName);
IngesterGenerator.LOGGER.info(_plus);
final IngesterGenerator.ParseHandlersAndMappingErrors handlersAndErrors = this.parseHandlersAndMappingErrors(this.jsonSchemaParser, generatorParamsList);
final String factory = this.generateJsonFactory(envName, factoryName, generatorParamsList);
GenerationResult _generationResult = new GenerationResult(false, factory);
GeneratedNameAndSource _generatedNameAndSource = new GeneratedNameAndSource(((envName + ".") + factoryName), _generationResult);
return new IngesterGenerator.GeneratedIngesters(_generatedNameAndSource,
handlersAndErrors.parseHandlers,
handlersAndErrors.errors);
}
private IngesterGenerator.ParseHandlersAndMappingErrors parseHandlersAndMappingErrors(final ModelParser modelParser, final List params) {
IngesterGenerator.ParseHandlersAndMappingErrors _xblockexpression = null;
{
final ArrayList parseHandlers = CollectionLiterals.newArrayList();
final ArrayList errors = CollectionLiterals.newArrayList();
for (final GeneratorParams param : params) {
{
final Pair, Collection> parsers = this.generateParsers(modelParser,
param.getSchema(),
param.getRosettaEntities(),
param.getSources(),
param.getTopLevelTags(),
param.getChildPackageName());
final Function1, GeneratedNameAndSource> _function = (Map.Entry it) -> {
String _childPackageName = param.getChildPackageName();
String _plus = (_childPackageName + ".");
String _key = it.getKey();
String _plus_1 = (_plus + _key);
String _plus_2 = (_plus_1 + "ParseHandler");
GenerationResult _value = it.getValue();
return new GeneratedNameAndSource(_plus_2, _value);
};
Iterables.addAll(parseHandlers, IterableExtensions., GeneratedNameAndSource>map(parsers.getKey().entrySet(), _function));
errors.addAll(parsers.getValue());
}
}
_xblockexpression = new IngesterGenerator.ParseHandlersAndMappingErrors(parseHandlers, errors);
}
return _xblockexpression;
}
private Pair, Collection> generateParsers(final ModelParser modelParser, final URL modelUrl, final Collection rosettaEntities, final Collection sources, final Collection topLevelTags, final String childPackageName) {
Pair, Collection> _xblockexpression = null;
{
final Schema schema = this.getSchema(modelParser, modelUrl, childPackageName);
_xblockexpression = this.generateParsers(sources, rosettaEntities, schema, topLevelTags, childPackageName);
}
return _xblockexpression;
}
public Schema getSchema(final ModelParser modelParser, final URL modelUrl, final String childPackageName) {
try {
Schema _xblockexpression = null;
{
String _baseFileName = UrlUtils.getBaseFileName(modelUrl);
final String jschemaFileName = (_baseFileName + ".schema");
final URL schemaURL = new URL(modelUrl, jschemaFileName);
try {
final long loadStart = System.currentTimeMillis();
final SchemaDeserialise deserial = new SchemaDeserialise();
Object _deserialise = deserial.deserialise(schemaURL.openStream());
final Schema schema = ((Schema) _deserialise);
long _currentTimeMillis = System.currentTimeMillis();
long _minus = (_currentTimeMillis - loadStart);
String _plus = ((("Loaded schema from file " + schemaURL) + " in ") + Long.valueOf(_minus));
IngesterGenerator.LOGGER.info(_plus);
return schema;
} catch (final Throwable _t) {
if (_t instanceof IOException || _t instanceof CustomDeserialise.ParseException) {
IngesterGenerator.LOGGER.info(("Failed to read schema file from " + schemaURL));
} else {
throw Exceptions.sneakyThrow(_t);
}
}
String _xifexpression = null;
String _lowerCase = UrlUtils.getFileExtension(modelUrl).toLowerCase();
boolean _equals = Objects.equal(_lowerCase, "xsd");
if (_equals) {
_xifexpression = "XSD";
} else {
_xifexpression = "JSON";
}
final String type = _xifexpression;
IngesterGenerator.LOGGER.info(((("Parsing " + type) + " model for ") + childPackageName));
final Schema schema = modelParser.parseModel(modelUrl);
boolean _isOpaque = schemaURL.toURI().isOpaque();
boolean _not = (!_isOpaque);
if (_not) {
URI _uRI = schemaURL.toURI();
final File schemaFile = new File(_uRI);
final SchemaSerialise serialise = new SchemaSerialise();
FileOutputStream _fileOutputStream = new FileOutputStream(schemaFile);
serialise.serialiseObject(schema, _fileOutputStream);
}
_xblockexpression = schema;
}
return _xblockexpression;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
public Pair, Collection> generateParsers(final Collection sources, final Collection rosettaEntities, final Schema schema, final Collection topLevelTags, final String childPackageName) {
IngesterGenerator.LOGGER.info("Building synonym map");
final List synonymSourceNames = GeneratorUtil.synonymSourceNames(sources);
final List externalSynonyms = GeneratorUtil.externalSynonymSources(sources);
final SynonymMapBuilder mappingBuilder = new SynonymMapBuilder(synonymSourceNames, externalSynonyms, this.typeTranslator);
HashMap _hashMap = new HashMap();
return this.generateParsers(mappingBuilder, sources, rosettaEntities, schema, topLevelTags, childPackageName, _hashMap);
}
public Pair, Collection> generateParsers(final SynonymMapBuilder mappingBuilder, final Collection sources, final Collection rosettaEntities, final Schema schema, final Collection topLevelTags, final String childPackageName, final Map synHashCache) {
final Function1 _function = (RosettaType c) -> {
return mappingBuilder.buildMap(c);
};
List syns = IterableExtensions.toList(IterableExtensions.map(rosettaEntities, _function));
IngesterGenerator.LOGGER.info("Validating synonyms");
final ModelCombiner combiner = new ModelCombiner();
final ArrayList combineErrors = CollectionLiterals.newArrayList();
syns = combiner.combineModels(schema, syns, combineErrors, topLevelTags);
IngesterGenerator.LOGGER.info("Pruning synonyms");
syns = combiner.prune(syns);
final Predicate _function_1 = (MappingError e) -> {
MappingError.MappingErrorLevel _level = e.getLevel();
return Objects.equal(_level, MappingError.MappingErrorLevel.ERROR);
};
boolean _anyMatch = combineErrors.stream().anyMatch(_function_1);
if (_anyMatch) {
}
IngesterGenerator.LOGGER.info("Checking cardinalities");
combineErrors.addAll(new CardinalityChecker().checkCardinalities(syns));
Map _generateParsers = this.generateParsers(syns, sources, childPackageName, synHashCache);
return new Pair, Collection>(_generateParsers, combineErrors);
}
public Map generateParsers(final Collection topLevels, final Collection sources, final String childName, final Map synHashCache) {
IngesterGenerator.LOGGER.debug("Creating java files");
final Map generated = new HashMap();
for (final SynonymMap mapping : topLevels) {
this.generateParsers(mapping, generated, sources, childName, synHashCache);
}
return generated;
}
private void generateParsers(final SynonymMap mapping, final Map generated, final Collection sources, final String childPackageName, final Map synHashCache) {
boolean _containsKey = generated.containsKey(mapping.getRosetta().getName());
if (_containsKey) {
return;
}
boolean _isClassOrData = this.isClassOrData(mapping.getRosetta());
if (_isClassOrData) {
this.generateClassParsers(mapping, generated, sources, childPackageName, synHashCache);
} else {
RosettaType _rosetta = mapping.getRosetta();
if ((_rosetta instanceof RosettaEnumeration)) {
this.generateEnumParsers(mapping, generated, childPackageName, synHashCache);
}
}
}
private boolean validNamespaces(final RosettaModel model, final String importedNamespace) {
Set _xifexpression = null;
ResourceSet _resourceSet = model.eResource().getResourceSet();
EList _resources = null;
if (_resourceSet!=null) {
_resources=_resourceSet.getResources();
}
boolean _tripleEquals = (_resources == null);
if (_tripleEquals) {
HashSet _xblockexpression = null;
{
String _string = model.eResource().getURI().toString();
String _plus = ("No resource set found for " + _string);
IngesterGenerator.LOGGER.warn(_plus);
_xblockexpression = CollectionLiterals.newHashSet();
}
_xifexpression = _xblockexpression;
} else {
final Function1> _function = (Resource it) -> {
return it.getContents();
};
final Function1> _function_1 = (RosettaModel it) -> {
return it.getElements();
};
final Function1 _function_2 = (RosettaRootElement it) -> {
return Boolean.valueOf(((it instanceof com.regnosys.rosetta.rosetta.simple.Data) || (it instanceof RosettaEnumeration)));
};
final Function1 _function_3 = (RosettaRootElement it) -> {
return RosettaType.class.cast(it);
};
final Function1 _function_4 = (RosettaType it) -> {
return it.getModel().getName();
};
_xifexpression = IterableExtensions.toSet(IterableExtensions.map(IterableExtensions.map(IterableExtensions.filter(IterableExtensions.flatMap(Iterables.filter(IterableExtensions.flatMap(model.eResource().getResourceSet().getResources(), _function), RosettaModel.class), _function_1), _function_2), _function_3), _function_4));
}
final Set validNamespacesSet = _xifexpression;
final String namespace = importedNamespace.substring(0, this.indexOrLength(importedNamespace, '.'));
return validNamespacesSet.contains(namespace);
}
private int indexOrLength(final String toSearch, final char find) {
int _xblockexpression = (int) 0;
{
final int index = toSearch.lastIndexOf(find);
int _xifexpression = (int) 0;
if ((index == (-1))) {
_xifexpression = toSearch.length();
} else {
_xifexpression = index;
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
private void generateClassParsers(final SynonymMap mapping, final Map generated, final Collection synonymSources, final String envName, final Map synHashCache) {
boolean _containsKey = generated.containsKey(IterableUtil.fullname(mapping.getRosetta()));
if (_containsKey) {
return;
}
EObject _eContainer = mapping.getRosetta().eContainer();
final RosettaModel rosettaModel = ((RosettaModel) _eContainer);
Resource _eResource = rosettaModel.eResource();
boolean _tripleEquals = (_eResource == null);
if (_tripleEquals) {
IngesterGenerator.LOGGER.warn(("Unable to generate translate parsers. No resource found for rosetta model: " + rosettaModel));
return;
}
final Long prevHash = synHashCache.get(IterableUtil.fullname(mapping.getRosetta()));
final long newHash = mapping.hashForGeneration();
if (((prevHash == null) || (newHash != (prevHash).longValue()))) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package ");
_builder.append(envName);
_builder.append(".");
String _packageName = IterableUtil.packageName(mapping.getRosetta());
_builder.append(_packageName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import java.math.BigDecimal;");
_builder.newLine();
_builder.append("import java.time.LocalDate;");
_builder.newLine();
_builder.append("import java.time.LocalTime;");
_builder.newLine();
_builder.append("import java.util.Collections;");
_builder.newLine();
_builder.append("import java.util.ArrayList;");
_builder.newLine();
_builder.append("import java.util.List;");
_builder.newLine();
_builder.append("import java.util.Set;");
_builder.newLine();
_builder.append("import java.util.Optional;");
_builder.newLine();
_builder.append("import java.util.Map;");
_builder.newLine();
_builder.append("import java.util.HashMap;");
_builder.newLine();
_builder.append("import java.util.LinkedHashMap;");
_builder.newLine();
_builder.append("import java.util.concurrent.atomic.AtomicBoolean;");
_builder.newLine();
_builder.append("import java.util.stream.Collectors;");
_builder.newLine();
_builder.newLine();
_builder.append("import com.google.common.collect.ImmutableList;");
_builder.newLine();
_builder.append("import com.google.common.collect.ImmutableMultimap;");
_builder.newLine();
_builder.append("import com.google.inject.Injector;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.translate.HandlerSupplier;");
_builder.newLine();
_builder.append("import com.rosetta.model.lib.meta.Reference;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.translate.GeneratorPathUtil;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.translate.HandlerCache;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.translate.IngestMerger;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.translate.MappingProcessorSupplier;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.translate.SynonymValueGroup;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.translate.ROMParseHandler;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.common.translation.Mapping;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.common.translation.MappingContext;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.common.translation.Path;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.common.util.PathUtils;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.translate.basic.*;");
_builder.newLine();
_builder.append("import com.regnosys.rosetta.common.translation.Path.PathElement;");
_builder.newLine();
{
EList _imports = rosettaModel.getImports();
for(final Import importResources : _imports) {
final String importedNamespace = importResources.getImportedNamespace();
_builder.newLineIfNotEmpty();
{
boolean _validNamespaces = this.validNamespaces(rosettaModel, importedNamespace);
if (_validNamespaces) {
_builder.append("import ");
_builder.append(importedNamespace);
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.append("import ");
String _name = rosettaModel.getName();
_builder.append(_name);
_builder.append(".*;");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
List _traversedImports = this.getTraversedImports(mapping);
for(final String traversedImports : _traversedImports) {
_builder.append("import ");
_builder.append(traversedImports);
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("import com.rosetta.model.lib.records.*;");
_builder.newLine();
_builder.append("import com.rosetta.model.lib.RosettaModelObjectBuilder;");
_builder.newLine();
_builder.append("import com.rosetta.model.lib.path.RosettaPath;");
_builder.newLine();
_builder.append("import com.rosetta.model.lib.process.BuilderProcessor;");
_builder.newLine();
_builder.append("import com.rosetta.model.metafields.MetaFields;");
_builder.newLine();
_builder.newLine();
final String header = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("public ");
{
boolean _isAbstract = this.isAbstract(mapping.getRosetta());
if (_isAbstract) {
_builder_1.append("abstract ");
}
}
_builder_1.append("class ");
CharSequence _pNameW = this.pNameW(mapping);
_builder_1.append(_pNameW);
_builder_1.append(" ");
CharSequence _romExtends = this.romExtends(mapping, envName);
_builder_1.append(_romExtends);
_builder_1.append(" {");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
String _pathConstants = this.pathConstants(mapping);
_builder_1.append(_pathConstants, "\t");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
CharSequence _conditionalValues = this.conditionalValues(mapping);
_builder_1.append(_conditionalValues, "\t");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
CharSequence _handlerCaches = this.handlerCaches(mapping, envName);
_builder_1.append(_handlerCaches, "\t");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
CharSequence _constructor = this.constructor(mapping);
_builder_1.append(_constructor, "\t");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("// regular handlers");
_builder_1.newLine();
{
final Function1 _function = (AttributeGroupMapping it) -> {
final Function1 _function_1 = (SynonymGroup it_1) -> {
return Boolean.valueOf(((!it_1.getSynonymValues().isEmpty()) && IterableExtensions.forall(it_1.getConditions(), ((Function1) (SynonymCondition it_2) -> {
return Boolean.valueOf(it_2.getCondition().isEmpty());
}))));
};
return Boolean.valueOf(IterableExtensions.exists(it.getGroup().getSynonymGroups(), _function_1));
};
final Function1 _function_1 = (AttributeGroupMapping it) -> {
return it.getGroup();
};
final Function1 _function_2 = (AttributeGroupMapping it) -> {
return this.toHandlerMethodName(it.getGroup());
};
List _sortBy = IterableExtensions.sortBy(IterableExtensions.sortBy(IterableExtensions.filter(mapping.getMappedGroups(), _function), _function_1), _function_2);
boolean _hasElements = false;
for(final AttributeGroupMapping h : _sortBy) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder_1.appendImmediate("\n", "\t");
}
_builder_1.append("\t");
CharSequence _handler = this.handler(h, mapping, envName);
_builder_1.append(_handler, "\t");
_builder_1.newLineIfNotEmpty();
}
}
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("// conditional handlers");
_builder_1.newLine();
{
final Function1 _function_3 = (AttributeGroupMapping it) -> {
final Function1 _function_4 = (SynonymGroup it_1) -> {
return Boolean.valueOf(((!it_1.getSynonymValues().isEmpty()) && IterableExtensions.exists(it_1.getConditions(), ((Function1) (SynonymCondition it_2) -> {
boolean _isEmpty = it_2.getCondition().isEmpty();
return Boolean.valueOf((!_isEmpty));
}))));
};
return Boolean.valueOf(IterableExtensions.exists(it.getGroup().getSynonymGroups(), _function_4));
};
final Function1 _function_4 = (AttributeGroupMapping it) -> {
return it.getGroup();
};
List _sortBy_1 = IterableExtensions.sortBy(IterableExtensions.filter(mapping.getMappedGroups(), _function_3), _function_4);
boolean _hasElements_1 = false;
for(final AttributeGroupMapping h_1 : _sortBy_1) {
if (!_hasElements_1) {
_hasElements_1 = true;
} else {
_builder_1.appendImmediate("\n", "\t");
}
_builder_1.append("\t");
CharSequence _condHandler = this.condHandler(h_1, mapping, envName);
_builder_1.append(_condHandler, "\t");
_builder_1.newLineIfNotEmpty();
}
}
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("// conditional capture handlers");
_builder_1.newLine();
{
final Function1>, String> _function_5 = (Map.Entry> e) -> {
return this.toConditionalHandlerMethodName(e.getKey());
};
List>> _sortBy_2 = IterableExtensions.>, String>sortBy(mapping.getConditionalCaptures().asMap().entrySet(), _function_5);
boolean _hasElements_2 = false;
for(final Map.Entry> ent : _sortBy_2) {
if (!_hasElements_2) {
_hasElements_2 = true;
} else {
_builder_1.appendImmediate("\n", "\t");
}
_builder_1.append("\t");
CharSequence _conditionalCaptureHandler = this.conditionalCaptureHandler(ent, mapping);
_builder_1.append(_conditionalCaptureHandler, "\t");
_builder_1.newLineIfNotEmpty();
}
}
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("// regular handler getter (for nested \'set to\' conditional mapping with path predicate)");
_builder_1.newLine();
_builder_1.append("\t");
final HashSet alreadyGenerated = CollectionLiterals.newHashSet();
_builder_1.newLineIfNotEmpty();
{
final Function1 _function_6 = (AttributeGroupMapping it) -> {
final Function1 _function_7 = (SynonymGroup it_1) -> {
return Boolean.valueOf(it_1.getSynonymValues().isEmpty());
};
return Boolean.valueOf(IterableExtensions.exists(it.getGroup().getSynonymGroups(), _function_7));
};
final Function1 _function_7 = (AttributeGroupMapping it) -> {
final Function1> _function_8 = (SynonymGroup it_1) -> {
return it_1.getConditions();
};
final Function1> _function_9 = (SynonymCondition it_1) -> {
return it_1.getCondition();
};
final Function1 _function_10 = (SynonymTest it_1) -> {
return Boolean.valueOf((it_1 instanceof SynonymPathTest));
};
return Boolean.valueOf(IterableExtensions.exists(IterableExtensions.flatMap(IterableExtensions.flatMap(it.getGroup().getSynonymGroups(), _function_8), _function_9), _function_10));
};
final Function1> _function_8 = (AttributeGroupMapping it) -> {
return it.getGroup().getAttributePath();
};
final Function1, Boolean> _function_9 = (List it) -> {
int _size = it.size();
return Boolean.valueOf((_size > 1));
};
Iterable> _filter = IterableExtensions.>filter(IterableExtensions.>map(IterableExtensions.filter(IterableExtensions.filter(mapping.getMappedGroups(), _function_6), _function_7), _function_8), _function_9);
boolean _hasElements_3 = false;
for(final List p : _filter) {
if (!_hasElements_3) {
_hasElements_3 = true;
} else {
_builder_1.appendImmediate("\n", "\t");
}
_builder_1.append("\t");
CharSequence _nestedSetToHandler = this.nestedSetToHandler(p, mapping, alreadyGenerated);
_builder_1.append(_nestedSetToHandler, "\t");
_builder_1.newLineIfNotEmpty();
}
}
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("// mappers");
_builder_1.newLine();
{
final Function1 _function_10 = (AttributeGroupMapping it) -> {
final Function1 _function_11 = (SynonymGroup it_1) -> {
String _mapperName = it_1.getMapperName();
return Boolean.valueOf((_mapperName != null));
};
return Boolean.valueOf(IterableExtensions.exists(it.getGroup().getSynonymGroups(), _function_11));
};
final Function1 _function_11 = (AttributeGroupMapping it) -> {
return it.getGroup();
};
List _sortBy_3 = IterableExtensions.sortBy(IterableExtensions.filter(mapping.getMappedGroups(), _function_10), _function_11);
boolean _hasElements_4 = false;
for(final AttributeGroupMapping h_2 : _sortBy_3) {
if (!_hasElements_4) {
_hasElements_4 = true;
} else {
_builder_1.appendImmediate("\n", "\t");
}
_builder_1.append("\t");
CharSequence _mappingProcessor = this.mappingProcessor(h_2, mapping);
_builder_1.append(_mappingProcessor, "\t");
_builder_1.newLineIfNotEmpty();
}
}
_builder_1.append("\t");
_builder_1.newLine();
{
boolean _isAbstract_1 = this.isAbstract(mapping.getRosetta());
boolean _not = (!_isAbstract_1);
if (_not) {
_builder_1.append("\t");
_builder_1.append("// builder proxy");
_builder_1.newLine();
_builder_1.append("\t");
CharSequence _generateBuilderProxy = this.generateBuilderProxy(mapping);
_builder_1.append(_generateBuilderProxy, "\t");
_builder_1.newLineIfNotEmpty();
}
}
_builder_1.append("}");
_builder_1.newLine();
final String body = _builder_1.toString();
StringConcatenation _builder_3 = new StringConcatenation();
_builder_3.append(header);
_builder_3.newLineIfNotEmpty();
_builder_3.newLine();
_builder_3.append(body);
_builder_3.newLineIfNotEmpty();
String parser = _builder_3.toString();
String _fullname = IterableUtil.fullname(mapping.getRosetta());
GenerationResult _generationResult = new GenerationResult(false, parser);
generated.put(_fullname, _generationResult);
synHashCache.put(IterableUtil.fullname(mapping.getRosetta()), Long.valueOf(newHash));
} else {
String _fullname_1 = IterableUtil.fullname(mapping.getRosetta());
GenerationResult _generationResult_1 = new GenerationResult(true, null);
generated.put(_fullname_1, _generationResult_1);
}
SynonymMap _superMap = mapping.getSuperMap();
boolean _tripleNotEquals = (_superMap != null);
if (_tripleNotEquals) {
this.generateParsers(mapping.getSuperMap(), generated, synonymSources, envName, synHashCache);
}
Collection _childMappings = mapping.childMappings();
for (final SynonymMap subParser : _childMappings) {
RosettaType _rosetta = subParser.getRosetta();
boolean _tripleNotEquals_1 = (_rosetta != null);
if (_tripleNotEquals_1) {
this.generateParsers(subParser, generated, synonymSources, envName, synHashCache);
}
}
}
private List getTraversedImports(final SynonymMap mapping) {
final Function1> _function = (AttributeGroup it) -> {
return it.getAttributePath();
};
final Function1 _function_1 = (ExpandedAttribute it) -> {
TypeCall _rosettaType = it.getRosettaType();
RosettaType _type = null;
if (_rosettaType!=null) {
_type=_rosettaType.getType();
}
return Boolean.valueOf((_type != null));
};
final Function1 _function_2 = (ExpandedAttribute it) -> {
TypeCall _rosettaType = it.getRosettaType();
RosettaType _type = null;
if (_rosettaType!=null) {
_type=_rosettaType.getType();
}
boolean _isBuiltInType = RosettaAttributeExtensions.toExpandedType(_type).isBuiltInType();
return Boolean.valueOf((!_isBuiltInType));
};
final Function1 _function_3 = (ExpandedAttribute it) -> {
RosettaModel _model = it.getType().getModel();
return Boolean.valueOf((_model != null));
};
final Function1 _function_4 = (ExpandedAttribute it) -> {
String _name = it.getType().getModel().getName();
String _plus = (_name + ".");
String _name_1 = it.getType().getName();
return (_plus + _name_1);
};
return IterableExtensions.sort(IterableUtil.distinct(IterableExtensions.map(IterableExtensions.filter(IterableExtensions.filter(IterableExtensions.filter(IterableExtensions.flatMap(mapping.attributeGroups(), _function), _function_1), _function_2), _function_3), _function_4)));
}
protected boolean _isAbstract(final RosettaType type) {
return true;
}
protected boolean _isAbstract(final com.regnosys.rosetta.rosetta.simple.Data type) {
return false;
}
public Multimap captureList(final List groups) {
final Multimap conditionals = LinkedListMultimap.create();
for (final SynonymGroup sg : groups) {
List _synonymValues = sg.getSynonymValues();
for (final SynonymValue sv : _synonymValues) {
conditionals.putAll(sv, sg.getConditions());
}
}
return conditionals;
}
private String toPathName(final SynonymValue synonymValue) {
final Function1 _function = (Element it) -> {
return it.getName();
};
return StringExtensions.toFirstLower(IterableExtensions.join(ListExtensions.map(synonymValue.getSynonymPath(), _function), "_"));
}
private CharSequence romExtends(final SynonymMap mapping, final String envName) {
CharSequence _xifexpression = null;
SynonymMap _superMap = mapping.getSuperMap();
boolean _tripleEquals = (_superMap == null);
if (_tripleEquals) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("extends ROMParseHandler");
_xifexpression = _builder;
} else {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("extends ");
CharSequence _pFullNameW = this.pFullNameW(mapping.getSuperMap(), envName);
_builder_1.append(_pFullNameW);
_builder_1.append("");
_xifexpression = _builder_1;
}
return _xifexpression;
}
private CharSequence pNameW(final SynonymMap mapping) {
return this.pNameW(mapping.getRosetta());
}
private CharSequence pFullNameT(final SynonymMap mapping, final String packageName) {
return this.pFullNameT(mapping.getRosetta(), packageName);
}
private CharSequence pNameW(final RosettaType rosetta) {
StringConcatenation _builder = new StringConcatenation();
String _name = rosetta.getName();
_builder.append(_name);
_builder.append("ParseHandler");
return _builder;
}
private CharSequence pFullNameT(final ExpandedType rosetta, final String envName) {
StringConcatenation _builder = new StringConcatenation();
_builder.append(envName);
_builder.append(".");
String _name = rosetta.getModel().getName();
_builder.append(_name);
_builder.append(".");
String _name_1 = rosetta.getName();
_builder.append(_name_1);
return _builder;
}
private CharSequence pFullNameW(final ExpandedType rosetta, final String envName) {
StringConcatenation _builder = new StringConcatenation();
CharSequence _pFullNameT = this.pFullNameT(rosetta, envName);
_builder.append(_pFullNameT);
_builder.append("ParseHandler");
return _builder;
}
private CharSequence pFullNameW(final SynonymMap mapping, final String envName) {
return this.pFullNameW(mapping.getRosetta(), envName);
}
private CharSequence pFullNameW(final RosettaType rosetta, final String envName) {
StringConcatenation _builder = new StringConcatenation();
_builder.append(envName);
_builder.append(".");
String _fullname = IterableUtil.fullname(rosetta);
_builder.append(_fullname);
_builder.append("ParseHandler");
return _builder;
}
private CharSequence pFullNameT(final RosettaType rosetta, final String envName) {
StringConcatenation _builder = new StringConcatenation();
_builder.append(envName);
_builder.append(".");
String _fullname = IterableUtil.fullname(rosetta);
_builder.append(_fullname);
_builder.append("ParseHandler<");
StringConcatenationClient _builder_1 = this.toBuilder(rosetta);
_builder.append(_builder_1);
_builder.append(">");
return _builder;
}
private CharSequence expandedTypeToBuilder(final ExpandedType type) {
CharSequence _xifexpression = null;
boolean _isType = type.isType();
if (_isType) {
StringConcatenation _builder = new StringConcatenation();
JavaClass _expandedTypeToJavaType = this.expandedTypeToJavaType(type);
JavaClass> _builderType = this.typeTranslator.toBuilderType(((JavaClass) _expandedTypeToJavaType));
_builder.append(_builderType);
_xifexpression = _builder;
} else {
StringConcatenation _builder_1 = new StringConcatenation();
JavaClass _expandedTypeToJavaType_1 = this.expandedTypeToJavaType(type);
_builder_1.append(_expandedTypeToJavaType_1);
_xifexpression = _builder_1;
}
return _xifexpression;
}
@Inject
private RosettaJavaPackages packages;
@Inject
private JavaTypeUtil typeUtil;
private JavaClass expandedTypeToJavaType(final ExpandedType type) {
if ((Objects.equal(type.getName(), RosettaAttributeExtensions.METAFIELDS_CLASS_NAME) || Objects.equal(type, RosettaAttributeExtensions.META_AND_TEMPLATE_FIELDS_CLASS_NAME))) {
DottedPath _basicMetafields = this.packages.basicMetafields();
String _name = type.getName();
return new GeneratedJavaClass(_basicMetafields, _name, Object.class);
}
boolean _isMetaType = type.isMetaType();
if (_isMetaType) {
return this.typeUtil.STRING;
}
boolean _isBuiltInType = type.isBuiltInType();
if (_isBuiltInType) {
return this.typeTranslator.toJavaReferenceType(this.builtins.getType(type.getName(), Collections.emptyMap()));
}
DottedPath _modelPackage = this.modelPackage(type.getModel());
String _name_1 = type.getName();
return new GeneratedJavaClass(_modelPackage, _name_1, Object.class);
}
private DottedPath modelPackage(final RosettaModel model) {
return DottedPath.splitOnDots(model.getName());
}
private StringConcatenationClient _toBuilder(final com.regnosys.rosetta.rosetta.simple.Data type) {
StringConcatenationClient _xblockexpression = null;
{
boolean _endsWith = type.getName().endsWith("WithMeta");
if (_endsWith) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
String _fullname = IterableUtil.fullname(type);
_builder.append(_fullname);
_builder.append(".");
String _name = type.getName();
_builder.append(_name);
_builder.append("Builder");
String _firstUpper = StringExtensions.toFirstUpper(type.getDefinition());
_builder.append(_firstUpper);
}
};
return _client;
}
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
String _fullname = IterableUtil.fullname(type);
_builder.append(_fullname);
_builder.append(".");
String _name = type.getName();
_builder.append(_name);
_builder.append("Builder");
}
};
_xblockexpression = _client_1;
}
return _xblockexpression;
}
private StringConcatenationClient _toBuilder(final RosettaEnumeration type) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
String _name = type.getName();
_builder.append(_name);
}
};
return _client;
}
private StringConcatenationClient _toBuilder(final RosettaBuiltinType type) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
Optional _type = IngesterGenerator.this.builtins.getType(type.getName(), CollectionLiterals.newHashMap());
_builder.append(_type);
}
};
return _client;
}
private StringConcatenationClient _toBuilder(final RosettaTypeAlias type) {
return this.toBuilder(type.getTypeCall().getType());
}
private String pathConstants(final SynonymMap mapping) {
final LinkedHashSet svs = new LinkedHashSet();
final Function1> _function = (AttributeGroup it) -> {
return it.getSynonymGroups();
};
Iterables.addAll(svs, IterableExtensions.flatMap(mapping.attributeGroups(), _function));
final Function1 _function_1 = (SynonymValue it) -> {
List _singletonList = Collections.singletonList(it);
List _emptyList = Collections.emptyList();
return new SynonymGroup(_singletonList, _emptyList, null, null, null, null, false);
};
Iterables.addAll(svs, IterableExtensions.map(mapping.getConditionalCaptures().keySet(), _function_1));
return this.pathConstants(svs);
}
private String pathConstants(final Iterable sgs) {
final Function1> _function = (SynonymGroup it) -> {
return it.getSynonymValues();
};
final Function1 _function_1 = (SynonymValue it) -> {
return this.toPathName(it);
};
final Function1 _function_2 = (SynonymValue synonymValue) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("private final static ImmutableList ");
String _pathName = this.toPathName(synonymValue);
_builder.append(_pathName);
_builder.append("Path = ImmutableList.of(");
CharSequence _list = this.list(synonymValue.getSynonymPath());
_builder.append(_list);
_builder.append(");");
return _builder.toString();
};
return IterableExtensions.join(IterableUtil.distinct(ListExtensions.map(IterableExtensions.sortBy(IterableExtensions.flatMap(sgs, _function), _function_1), _function_2)), "\n");
}
/**
* There are two types of temporary conditional values
* one where a primitive typed mapping has a condition meaning that the value may or may not be used
* the other where there is a path in a when clause and we need to capture the value of that path
*/
private CharSequence conditionalValues(final SynonymMap mapping) {
StringConcatenation _builder = new StringConcatenation();
final Function1 _function = (AttributeGroup it) -> {
return this.toAttPathName(it);
};
final List groups = IterableExtensions.sortBy(mapping.attributeGroups(), _function);
_builder.newLineIfNotEmpty();
{
final Function1 _function_1 = (AttributeGroup it) -> {
final Function1 _function_2 = (SynonymGroup it_1) -> {
return Boolean.valueOf(((!it_1.getSynonymValues().isEmpty()) && IterableExtensions.exists(it_1.getConditions(), ((Function1) (SynonymCondition it_2) -> {
boolean _isEmpty = it_2.getCondition().isEmpty();
return Boolean.valueOf((!_isEmpty));
}))));
};
return Boolean.valueOf(IterableExtensions.exists(it.getSynonymGroups(), _function_2));
};
Iterable _filter = IterableExtensions.filter(groups, _function_1);
for(final AttributeGroup group : _filter) {
_builder.append("protected Maplast(group.getAttributePath()).getType());
_builder.append(_expandedTypeToBuilder);
_builder.append("> ");
String _attPathName = this.toAttPathName(group);
_builder.append(_attPathName);
_builder.append("Values = new LinkedHashMap<>();");
_builder.newLineIfNotEmpty();
}
}
{
final Function1>, String> _function_2 = (Map.Entry> it) -> {
return this.toPathName(it.getKey());
};
List>> _sortBy = IterableExtensions.>, String>sortBy(mapping.getConditionalCaptures().asMap().entrySet(), _function_2);
for(final Map.Entry> e : _sortBy) {
{
final Function1 _function_3 = (Element it) -> {
Cardinality _cardinality = it.getCardinality();
return Boolean.valueOf((_cardinality == Cardinality.MULTIPLE));
};
boolean _exists = IterableExtensions.exists(e.getKey().getSynonymPath(), _function_3);
if (_exists) {
_builder.append("protected Map ");
String _pathName = this.toPathName(e.getKey());
_builder.append(_pathName);
_builder.append("Values = new HashMap<>();");
_builder.newLineIfNotEmpty();
} else {
_builder.append("protected String ");
String _pathName_1 = this.toPathName(e.getKey());
_builder.append(_pathName_1);
_builder.append("Value;");
_builder.newLineIfNotEmpty();
}
}
}
}
return _builder;
}
private CharSequence handlerCaches(final SynonymMap mapping, final String packageName) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("// basic");
_builder.newLine();
CharSequence _basicTypeCaches = this.basicTypeCaches(mapping);
_builder.append(_basicTypeCaches);
_builder.newLineIfNotEmpty();
_builder.append("// rosetta");
_builder.newLine();
CharSequence _rosettaTypeCaches = this.rosettaTypeCaches(mapping, packageName);
_builder.append(_rosettaTypeCaches);
_builder.newLineIfNotEmpty();
return _builder;
}
private CharSequence basicTypeCaches(final SynonymMap mapping) {
CharSequence _xblockexpression = null;
{
final Function1 _function = (AttributeGroupMapping it) -> {
boolean _isClassOrData = this.isClassOrData(it.getMappings().getRosetta());
return Boolean.valueOf((!_isClassOrData));
};
final Function1 _function_1 = (AttributeGroupMapping it) -> {
return it.getGroup();
};
final Iterable attrPathSynGroups = IterableExtensions.map(IterableExtensions.filter(mapping.getMappedGroups(), _function), _function_1);
final Function1 _function_2 = (AttributeGroup it) -> {
int _size = it.getAttributePath().size();
return Boolean.valueOf((_size > 1));
};
final Function1 _function_3 = (AttributeGroup it) -> {
return this.toAttPathName(this.toFirstMultiple(it));
};
final Map> chopped = IterableExtensions.groupBy(IterableExtensions.filter(attrPathSynGroups, _function_2), _function_3);
_xblockexpression = this.handlerCache(chopped);
}
return _xblockexpression;
}
private ArrayList toFirstMultiple(final AttributeGroup group) {
return this.toFirstMultiple(group.getAttributePath());
}
/**
* @param atts - list of attributes represents a path (with attribute name/type for each path element).
* @returns the first attribute that has multiple cardinality
*/
private ArrayList toFirstMultiple(final Iterable atts) {
ArrayList _xblockexpression = null;
{
final ArrayList result = CollectionLiterals.newArrayList();
boolean multiple = false;
int i = 0;
while (((!multiple) && (i <= (IterableExtensions.size(atts) - 2)))) {
{
int _plusPlus = i++;
final ExpandedAttribute att = ((ExpandedAttribute[])Conversions.unwrapArray(atts, ExpandedAttribute.class))[_plusPlus];
result.add(att);
multiple = att.isMultiple();
}
}
_xblockexpression = result;
}
return _xblockexpression;
}
private CharSequence handlerCache(final Map> attributeGroupMap) {
StringConcatenation _builder = new StringConcatenation();
{
final Function1>, String> _function = (Map.Entry> it) -> {
final Function1 _function_1 = (AttributeGroup it_1) -> {
return this.toAttPathName(it_1);
};
return this.toAttPathName(IterableExtensions.last(IterableExtensions.sortBy(it.getValue(), _function_1)));
};
List>> _sortBy = IterableExtensions.>, String>sortBy(attributeGroupMap.entrySet(), _function);
for(final Map.Entry> attrPathSynGroups : _sortBy) {
{
final Function1 _function_1 = (AttributeGroup it) -> {
return this.removeLast(it);
};
final Function1 _function_2 = (AttributeGroup it) -> {
return Boolean.valueOf(this.multipleCardinality(it));
};
boolean _exists = IterableExtensions.exists(ListExtensions.map(attrPathSynGroups.getValue(), _function_1), _function_2);
if (_exists) {
_builder.append("protected HandlerCache<");
CharSequence _expandedTypeToBuilder = this.expandedTypeToBuilder(IterableExtensions.last(this.toFirstMultiple(IterableExtensions.