Skip to content

Commit

Permalink
Process fix (finos#835)
Browse files Browse the repository at this point in the history
* Process fix

* Cleaned

* Made order of metafields interfaces consistent
  • Loading branch information
SimonCockx authored Sep 13, 2024
1 parent b0676e5 commit a0d3883
Show file tree
Hide file tree
Showing 7 changed files with 2,455 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ import com.regnosys.rosetta.scoping.RosettaScopeProvider
import com.regnosys.rosetta.rosetta.simple.SimpleFactory
import com.regnosys.rosetta.types.RObjectFactory
import java.util.LinkedHashSet
import com.regnosys.rosetta.types.TypeSystem

@Singleton // see `metaFieldsCache`
class RosettaEcoreUtil {

@Inject RBuiltinTypeService builtins
@Inject RObjectFactory objectFactory
@Inject extension TypeSystem typeSystem

def boolean isResolved(EObject obj) {
obj !== null && !obj.eIsProxy
Expand Down Expand Up @@ -237,7 +239,7 @@ class RosettaEcoreUtil {
}
// Copied over from RosettaAttributeExtensions.
@Deprecated
def List<RAttribute> additionalAttributes(RDataType t) {
private def List<RAttribute> additionalAttributes(RDataType t) {
val res = newArrayList
if(hasKeyedAnnotation(t.EObject)){
res.add(new RAttribute(
Expand All @@ -253,6 +255,27 @@ class RosettaEcoreUtil {
}
return res
}
def List<RAttribute> javaAttributes(RDataType t) {
(t.ownAttributes + t.additionalAttributes).toList
}
def List<RAttribute> allJavaAttributes(RDataType t) {
val atts = t.javaAttributes
if (t.superType !== null) {
val attsWithSuper = (t.superType.stripFromTypeAliases as RDataType).allJavaAttributes
val result = newArrayList
attsWithSuper.forEach[
val overridenAtt = atts.findFirst[att| att.name == name]
if (overridenAtt !== null) {
result.add(overridenAtt)
} else {
result.add(it)
}
]
result.addAll(atts.filter[att| !result.contains(att)].toList)
return result
}
return atts
}

@Deprecated
String METAFIELDS_CLASS_NAME = 'MetaFields'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class MetaFieldGenerator {
cardSingle
}

def List<Attribute> getMetaFieldTypes(Collection<RosettaMetaType> utypes) {
def List<Attribute> getMetaFieldTypes(List<RosettaMetaType> utypes) {
val cardMult = RosettaFactory.eINSTANCE.createRosettaCardinality
cardMult.inf = 0;
cardMult.sup = 1000;
Expand All @@ -167,7 +167,7 @@ class MetaFieldGenerator {
keysAttribute.typeCall = keysType.toTypeCall
keysAttribute.card = cardMult

val filteredTypes = utypes.filter[t|t.name != "key" && t.name != "id" && t.name != "reference"].toSet;
val filteredTypes = utypes.filter[t|t.name != "key" && t.name != "id" && t.name != "reference"].toSet
val result = filteredTypes.map[toAttribute].toList
result.addAll(#[globalKeyAttribute, externalKeyAttribute, keysAttribute])
return result
Expand All @@ -181,7 +181,7 @@ class MetaFieldGenerator {
return newAttribute
}

def getMetaAndTemplateFieldTypes(Collection<RosettaMetaType> utypes) {
def getMetaAndTemplateFieldTypes(List<RosettaMetaType> utypes) {
val templateGlobalReferenceType = RosettaFactoryImpl.eINSTANCE.createRosettaMetaType()
templateGlobalReferenceType.name = "templateGlobalReference"
templateGlobalReferenceType.typeCall = stringType
Expand All @@ -196,7 +196,7 @@ class MetaFieldGenerator {
return metaFieldTypes
}

def metaFields(String name, Collection<Object> interfaces, Collection<Attribute> attributes) {
def metaFields(String name, List<Object> interfaces, List<Attribute> attributes) {
if (attributes.exists[t|t.name == "scheme"]) {
interfaces.add(MetaDataFields)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.regnosys.rosetta.types.TypeSystem
import com.regnosys.rosetta.types.RAttribute
import com.regnosys.rosetta.types.REnumType
import com.regnosys.rosetta.RosettaEcoreUtil
import java.util.List

class ModelObjectBoilerPlate {

Expand All @@ -35,16 +36,16 @@ class ModelObjectBoilerPlate {
val identity = [String s|s]

def StringConcatenationClient builderBoilerPlate(RDataType c, JavaScope scope) {
val attrs = c.ownAttributes
val attrs = c.javaAttributes
'''
«c.contributeEquals(attrs, scope)»
«c.contributeHashCode(attrs, scope)»
«c.contributeToString(toBuilder, scope)»
'''
}

def StringConcatenationClient implementsClause(RDataType d, Collection<Object> extraInterfaces) {
val interfaces = newHashSet
def StringConcatenationClient implementsClause(RDataType d, List<Object> extraInterfaces) {
val interfaces = newLinkedHashSet
if(d.EObject.hasKeyedAnnotation)
interfaces.add(GlobalKey)
if(d.EObject.hasTemplateAnnotation)
Expand All @@ -63,7 +64,7 @@ class ModelObjectBoilerPlate {
}

def StringConcatenationClient boilerPlate(RDataType t, JavaScope scope) {
val attributes = t.ownAttributes + t.additionalAttributes
val attributes = t.javaAttributes
'''
«t.contributeEquals(attributes, scope)»
«t.contributeHashCode(attributes, scope)»
Expand Down Expand Up @@ -107,7 +108,7 @@ class ModelObjectBoilerPlate {
@Override
public String toString() {
return "«classNameFunc.apply(t.name)» {" +
«FOR attribute : t.ownAttributes + t.additionalAttributes SEPARATOR ' ", " +'»
«FOR attribute : t.javaAttributes SEPARATOR ' ", " +'»
"«attribute.name»=" + this.«methodScope.getIdentifierOrThrow(attribute)» +
«ENDFOR»
'}'«IF t.hasSuperDataType» + " " + super.toString()«ENDIF»;
Expand Down Expand Up @@ -166,7 +167,7 @@ class ModelObjectBoilerPlate {
def StringConcatenationClient builderProcessMethod(RDataType t) '''
@Override
default void process(«RosettaPath» path, «BuilderProcessor» processor) {
«FOR a : t.allNonOverridenAttributes + t.additionalAttributes»
«FOR a : t.allJavaAttributes»
«IF a.RType instanceof RDataType || !a.metaAnnotations.isEmpty»
processRosetta(path.newSubPath("«a.name»"), processor, «a.toBuilderTypeSingle».class, get«a.name.toFirstUpper»()«a.metaFlags»);
«ELSE»
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class ModelObjectBuilderGenerator {
val javaType = t.toJavaType
val superInterface = javaType.interfaces.head
val builderScope = scope.classScope('''«javaType»BuilderImpl''')
val attrs = t.ownAttributes + t.additionalAttributes
val allAttrs = t.allNonOverridenAttributes + t.additionalAttributes
val attrs = t.javaAttributes
val allAttrs = t.allJavaAttributes
allAttrs.forEach[
builderScope.createIdentifier(it, it.name.toFirstLower)
]
Expand Down Expand Up @@ -163,7 +163,7 @@ class ModelObjectBuilderGenerator {
private def StringConcatenationClient setters(RDataType t, JavaScope scope)
'''
«FOR attribute : t.allNonOverridenAttributes + t.additionalAttributes»
«FOR attribute : t.allJavaAttributes»
«doSetter(t, attribute, scope)»
«ENDFOR»
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ModelObjectGenerator {
classBody(t, scope, metaType, version, Collections.emptyList)
}

def StringConcatenationClient classBody(RDataType t, JavaScope scope, JavaClass<?> metaType, String version, Collection<Object> interfaces) {
def StringConcatenationClient classBody(RDataType t, JavaScope scope, JavaClass<?> metaType, String version, List<Object> interfaces) {
val javaType = t.toJavaType
val superInterface = javaType.interfaces.head
val interfaceScope = scope.classScope(javaType.toString)
Expand Down Expand Up @@ -101,7 +101,7 @@ class ModelObjectGenerator {
}

protected def StringConcatenationClient pojoBuilderInterfaceGetterMethods(RDataType t, JavaClass<?> javaType, JavaScope builderScope) '''
«FOR attribute : t.ownAttributes + t.additionalAttributes»
«FOR attribute : t.javaAttributes»
«IF attribute.RType instanceof RDataType || !attribute.metaAnnotations.isEmpty»
«IF !attribute.isMulti»
«attribute.toBuilderTypeSingle» getOrCreate«attribute.name.toFirstUpper»();
Expand All @@ -112,7 +112,7 @@ class ModelObjectGenerator {
«ENDIF»
«ENDIF»
«ENDFOR»
«FOR attribute : t.allNonOverridenAttributes + t.additionalAttributes»
«FOR attribute : t.allJavaAttributes»
«IF !attribute.isMulti»
«javaType.toBuilderType» set«attribute.name.toFirstUpper»(«attribute.toMetaJavaType» «builderScope.createUniqueIdentifier(attribute.name)»);
«IF !attribute.metaAnnotations.isEmpty»«javaType.toBuilderType» set«attribute.name.toFirstUpper»Value(«attribute.toJavaType» «builderScope.createUniqueIdentifier(attribute.name)»);«ENDIF»
Expand Down Expand Up @@ -154,7 +154,7 @@ class ModelObjectGenerator {
protected def StringConcatenationClient pojoInterfaceGetterMethods(JavaClass<?> javaType, RDataType t) '''
«FOR attribute : t.ownAttributes + t.additionalAttributes»
«FOR attribute : t.javaAttributes»
«javadoc(attribute.definition, attribute.docReferences, null
«attribute.toMetaJavaType» get«attribute.name.toFirstUpper»();
«ENDFOR»
Expand Down Expand Up @@ -196,7 +196,7 @@ class ModelObjectGenerator {
}
private def StringConcatenationClient rosettaClass(RDataType t, JavaScope scope) {
val attributes = t.ownAttributes + t.additionalAttributes
val attributes = t.javaAttributes
val javaType = t.toJavaType
val superInterface = javaType.interfaces.head
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.regnosys.rosetta.rosetta.RosettaCardinality;
import com.regnosys.rosetta.rosetta.RosettaEnumeration;
import com.regnosys.rosetta.rosetta.RosettaFactory;
import com.regnosys.rosetta.rosetta.RosettaMetaType;
import com.regnosys.rosetta.rosetta.RosettaReport;
import com.regnosys.rosetta.rosetta.RosettaRule;
import com.regnosys.rosetta.rosetta.expression.ExpressionFactory;
Expand Down Expand Up @@ -71,7 +72,8 @@ public RFunction buildRFunction(Function function) {
function.getAnnotations());
}

private RAttribute createArtificialAttribute(String name, RType type, boolean isMulti) {
// TODO: should be private
public RAttribute createArtificialAttribute(String name, RType type, boolean isMulti) {
return new RAttribute(name, null, Collections.emptyList(), type, List.of(), isMulti ? PositiveIntegerInterval.boundedLeft(0) : PositiveIntegerInterval.bounded(0, 1), null, null);
}
public RFunction buildRFunction(RosettaRule rule) {
Expand Down Expand Up @@ -168,7 +170,7 @@ private ROperation generateOperationForRuleReference(Attribute inputAttribute, R
}

public RAttribute buildRAttribute(Attribute attribute) {
return buildRAttribute(attribute, false);
return buildRAttribute(attribute, attribute.getTypeCall().getType() instanceof RosettaMetaType);
}
private RAttribute buildRAttribute(Attribute attribute, boolean isMeta) {
RType rType = typeProvider.getRTypeOfSymbol(attribute);
Expand Down
Loading

0 comments on commit a0d3883

Please sign in to comment.