Skip to content

Commit

Permalink
misc updates 3
Browse files Browse the repository at this point in the history
  • Loading branch information
seed-master committed Sep 24, 2023
1 parent 862a89e commit a14b70f
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 154 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/seed/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class C {
public static final String ACTION = "action";
public static final String ANALYSIS = "analysis";
public static final String ANNOTATION = "annotation";
public static final String AUTOLAYOUT = "autoLayout";
public static final String BASE = "base";
public static final String CASCADE = "cascade";
public static final String CHUNKSIZE = "chunkSize";
Expand Down
46 changes: 24 additions & 22 deletions src/main/java/org/seed/core/entity/EntityRelation.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public void setName(String name) {

@XmlAttribute
public String getRelatedEntityUid() {
return relatedEntity != null ? relatedEntity.getUid() : relatedEntityUid;
return relatedEntity != null
? relatedEntity.getUid()
: relatedEntityUid;
}

public void setRelatedEntityUid(String relatedEntityUid) {
Expand All @@ -101,7 +103,9 @@ public void setRelatedEntityUid(String relatedEntityUid) {

@JsonIgnore
public String getInternalName() {
return name != null ? NameUtils.getInternalName(name).toLowerCase() : null;
return name != null
? NameUtils.getInternalName(name).toLowerCase()
: null;
}

@JsonIgnore
Expand Down Expand Up @@ -146,12 +150,10 @@ public boolean isEqual(Object other) {

public EntityRelation createInverseRelation(Entity relatedEntity) {
Assert.notNull(relatedEntity, "related entity");
if (entity.isGeneric()) {
Assert.stateAvailable(derivedEntity, "derived entity");

return createRelation(derivedEntity, relatedEntity);
}
return createRelation(entity, relatedEntity);

return entity.isGeneric()
? createRelation(getDerivedEntity(), relatedEntity)
: createRelation(entity, relatedEntity);
}

public EntityRelation createDescendantRelation(Entity descendantEntity) {
Expand All @@ -160,26 +162,26 @@ public EntityRelation createDescendantRelation(Entity descendantEntity) {
return createRelation(descendantEntity, relatedEntity);
}

void setDerivedEntity(Entity realEntity) {
this.derivedEntity = realEntity;
void setDerivedEntity(Entity derivedEntity) {
this.derivedEntity = derivedEntity;
}

private Entity getDerivedEntity() {
Assert.stateAvailable(derivedEntity, "derived entity");

return derivedEntity;
}

boolean isEntityAudited() {
if (entity.isGeneric()) {
Assert.stateAvailable(derivedEntity, "derived entity");

return derivedEntity.isAudited();
}
return entity.isAudited();
return entity.isGeneric()
? getDerivedEntity().isAudited()
: entity.isAudited();
}

private String getEntityTableName() {
if (entity.isGeneric()) {
Assert.stateAvailable(derivedEntity, "derived entity");

return derivedEntity.getEffectiveTableName();
}
return entity.getEffectiveTableName();
return entity.isGeneric()
? getDerivedEntity().getEffectiveTableName()
: entity.getEffectiveTableName();
}

private static EntityRelation createRelation(Entity entity, Entity relatedEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,9 @@ else if (entity.hasStatus()) {
buildNesteds();
}

// relations
if (!entity.isGeneric() && entity.hasAllRelations()) {
buildRelations();
}

// entityId
// relations / entityId
if (!entity.isGeneric()) {
buildRelations();
buildEntityIdGetter();
}

Expand All @@ -173,7 +169,7 @@ else if (entity.hasStatus()) {
}

// relation methods
if (!entity.isGeneric() && entity.hasAllRelations()) {
if (!entity.isGeneric()) {
buildRelationMethods();
}

Expand Down Expand Up @@ -271,7 +267,7 @@ else if (entity.hasStatus()) {
}
});
}
if (!entity.isGeneric() && entity.hasAllRelations()) {
if (!entity.isGeneric()) {
entity.getAllRelations().forEach(relation ->
addGetterAndSetter(relation.getInternalName()));
}
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/org/seed/core/entity/doc/ERDiagramBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ private static void buildEntity(StringBuilder buf, Entity entity) {
buf.append("entity ").append(entity.getEffectiveTableName()).append(" {\n")
.append(SystemField.ID.columName).append(COLON).append("number <<generated>>\n")
.append("--\n");
if (entity.hasAllFields()) {
entity.getAllFields().forEach(field -> buildField(buf, field));
}
entity.getAllFields().forEach(field -> buildField(buf, field));

buildSystemField(buf, SystemField.CREATEDBY);
buildSystemField(buf, SystemField.CREATEDON);
buildSystemField(buf, SystemField.MODIFIEDBY);
Expand All @@ -62,9 +61,7 @@ private static void buildEntity(StringBuilder buf, Entity entity) {
}

private static void buildRelationEntities(StringBuilder buf, Entity entity) {
if (entity.hasAllRelations()) {
entity.getAllRelations().forEach(relation -> buildRelationEntity(buf, relation));
}
entity.getAllRelations().forEach(relation -> buildRelationEntity(buf, relation));
}

private static void buildRelationEntity(StringBuilder buf, EntityRelation relation) {
Expand All @@ -75,23 +72,19 @@ private static void buildRelationEntity(StringBuilder buf, EntityRelation relati
}

private static void buildReferences(StringBuilder buf, Entity entity) {
if (entity.hasAllFields()) {
filterAndForEach(entity.getAllFields(),
EntityField::isReferenceField,
field -> buildReference(buf, field));
}
filterAndForEach(entity.getAllFields(),
EntityField::isReferenceField,
field -> buildReference(buf, field));
}

private static void buildReference(StringBuilder buf, EntityField field) {
buf.append(field.getEntity().getEffectiveTableName()).append(" }o..")
.append(field.isMandatory() ? "||" : "o|")
.append(field.getReferenceEntity().getEffectiveTableName()).append("\n\n");
.append(field.isMandatory() ? "||" : "o|")
.append(field.getReferenceEntity().getEffectiveTableName()).append("\n\n");
}

private static void buildRelations(StringBuilder buf, Entity entity) {
if (entity.hasAllRelations()) {
entity.getAllRelations().forEach(relation -> buildRelation(buf, relation));
}
entity.getAllRelations().forEach(relation -> buildRelation(buf, relation));
}

private static void buildRelation(StringBuilder buf, EntityRelation relation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,24 @@ public void initObject(Transfer transfer) throws ValidationException {
public List<TransferElement> getAvailableElements(Transfer transfer, List<TransferElement> elements) {
Assert.notNull(transfer, C.TRANSFER);
Assert.notNull(elements, ELEMENTS);

final var entity = transfer.getEntity();
final var result = new ArrayList<TransferElement>();
if (entity.hasAllFields()) {
boolean identifierFound = false;
for (EntityField entityField : entity.getAllFields()) {
// skip non-transferable types
if (entityField.getType().isBinary() ||
entityField.getType().isFile() ||
entityField.isReferenceField()) {
continue;
}
if (!anyMatch(elements, elem -> entityField.equals(elem.getEntityField()))) {
final var element = createElement(transfer, entityField);
if (entityField.isUnique() && !identifierFound) {
element.setIdentifier(true);
identifierFound = true;
}
result.add(element);

boolean identifierFound = false;
for (EntityField entityField : entity.getAllFields()) {
// skip non-transferable types
if (entityField.getType().isBinary() ||
entityField.getType().isFile() ||
entityField.isReferenceField()) {
continue;
}
if (!anyMatch(elements, elem -> entityField.equals(elem.getEntityField()))) {
final var element = createElement(transfer, entityField);
if (entityField.isUnique() && !identifierFound) {
element.setIdentifier(true);
identifierFound = true;
}
result.add(element);
}
}
return result;
Expand All @@ -182,21 +180,19 @@ public List<TransferElement> getAvailableElements(Transfer transfer, List<Transf
public List<TransferElement> getAvailableNestedElements(NestedTransfer nestedTransfer, List<TransferElement> elements) {
Assert.notNull(nestedTransfer, "NestedTransfer");
Assert.notNull(elements, ELEMENTS);

final var entity = nestedTransfer.getNested().getNestedEntity();
final var result = new ArrayList<TransferElement>();
if (entity.hasAllFields()) {
for (EntityField entityField : entity.getAllFields()) {
if (entityField.getType().isBinary() ||
entityField.getType().isFile() ||
entityField.isReferenceField()) {
continue;
}
if (!anyMatch(elements, elem -> entityField.equals(elem.getEntityField()))) {
final var element = new TransferElement();
element.setEntityField(entityField);
result.add(element);
}

for (EntityField entityField : entity.getAllFields()) {
if (entityField.getType().isBinary() ||
entityField.getType().isFile() ||
entityField.isReferenceField()) {
continue;
}
if (!anyMatch(elements, elem -> entityField.equals(elem.getEntityField()))) {
final var element = new TransferElement();
element.setEntityField(entityField);
result.add(element);
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,20 +457,17 @@ public boolean autoMatchFields(Transformer transformer, List<TransformerElement>
Assert.notNull(elements, "elements");

boolean matched = false;
if (transformer.getSourceEntity().hasAllFields() &&
transformer.getTargetEntity().hasAllFields()) {
for (EntityField sourceField : transformer.getSourceEntity().getAllFields()) {
for (EntityField targetField : transformer.getTargetEntity().getAllFields()) {
if (sourceField.getType() == targetField.getType() &&
sourceField.getName().equalsIgnoreCase(targetField.getName()) &&
!containsElement(elements, sourceField, targetField)) {

final var element = createElement(sourceField, targetField);
element.setTransformer(transformer);
elements.add(element);
matched = true;
break;
}
for (EntityField sourceField : transformer.getSourceEntity().getAllFields()) {
for (EntityField targetField : transformer.getTargetEntity().getAllFields()) {
if (sourceField.getType() == targetField.getType() &&
sourceField.getName().equalsIgnoreCase(targetField.getName()) &&
!containsElement(elements, sourceField, targetField)) {

final var element = createElement(sourceField, targetField);
element.setTransformer(transformer);
elements.add(element);
matched = true;
break;
}
}
}
Expand All @@ -482,18 +479,15 @@ public boolean autoMatchFields(NestedTransformer transformer) {
Assert.notNull(transformer, C.TRANSFORMER);

boolean matched = false;
if (transformer.getSourceNested().getNestedEntity().hasAllFields() &&
transformer.getTargetNested().getNestedEntity().hasAllFields()) {
for (EntityField sourceField : transformer.getSourceNested().getFields(true)) {
for (EntityField targetField : transformer.getTargetNested().getFields(true)) {
if (sourceField.getType() == targetField.getType() &&
sourceField.getName().equalsIgnoreCase(targetField.getName()) &&
!transformer.containsElement(sourceField, targetField)) {

transformer.addElement(createElement(sourceField, targetField));
matched = true;
break;
}
for (EntityField sourceField : transformer.getSourceNested().getFields(true)) {
for (EntityField targetField : transformer.getTargetNested().getFields(true)) {
if (sourceField.getType() == targetField.getType() &&
sourceField.getName().equalsIgnoreCase(targetField.getName()) &&
!transformer.containsElement(sourceField, targetField)) {

transformer.addElement(createElement(sourceField, targetField));
matched = true;
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,8 @@ protected String getIdentifier(ValueObject object, Session session) {
private String resolveIdentifierPattern(Entity entity, ValueObject object) {
String pattern = entity.getIdentifierPattern();
pattern = pattern.replace("{entity}", entity.getName());
if (entity.hasAllFields()) {
for (EntityField field : entity.getAllFields()) {
pattern = resolveFieldPattern(field, pattern, object);
}
for (EntityField field : entity.getAllFields()) {
pattern = resolveFieldPattern(field, pattern, object);
}
if (StringUtils.hasText(pattern)) {
return pattern;
Expand Down Expand Up @@ -576,12 +574,10 @@ private Map<String, Object> getValueMap(ValueObject object, NestedEntity nestedE

private Map<String, Object> getValueMap(ValueObject object, Entity entity) {
final var valueMap = new HashMap<String, Object>();
if (entity.hasAllFields()) {
for (EntityField field : entity.getAllFields()) {
final Object value = objectAccess.getValue(object, field);
if (value != null) {
valueMap.put(field.getUid(), value);
}
for (EntityField field : entity.getAllFields()) {
final Object value = objectAccess.getValue(object, field);
if (value != null) {
valueMap.put(field.getUid(), value);
}
}
return valueMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,9 @@ private boolean setObjectValues(Session session, Entity entity, ValueObject obje

boolean isModified = false;
final var caseInsensitiveKeyMap = toCaseInsensitiveKeyMap(valueMap);
if (entity.hasAllFields()) {
for (EntityField field : entity.getAllFields()) {
if (setObjectFieldValue(session, field, object, user, caseInsensitiveKeyMap)) {
isModified = true;
}
for (EntityField field : entity.getAllFields()) {
if (setObjectFieldValue(session, field, object, user, caseInsensitiveKeyMap)) {
isModified = true;
}
}
if (entity.hasNesteds()) {
Expand Down
Loading

0 comments on commit a14b70f

Please sign in to comment.