Skip to content

Commit

Permalink
Story 2585 open source reporting (#621)
Browse files Browse the repository at this point in the history
* Added new report interfaces

* Added split method to DottedPath

* Added concat method to DottedPath

* Adjusted interfaces

* Implemented tabulator generator

* Cleaned

* make stripFromTypeAliases recursive

* save

* Restored multi basic type error for legacy rules

* save

* Renamed corpuses to corpusList

* Renamed corpuses to corpusList

* save

* save

* save

* save

* fix formatting of function generator

* fix qualifier functions

* add rule generator to top level generator

* fix function spacing

* add shortcuts to function dependencies

* fix lhsExpand

* update validator test expectation

* update dispatch function names

* update dispatch function test expectation

* fix for reporting rules namespace

* fix implicit var and update test expectations

* Merged with feature branch

* add initial report generator

* create fFunction builder for RosettaBlueprintReport

* Support for wrapping legacy rules in functions

* save

* save

* Create builder for BlueprintReport to RFunction

* Create outer report function

* add functional interface to report

* Added support for wrapping legacy repeatable rules in a functional interface

* Fixed runtime

* pass expression in operation generation

* fix operation expression path

* Fixed tests

* Fixed tabulator references

* fix all report tests

* Removed ModelReportId

* Fixed tabulator references

* Task 5924 generate report definitions (#623)

* add initial report generator

* create fFunction builder for RosettaBlueprintReport

* save

* save

* Create builder for BlueprintReport to RFunction

* Create outer report function

* add functional interface to report

* pass expression in operation generation

* fix operation expression path

* Fixed tests

* Fixed tabulator references

* fix all report tests

* Removed ModelReportId

* Fixed tabulator references

---------

Co-authored-by: Simon Cockx <[email protected]>

* Fixed dispatch functions

* Fixed casing of dispatch functions

* add temporary reporting identifier

* Added context to FieldValue visitor

* Added comments

* handle report naming for legacy and non legacy reports (#624)

* Fixed feedback

* Fixed feedback

* Fixed empty legacy report throws

* Cleaned

* Fixed enum toString

* Fixed enum serialization

* wrap legacy rule output in List where needed

* Fixed functions not building their output

* Fixed test

* Fixed function generator

* Cleanup

* Fixed tests

* Added equals to tabulated fieldvalues

* Cleaned

* Fixed tests

* Fixed comment

---------

Co-authored-by: Simon Cockx <[email protected]>
Co-authored-by: SimonCockx <[email protected]>
  • Loading branch information
3 people authored Aug 29, 2023
1 parent d6110b9 commit a936724
Show file tree
Hide file tree
Showing 168 changed files with 7,084 additions and 2,960 deletions.
12 changes: 12 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<!-- Forbid using Google Inject in favor of javax Inject. -->
<module name="IllegalImport">
<property name="illegalClasses"
value="com.google.inject.Inject, com.google.inject.name.Named, com.google.inject.Provider" />
</module>
</module>
</module>
32 changes: 30 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<!-- Plugin and plugin dependency management -->
<org.eclipse.emf.ecore.xcore.version>1.23.0</org.eclipse.emf.ecore.xcore.version>
<maven-enforcer-plugin.version>3.3.0</maven-enforcer-plugin.version>
<maven-checkstyle-plugin.version>3.3.0</maven-checkstyle-plugin.version>
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
<maven-clean-plugin.version>3.3.1</maven-clean-plugin.version>
<build-helper-maven-plugin.version>3.4.0</build-helper-maven-plugin.version>
Expand Down Expand Up @@ -102,7 +103,7 @@
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>

<!-- Runtime dependencies -->
<dependency>
<groupId>org.eclipse.xtext</groupId>
Expand Down Expand Up @@ -303,7 +304,8 @@
<bannedDependencies>
<excludes>
<exclude>log4j:log4j</exclude>
<exclude>org.apache.logging.log4j:log4j-core</exclude>
<exclude>
org.apache.logging.log4j:log4j-core</exclude>
<exclude>ch.qos.reload4j:reload4j</exclude>
</excludes>
</bannedDependencies>
Expand All @@ -312,6 +314,32 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<sourceDirectories>
<sourceDirectory>src/main/java</sourceDirectory>
<sourceDirectory>src/test/java</sourceDirectory>
<sourceDirectory>target/xtend-gen/main/java</sourceDirectory>
<sourceDirectory>target/xtend-gen/test/java</sourceDirectory>
</sourceDirectories>
</configuration>
<executions>
<execution>
<id>Check style</id>
<!-- This needs to run /after/ xtend (test) source generation is done. -->
<phase>process-test-sources</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Provider;

import org.eclipse.lsp4j.FormattingOptions;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.xtext.formatting.IIndentationInformation;
Expand All @@ -16,8 +19,6 @@
import org.eclipse.xtext.util.TextRegion;

import com.google.common.base.Strings;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.regnosys.rosetta.formatting2.RosettaFormatterPreferenceKeys;

/**
Expand All @@ -34,7 +35,7 @@ public class RosettaFormattingService extends FormattingService {
public static String PREFERENCE_MAX_LINE_WIDTH_KEY = "maxLineWidth";
public static String PREFERENCE_CONDITIONAL_MAX_LINE_WIDTH_KEY = "conditionalMaxLineWidth";

@Inject(optional = true)
@Inject
private Provider<IFormatter2> formatter2Provider;

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test
// TODO: fix completion
class ContentAssistTest extends AbstractRosettaLanguageServerTest {
@Test
def testInheritedAttributesDataRule() {
def testInheritedAttributesCondition() {
val model = '''
namespace "test"
version "test"
Expand Down Expand Up @@ -87,7 +87,7 @@ class ContentAssistTest extends AbstractRosettaLanguageServerTest {

// TODO: debug null pointer exception in log
@Test
def void testDataRuleAfterArrow() {
def void testConditionAfterArrow() {
val model = '''
namespace "test"
version "test"
Expand Down Expand Up @@ -182,7 +182,7 @@ class ContentAssistTest extends AbstractRosettaLanguageServerTest {
}

@Test
def void testDataRuleAfterArrow2() {
def void testConditionAfterArrow2() {
val model = '''
namespace "test"
version "test"
Expand Down
12 changes: 2 additions & 10 deletions rosetta-lang/model/RosettaSimple.xcore
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,17 @@ class Condition extends RosettaDefinable, Annotated, RosettaNamed, References {
contains RosettaExpression expression
}

abstract class Operation extends RosettaDefinable {
class Operation extends RosettaDefinable {
container Function function opposite operations
refers AssignPathRoot assignRoot
contains Segment path
contains RosettaExpression expression
boolean add
op Segment[] pathAsSegmentList() {
return if(path !== null) path.asSegmentList(path) else new BasicEList
}
}

class AssignOutputOperation extends Operation {
}

class OutputOperation extends Operation {
boolean add
refers AssignPathRoot input
}


class Segment {
refers Attribute attribute
contains Segment next opposite prev
Expand Down
10 changes: 0 additions & 10 deletions rosetta-lang/src/main/java/com/regnosys/rosetta/Rosetta.xtext
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ PostCondition returns Condition:
;

Operation:
AssignOutputOperation | OutputOperation
;

// @Compat deprecated - to be deleted once all models updated
AssignOutputOperation:
'assign-output' assignRoot = [AssignPathRoot|ValidID] (path = Segment)? ':' =>RosettaDefinable?
expression = RosettaCalcExpressionWithAsKey
;

OutputOperation:
('set' | add ?= 'add') assignRoot = [AssignPathRoot|ValidID] (path = Segment)? ':' =>RosettaDefinable?
expression = RosettaCalcExpressionWithAsKey
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import com.regnosys.rosetta.types.builtin.RRecordType
import com.regnosys.rosetta.types.builtin.RBuiltinTypeService
import org.eclipse.emf.ecore.resource.ResourceSet
import com.regnosys.rosetta.rosetta.RosettaRecordType
import java.util.Optional
import com.regnosys.rosetta.types.RAttribute

class RosettaExtensions {

Expand Down Expand Up @@ -88,13 +90,15 @@ class RosettaExtensions {
val atts = newArrayList;
atts.addAll(data.attributes)
if (data.hasSuperType) {
atts.addAll(data.superType.allNonOverridesAttributes
val attsWithSuper = data.superType.allNonOverridesAttributes
.filter[superAttr| !atts.exists[extendedAttr|
superAttr.name == extendedAttr.name &&
superAttr.typeCall.type == extendedAttr.typeCall.type &&
superAttr.card.inf == extendedAttr.card.inf &&
superAttr.card.sup == extendedAttr.card.sup
]].toList)
]].toList
attsWithSuper.addAll(atts)
return attsWithSuper
}
return atts
}
Expand Down Expand Up @@ -165,6 +169,10 @@ class RosettaExtensions {
metaAnnotations.exists[attribute?.name == "template"]
}

def boolean hasMetaDataAnnotations(RAttribute attribute) {
attribute.metaAnnotations.exists[name == "reference" || name == "location" || name == "scheme" || name == "id"]
}

def boolean hasMetaDataAnnotations(Annotated it) {
metaAnnotations.exists[attribute?.name == "reference" || attribute?.name == "location" || attribute?.name == "scheme" || attribute?.name == "id"]
}
Expand All @@ -173,6 +181,10 @@ class RosettaExtensions {
metaAnnotations.exists[attribute?.name != "reference" && attribute?.name != "address"]
}

def boolean hasMetaDataAddress(RAttribute attribute) {
attribute.metaAnnotations.exists[name == "address"]
}

def boolean hasMetaDataAddress(Annotated it) {
metaAnnotations.exists[attribute?.name == "address"]
}
Expand Down Expand Up @@ -236,17 +248,22 @@ class RosettaExtensions {
/**
* Get all reporting rules for blueprint report
*/
def getAllReportingRules(RosettaBlueprintReport report, boolean allLeafNodes) {
// TODO: remove `onlyLeafNodes` and `skipRepeatable` once blueprints are removed.
def getAllReportingRules(RosettaBlueprintReport report, boolean onlyLeafNodes, boolean skipRepeatable) {
getAllReportingRules(report.reportType, Optional.ofNullable(report.ruleSource), onlyLeafNodes, skipRepeatable)
}

def getAllReportingRules(Data type, Optional<RosettaExternalRuleSource> ruleSource, boolean onlyLeafNodes, boolean skipRepeatable) {
val rules = newHashMap
val path = RosettaPath.valueOf(report.reportType.name)
report.reportType.collectReportingRules(path, report.ruleSource, rules, newHashSet, allLeafNodes)
return rules
val path = RosettaPath.valueOf(type.name)
type.collectReportingRules(path, ruleSource, rules, newHashSet, onlyLeafNodes, skipRepeatable)
rules
}

/**
* Recursively collects all reporting rules for all attributes
*/
def void collectReportingRules(Data dataType, RosettaPath path, RosettaExternalRuleSource ruleSource, Map<PathAttribute, RosettaBlueprint> visitor, Set<Data> collectedTypes, boolean allLeafNodes) {
private def void collectReportingRules(Data dataType, RosettaPath path, Optional<RosettaExternalRuleSource> ruleSource, Map<PathAttribute, RosettaBlueprint> visitor, Set<Data> collectedTypes, boolean onlyLeafNodes, boolean skipRepeatable) {
val attrRules = externalAnn.getAllRuleReferencesForType(ruleSource, dataType)

dataType.allNonOverridesAttributes.forEach[attr |
Expand All @@ -260,20 +277,19 @@ class RosettaExtensions {
}
}
else if (attrType instanceof Data) {
if (!collectedTypes.contains(attrType)) {
collectedTypes.add(attrType)
// TODO - get rid of repeatable rules
// if allLeafNodes is false - for repeatable rules only collect rules from nested type
// if no rule exists at the top level, e.g., nested reporting rules are not supported
// (except for repeatable rules where only the top level rule should be collected)
if (rule !== null && (!attrEx.isMultiple || !allLeafNodes)) {
visitor.put(new PathAttribute(path, attr), rule.reportingRule)
}
if (rule === null || allLeafNodes) {
// TODO - get rid of repeatable rules
// if allLeafNodes is false - for repeatable rules only collect rules from nested type
// if no rule exists at the top level, e.g., nested reporting rules are not supported
// (except for repeatable rules where only the top level rule should be collected)
if (rule !== null && (!attrEx.isMultiple || !onlyLeafNodes)) {
visitor.put(new PathAttribute(path, attr), rule.reportingRule)
}
if (collectedTypes.add(attrType)) {
if (rule === null || !skipRepeatable) {
val subPath = attrEx.isMultiple ?
path.newSubPath(attr.name, 0) :
path.newSubPath(attr.name)
attrType.collectReportingRules(subPath, ruleSource, visitor, collectedTypes, allLeafNodes)
attrType.collectReportingRules(subPath, ruleSource, visitor, collectedTypes, onlyLeafNodes, skipRepeatable)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
package com.regnosys.rosetta

import com.google.inject.Provider
import com.regnosys.rosetta.derivedstate.RosettaDerivedStateComputer
import com.regnosys.rosetta.generator.RosettaOutputConfigurationProvider
import com.regnosys.rosetta.generator.external.EmptyExternalGeneratorsProvider
Expand Down Expand Up @@ -39,6 +38,7 @@ import com.regnosys.rosetta.formatting2.RosettaExpressionFormatter
import org.eclipse.xtext.serializer.impl.Serializer
import com.regnosys.rosetta.formatting2.FormattingUtil
import com.regnosys.rosetta.generator.java.util.RecordFeatureMap
import javax.inject.Provider

/* Use this class to register components to be used at runtime / without the Equinox extension registry.*/
class RosettaRuntimeModule extends AbstractRosettaRuntimeModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*/
package com.regnosys.rosetta

import com.google.inject.Injector
import com.regnosys.rosetta.rosetta.RosettaPackage
import com.regnosys.rosetta.rosetta.simple.SimplePackage
import org.eclipse.emf.ecore.EPackage
import com.regnosys.rosetta.rosetta.expression.ExpressionPackage
import com.google.inject.Injector

/**
* Initialization support for running Xtext languages without Equinox extension registry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
package com.regnosys.rosetta.formatting2

import com.google.inject.Inject
import com.regnosys.rosetta.rosetta.RosettaClassSynonym
import com.regnosys.rosetta.rosetta.RosettaDocReference
import com.regnosys.rosetta.rosetta.RosettaEnumSynonym
Expand Down Expand Up @@ -57,6 +56,7 @@ import com.regnosys.rosetta.rosetta.RosettaTypeAlias
import com.regnosys.rosetta.rosetta.ParametrizedRosettaType
import com.regnosys.rosetta.rosetta.TypeParameter
import com.regnosys.rosetta.rosetta.TypeCallArgument
import javax.inject.Inject

class RosettaFormatter extends AbstractRosettaFormatter2 {

Expand Down Expand Up @@ -498,7 +498,7 @@ class RosettaFormatter extends AbstractRosettaFormatter2 {
}

def dispatch void format(Operation ele, extension IFormattableDocument document) {
val extension outputOperationGrammarAccess = outputOperationAccess
val extension operationGrammarAccess = operationAccess

ele.regionFor.keyword(setKeyword_0_0)
.append[oneSpace]
Expand Down
Loading

0 comments on commit a936724

Please sign in to comment.