Search in sources :

Example 6 with ProcessInstanceDuplicatedException

use of io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException in project automatiko-engine by automatiko-io.

the class MongodbProcessInstances method update.

@Override
public void update(String id, ProcessInstance instance) {
    String resolvedId = resolveId(id, instance);
    try {
        if (isActive(instance)) {
            byte[] data = codec.encode(marshaller.marhsallProcessInstance(instance));
            if (data == null) {
                return;
            }
            Model entity = (Model) instance.variables();
            String variablesJson = marshallingStrategy.mapper().writeValueAsString(entity);
            Document variables = Document.parse(variablesJson);
            removeTransientVariables(variables, instance);
            Collection<String> tags = new LinkedHashSet<>(instance.tags().values());
            tags.add(resolvedId);
            if (instance.businessKey() != null) {
                tags.add(instance.businessKey());
            }
            Document item = new Document(INSTANCE_ID_FIELD, resolvedId).append(CONTENT_FIELD, data).append(STATUS_FIELD, instance.status()).append(TAGS_FIELD, tags).append(VERSION_FIELD, ((AbstractProcessInstance<?>) instance).getVersionTracker()).append(VARIABLES_FIELD, variables);
            try {
                Document replaced = collection().findOneAndReplace(and(eq(INSTANCE_ID_FIELD, resolvedId), eq(VERSION_FIELD, ((AbstractProcessInstance<?>) instance).getVersionTracker())), item);
                if (replaced == null) {
                    throw new ConflictingVersionException("Process instance with id '" + instance.id() + "' has older version than the stored one");
                }
            } finally {
                cachedInstances.remove(resolvedId);
                cachedInstances.remove(id);
                disconnect(instance);
            }
        } else if (isPending(instance)) {
            if (cachedInstances.putIfAbsent(resolvedId, instance) != null) {
                throw new ProcessInstanceDuplicatedException(id);
            }
        } else {
            cachedInstances.remove(resolvedId);
            cachedInstances.remove(id);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ConflictingVersionException(io.automatiko.engine.api.workflow.ConflictingVersionException) ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) Model(io.automatiko.engine.api.Model) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Document(org.bson.Document)

Example 7 with ProcessInstanceDuplicatedException

use of io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException in project automatiko-engine by automatiko-io.

the class MongodbProcessInstances method importInstance.

@Override
public ProcessInstance importInstance(ExportedProcessInstance instance, Process process) {
    ProcessInstance imported = marshaller.importProcessInstance(instance, process);
    if (exists(imported.id())) {
        throw new ProcessInstanceDuplicatedException(imported.id());
    }
    create(imported.id(), imported);
    return imported;
}
Also used : ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance)

Example 8 with ProcessInstanceDuplicatedException

use of io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException in project automatiko-engine by automatiko-io.

the class MongodbProcessInstances method create.

@Override
public void create(String id, ProcessInstance instance) {
    String resolvedId = resolveId(id, instance);
    try {
        if (isActive(instance)) {
            byte[] data = codec.encode(marshaller.marhsallProcessInstance(instance));
            if (data == null) {
                return;
            }
            Model entity = (Model) instance.variables();
            String variablesJson = marshallingStrategy.mapper().writeValueAsString(entity);
            Document variables = Document.parse(variablesJson);
            removeTransientVariables(variables, instance);
            Collection<String> tags = new LinkedHashSet<>(instance.tags().values());
            tags.add(resolvedId);
            if (instance.businessKey() != null) {
                tags.add(instance.businessKey());
            }
            Document item = new Document(INSTANCE_ID_FIELD, resolvedId).append(CONTENT_FIELD, data).append(STATUS_FIELD, instance.status()).append(TAGS_FIELD, tags).append(VERSION_FIELD, ((AbstractProcessInstance<?>) instance).getVersionTracker()).append(VARIABLES_FIELD, variables);
            try {
                collection().insertOne(item);
            } finally {
                cachedInstances.remove(resolvedId);
                cachedInstances.remove(id);
                disconnect(instance);
            }
        } else if (isPending(instance)) {
            if (cachedInstances.putIfAbsent(resolvedId, instance) != null) {
                throw new ProcessInstanceDuplicatedException(id);
            }
        } else {
            cachedInstances.remove(resolvedId);
            cachedInstances.remove(id);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) Model(io.automatiko.engine.api.Model) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Document(org.bson.Document)

Example 9 with ProcessInstanceDuplicatedException

use of io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException in project automatiko-engine by automatiko-io.

the class FileSystemProcessInstances method importInstance.

@Override
public ProcessInstance importInstance(ExportedProcessInstance instance, Process process) {
    ProcessInstance imported = marshaller.importProcessInstance(instance, process);
    if (exists(imported.id())) {
        throw new ProcessInstanceDuplicatedException(imported.id());
    }
    create(imported.id(), imported);
    return imported;
}
Also used : ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance)

Example 10 with ProcessInstanceDuplicatedException

use of io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException in project automatiko-engine by automatiko-io.

the class BaseExceptionHandlerTest method testMapProcessInstanceDuplicatedException.

@Test
void testMapProcessInstanceDuplicatedException() {
    Object response = tested.mapException(new ProcessInstanceDuplicatedException("processInstanceId"));
    assertThat(response).isEqualTo(conflictResponse);
}
Also used : ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessInstanceDuplicatedException (io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException)16 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)9 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)9 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)6 TrustedIdentityProvider (io.automatiko.engine.api.auth.TrustedIdentityProvider)3 LinkedHashSet (java.util.LinkedHashSet)3 Model (io.automatiko.engine.api.Model)2 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Document (org.bson.Document)2 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)1 QueryExecutionException (com.datastax.oss.driver.api.core.servererrors.QueryExecutionException)1 Insert (com.datastax.oss.driver.api.querybuilder.insert.Insert)1 ConflictingVersionException (io.automatiko.engine.api.workflow.ConflictingVersionException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1