Skip to content
Merged
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
Expand Up @@ -5,6 +5,7 @@
import com.netgrif.application.engine.objects.auth.domain.ActorTransformer;
import com.netgrif.application.engine.configuration.properties.CacheConfigurationProperties;
import com.netgrif.application.engine.files.minio.StorageConfigurationProperties;
import com.netgrif.application.engine.objects.event.events.petrinet.ProcessEvent;
import com.netgrif.application.engine.objects.petrinet.domain.PetriNet;
import com.netgrif.application.engine.objects.petrinet.domain.PetriNetSearch;
import com.netgrif.application.engine.objects.petrinet.domain.Transition;
Expand Down Expand Up @@ -60,6 +61,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static com.netgrif.application.engine.petrinet.service.interfaces.IPetriNetService.transformToReference;
Expand Down Expand Up @@ -208,21 +210,39 @@ public ImportPetriNetEventOutcome importPetriNet(InputStream xmlFile, VersionTyp
xmlCopy.close();
log.info("Petri net " + newProcess.getTitle() + " (" + newProcess.getInitials() + " v" + newProcess.getVersion() + ") imported successfully and saved in a folder: " + savedPath.toString());

outcome.setOutcomes(eventService.runActions(newProcess.getPreUploadActions(), null, Optional.empty(), params));
publisher.publishEvent(new ProcessDeployEvent(outcome, EventPhase.PRE));
runActionAndPublishEvent(outcome, null, newProcess.getPreUploadActions(), params, new ProcessDeployEvent(outcome, EventPhase.PRE));

if (processToMakeNonDefault != null) {
doSaveInternal(processToMakeNonDefault);
}
Optional<PetriNet> saveProcessOpt = doSaveInternal(newProcess);
functionCacheService.cachePetriNetFunctions(newProcess);

outcome.setOutcomes(eventService.runActions(newProcess.getPostUploadActions(), null, Optional.empty(), params));
outcome.setNet(saveProcessOpt.orElseThrow());
publisher.publishEvent(new ProcessDeployEvent(outcome, EventPhase.POST));
runActionAndPublishEvent(outcome, saveProcessOpt.orElseThrow(), newProcess.getPostUploadActions(), params, new ProcessDeployEvent(outcome, EventPhase.POST));

return outcome;
}


/**
* Executes a list of actions associated with a Petri net and publishes a corresponding event after execution.
*
* <p>This method is responsible for running the specified actions using the event service, updating the
* provided {@link ImportPetriNetEventOutcome} instance with the outcomes of the executed actions,
* setting the processed Petri net, and publishing the given event through the application event publisher.</p>
*
* @param outcome the {@link ImportPetriNetEventOutcome} instance where the results of the action executions are stored
* @param saveProcess the Petri net that has been processed and potentially saved
* @param actions a list of {@link Action}s to be executed
* @param params a map of key-value pairs containing execution parameters for the actions
* @param event the {@link ProcessEvent} associated with the execution and used for event publication
*/
protected void runActionAndPublishEvent(ImportPetriNetEventOutcome outcome, PetriNet saveProcess, List<Action> actions, Map<String, String> params, ProcessEvent event) {
outcome.setOutcomes(eventService.runActions(actions, null, Optional.empty(), params));
outcome.setNet(saveProcess);
publisher.publishEvent(event);
}

/**
* Validates the version of an importing process. This method can update 'newProces': initialize version,
* initialize default version attribute. This method can also update the current default version of the process if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public List<ProcessRole> findAllByIds(Collection<ProcessResourceId> collection)
@Override
public List<ProcessRole> saveAll(Collection<ProcessRole> entities) {
return StreamSupport.stream(entities.spliterator(), false).map(processRole -> {
if (!processRole.isGlobal() || processRoleRepository.findByImportId(processRole.getImportId()).isEmpty()) {
if (!processRole.isGlobal() || findAllByImportId(processRole.getImportId(), Pageable.ofSize(1)).isEmpty()) {
return processRoleRepository.save(processRole);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void resolveIndexes(String collectionName, Class<?> collectionType) {
}
addAnnotatedFields(collectionType, indexDefinitions);
addConfiguredFields(collectionType, indexDefinitions);
indexDefinitions.forEach(indexOps::ensureIndex);
indexDefinitions.forEach(indexOps::createIndex);
}

private void addAnnotatedFields(Class<?> collectionType, List<IndexDefinition> indexDefinitions) {
Expand Down
Loading