Skip to content

Commit f76cf79

Browse files
author
Bob Garner
committed
Added realm support and improved Released transform.
1 parent 533175a commit f76cf79

File tree

14 files changed

+837
-382
lines changed

14 files changed

+837
-382
lines changed

docs/emc/EMC_config.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,16 @@ Indicates whether this space has a metadata name/value for the specified name.
350350

351351
<hr/>
352352

353+
#### `boolean hasRealmWithName(String realm)`
354+
355+
Returns true if there is a realm by this name.
356+
357+
| Parameter | Description |
358+
|-----|-----|
359+
|`String realm` | *no description* |
360+
361+
<hr/>
362+
353363
#### `List` **`importEntityNames`**
354364

355365
Returns the names of the entities that have been imported into this space.
@@ -372,6 +382,16 @@ Spaces can define a dictionary of name/value pairs that provide some meta data a
372382

373383
<hr/>
374384

385+
#### `MTRealm realmWithName(String realm)`
386+
387+
Returns the realm object by its name.
388+
389+
| Parameter | Description |
390+
|-----|-----|
391+
|`String realm` | *no description* |
392+
393+
<hr/>
394+
375395
#### `MTRepository repository(String name)`
376396

377397
Returns the repository object by its name.

src/main/antlr4/org/entityc/compiler/EntityLanguage.g4

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ HUMAN : 'human' ;
9191
READABLE : 'readable' ;
9292
IDENTIFICATION : 'identification' ;
9393

94+
REALM : 'realm' ;
9495
DOMAIN : 'domain' ;
9596
ATTRIBUTES : 'attributes' ;
9697
REPLACES : 'replaces' ;
@@ -189,7 +190,7 @@ ident
189190
| INTERFACE | OPERATION | QUERY | STATUS | CUSTOM | PARAM | TYPE | ENDPOINT
190191
| CONFIG | CONTEXT | ARGUMENT | HUMAN | READABLE | IDENTIFICATION | NAME | ORGANIZATION
191192
| REQUIRES | ROLE | READ | WRITE | WHEN | USER | ARRAY
192-
| APPLY | DESCRIPTION | TAGS | METADATA | FORMATTING | FORMAT | COMMENTS
193+
| APPLY | DESCRIPTION | TAGS | METADATA | FORMATTING | FORMAT | COMMENTS | REALM
193194
;
194195

195196
macro
@@ -274,6 +275,7 @@ root
274275
| entity
275276
| enumStatement
276277
| domain
278+
| realm
277279
| configuration
278280
| units
279281
| language
@@ -585,6 +587,17 @@ bitCount
585587
: '(' INTEGER ')'
586588
;
587589

590+
realm
591+
: REALM id '{' realmBody '}'
592+
;
593+
594+
realmBody
595+
:
596+
( descriptionStatement
597+
| tagStatement
598+
| domain
599+
)*
600+
;
588601
/*
589602
*
590603
DOMAIN
@@ -755,15 +768,15 @@ domainApplyTemplateBody
755768
:
756769
( descriptionStatement
757770
| tagStatement
758-
| templateConfig
771+
| transformConfig
759772
)*
760773
;
761774

762775
defaultTemplateConfig
763776
: DEFAULT CONFIG jsonObj
764777
;
765778

766-
templateConfig
779+
transformConfig
767780
: CONFIG jsonObj
768781
;
769782

@@ -1247,7 +1260,7 @@ templateBody
12471260
( descriptionStatement
12481261
| tagStatement
12491262
| outputSpec
1250-
| templateConfig
1263+
| transformConfig
12511264
)*
12521265
;
12531266

@@ -1267,6 +1280,8 @@ transform
12671280
transformBody
12681281
:
12691282
( outputSpec
1283+
| transformConfig
1284+
| REALM id
12701285
)*
12711286
;
12721287

src/main/java/org/entityc/compiler/ASTVisitor.java

Lines changed: 490 additions & 346 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.entityc.compiler.model;
2+
3+
import org.entityc.compiler.model.domain.MTNamed;
4+
import org.entityc.compiler.model.entity.MTTemplateSupport;
5+
import org.entityc.compiler.model.visitor.MTVisitor;
6+
7+
public class MTRealm extends MTNode implements MTTemplateSupport, MTNamed {
8+
9+
private final String name;
10+
11+
public MTRealm(String name) {
12+
this.name = name;
13+
}
14+
15+
@Override
16+
public void accept(MTVisitor visitor) {
17+
18+
}
19+
20+
@Override
21+
public String getName() {
22+
return this.name;
23+
}
24+
}

src/main/java/org/entityc/compiler/model/config/MTSpace.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
import org.entityc.compiler.doc.annotation.ModelMethod;
1414
import org.entityc.compiler.doc.annotation.ModelMethodCategory;
1515
import org.entityc.compiler.doc.annotation.ModelMethodParameter;
16-
import org.entityc.compiler.model.MTModule;
17-
import org.entityc.compiler.model.MTNamespace;
18-
import org.entityc.compiler.model.MTNode;
19-
import org.entityc.compiler.model.MTReferenceResolution;
16+
import org.entityc.compiler.model.*;
2017
import org.entityc.compiler.model.domain.MTDomain;
2118
import org.entityc.compiler.model.domain.MTNamed;
2219
import org.entityc.compiler.model.entity.MTEntity;
@@ -46,6 +43,7 @@
4643
+ "list of modules or entities in your model.")
4744
public class MTSpace extends MTNode implements MTReferenceResolution, MTTemplateSupport, MTNamed {
4845

46+
private final Map<String, MTRealm> realmMap = new HashMap<>();
4947
private final Map<String, MTModule> moduleMap = new HashMap<>();
5048
private final Map<String, MTEntity> entityMap = new HashMap<>();
5149
private final Map<String, MTEntityTemplate> entityTemplateMap = new HashMap<>();
@@ -132,6 +130,20 @@ public MTRepository getRepository(
132130
return repositoryMap.get(name);
133131
}
134132

133+
public void addRealm(MTRealm realm) {
134+
realmMap.put(realm.getName(), realm);
135+
}
136+
137+
@ModelMethod(category = ModelMethodCategory.CONFIGURATION, description = "Returns the realm object by its name.")
138+
public MTRealm getRealmWithName(String realm) {
139+
return realmMap.get(realm);
140+
}
141+
142+
@ModelMethod(category = ModelMethodCategory.CONFIGURATION, description = "Returns true if there is a realm by this name.")
143+
public boolean hasRealmWithName(String realm) {
144+
return realmMap.containsKey(realm);
145+
}
146+
135147
public void addModule(MTModule module) {
136148
module.setIncluded(includeMode);
137149
moduleMap.put(module.getName(), module);

src/main/java/org/entityc/compiler/model/domain/MTDomain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public void accept(MTVisitor visitor) {
365365
public void checkValidReferences(MTSpace space) {
366366
for (MTDEntity domainEntity : domainEntities) {
367367
if (domainEntity.getEntity() == null) {
368-
ECLog.logFatal(domainEntity, "Could not find entity: " + domainEntity.getEntityName());
368+
//ECLog.logFatal(domainEntity, "Could not find entity: " + domainEntity.getEntityName());
369369
}
370370
}
371371
}

src/main/java/org/entityc/compiler/model/entity/MTCompositeEntity.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ public class MTCompositeEntity extends MTEntity {
1212
public static final String ObjectTag = "object";
1313
public static final String VersionTag = "version";
1414
public static final String ReleaseTag = "release";
15+
public static final String BinderTag = "binder";
1516

1617
Map<String,MTEntity> constituentEntities = new HashMap<>();
1718

1819
public MTCompositeEntity(ParserRuleContext ctx, MTModule module, String name) {
1920
super(ctx, module, name);
2021
}
2122

22-
private void addConstituentEntity(String tag, MTEntity entity) {
23+
public void addConstituentEntity(String tag, MTEntity entity) {
2324
if (this.constituentEntities.containsKey(tag) ) {
2425
if (!this.constituentEntities.get(tag).name.equals(entity.name)) {
2526
ECLog.logFatal("This composite entity " + this.name + " is already associated to a different entity with the " + tag + " tag.");
@@ -34,6 +35,38 @@ public MTEntity getConstituentEntity(String tag) {
3435
return constituentEntities.get(tag);
3536
}
3637

38+
public boolean hasConstituentEntity(String tag) {
39+
return constituentEntities.containsKey(tag);
40+
}
41+
42+
public MTEntity getAnyConstituentEntity(String tag) {
43+
MTEntity constituentEntity = constituentEntities.get(tag);
44+
if (constituentEntity != null) {
45+
return constituentEntity;
46+
}
47+
ECLog.logInfo("getAnyConstituentEntity(" + tag + ") Checking relationships for " + getName() + "...");
48+
for (MTRelationship relationship : getRelationships()) {
49+
MTEntity toEntity = relationship.getTo().getEntity();
50+
if (toEntity.hasTag("release:top") && tag.equals(ReleaseTag)) {
51+
return toEntity;
52+
}
53+
if (toEntity == null || !toEntity.isCompositeEntity()) {
54+
ECLog.logInfo(" Relationship " + relationship.getName() + " to entity " + toEntity.getName() + " is not to a composite entity.");
55+
continue;
56+
}
57+
MTEntity compositeToEntity = ((MTCompositeEntity)toEntity).getAnyConstituentEntity(tag);
58+
if (compositeToEntity != null) {
59+
return compositeToEntity;
60+
}
61+
}
62+
ECLog.logInfo(" Unable to find child constituent entity!");
63+
return null;
64+
}
65+
66+
public boolean hasAnyConstituentEntity(String tag) {
67+
return getAnyConstituentEntity(tag) != null;
68+
}
69+
3770
public void addAttribute(String tag, MTAttribute attribute, MTEntity fromEntity) {
3871
addConstituentEntity(tag, fromEntity);
3972
MTAttribute constituentAttribute = MTAttribute.Copy(attribute, this);

src/main/java/org/entityc/compiler/model/entity/MTEntity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public String getName() {
8787
@ModelMethod(category = ModelMethodCategory.ENTITY,
8888
description = "Adds the entity to a realm.")
8989
public void addRealm(String realm) {
90-
ECLog.logInfo("Added entity: " + getName() + " to realm " + realm);
90+
//ECLog.logInfo("Added entity: " + getName() + " to realm " + realm);
9191
realms.add(realm);
9292
}
9393

@@ -97,6 +97,12 @@ public boolean isInRealm(String realm) {
9797
return this.realms.contains(realm);
9898
}
9999

100+
@ModelMethod(category = ModelMethodCategory.ENTITY,
101+
description = "Returns true if this entity is a composite entity.")
102+
public boolean isCompositeEntity() {
103+
return this instanceof MTCompositeEntity;
104+
}
105+
100106
public static MTEntity AddImplicitManyToManyEntity(MTSpace space, MTEntity fromEntity, MTEntity toEntity) {
101107
MTEntity combinedEntity = CombineEntities(fromEntity, toEntity);
102108
MTEntity alreadyCreatedEntity = space.getEntityWithName(combinedEntity.getName());

src/main/java/org/entityc/compiler/model/entity/MTRelationship.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ protected MTRelationship(String secondaryName, MTRelationship primaryRelationshi
7979
this.templateArgName = primaryRelationship.templateArgName;
8080
}
8181

82+
@Override
83+
public String toString() {
84+
return getFrom().getEntityName() + "." + getName() + " -(" + to.getPlurality().toString() + ")-> " + getTo().getEntityName();
85+
}
8286
public static MTRelationship Copy(MTRelationship relationship, MTEntity newFromEntity, MTEntity newToEntity) {
8387

8488
MTRelationshipHalf fromHalf = new MTRelationshipHalf(relationship.getParserRuleContext(),
@@ -326,7 +330,7 @@ public boolean resolveReferences(MTSpace space, int pass) {
326330
}
327331
else {
328332
// good unnamed pairing
329-
System.out.println("unnamed Relationship \"" + getName() + "\" pairing between " + from.getEntityName() + "." + this.getName() + " and " + to.getEntityName() + "." + fromRelationship.getName());
333+
//System.out.println("unnamed Relationship \"" + getName() + "\" pairing between " + from.getEntityName() + "." + this.getName() + " and " + to.getEntityName() + "." + fromRelationship.getName());
330334
this.reverseRelationship = fromRelationship;
331335
this.from.setPlurality(fromRelationship.to.getPlurality());
332336
found = true;

src/main/java/org/entityc/compiler/transform/MTVImplicitTransform.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ public void visitRelationship(MTRelationship relationship) {
7777
// if this is a realm based transform then make sure we are operating on entities from that realm.
7878
if (realm != null) {
7979
if (!(fromEntity instanceof MTCompositeEntity) && (toEntity instanceof MTCompositeEntity)) {
80-
ECLog.logInfo("(wrong class) REALM " + realm + ": not processing fromEntity: " + fromEntity.getName() + " toEntity: " + toEntity.getName());
80+
//ECLog.logInfo("(wrong class) REALM " + realm + ": not processing fromEntity: " + fromEntity.getName() + " toEntity: " + toEntity.getName());
8181
return;
8282
}
8383
if (!fromEntity.isInRealm(realm) || !toEntity.isInRealm(realm)) {
84-
ECLog.logInfo("(wrong realm) REALM " + realm + ": not processing fromEntity: " + fromEntity.getName() + " toEntity: " + toEntity.getName());
84+
//ECLog.logInfo("(wrong realm) REALM " + realm + ": not processing fromEntity: " + fromEntity.getName() + " toEntity: " + toEntity.getName());
8585
return;
8686
}
87-
ECLog.logInfo("REALM " + realm + ": PROCESSING fromEntity: " + fromEntity.getName() + " toEntity: " + toEntity.getName());
87+
//ECLog.logInfo("REALM " + realm + ": PROCESSING fromEntity: " + fromEntity.getName() + " toEntity: " + toEntity.getName());
8888
}
8989

9090
MTPrimaryKey toPrimaryKey = toEntity.getPrimaryKey();

0 commit comments

Comments
 (0)