diff --git a/application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/CaseMigrationHelper.groovy b/application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/CaseMigrationHelper.groovy index f64df517c1a..74edc3612e3 100644 --- a/application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/CaseMigrationHelper.groovy +++ b/application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/CaseMigrationHelper.groovy @@ -461,7 +461,7 @@ class CaseMigrationHelper extends AbstractMigrationHelper { */ void migratePetriNet(Case useCase, PetriNet newNet, MigrationErrorPolicy errorPolicy = defaultErrorPolicy()) { log.debug("Starting migratePetriNet for case: ${useCase.stringId}, new net: ${newNet.stringId}") - ProcessResourceId newCaseId = new ProcessResourceId(newNet.getStringId(), useCase.get_id().getObjectId()) + ProcessResourceId newCaseId = new ProcessResourceId(newNet.getIdentifier(), useCase.get_id().getObjectId()) useCase.set_id(newCaseId) useCase.setPetriNetObjectId(newNet.objectId) log.trace("Updated petriNet reference for case: ${useCase.stringId} to net: ${newNet.stringId}") diff --git a/application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/TaskMigrationHelper.groovy b/application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/TaskMigrationHelper.groovy index dbb369f4249..8730ed1d25f 100644 --- a/application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/TaskMigrationHelper.groovy +++ b/application-engine/src/main/groovy/com/netgrif/application/engine/migration/helpers/TaskMigrationHelper.groovy @@ -268,6 +268,7 @@ class TaskMigrationHelper extends AbstractMigrationHelper { Task oldTask = taskService.findOne(taskPair.task) log.trace("Updating task roles and permissions for task: ${oldTask.stringId}") oldTask.setProcessId(net.stringId) + oldTask.setProcessIdentifier(net.identifier) oldTask.setRoles(newTransition.roles) oldTask.setNegativeViewRoles(newTransition.negativeViewRoles) oldTask.resolveViewRoles() diff --git a/application-engine/src/main/java/com/netgrif/application/engine/importer/service/Importer.java b/application-engine/src/main/java/com/netgrif/application/engine/importer/service/Importer.java index 31396dec463..bce35352d99 100644 --- a/application-engine/src/main/java/com/netgrif/application/engine/importer/service/Importer.java +++ b/application-engine/src/main/java/com/netgrif/application/engine/importer/service/Importer.java @@ -1057,7 +1057,7 @@ protected ProcessRole initRole(Role importRole) { if (importRole.isGlobal() != null && importRole.isGlobal()) { role.setGlobal(importRole.isGlobal()); } else { - role.set_id(new ProcessResourceId(new ObjectId(net.getStringId()))); + role.set_id(new ProcessResourceId(net.getIdentifier(), new ObjectId())); role.setProcessId(net.getStringId()); role.setProcessTitle(net.getTitle()); role.setProcessIdentifier(net.getIdentifier()); diff --git a/application-engine/src/main/java/com/netgrif/application/engine/workflow/service/TaskService.java b/application-engine/src/main/java/com/netgrif/application/engine/workflow/service/TaskService.java index 17a11676007..60e327f519b 100644 --- a/application-engine/src/main/java/com/netgrif/application/engine/workflow/service/TaskService.java +++ b/application-engine/src/main/java/com/netgrif/application/engine/workflow/service/TaskService.java @@ -886,6 +886,7 @@ private Task createFromTransition(Transition transition, Case useCase) { final Task task = com.netgrif.application.engine.adapter.spring.workflow.domain.Task.with() .title(transition.getTitle()) .processId(useCase.getPetriNetId()) + .processIdentifier(useCase.getProcessIdentifier()) .caseId(useCase.get_id().toString()) .transitionId(transition.getImportId()) .layout(transition.getLayout()) diff --git a/nae-object-library/src/main/java/com/netgrif/application/engine/objects/petrinet/domain/roles/ProcessRole.java b/nae-object-library/src/main/java/com/netgrif/application/engine/objects/petrinet/domain/roles/ProcessRole.java index 851a4974b11..758346192b5 100644 --- a/nae-object-library/src/main/java/com/netgrif/application/engine/objects/petrinet/domain/roles/ProcessRole.java +++ b/nae-object-library/src/main/java/com/netgrif/application/engine/objects/petrinet/domain/roles/ProcessRole.java @@ -63,7 +63,7 @@ public ProcessRole() { if (this.getProcessId() == null) { _id = new ProcessResourceId(); } else { - _id = new ProcessResourceId(new ObjectId(this.getProcessId())); + _id = new ProcessResourceId(processIdentifier, new ObjectId()); } } diff --git a/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Case.java b/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Case.java index e8669c691ce..18864d0ed6f 100644 --- a/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Case.java +++ b/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Case.java @@ -147,7 +147,7 @@ protected Case() { public Case(PetriNet petriNet) { this(); - this._id = new ProcessResourceId(petriNet.getObjectId()); + this._id = new ProcessResourceId(petriNet.getIdentifier(), new ObjectId()); petriNetObjectId = petriNet.getObjectId(); processIdentifier = petriNet.getIdentifier(); this.petriNet = petriNet; diff --git a/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/ProcessResourceId.java b/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/ProcessResourceId.java index abcbb4b859d..8b903315fd3 100644 --- a/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/ProcessResourceId.java +++ b/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/ProcessResourceId.java @@ -1,6 +1,7 @@ package com.netgrif.application.engine.objects.workflow.domain; import lombok.Getter; +import lombok.Setter; import org.bson.types.ObjectId; import java.io.Serial; @@ -10,6 +11,7 @@ import java.util.Objects; @Getter +@Setter public final class ProcessResourceId implements Comparable, Serializable { @Serial @@ -23,39 +25,38 @@ public final class ProcessResourceId implements Comparable, S // todo add example values to javadoc private ObjectId objectId; + + private String shortProcessIdentifier; + + @Deprecated(since = "7.0.0", forRemoval = true) private String shortProcessId; public ProcessResourceId() { this.objectId = new ObjectId(); - this.shortProcessId = NONE_SHORT_ID_VALUE; - } - - public ProcessResourceId(ObjectId processId) { - this.objectId = new ObjectId(); - this.shortProcessId = generateShortProcessId(processId.toString()); + this.shortProcessIdentifier = NONE_SHORT_ID_VALUE; } - public ProcessResourceId(String processId, String objectId) { + public ProcessResourceId(String processIdentifier, String objectId) { this.objectId = new ObjectId(objectId); - this.shortProcessId = generateShortProcessId(processId); + this.shortProcessIdentifier = generateShortProcessIdentifier(processIdentifier); } - public ProcessResourceId(String processId, ObjectId objectId) { + public ProcessResourceId(String processIdentifier, ObjectId objectId) { this.objectId = objectId; - this.shortProcessId = generateShortProcessId(processId); + this.shortProcessIdentifier = generateShortProcessIdentifier(processIdentifier); } public ProcessResourceId(String compositeId) { - String[] parts = compositeId.split("-"); + String[] parts = compositeId.split(ID_SEPARATOR); if (parts.length != 2) { throw new IllegalArgumentException("Invalid composite ID format: " + compositeId); } - this.shortProcessId = parts[0]; + this.shortProcessIdentifier = parts[0]; this.objectId = new ObjectId(parts[1]); } public String getFullId() { - return shortProcessId + ID_SEPARATOR + objectId.toHexString(); + return shortProcessIdentifier + ID_SEPARATOR + objectId.toHexString(); } public String getStringId() { @@ -75,12 +76,28 @@ public String toString() { return getFullId(); } - private static String generateShortProcessId(String processId) { - if (processId == null || processId.isEmpty()) { + public static String decodeShortProcessId(String shortProcessId) { + if (shortProcessId == null || shortProcessId.isEmpty()) { + return null; + } + BigInteger number = BigInteger.ZERO; + for (char c : shortProcessId.toCharArray()) { + number = number.multiply(CHAR_ARRAY_LENGTH); + int index = CHAR_ARRAY.indexOf(c); + if (index == -1) { + throw new IllegalArgumentException("Invalid character in short process ID: " + c); + } + number = number.add(BigInteger.valueOf(index)); + } + return number.toString(16); + } + + private static String generateShortProcessIdentifier(String processIdentifier) { + if (processIdentifier == null || processIdentifier.isEmpty()) { return null; } try { - BigInteger number = new BigInteger(processId, 16); + BigInteger number = new BigInteger(1, processIdentifier.getBytes()); StringBuilder shortIdBuilder = new StringBuilder(); while (number.compareTo(BigInteger.ZERO) > 0) { @@ -91,11 +108,11 @@ private static String generateShortProcessId(String processId) { return shortIdBuilder.reverse().toString(); } catch (NumberFormatException e) { - throw new IllegalArgumentException("Invalid input string for encoding: " + processId, e); + throw new IllegalArgumentException("Invalid input string for encoding: " + processIdentifier, e); } } - public static String decodeShortProcessId(String shortProcessId) { + public static String decodeShortProcessIdentifier(String shortProcessId) { if (shortProcessId == null || shortProcessId.isEmpty()) { return null; } @@ -108,7 +125,7 @@ public static String decodeShortProcessId(String shortProcessId) { } number = number.add(BigInteger.valueOf(index)); } - return number.toString(16); + return new String(number.toByteArray()); } @Override @@ -121,12 +138,12 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ProcessResourceId that = (ProcessResourceId) o; - return Objects.equals(objectId, that.objectId) && Objects.equals(shortProcessId, that.shortProcessId); + return Objects.equals(objectId, that.objectId) && Objects.equals(shortProcessIdentifier, that.shortProcessIdentifier); } @Override public int hashCode() { - return Objects.hash(objectId, shortProcessId); + return Objects.hash(objectId, shortProcessIdentifier); } } diff --git a/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Task.java b/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Task.java index 87fd58c5a0e..dda61362630 100644 --- a/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Task.java +++ b/nae-object-library/src/main/java/com/netgrif/application/engine/objects/workflow/domain/Task.java @@ -34,12 +34,18 @@ public abstract class Task implements Serializable { @Serial private static final long serialVersionUID = -7112277728921547546L; + @Setter private ProcessResourceId _id; + @Setter @Getter @Indexed private String processId; + @Getter + @Indexed + private String processIdentifier; + @Getter @Setter @Indexed @@ -169,8 +175,8 @@ public abstract class Task implements Serializable { private Map tags = new HashMap<>(); public Task() { - if (this.processId != null && !this.processId.isEmpty()) { - this._id = new ProcessResourceId(new ObjectId(this.processId)); + if (this.processIdentifier != null && !this.processIdentifier.isEmpty()) { + this._id = new ProcessResourceId(this.processIdentifier, new ObjectId()); } } @@ -179,17 +185,17 @@ public ProcessResourceId getObjectId() { return _id; } - public void setProcessId(String processId) { - this.processId = processId; - if (processId != null && !processId.isEmpty()) { - this._id = new ProcessResourceId(new ObjectId(processId)); + public void setProcessIdentifier(String processIdentifier) { + this.processIdentifier = processIdentifier; + if (processIdentifier != null && !processIdentifier.isEmpty()) { + this._id = new ProcessResourceId(processIdentifier, new ObjectId()); } } public ProcessResourceId get_id() { if (this._id == null) { this._id = this.processId != null && !this.processId.isEmpty() - ? new ProcessResourceId(new ObjectId(this.processId)) + ? new ProcessResourceId(this.processIdentifier, new ObjectId()) : new ProcessResourceId(); } return this._id; diff --git a/nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Task.java b/nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Task.java index 6b9117b18e4..fe13692850c 100644 --- a/nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Task.java +++ b/nae-spring-core-adapter/src/main/java/com/netgrif/application/engine/adapter/spring/workflow/domain/Task.java @@ -30,7 +30,7 @@ public Task() { } @Builder(builderMethodName = "with") - public Task(ProcessResourceId _id, String processId, String caseId, String transitionId, TaskLayout layout, I18nString title, + public Task(ProcessResourceId _id, String processId, String processIdentifier, String caseId, String transitionId, TaskLayout layout, I18nString title, String caseColor, String caseTitle, Integer priority, ActorRef assignee, AbstractUser user, List triggers, Map> roles, Map> actorRefs, Map> actors, List viewRoles, List viewActorRefs, List viewActors, @@ -38,7 +38,7 @@ public Task(ProcessResourceId _id, String processId, String caseId, String trans String finishedBy, String transactionId, Boolean requiredFilled, LinkedHashSet immediateDataFields, List> immediateData, String icon, AssignPolicy assignPolicy, DataFocusPolicy dataFocusPolicy, FinishPolicy finishPolicy, Map eventTitles, Map assignedUserPolicy, Map consumedTokens, Map tags) { - super(_id, processId, caseId, transitionId, layout, title, caseColor, caseTitle, priority, assignee, user, + super(_id, processId, processIdentifier, caseId, transitionId, layout, title, caseColor, caseTitle, priority, assignee, user, triggers, roles, actorRefs, actors, viewRoles, viewActorRefs, viewActors, negativeViewRoles, negativeViewActors, startDate, finishDate, finishedBy, transactionId, requiredFilled, immediateDataFields, immediateData, icon, assignPolicy, dataFocusPolicy, finishPolicy, eventTitles, assignedUserPolicy, consumedTokens, tags); diff --git a/pom.xml b/pom.xml index be06c1a59a8..01fef9a9f02 100644 --- a/pom.xml +++ b/pom.xml @@ -74,8 +74,8 @@ 3.4.1 5.8.0 - 3.1.2 - 3.1.2 + 3.1.5 + 3.1.5 4.1.0 3.0.3