Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.netgrif.application.engine.petrinet.domain.dataset

import org.springframework.data.mongodb.core.mapping.Document

@Document
class CaseFilterField extends Field<String> {

CaseFilterField() {
super()
}

@Override
FieldType getType() {
return FieldType.CASE_FILTER
}

@Override
Field clone() {
CaseFilterField clone = new CaseFilterField()
super.clone(clone)
return clone
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ enum FieldType {
DATETIME("dateTime"),
BUTTON("button"),
TASK_REF("taskRef"),
FILTER("filter"),
CASE_FILTER("caseFilter"),
TASK_FILTER("taskFilter"),
PROCESS_FILTER("processFilter"),
I18N("i18n"),
STRING_COLLECTION("stringCollection")

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.netgrif.application.engine.petrinet.domain.dataset

import org.springframework.data.mongodb.core.mapping.Document

@Document
class ProcessFilterField extends Field<String> {

ProcessFilterField() {
super()
}

@Override
FieldType getType() {
return FieldType.PROCESS_FILTER
}

@Override
Field clone() {
ProcessFilterField clone = new ProcessFilterField()
super.clone(clone)
return clone
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.netgrif.application.engine.petrinet.domain.dataset

import org.springframework.data.mongodb.core.mapping.Document

@Document
class TaskFilterField extends Field<String> {

TaskFilterField() {
super()
}

@Override
FieldType getType() {
return FieldType.TASK_FILTER
}

@Override
Field clone() {
TaskFilterField clone = new TaskFilterField()
super.clone(clone)
return clone
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ class ActionDelegate {
saveChangedChoices(field, targetCase, targetTask)
},
allowedNets : { cl ->
if (!(field instanceof CaseField)) // TODO make this work with FilterField as well
if (!(field instanceof CaseField))
return

def allowedNets = cl()
Expand Down Expand Up @@ -1571,7 +1571,6 @@ class ActionDelegate {
* @param icon filter case icon
* @param allowedNets List of process identifiers
* @param visibility Possible values: {@value DefaultFiltersRunner#FILTER_VISIBILITY_PRIVATE} or {@value DefaultFiltersRunner#FILTER_VISIBILITY_PUBLIC}
* @param filterMetadata metadata for filter. If no value is provided, then default value is used: {@link #defaultFilterMetadata(String)}
*
* @return created {@link Case} instance of filter
*/
Expand All @@ -1589,7 +1588,6 @@ class ActionDelegate {
* @param icon filter case icon
* @param allowedNets List of process identifiers
* @param visibility Possible values: {@value DefaultFiltersRunner#FILTER_VISIBILITY_PRIVATE} or {@value DefaultFiltersRunner#FILTER_VISIBILITY_PUBLIC}
* @param filterMetadata metadata for filter. If no value is provided, then default value is used: {@link #defaultFilterMetadata(String)}
*
* @return created {@link Case} instance of filter
*/
Expand All @@ -1608,7 +1606,6 @@ class ActionDelegate {
* @param icon filter case icon
* @param allowedNets List of process identifiers
* @param visibility Possible values: {@value DefaultFiltersRunner#FILTER_VISIBILITY_PRIVATE} or {@value DefaultFiltersRunner#FILTER_VISIBILITY_PUBLIC}
* @param filterMetadata metadata for filter. If no value is provided, then default value is used: {@link #defaultFilterMetadata(String)}
*
* @return created {@link Case} instance of filter
*/
Expand Down Expand Up @@ -1663,26 +1660,6 @@ class ActionDelegate {
]
])
},
allowedNets : { cl ->
String currentQuery = workflowService.findOne(filter.stringId).dataSet[DefaultFiltersRunner.FILTER_FIELD_ID].value
updateFilter(filter, [
(DefaultFiltersRunner.FILTER_FIELD_ID): [
"type" : "filter",
"value" : currentQuery,
"allowedNets": cl() as List<String>
]
])
},
filterMetadata: { cl ->
String currentQuery = workflowService.findOne(filter.stringId).dataSet[DefaultFiltersRunner.FILTER_FIELD_ID].value
updateFilter(filter, [
(DefaultFiltersRunner.FILTER_FIELD_ID): [
"type" : "filter",
"value" : currentQuery,
"filterMetadata": cl() as Map<String, Object>
]
])
},
title : { cl ->
filter = workflowService.findOne(filter.stringId)
def value = cl()
Expand Down Expand Up @@ -2043,7 +2020,6 @@ class ActionDelegate {
* identifier where the role exists
* @param itemCaseDefaultHeaders List of headers displayed in case view
* @param itemTaskDefaultHeaders List of headers displayed in task view
* @param filterMetadata metadata for filter. If no value is provided, then default value is used: {@link #defaultFilterMetadata(String)}
*
* @return created {@link Case} instance of menu_item
* */
Expand Down Expand Up @@ -2077,7 +2053,6 @@ class ActionDelegate {
* @param filterVisibility possible values: {@value DefaultFiltersRunner#FILTER_VISIBILITY_PRIVATE} or
* {@value DefaultFiltersRunner#FILTER_VISIBILITY_PUBLIC}
* @param filterAllowedNets List of allowed nets. Element of list is process identifier
* @param filterMetadata metadata for filter. If no value is provided, then default value is used: {@link #defaultFilterMetadata(String)}
*
* @return created {@link Case} instance of menu_item
* */
Expand Down Expand Up @@ -2470,7 +2445,6 @@ class ActionDelegate {
* identifier where the role exists
* @param itemCaseDefaultHeaders List of headers displayed in case view
* @param itemTaskDefaultHeaders List of headers displayed in task view
* @param filterMetadata metadata for filter. If no value is provided, then default value is used: {@link #defaultFilterMetadata(String)}
*
* @return created or updated menu item instance along with the actual filter
* */
Expand Down Expand Up @@ -2521,7 +2495,6 @@ class ActionDelegate {
* @param filterVisibility possible values: {@value DefaultFiltersRunner#FILTER_VISIBILITY_PRIVATE} or
* {@value DefaultFiltersRunner#FILTER_VISIBILITY_PUBLIC}
* @param filterAllowedNets List of allowed nets. Element of list is process identifier
* @param filterMetadata metadata for filter. If no value is provided, then default value is used: {@link #defaultFilterMetadata(String)}
*
* @return created or updated menu item instance along with the actual filter
* */
Expand All @@ -2534,10 +2507,7 @@ class ActionDelegate {
filterBody.setTitle(body.getMenuName())
filterBody.setQuery(filterQuery)
filterBody.setType(filterType)
filterBody.setAllowedNets(filterAllowedNets)
filterBody.setIcon(body.getMenuIcon())
filterBody.setVisibility(filterVisibility)
filterBody.setMetadata(filterMetadata as Map<String, Object>)
body.setView(createLegacyMenuItemViews(filterBody))

return menuItemService.createOrUpdateMenuItem(body)
Expand Down Expand Up @@ -2571,10 +2541,7 @@ class ActionDelegate {
filterBody.setTitle(body.getMenuName())
filterBody.setQuery(filterQuery)
filterBody.setType(filterType)
filterBody.setAllowedNets(filterAllowedNets)
filterBody.setIcon(body.getMenuIcon())
filterBody.setVisibility(filterVisibility)
filterBody.setMetadata(filterMetadata as Map<String, Object>)

body.setView(createLegacyMenuItemViews(filterBody))

Expand All @@ -2593,10 +2560,6 @@ class ActionDelegate {
return menuItemService.updateMenuItem(item, body)
}

static Map defaultFilterMetadata(String type) {
return FilterBody.getDefaultMetadata(type)
}

void removeChildItemFromParent(String folderId, Case childItem) {
menuItemService.removeChildItemFromParent(folderId, childItem)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ public static String parseEnumerationMapValue(Case useCase, String fieldId) {
}

// TODO: refactor this shit
Field getField(Data data, Importer importer) throws IllegalArgumentException, MissingIconKeyException {
Field field;
Field<?> getField(Data data, Importer importer) throws IllegalArgumentException, MissingIconKeyException {
Field<?> field;
switch (data.getType()) {
case TEXT:
field = buildTextField(data);
Expand Down Expand Up @@ -248,8 +248,15 @@ Field getField(Data data, Importer importer) throws IllegalArgumentException, Mi
case MULTICHOICE_MAP:
field = buildMultichoiceMapField(data, importer);
break;
case FILTER:
field = buildFilterField(data);
case FILTER: // "FILTER" is deprecated
case CASE_FILTER:
field = buildCaseFilterField(data);
break;
Comment on lines +251 to +254
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Don't coerce every legacy FILTER import into a case filter.

Lines 251-254 currently map the deprecated FILTER type straight to CaseFilterField, so any legacy task/process filter imported through the old generic type will silently change behavior during migration. Please infer the dedicated filter field type from the legacy definition before constructing it, or fail fast when that information is unavailable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/com/netgrif/application/engine/importer/service/FieldFactory.java`
around lines 251 - 254, The code in FieldFactory currently maps the deprecated
FILTER token directly to buildCaseFilterField, which will misclassify legacy
filters; update the FILTER branch in the switch inside FieldFactory to inspect
the incoming legacy definition (e.g., a "filterType" discriminator or other
distinguishing attributes on the data object) and route to the correct builder
(e.g., buildCaseFilterField or the task/process-specific builder), and if the
discriminator is missing or ambiguous, fail fast by throwing a descriptive
exception rather than silently coercing; reference the FILTER and CASE_FILTER
enum values and the buildCaseFilterField method when implementing the
discriminator check and error path.

case TASK_FILTER:
field = buildTaskFilterField(data);
break;
case PROCESS_FILTER:
field = buildProcessFilterField(data);
break;
case I_18_N:
field = buildI18nField(data, importer);
Expand Down Expand Up @@ -549,13 +556,22 @@ private FileListField buildFileListField(Data data) {
return fileListField;
}

private FilterField buildFilterField(Data data) {
AllowedNets nets = data.getAllowedNets();
if (nets == null) {
return new FilterField();
} else {
return new FilterField(new ArrayList<>(nets.getAllowedNet()));
}
private CaseFilterField buildCaseFilterField(Data data) {
CaseFilterField field = new CaseFilterField();
setDefaultValue(field, data, field::setDefaultValue);
return field;
}

private TaskFilterField buildTaskFilterField(Data data) {
TaskFilterField field = new TaskFilterField();
setDefaultValue(field, data, field::setDefaultValue);
return field;
}

private ProcessFilterField buildProcessFilterField(Data data) {
ProcessFilterField field = new ProcessFilterField();
setDefaultValue(field, data, field::setDefaultValue);
return field;
}

private I18nField buildI18nField(Data data, Importer importer) {
Expand Down Expand Up @@ -611,8 +627,6 @@ private Field buildField(Case useCase, String fieldId, boolean withValidation, S
resolveMapOptions((MapOptionsField) field, useCase);
if (field instanceof FieldWithAllowedNets)
resolveAllowedNets((FieldWithAllowedNets) field, useCase);
if (field instanceof FilterField)
resolveFilterMetadata((FilterField) field, useCase);
if (withValidation)
resolveValidations(field, useCase);
return field;
Expand Down Expand Up @@ -661,13 +675,6 @@ private void resolveAllowedNets(FieldWithAllowedNets field, Case useCase) {
field.setAllowedNets(allowedNets);
}

private void resolveFilterMetadata(FilterField field, Case useCase) {
Map<String, Object> metadata = useCase.getDataField(field.getImportId()).getFilterMetadata();
if (metadata == null)
return;
field.setFilterMetadata(metadata);
}

public Field buildImmediateField(Case useCase, String fieldId) {
Field field = useCase.getPetriNet().getDataSet().get(fieldId).clone();
resolveDataValues(field, useCase, fieldId);
Expand Down Expand Up @@ -788,14 +795,10 @@ private void parseFileListValue(FileListField field, Case useCase, String fieldI

private void resolveAttributeValues(Field field, Case useCase, String fieldId) {
DataField dataField = useCase.getDataSet().get(fieldId);
if (field.getType().equals(FieldType.CASE_REF) || field.getType().equals(FieldType.FILTER)) {
if (field.getType().equals(FieldType.CASE_REF)) {
List<String> allowedNets = new ArrayList<>(dataField.getAllowedNets());
((FieldWithAllowedNets) field).setAllowedNets(allowedNets);
}
if (field.getType().equals(FieldType.FILTER)) {
Map<String, Object> filterMetadata = new HashMap<>(dataField.getFilterMetadata());
((FilterField) field).setFilterMetadata(filterMetadata);
}
}

private <T> void setDefaultValue(Field<T> field, Data data, Consumer<String> setDefault) {
Expand Down
Loading
Loading