Skip to content

Commit

Permalink
generic entity fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seed-master committed Sep 30, 2023
1 parent 067eb58 commit 98758b9
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/seed/core/entity/EntityServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ private void renamePackages(Entity entity, Entity currentVersionEntity) {
}

private void beforeSaveObject(Entity entity, Session session, boolean isInsert) {
if (!isInsert && !entity.isGeneric()) {
if (!isInsert) {
getChangeAwareObjects().forEach(aware -> aware.notifyBeforeChange(entity, session));
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/seed/core/entity/EntityValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ private void validateRemoveFieldDependent(EntityField field, EntityDependent<? e
errors.addError("val.inuse.fieldform", systemEntity.getName());
break;

case C.TRANSFER:
errors.addError("val.inuse.fieldtransfer", systemEntity.getName());
break;

case C.TRANSFORM:
errors.addError("val.inuse.fieldtransform", systemEntity.getName());
break;
Expand Down
65 changes: 38 additions & 27 deletions src/main/java/org/seed/core/form/FormActionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@
import java.util.List;

public enum FormActionType {
// first (if default is true)
// default defsel list detail subfrm tmpl-list tmpl-detail icon
CUSTOM (false, false, false, true, true, Template.SELECT, null, "z-icon-exclamation"),
OVERVIEW (true, true, false, true, false, null, null, "z-icon-arrow-left"),
BACKSEARCH (true, true, true, false, false, Template.SEARCH, null, "z-icon-arrow-left"),
SAVE (false, true, false, true, false, null, Template.DIRTY, "z-icon-save"),
REFRESH (false, true, true, true, false, null, Template.NOTNEW, "z-icon-refresh"),
SEARCH (false, true, true, true, false, null, null, "z-icon-search"),
NEWOBJECT (false, true, true, true, true, null, null, "z-icon-file-o"),
DETAIL (false, true, true, false, false, Template.SELECT, null, "z-icon-edit"),
DELETE (false, true, true, true, true, Template.SELECT, Template.NOTNEW, "z-icon-remove"),
PRINT (false, true, true, true, false, Template.PRINT, Template.PRINT, "z-icon-print"),
STATUS (true, false, true, true, false, Template.STATUS, Template.STATUS, null),
TRANSFORM (true, false, true, true, false, Template.TRANSFORM, Template.TRANSFORM, null),
SELECTCOLS (true, false, true, false, false, null, null, "z-icon-columns"),
EXPORTLIST (false, true, true, false, false, null, null, "z-icon-download");
// comes first (if default is true)
// default defsel visibility tmpl-list tmpl-detail icon
CUSTOM (false, false, detail()|sub(), Template.SELECT, null, "z-icon-exclamation"),
OVERVIEW (true, true, detail(), null, null, "z-icon-arrow-left"),
BACKSEARCH (true, true, list(), Template.SEARCH, null, "z-icon-arrow-left"),
SAVE (false, true, detail(), null, Template.DIRTY, "z-icon-save"),
REFRESH (false, true, list()|detail(), null, Template.NOTNEW, "z-icon-refresh"),
SEARCH (false, true, list()|detail(), null, null, "z-icon-search"),
NEWOBJECT (false, true, list()|detail()|sub(), null, null, "z-icon-file-o"),
DETAIL (false, true, list(), Template.SELECT, null, "z-icon-edit"),
DELETE (false, true, list()|detail()|sub(), Template.SELECT, Template.NOTNEW, "z-icon-remove"),
PRINT (false, true, list()|detail(), Template.PRINT, Template.PRINT, "z-icon-print"),
STATUS (true, false, list()|detail(), Template.STATUS, Template.STATUS, null),
TRANSFORM (true, false, list()|detail(), Template.TRANSFORM,Template.TRANSFORM, null),
SELECTCOLS (true, false, list(), null, null, "z-icon-columns"),
EXPORTLIST (false, true, list(), null, null, "z-icon-download");

private static final int VISIBILITY_LIST = 0B001;
private static final int VISIBILITY_DETAIL = 0B010;
private static final int VISIBILITY_SUBFORM = 0B100;

// if true, action is always present and can't be deseleted
public final boolean isDefault;
Expand All @@ -57,17 +61,13 @@ public enum FormActionType {

private final String icon;

private FormActionType(boolean isDefault, boolean isDefaultSelected,
boolean isVisibleAtList, boolean isVisibleAtDetail,
boolean isVisibleAtSubform,
Template listTemplate, Template detailTemplate,
String icon) {

private FormActionType(boolean isDefault, boolean isDefaultSelected, int visibility,
Template listTemplate, Template detailTemplate, String icon) {
this.isDefault = isDefault;
this.isDefaultSelected = isDefaultSelected;
this.isVisibleAtList = isVisibleAtList;
this.isVisibleAtDetail = isVisibleAtDetail;
this.isVisibleAtSubform = isVisibleAtSubform;
this.isVisibleAtList = (visibility & VISIBILITY_LIST) != 0;
this.isVisibleAtDetail = (visibility & VISIBILITY_DETAIL) != 0;
this.isVisibleAtSubform = (visibility & VISIBILITY_SUBFORM) != 0;
this.listTemplate = listTemplate;
this.detailTemplate = detailTemplate;
this.icon = icon;
Expand All @@ -85,9 +85,8 @@ public String getIcon() {
return icon;
}

// if isDefault is true
boolean comesFirst() {
return isDefaultSelected;
return isDefault && isDefaultSelected;
}

static List<FormActionType> defaultActionTypes(boolean isList, boolean comesFirst) {
Expand All @@ -98,6 +97,18 @@ static List<FormActionType> defaultActionTypes(boolean isList, boolean comesFirs
(!isList && type.isVisibleAtDetail))));
}

private static int list() {
return VISIBILITY_LIST;
}

private static int detail() {
return VISIBILITY_DETAIL;
}

private static int sub() {
return VISIBILITY_SUBFORM;
}

private enum Template {

DIRTY,
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/org/seed/core/form/FormServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,16 +579,35 @@ public void notifyBeforeChange(Entity entity, Session session) {
Assert.notNull(entity, C.ENTITY);
Assert.notNull(session, C.SESSION);

for (Form form : formRepository.find(session, queryParam(C.ENTITY, entity))) {
if (form.hasSubForms()) {
notifyBeforeChangeSubForms(form, entity, session);
}
if (form.hasFieldExtras()) {
notifyBeforeChangeFieldExtras(form, entity, session);
notifyBeforeFields(entity, session);

if (!entity.isGeneric()) {
for (Form form : formRepository.find(session, queryParam(C.ENTITY, entity))) {
if (form.hasSubForms()) {
notifyBeforeChangeSubForms(form, entity, session);
}
if (form.hasFieldExtras()) {
notifyBeforeChangeFieldExtras(form, entity, session);
}
}
}
}

private void notifyBeforeFields(Entity entity, Session session) {
final var currentVersionEntity = entityService.getObject(entity.getId());
final var query = session.createQuery("from FormField where entityField = :field");
// delete form field if entity field no longer exist
for (EntityField field : subList(currentVersionEntity.getFields(),
not(entity::containsField))) {
query.setParameter(C.FIELD, field);
final List<FormField> formFields = MiscUtils.castList(query.getResultList());
for (FormField formField : formFields) {
formField.getForm().removeField(formField);
session.saveOrUpdate(formField.getForm());
}
}
}

private void notifyBeforeChangeSubForms(Form form, Entity entity, Session session) {
// delete sub form if nested no longer exist
for (SubForm subForm : new ArrayList<>(form.getSubForms())) {
Expand Down Expand Up @@ -616,9 +635,6 @@ public void notifyChange(Entity entity, Session session) {

if (!entity.isGeneric()) {
for (Form form : findNonExpertForms(entity, session)) {
// remove field if entity field no longer exist
form.getFields().removeIf(field -> field.getEntityField() != null &&
!entity.containsAllField(field.getEntityField()));
updateFormLayout(form, entity, session);
}
// update parent entity forms (entity is used as nested entity)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/metainfo/zk-label.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ val.inuse.fieldgroupentity = Field group is still used in entity <b>"{0}"</b> in
val.inuse.fieldfilter = Field is still used in filter <b>"{0}"</b>
val.inuse.fieldform = Field is still used in form <b>"{0}"</b>
val.inuse.fieldformula = Field is still used in a calculation formula in field <b>"{0}"</b>
val.inuse.fieldtransfer = Field is still used in Import / Export <b>"{0}"</b>
val.inuse.fieldtransform = Field is still used in transformation <b>"{0}"</b>
val.inuse.fieldview = Field is still used in view <b>"{0}"</b>
val.inuse.fieldviewtype = Data type of field <b>"{0}"</b> cannot be changed because it is still used in the view <b>"{1}"</b>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/metainfo/zk-label_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ val.inuse.fieldgroupentity = Die Feldgruppe wird noch in der Entität <b>"{0}"</
val.inuse.fieldfilter = Das Feld wird noch im Filter <b>"{0}"</b> verwendet
val.inuse.fieldform = Das Feld wird noch im Formular <b>"{0}"</b> verwendet
val.inuse.fieldformula = Das Feld wird noch in einer Berechnungsformel im Feld <b>"{0}"</b> verwendet
val.inuse.fieldtransfer = Das Feld wird noch im Import / Export <b>"{0}"</b> verwendet
val.inuse.fieldtransform = Das Feld wird noch in der Transformation <b>"{0}"</b> verwendet
val.inuse.fieldview = Das Feld wird noch von der View <b>"{0}"</b> verwendet
val.inuse.fieldviewtype = Der Datentyp des Felds <b>"{0}"</b> kann nicht geändert werden, da es noch in der View <b>"{1}"</b> verwendet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ void testRemoveGenericRelation() {

@Test
@Order(13)
void testRemoveGenericField() {
WebElement tabpanel = showEntity("generictest");
assertEquals("Entitäten: GenericTest", findTab("entitaeten").getText());
findTab(tabpanel, "fields");
WebElement tabpanelFields = findTabpanel(tabpanel, "fields");
clickListItem(tabpanelFields, "generictext");
clickButton(tabpanelFields, "remove");
saveEntity(tabpanel);

pause(5000);
}

@Test
@Order(14)
void testDeleteDerivedEntity() {
WebElement tabpanel = showEntity("derivedtest");
assertEquals("Entitäten: DerivedTest", findTab("entitaeten").getText());
Expand All @@ -190,7 +204,7 @@ void testDeleteDerivedEntity() {
}

@Test
@Order(14)
@Order(15)
void testDeleteGenericEntity() {
WebElement tabpanel = showEntity("generictest");
assertEquals("Entitäten: GenericTest", findTab("entitaeten").getText());
Expand All @@ -202,7 +216,7 @@ void testDeleteGenericEntity() {
}

@Test
@Order(15)
@Order(16)
void testDeleteTransferableEntity() {
WebElement tabpanel = showEntity("transferabletestnew");
assertEquals("Entitäten: TransferableTestNew", findTab("entitaeten").getText());
Expand All @@ -214,7 +228,7 @@ void testDeleteTransferableEntity() {
}

@Test
@Order(16)
@Order(17)
void testDeleteNestedEntity() {
WebElement tabpanel = showEntity("nestedtest");
assertEquals("Entitäten: NestedTest", findTab("entitaeten").getText());
Expand All @@ -226,7 +240,7 @@ void testDeleteNestedEntity() {
}

@Test
@Order(17)
@Order(18)
void testDeleteEntity() {
WebElement tabpanel = showEntity("integrationtest");
assertEquals("Entitäten: IntegrationTest", findTab("entitaeten").getText());
Expand Down

0 comments on commit 98758b9

Please sign in to comment.