Skip to content

Commit 533175a

Browse files
author
Bob Garner
committed
Added support for Released Transform.
This will merge “object” and “version” tagged entities along with a “release” entity into a single Released entity.
1 parent d2cdba9 commit 533175a

20 files changed

+466
-44
lines changed

docs/emc/EMC_domain.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Model classes that are domain specific are of this type. The classes are briefly
1111
|[`MTDEAttribute`](#class_MTDEAttribute)|Represents an attribute in your model in the context of a domain.|
1212
|[`MTDEAttributeConstraintExpression`](#class_MTDEAttributeConstraintExpression)|Represents a constraint on an attribute in the form of an expression.|
1313
|[`MTDERelationship`](#class_MTDERelationship)|Represents a relationship in your model in the context of a domain.|
14+
|[`MTDERelationshipField`](#class_MTDERelationshipField)|Represents a field (attribute or relationship) associated with the __to__ entity of the relationship.|
1415
|[`MTDEntity`](#class_MTDEntity)|Represents an entity in your model in the context of a domain.|
1516
|[`MTDEnum`](#class_MTDEnum)|Represents an enum in the context of a domain.|
1617
|[`MTDEnumItem`](#class_MTDEnumItem)|Represents an enum item in the context of a domain.|
@@ -236,6 +237,12 @@ If this relationship was explicitly renamed within its domain, it will return th
236237

237238
<hr/>
238239

240+
#### `Collection` **`fields`**
241+
242+
Returns all the declared fields of this relationship.
243+
244+
<hr/>
245+
239246
#### `String fullname(String delim)`
240247

241248
This returns the full name of this domain relationship which includes not only its domain based name but is also preceded with the domain's entity's full name. The delimiter can be provided which is used between all parts of the full name.
@@ -551,6 +558,18 @@ Returns the domain specific version of the specified relationship.
551558

552559
<hr/>
553560

561+
#### `boolean` **`hasDeclaredDomainRelationships`**
562+
563+
Indicates if any relationships were declared in this domain entity declaration.
564+
565+
<hr/>
566+
567+
#### `boolean` **`hasParentRelationship`**
568+
569+
Indicates whether this domain entity has a parent relationship. A parent relationship is one that has been declared as `parent`
570+
571+
<hr/>
572+
554573
#### `boolean` **`hasPrimaryParentRelationship`**
555574

556575
Indicates whether this domain entity has a primary parent relationship. A primary parent relationship is one that has been declared as `parent` and **not** declared `optional`.

docs/emc/EMC_entity.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,16 @@ These methods relate to an entity.
355355

356356
<hr/>
357357

358+
#### `void addRealm(String realm)`
359+
360+
Adds the entity to a realm.
361+
362+
| Parameter | Description |
363+
|-----|-----|
364+
|`String realm` | *no description* |
365+
366+
<hr/>
367+
358368
#### `boolean` **`isDeclaredAsPrimary`**
359369

360370
Indicates whether this entity was **declared** `primary`. If the entity was **not** declared with the `primary` keyword then this will return false even if it is implied as primary.
@@ -379,6 +389,16 @@ Indicates whether this entity was created by the compiler because it represents
379389

380390
<hr/>
381391

392+
#### `boolean isInRealm(String realm)`
393+
394+
Returns true if this entity is part of a realm.
395+
396+
| Parameter | Description |
397+
|-----|-----|
398+
|`String realm` | *no description* |
399+
400+
<hr/>
401+
382402
#### `boolean` **`isPrimary`**
383403

384404
Indicates whether this entity was declared `primary` or if it was inferred as primary. If an entity has a primary key it is inferred to be a primary entity.
@@ -848,6 +868,16 @@ Indicates whether this entity has at least one relationship with the specified t
848868

849869
<hr/>
850870

871+
#### `boolean hasRelationshipToEntityNamed(String toEntityName)`
872+
873+
Indicates whether this entity has at least one relationship to a named other entity.
874+
875+
| Parameter | Description |
876+
|-----|-----|
877+
|`String toEntityName` | The name of the other entity. |
878+
879+
<hr/>
880+
851881
#### `boolean hasRelationshipToEntityTagged(String tag)`
852882

853883
Indicates whether the entity **to** which a relationship references is tagged with the specified tag.
@@ -924,6 +954,16 @@ Indicates whether this was declared as `extern`.
924954

925955
<hr/>
926956

957+
#### `MTEnumItem item(Long index)`
958+
959+
Returns an item by its index.
960+
961+
| Parameter | Description |
962+
|-----|-----|
963+
|`Long index` | *no description* |
964+
965+
<hr/>
966+
927967
#### `List` **`items`**
928968

929969
Gets the enum items.
@@ -1366,6 +1406,12 @@ Indicates whether this type is both an array type and also `byte` data type.
13661406

13671407
<hr/>
13681408

1409+
#### `boolean` **`isDataType`**
1410+
1411+
Indicates whether this type is the `data` data type.
1412+
1413+
<hr/>
1414+
13691415
#### `boolean` **`isDateType`**
13701416

13711417
Indicates whether this type is the `date` data type.

docs/emc/EMC_foundation.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ Returns the first item in the array.
7575

7676
<hr/>
7777

78+
#### `Object get(Integer index)`
79+
80+
Returns the specified item by its index into the array.
81+
82+
| Parameter | Description |
83+
|-----|-----|
84+
|`Integer index` | The index into the array that points to the item to be returned. |
85+
86+
<hr/>
87+
7888
#### `Object get(Long index)`
7989

8090
Returns the specified item by its index into the array.

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,7 @@
2323
import org.entityc.compiler.model.config.MTTemplate;
2424
import org.entityc.compiler.model.config.MTTransform;
2525
import org.entityc.compiler.model.domain.*;
26-
import org.entityc.compiler.model.entity.HalfRelationshipPlurality;
27-
import org.entityc.compiler.model.entity.MTAttribute;
28-
import org.entityc.compiler.model.entity.MTAttributeConstraint;
29-
import org.entityc.compiler.model.entity.MTBitField;
30-
import org.entityc.compiler.model.entity.MTEntity;
31-
import org.entityc.compiler.model.entity.MTEntityTemplate;
32-
import org.entityc.compiler.model.entity.MTEntityTemplateInstantiation;
33-
import org.entityc.compiler.model.entity.MTEnum;
34-
import org.entityc.compiler.model.entity.MTEnumItem;
35-
import org.entityc.compiler.model.entity.MTNativeType;
36-
import org.entityc.compiler.model.entity.MTPrimaryKey;
37-
import org.entityc.compiler.model.entity.MTRelationship;
38-
import org.entityc.compiler.model.entity.MTTagSet;
39-
import org.entityc.compiler.model.entity.MTTypedef;
40-
import org.entityc.compiler.model.entity.MTUnit;
41-
import org.entityc.compiler.model.entity.MTView;
26+
import org.entityc.compiler.model.entity.*;
4227
import org.entityc.compiler.model.expression.MTConstant;
4328
import org.entityc.compiler.model.expression.MTExpression;
4429
import org.entityc.compiler.model.expression.MTMethodCall;
@@ -1652,6 +1637,7 @@ public Object visitDomainNaming(EntityLanguageParser.DomainNamingContext ctx) {
16521637
} else if (namingClassContext.MODULE() != null) {
16531638
classesWithNaming.add(MTModule.class);
16541639
} else if (namingClassContext.ENTITY() != null) {
1640+
classesWithNaming.add(MTCompositeEntity.class);
16551641
classesWithNaming.add(MTEntity.class);
16561642
classesWithNaming.add(MTView.class);
16571643
} else if (namingClassContext.ATTRIBUTE() != null) {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.entityc.compiler.repository.RepositoryFile;
2525
import org.entityc.compiler.repository.RepositoryImportManager;
2626
import org.entityc.compiler.transform.MTBaseTransform;
27+
import org.entityc.compiler.transform.MTVImplicitTransform;
28+
import org.entityc.compiler.transform.MTVReleasedTransform;
2729
import org.entityc.compiler.transform.TransformManager;
2830
import org.entityc.compiler.transform.template.FileTemplateTransform;
2931
import org.entityc.compiler.transform.template.TemplatePublishing;
@@ -132,8 +134,9 @@ public static void RunTransforms(MTRoot root, MTConfiguration configuration) {
132134
root.resolveReferences(false);
133135
//model.processAssetAttributes();
134136
root.getSpace().checkValidReferences();
137+
final String ImplicitTransformName = "Implicit";
135138

136-
TransformManager.GetTransformByName("Implicit").start();
139+
TransformManager.GetTransformByName(ImplicitTransformName).start(null);
137140

138141
for (MTTransform transformSpec : configuration.getTransforms()) {
139142
MTBaseTransform transform = TransformManager.GetTransformByName(transformSpec.getName());
@@ -143,8 +146,10 @@ public static void RunTransforms(MTRoot root, MTConfiguration configuration) {
143146
if (commandLine.verbose) {
144147
System.out.println("Running " + "transform" + " " + transform.getName());
145148
}
146-
transform.start();
149+
transform.start(null);
147150
}
151+
MTBaseTransform implicitTransform = TransformManager.GetTransformByName(ImplicitTransformName);
152+
((MTVImplicitTransform)implicitTransform).start(MTVReleasedTransform.realm);
148153

149154
root.resolveReferences(true);
150155
root.getSpace().checkValidReferences();

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public boolean hasDeclaredDomainAttributes() {
104104
return declaredDomainAttributes.size() > 0;
105105
}
106106

107+
@ModelMethod(category = ModelMethodCategory.RELATIONSHIP,
108+
description = "Indicates if any relationships were declared in this domain entity declaration.")
109+
public boolean hasDeclaredDomainRelationships() {
110+
return declaredDomainRelationships.size() > 0;
111+
}
112+
107113
public void addAttribute(MTAttribute attribute) {
108114
if (entity != null && entity.hasAttributeNamed(attribute.getName())) {
109115
ECLog.logFatal(attribute, "The entity already has an attribute by the name: " + attribute.getName());
@@ -564,11 +570,18 @@ public MTDEntity primaryParentEntity() {
564570

565571
@ModelMethod(category = ModelMethodCategory.RELATIONSHIP,
566572
description = "Returns the primary parent relationship of this domain entity. A primary parent "
567-
+ "relationship is one that has been declared as `parent` and **not** declared `optional`.")
573+
+ "relationship is one that has been declared as `parent` and **not** declared `optional`.")
568574
public MTDERelationship primaryParentRelationship() {
569575
return getDomainEntityRelationshipByName(entity.getPrimaryParentRelationship().getName(), true);
570576
}
571577

578+
@ModelMethod(category = ModelMethodCategory.RELATIONSHIP,
579+
description = "Indicates whether this domain entity has a parent relationship. A parent "
580+
+ "relationship is one that has been declared as `parent`")
581+
public boolean hasParentRelationship() {
582+
return entity != null && entity.hasParentRelationship();
583+
}
584+
572585
public MTDView getDomainEntityViewByName(String viewName, boolean createIfNeeded) {
573586
MTDView domainEntityView = domainViewMap.get(viewName);
574587
if (domainEntityView == null && domain.getParentDomain() != null) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public MTAttribute(ParserRuleContext ctx, String entityName, String typeName, St
9595
protected MTAttribute(String secondaryName, MTAttribute primaryAttribute) {
9696
super(primaryAttribute.getParserRuleContext());
9797
this.name = secondaryName;
98+
this.description = primaryAttribute.getDescription();
99+
this.setSummary(primaryAttribute.getSummary());;
100+
this.setDetail(primaryAttribute.getDetail());;
98101
this.entityName = primaryAttribute.entityName;
99102
this.entity = primaryAttribute.entity;
100103
this.unit = primaryAttribute.unit;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.entityc.compiler.model.entity;
2+
3+
import org.antlr.v4.runtime.ParserRuleContext;
4+
import org.entityc.compiler.model.MTModule;
5+
import org.entityc.compiler.util.ECLog;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
public class MTCompositeEntity extends MTEntity {
11+
12+
public static final String ObjectTag = "object";
13+
public static final String VersionTag = "version";
14+
public static final String ReleaseTag = "release";
15+
16+
Map<String,MTEntity> constituentEntities = new HashMap<>();
17+
18+
public MTCompositeEntity(ParserRuleContext ctx, MTModule module, String name) {
19+
super(ctx, module, name);
20+
}
21+
22+
private void addConstituentEntity(String tag, MTEntity entity) {
23+
if (this.constituentEntities.containsKey(tag) ) {
24+
if (!this.constituentEntities.get(tag).name.equals(entity.name)) {
25+
ECLog.logFatal("This composite entity " + this.name + " is already associated to a different entity with the " + tag + " tag.");
26+
} else {
27+
return;
28+
}
29+
}
30+
this.constituentEntities.put(tag, entity);
31+
}
32+
33+
public MTEntity getConstituentEntity(String tag) {
34+
return constituentEntities.get(tag);
35+
}
36+
37+
public void addAttribute(String tag, MTAttribute attribute, MTEntity fromEntity) {
38+
addConstituentEntity(tag, fromEntity);
39+
MTAttribute constituentAttribute = MTAttribute.Copy(attribute, this);
40+
super.addAttribute(constituentAttribute);
41+
}
42+
}

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@
2121
import org.entityc.compiler.util.ECLog;
2222
import org.entityc.compiler.util.ECStringUtil;
2323

24-
import java.util.ArrayList;
25-
import java.util.Comparator;
26-
import java.util.HashMap;
27-
import java.util.List;
28-
import java.util.Map;
29-
import java.util.Stack;
30-
import java.util.Vector;
24+
import java.util.*;
3125
import java.util.stream.Collectors;
3226

3327
import static org.entityc.compiler.doc.annotation.ModelMethodCategory.ENTITY_TEMPLATE;
@@ -59,6 +53,7 @@ public class MTEntity extends MTType implements MTReferenceResolution, MTNamed,
5953
private int largestFieldNumber = 0;
6054
private MTSpace space;
6155
private MTAttribute manyAttribute = null; // if the entity was created from a "many <Entity> attributeName"
56+
protected Set<String> realms = new HashSet<>(); // a space entities can live in separate from the others - such as for composite entities
6257

6358
public MTEntity(ParserRuleContext ctx, MTModule module, String name) {
6459
super(ctx);
@@ -89,6 +84,19 @@ public String getName() {
8984
return name;
9085
}
9186

87+
@ModelMethod(category = ModelMethodCategory.ENTITY,
88+
description = "Adds the entity to a realm.")
89+
public void addRealm(String realm) {
90+
ECLog.logInfo("Added entity: " + getName() + " to realm " + realm);
91+
realms.add(realm);
92+
}
93+
94+
@ModelMethod(category = ModelMethodCategory.ENTITY,
95+
description = "Returns true if this entity is part of a realm.")
96+
public boolean isInRealm(String realm) {
97+
return this.realms.contains(realm);
98+
}
99+
92100
public static MTEntity AddImplicitManyToManyEntity(MTSpace space, MTEntity fromEntity, MTEntity toEntity) {
93101
MTEntity combinedEntity = CombineEntities(fromEntity, toEntity);
94102
MTEntity alreadyCreatedEntity = space.getEntityWithName(combinedEntity.getName());
@@ -929,7 +937,7 @@ public MTAttribute attributeTagged(
929937
description = "Indicates whether this entity has at least one relationship with the specified tag.")
930938
public boolean hasRelationshipTagged(
931939
@ModelMethodParameter(description = "The tag with which to search.")
932-
String tag) {
940+
String tag) {
933941
for (MTRelationship relationship : getRelationships()) {
934942
if (relationship.hasTag(tag)) {
935943
return true;
@@ -938,6 +946,20 @@ public boolean hasRelationshipTagged(
938946
return false;
939947
}
940948

949+
@ModelMethod(
950+
category = ModelMethodCategory.TAGGING,
951+
description = "Indicates whether this entity has at least one relationship to a named other entity.")
952+
public boolean hasRelationshipToEntityNamed(
953+
@ModelMethodParameter(description = "The name of the other entity.")
954+
String toEntityName) {
955+
for (MTRelationship relationship : getRelationships()) {
956+
if (relationship.getTo().getEntityName().equals(toEntityName)) {
957+
return true;
958+
}
959+
}
960+
return false;
961+
}
962+
941963
@ModelMethod(
942964
category = ModelMethodCategory.TAGGING,
943965
description = "Returns a relationship of this entity that is tagged with the specified tag.")

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public int getItemCount() {
6565
return items.size();
6666
}
6767

68+
@ModelMethod(category = ModelMethodCategory.ENUM, description = "Returns an item by its index.")
69+
public MTEnumItem getItem(Long index) {
70+
return getItem(index.intValue());
71+
}
6872
public MTEnumItem getItem(int index) {
6973
return items.get(index);
7074
}

0 commit comments

Comments
 (0)