Skip to content

Commit 1364bc7

Browse files
committed
Merge remote-tracking branch 'origin/release/7.0.0-rev7' into release/7.0.0-rev8
# Conflicts: # application-engine/pom.xml # nae-object-library/pom.xml # nae-spring-core-adapter/pom.xml # nae-user-ce/pom.xml # nae-user-common/pom.xml # pom.xml
2 parents 786a111 + da1c6ad commit 1364bc7

15 files changed

Lines changed: 137 additions & 59 deletions

File tree

application-engine/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.netgrif</groupId>
88
<artifactId>application-engine-parent</artifactId>
9-
<version>7.0.0-SNAPSHOT</version>
9+
<version>7.0.0-RC7.1</version>
1010
</parent>
1111

1212
<artifactId>application-engine</artifactId>
@@ -135,6 +135,11 @@
135135
<artifactId>nae-user-ce</artifactId>
136136
<version>${project.version}</version>
137137
</dependency>
138+
<dependency>
139+
<groupId>com.netgrif</groupId>
140+
<artifactId>nae-spring-core-adapter</artifactId>
141+
<version>${project.version}</version>
142+
</dependency>
138143

139144
<!-- Loader -->
140145
<dependency>

application-engine/src/main/groovy/com/netgrif/application/engine/integration/modules/ModuleServiceInjector.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package com.netgrif.application.engine.integration.modules
33
import com.netgrif.application.engine.configuration.ApplicationContextProvider
44
import com.netgrif.application.engine.startup.ApplicationEngineFinishRunner
55
import com.netgrif.application.engine.startup.annotation.RunnerOrder
6+
import com.netgrif.application.engine.adapter.spring.utils.NaeReflectionUtils
67
import org.slf4j.Logger
78
import org.slf4j.LoggerFactory
89
import org.springframework.boot.ApplicationArguments
910
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
11+
import org.springframework.core.annotation.AnnotatedElementUtils
1012
import org.springframework.stereotype.Component
1113

1214
/**
@@ -75,7 +77,8 @@ class ModuleServiceInjector implements ApplicationEngineFinishRunner {
7577
private Map<String, Map<String, Object>> groupServicesByModule(Map<String, Object> services) {
7678
Map<String, Map<String, Object>> grouped = [(DEFAULT_KEY): [:]]
7779
services.each { entry ->
78-
ModuleService[] annotations = entry.value.getClass().getAnnotationsByType(ModuleService.class)
80+
Class serviceClass = NaeReflectionUtils.resolveClass(entry.value)
81+
ModuleService[] annotations = serviceClass.getAnnotationsByType(ModuleService.class)
7982
if (annotations.length == 0) throw new IllegalStateException("Module Service bean must have @ModuleService annotations")
8083
ModuleService annotation = annotations[0]
8184
if (annotation.value().isBlank()) {

application-engine/src/main/java/com/netgrif/application/engine/menu/services/MenuItemService.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.netgrif.application.engine.workflow.service.interfaces.IDataService;
2929
import com.netgrif.application.engine.workflow.service.interfaces.ITaskService;
3030
import com.netgrif.application.engine.workflow.service.interfaces.IWorkflowService;
31+
import com.querydsl.core.types.Predicate;
3132
import lombok.RequiredArgsConstructor;
3233
import lombok.extern.slf4j.Slf4j;
3334
import org.springframework.data.domain.Page;
@@ -194,9 +195,9 @@ public Case findMenuItem(String identifier) {
194195

195196
@Override
196197
public Case findMenuItem(String identifier, boolean retry) {
197-
String query = String.format("processIdentifier:%s AND dataSet.%s.textValue.keyword:\"%s\"",
198-
MenuProcessRunner.MENU_NET_IDENTIFIER, MenuItemConstants.FIELD_IDENTIFIER, identifier);
199-
return findCase(MenuProcessRunner.MENU_NET_IDENTIFIER, query);
198+
return findCase(QCase.case$.processIdentifier
199+
.eq(MenuProcessRunner.MENU_NET_IDENTIFIER)
200+
.and(QCase.case$.dataSet.get(MenuItemConstants.FIELD_IDENTIFIER).value.eq(identifier)));
200201
}
201202

202203
/**
@@ -208,10 +209,10 @@ public Case findMenuItem(String identifier, boolean retry) {
208209
*/
209210
@Override
210211
public Case findMenuItem(String path, String name) {
211-
// TODO retry
212-
String query = String.format("processIdentifier:%s AND title.keyword:\"%s\" AND nodePath:\"%s\"",
213-
MenuProcessRunner.MENU_NET_IDENTIFIER, name, path);
214-
return findCase(MenuProcessRunner.MENU_NET_IDENTIFIER, query);
212+
return findCase(QCase.case$.processIdentifier
213+
.eq(MenuProcessRunner.MENU_NET_IDENTIFIER)
214+
.and(QCase.case$.title.eq(name))
215+
.and(QCase.case$.dataSet.get(MenuItemConstants.FIELD_NODE_PATH).value.eq(path)));
215216
}
216217

217218
/**
@@ -223,9 +224,9 @@ public Case findMenuItem(String path, String name) {
223224
@Override
224225
public Case findFolderCase(String path) {
225226
// TODO
226-
String query = String.format("processIdentifier:%s AND dataSet.%s.textValue.keyword:\"%s\"",
227-
MenuProcessRunner.MENU_NET_IDENTIFIER, MenuItemConstants.FIELD_NODE_PATH, path);
228-
return findCase(MenuProcessRunner.MENU_NET_IDENTIFIER, query);
227+
return findCase(QCase.case$.processIdentifier
228+
.eq(MenuProcessRunner.MENU_NET_IDENTIFIER)
229+
.and(QCase.case$.dataSet.get(MenuItemConstants.FIELD_NODE_PATH).value.eq(path)));
229230
}
230231

231232
/**
@@ -384,6 +385,10 @@ public Case removeChildItemFromParent(String folderId, Case childItem) {
384385
return workflowService.save(parentFolder);
385386
}
386387

388+
protected Case findCase(Predicate predicate) {
389+
return workflowService.searchOne(predicate);
390+
}
391+
387392
protected Case findCase(String processIdentifier, String query) {
388393
CaseSearchRequest request = CaseSearchRequest.builder()
389394
.process(Collections.singletonList(new CaseSearchRequest.PetriNet(processIdentifier)))

application-engine/src/main/java/com/netgrif/application/engine/startup/ApplicationRunnerExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import java.util.Map;
1414

15-
import static com.netgrif.application.engine.startup.ApplicationRunnerOrderResolver.resolveClass;
15+
import static com.netgrif.application.engine.adapter.spring.utils.NaeReflectionUtils.resolveClass;
1616

1717
@Slf4j
1818
@Component

application-engine/src/main/java/com/netgrif/application/engine/startup/ApplicationRunnerOrderResolver.java

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import lombok.Getter;
99
import lombok.RequiredArgsConstructor;
1010
import lombok.extern.slf4j.Slf4j;
11-
import org.springframework.aop.support.AopUtils;
1211
import org.springframework.stereotype.Component;
1312

1413
import java.lang.annotation.Annotation;
1514
import java.util.*;
1615
import java.util.function.Function;
1716

17+
import static com.netgrif.application.engine.adapter.spring.utils.NaeReflectionUtils.indexOfClass;
18+
import static com.netgrif.application.engine.adapter.spring.utils.NaeReflectionUtils.resolveClass;
19+
1820
@Slf4j
1921
@Component
2022
@RequiredArgsConstructor
@@ -54,11 +56,6 @@ public <T> SortedRunners<T> sortByRunnerOrderAnnotation(Collection<T> runners) {
5456
return new SortedRunners<>(ordered.values().stream().flatMap(List::stream).toList(), unresolved);
5557
}
5658

57-
public static <T> Class<?> resolveClass(T object) {
58-
if (object instanceof Class) return (Class<?>) object;
59-
else return AopUtils.isAopProxy(object) ? AopUtils.getTargetClass(object) : object.getClass();
60-
}
61-
6259
@Getter
6360
public static class SortedRunners<T> {
6461
private final List<T> sorted;
@@ -91,7 +88,6 @@ public SortedRunners(List<T> sorted, List<T> unresolved) {
9188
* @return {@code true} if all unresolved runners have been successfully sorted and the unresolved list is empty;
9289
* {@code false} otherwise.
9390
*/
94-
9591
public boolean resolveAllRunners() {
9692
sortUnresolvedRunners();
9793
replaced.values().forEach(this::removeRunner);
@@ -171,29 +167,6 @@ protected boolean replaceRunner(T item) {
171167
return changed;
172168
}
173169

174-
/**
175-
* Returns the index of the first occurrence of the specified class in the given list.
176-
* If the list contains an element whose class matches the specified class, the index of that element is returned.
177-
* If the specified class is {@code null}, the method returns the index of the first {@code null} element in the list.
178-
* If the list is {@code null} or empty, or if the class is not found, the method returns {@code -1}.
179-
*
180-
* @param <I> the type of elements in the list
181-
* @param list the list to search for the specified class
182-
* @param clazz the class to search for in the list
183-
* @return the index of the first occurrence of the specified class in the list, or {@code -1} if the class is not found
184-
*/
185-
public static <I> int indexOfClass(List<I> list, Class<?> clazz) {
186-
if (list == null) return -1;
187-
if (list.isEmpty()) return -1;
188-
if (clazz == null) return list.indexOf(null);
189-
for (int i = 0; i < list.size(); i++) {
190-
if (resolveClass(list.get(i)).equals(clazz)) {
191-
return i;
192-
}
193-
}
194-
return -1;
195-
}
196-
197170
}
198171

199172
}

application-engine/src/main/java/com/netgrif/application/engine/workflow/service/CaseEventHandler.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package com.netgrif.application.engine.workflow.service;
22

33
import com.netgrif.application.engine.elastic.service.interfaces.IElasticCaseService;
4+
import com.netgrif.application.engine.importer.service.FieldFactory;
5+
import com.netgrif.application.engine.objects.petrinet.domain.dataset.Field;
46
import com.netgrif.application.engine.objects.workflow.domain.Case;
7+
import com.netgrif.application.engine.workflow.service.interfaces.IWorkflowService;
58
import org.bson.Document;
6-
import org.bson.types.ObjectId;
79
import org.slf4j.Logger;
810
import org.slf4j.LoggerFactory;
911
import org.springframework.beans.factory.annotation.Autowired;
1012
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;
13+
import org.springframework.data.mongodb.core.mapping.event.AfterConvertEvent;
1114
import org.springframework.data.mongodb.core.mapping.event.AfterDeleteEvent;
1215
import org.springframework.stereotype.Component;
1316

17+
import java.util.ArrayList;
18+
import java.util.List;
19+
1420
@Component
1521
public class CaseEventHandler extends AbstractMongoEventListener<Case> {
1622

@@ -19,6 +25,30 @@ public class CaseEventHandler extends AbstractMongoEventListener<Case> {
1925
@Autowired
2026
private IElasticCaseService service;
2127

28+
@Autowired
29+
private FieldFactory fieldFactory;
30+
31+
@Autowired
32+
private IWorkflowService workflowService;
33+
34+
@Override
35+
public void onAfterConvert(AfterConvertEvent<Case> event) {
36+
Case useCase = event.getSource();
37+
workflowService.setPetriNet(useCase);
38+
List<Field<?>> immediateFields = new ArrayList<>();
39+
if (useCase.getImmediateDataFields() != null) {
40+
useCase.getImmediateDataFields().forEach(fieldId -> {
41+
try {
42+
immediateFields.add(fieldFactory.buildImmediateField(useCase, fieldId));
43+
} catch (Exception e) {
44+
log.error("Could not build immediate field for case {} and field {}", useCase.getStringId(), fieldId, e);
45+
}
46+
}
47+
);
48+
useCase.setImmediateData(immediateFields);
49+
}
50+
}
51+
2252
@Override
2353
public void onAfterDelete(AfterDeleteEvent<Case> event) {
2454
Document document = event.getDocument();

application-engine/src/main/java/com/netgrif/application/engine/workflow/service/WorkflowService.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,17 @@ public Map<String, I18nString> listToMap(List<Case> cases) {
497497
return options;
498498
}
499499

500+
@Override
501+
public void setPetriNet(Case useCase) {
502+
PetriNet model = useCase.getPetriNet();
503+
if (model == null) {
504+
model = new com.netgrif.application.engine.adapter.spring.petrinet.domain.PetriNet((com.netgrif.application.engine.adapter.spring.petrinet.domain.PetriNet) petriNetService.get(new ObjectId(useCase.getPetriNetId())));
505+
useCase.setPetriNet(model);
506+
}
507+
model.initializeTokens(useCase.getActivePlaces());
508+
model.initializeArcs(useCase.getDataSet());
509+
}
510+
500511
private void resolveTaskRefs(Case useCase) {
501512
useCase.getPetriNet().getDataSet().values().stream().filter(f -> f instanceof TaskField).map(TaskField.class::cast).forEach(field -> {
502513
if (field.getDefaultValue() != null && !field.getDefaultValue().isEmpty() && useCase.getDataField(field.getStringId()).getValue() != null &&
@@ -608,16 +619,6 @@ private Map<DataField, String> getEncryptedDataSet(Case useCase) {
608619
return encryptedDataSet;
609620
}
610621

611-
private void setPetriNet(Case useCase) {
612-
PetriNet model = useCase.getPetriNet();
613-
if (model == null) {
614-
model = new com.netgrif.application.engine.adapter.spring.petrinet.domain.PetriNet((com.netgrif.application.engine.adapter.spring.petrinet.domain.PetriNet) petriNetService.get(new ObjectId(useCase.getPetriNetId())));
615-
useCase.setPetriNet(model);
616-
}
617-
model.initializeTokens(useCase.getActivePlaces());
618-
model.initializeArcs(useCase.getDataSet());
619-
}
620-
621622
private EventOutcome addMessageToOutcome(PetriNet net, CaseEventType type, EventOutcome outcome) {
622623
if (net.getCaseEvents().containsKey(type)) {
623624
outcome.setMessage(net.getCaseEvents().get(type).getMessage());

application-engine/src/main/java/com/netgrif/application/engine/workflow/service/interfaces/IWorkflowService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ public interface IWorkflowService {
8282
boolean removeTasksFromCase(List<Task> tasks, Case useCase);
8383

8484
Page<Case> search(Predicate predicate, Pageable pageable);
85+
86+
void setPetriNet(Case useCase);
8587
}

nae-object-library/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.netgrif</groupId>
99
<artifactId>application-engine-parent</artifactId>
10-
<version>7.0.0-SNAPSHOT</version>
10+
<version>7.0.0-RC7.1</version>
1111
</parent>
1212

1313
<artifactId>nae-object-library</artifactId>

nae-spring-core-adapter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.netgrif</groupId>
99
<artifactId>application-engine-parent</artifactId>
10-
<version>7.0.0-SNAPSHOT</version>
10+
<version>7.0.0-RC7.1</version>
1111
</parent>
1212

1313
<artifactId>nae-spring-core-adapter</artifactId>

0 commit comments

Comments
 (0)