Search in sources :

Example 1 with BusinessSnapshotMilestoning

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessSnapshotMilestoning in project legend-pure by finos.

the class TestSimpleGrammar method testTableWithBusinessSnapshotMilestoning.

@Test
public void testTableWithBusinessSnapshotMilestoning() {
    this.runtime.createInMemorySource("test.pure", "###Relational\n" + "Database pack::ProductDatabase (\n" + "   Table ProductTable\n" + "   (\n" + "       milestoning( \n" + "          business(BUS_SNAPSHOT_DATE = snapshotDate)\n" + "       )" + "       id INT PRIMARY KEY,\n" + "       name VARCHAR(200),\n" + "       snapshotDate Date\n" + "   )\n" + ")\n");
    this.runtime.compile();
    Database productDatabase = (Database) this.runtime.getCoreInstance("pack::ProductDatabase");
    RichIterable<? extends Milestoning> milestonings = productDatabase._schemas().getFirst()._tables().getFirst()._milestoning().selectInstancesOf(BusinessSnapshotMilestoning.class);
    Assert.assertEquals(1, milestonings.size());
    Assert.assertTrue(milestonings.getFirst() instanceof BusinessSnapshotMilestoning);
    BusinessSnapshotMilestoning businessSnapshotMilestoning = (BusinessSnapshotMilestoning) milestonings.getFirst();
    Assert.assertEquals("snapshotDate", businessSnapshotMilestoning._snapshotDate()._name());
    Assert.assertNull(businessSnapshotMilestoning._infinityDate());
}
Also used : BusinessSnapshotMilestoning(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessSnapshotMilestoning) Database(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database) Test(org.junit.Test)

Example 2 with BusinessSnapshotMilestoning

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessSnapshotMilestoning in project legend-pure by finos.

the class DatabaseProcessor method processTableMilestoning.

private static void processTableMilestoning(CoreInstance tableCoreInstance, MapIterable<String, Column> columnsByName, Matcher matcher, ProcessorState processorState, ProcessorSupport processorSupport) {
    if (tableCoreInstance instanceof Table) {
        Table table = (Table) tableCoreInstance;
        for (Milestoning milestoningInfo : table._milestoning()) {
            milestoningInfo._owner(table);
            if (milestoningInfo instanceof BusinessMilestoning) {
                BusinessMilestoning businessMilestoning = (BusinessMilestoning) milestoningInfo;
                if (processorSupport.instance_instanceOf(businessMilestoning._from(), M3Paths.String)) {
                    String businessFrom = businessMilestoning._from() == null ? "" : businessMilestoning._from().getName();
                    Column businessFromColumn = getColumn(table, columnsByName, businessFrom);
                    businessMilestoning._from(businessFromColumn);
                }
                if (processorSupport.instance_instanceOf(businessMilestoning._thru(), M3Paths.String)) {
                    String businessThru = businessMilestoning._thru() == null ? "" : businessMilestoning._thru().getName();
                    Column businessThruColumn = getColumn(table, columnsByName, businessThru);
                    businessMilestoning._thru(businessThruColumn);
                }
            } else if (milestoningInfo instanceof BusinessSnapshotMilestoning) {
                BusinessSnapshotMilestoning businessSnapshotMilestoning = (BusinessSnapshotMilestoning) milestoningInfo;
                if (processorSupport.instance_instanceOf(businessSnapshotMilestoning._snapshotDate(), M3Paths.String)) {
                    String snapshotDateColumnName = businessSnapshotMilestoning._snapshotDate().getName();
                    Column snapshotDateColumn = getColumn(table, columnsByName, snapshotDateColumnName);
                    if (!(snapshotDateColumn._type() instanceof Date)) {
                        throw new PureCompilationException(snapshotDateColumn.getSourceInformation(), "Column set as BUS_SNAPSHOT_DATE can only be of type : [Date]");
                    }
                    businessSnapshotMilestoning._snapshotDate(snapshotDateColumn);
                }
            } else if (milestoningInfo instanceof ProcessingMilestoning) {
                ProcessingMilestoning processingMilestoning = (ProcessingMilestoning) milestoningInfo;
                if (processorSupport.instance_instanceOf(processingMilestoning._in(), M3Paths.String)) {
                    String processingIn = processingMilestoning._in() == null ? "" : processingMilestoning._in().getName();
                    Column processingInColumn = getColumn(table, columnsByName, processingIn);
                    processingMilestoning._in(processingInColumn);
                }
                if (processorSupport.instance_instanceOf(processingMilestoning._out(), M3Paths.String)) {
                    String processingOut = processingMilestoning._out() == null ? "" : processingMilestoning._out().getName();
                    Column processingOutColumn = getColumn(table, columnsByName, processingOut);
                    processingMilestoning._out(processingOutColumn);
                }
            } else {
                PostProcessor.processElement(matcher, milestoningInfo, processorState, processorSupport);
                if (!milestoningInfo.hasBeenProcessed()) {
                    throw new PureCompilationException(milestoningInfo.getSourceInformation(), "Unknown milestoning type: " + PackageableElement.getUserPathForPackageableElement(milestoningInfo.getClassifier()));
                }
            }
        }
    }
}
Also used : BusinessMilestoning(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessMilestoning) Milestoning(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Milestoning) ProcessingMilestoning(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.ProcessingMilestoning) BusinessSnapshotMilestoning(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessSnapshotMilestoning) Table(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Table) BusinessSnapshotMilestoning(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessSnapshotMilestoning) TableAliasColumn(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn) Column(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Column) BusinessMilestoning(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessMilestoning) ProcessingMilestoning(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.ProcessingMilestoning) Date(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.Date) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

BusinessSnapshotMilestoning (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessSnapshotMilestoning)2 Column (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Column)1 Database (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database)1 TableAliasColumn (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn)1 Date (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.datatype.Date)1 BusinessMilestoning (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.BusinessMilestoning)1 Milestoning (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Milestoning)1 ProcessingMilestoning (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.ProcessingMilestoning)1 Table (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Table)1 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)1 Test (org.junit.Test)1