Search in sources :

Example 1 with PartialProcessKey

use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.

the class FormResourceV1 method submit.

/**
 * Submit form instance's data, potentially resuming a suspended process.
 */
@POST
@ApiOperation(value = "Submit JSON form data")
@Path("/{processInstanceId}/form/{formName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public FormSubmitResponse submit(@ApiParam @PathParam("processInstanceId") UUID processInstanceId, @ApiParam @PathParam("formName") String formName, @ApiParam Map<String, Object> data) {
    PartialProcessKey processKey = PartialProcessKey.from(processInstanceId);
    Form form = formService.get(processKey, formName);
    if (form == null) {
        throw new ConcordApplicationException("Form " + formName + " not found. Process ID: " + processInstanceId, Status.NOT_FOUND);
    }
    try {
        data = FormUtils.convert(validatorLocale, form, data);
    } catch (ValidationException e) {
        Map<String, String> errors = Collections.singletonMap(e.getField().getName(), e.getMessage());
        return new FormSubmitResponse(processInstanceId, errors);
    }
    FormSubmitResult result = formService.submit(processKey, formName, data);
    Map<String, String> errors = FormUtils.mergeErrors(result.getErrors());
    return new FormSubmitResponse(result.getProcessInstanceId(), errors);
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ValidationException(com.walmartlabs.concord.server.process.form.FormUtils.ValidationException) Form(io.takari.bpm.form.Form) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with PartialProcessKey

use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.

the class FormResourceV2 method get.

/**
 * Return the current state of a form instance.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public FormInstanceEntry get(UUID processInstanceId, String formName) {
    PartialProcessKey processKey = PartialProcessKey.from(processInstanceId);
    Form form = formService.get(processKey, formName);
    if (form == null) {
        throw new ConcordApplicationException("Form " + formName + " not found. Process ID: " + processKey, Status.NOT_FOUND);
    }
    List<FormInstanceEntry.Field> fields = new ArrayList<>();
    for (FormField f : form.fields()) {
        String fieldName = f.name();
        FormInstanceEntry.Cardinality c = map(f.cardinality());
        String type = f.type();
        Serializable value = f.defaultValue();
        Serializable allowedValue = f.allowedValue();
        Map options = f.options();
        fields.add(new FormInstanceEntry.Field(fieldName, f.label(), type, c, value, allowedValue, options));
    }
    String name = form.name();
    boolean yield = form.options().yield();
    String resourcePath = FORMS_RESOURCES_PATH + "/" + name;
    boolean isCustomForm = formService.exists(processKey, resourcePath);
    return new FormInstanceEntry(processInstanceId.toString(), name, fields, isCustomForm, yield);
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) Serializable(java.io.Serializable) Form(com.walmartlabs.concord.forms.Form) FormField(com.walmartlabs.concord.forms.FormField) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) FormField(com.walmartlabs.concord.forms.FormField)

Example 3 with PartialProcessKey

use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.

the class SessionKeyRealm method doGetAuthenticationInfo.

@Override
@WithTimer
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    SessionKey t = (SessionKey) token;
    PartialProcessKey processKey = PartialProcessKey.from(t.getInstanceId());
    try {
        ProcessInitiatorEntry p = processQueueManager.getInitiator(processKey);
        if (p == null) {
            log.warn("doGetAuthenticationInfo -> process not found: {}", t.getInstanceId());
            return null;
        }
        if (p.initiatorId() == null) {
            log.warn("doGetAuthenticationInfo -> initiator not found: {}", t.getInstanceId());
            return null;
        }
        if (isFinished(p)) {
            log.warn("doGetAuthenticationInfo -> process is finished: {}", t.getInstanceId());
            return null;
        }
        PrincipalCollection principals = getPrincipals(processKey);
        return new SimpleAccount(principals, t.getInstanceId(), getName());
    } catch (Exception e) {
        log.error("doGetAuthenticationInfo ['{}'] -> error", t.getInstanceId(), e);
        throw e;
    }
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessInitiatorEntry(com.walmartlabs.concord.server.process.queue.ProcessInitiatorEntry) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) AuthenticationException(org.apache.shiro.authc.AuthenticationException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 4 with PartialProcessKey

use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.

the class ProjectProcessResource method doStartProcess.

private Response doStartProcess(UUID orgId, UUID projectId, UUID repoId, String branchOrTag, String commitId, String entryPoint, String activeProfiles, HttpServletRequest request) {
    Map<String, Object> cfg = new HashMap<>();
    if (branchOrTag != null) {
        cfg.put(Constants.Request.REPO_BRANCH_OR_TAG, branchOrTag);
    }
    if (commitId != null) {
        cfg.put(Constants.Request.REPO_COMMIT_ID, commitId);
    }
    if (activeProfiles != null) {
        String[] as = activeProfiles.split(",");
        cfg.put(Constants.Request.ACTIVE_PROFILES_KEY, Arrays.asList(as));
    }
    PartialProcessKey processKey = PartialProcessKey.create();
    try {
        UserPrincipal initiator = UserPrincipal.assertCurrent();
        Payload payload = PayloadBuilder.start(processKey).organization(orgId).project(projectId).repository(repoId).entryPoint(entryPoint).initiator(initiator.getId(), initiator.getUsername()).configuration(cfg).request(request).build();
        processManager.start(payload);
    } catch (Exception e) {
        return processError(processKey, e.getMessage(), e);
    }
    return proceed(processKey);
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException)

Example 5 with PartialProcessKey

use of com.walmartlabs.concord.server.sdk.PartialProcessKey in project concord by walmartlabs.

the class TriggerProcessExecutor method submitProcess.

private Future<PartialProcessKey> submitProcess(Event event, TriggerEntry t, TriggerEventInitiatorResolver initiatorResolver, ProcessConfigurationEnricher cfgEnricher, TriggerExclusiveParamsResolver exclusiveResolver) {
    UserEntry initiator;
    try {
        initiator = initiatorResolver.resolve(t, event);
    } catch (Exception e) {
        log.error("process ['{}', '{}', '{}'] -> error", event.id(), event.name(), t.getId(), e);
        SettableFuture<PartialProcessKey> f = SettableFuture.create();
        f.set(null);
        return f;
    }
    return executor.submit(() -> {
        Map<String, Object> args = new HashMap<>();
        if (t.getArguments() != null) {
            args.putAll(t.getArguments());
        }
        args.put("event", ExpressionUtils.escapeMap(event.attributes()));
        Map<String, Object> cfg = new HashMap<>();
        cfg.put(Constants.Request.ARGUMENTS_KEY, args);
        if (TriggerUtils.getEntryPoint(t) != null) {
            cfg.put(Constants.Request.ENTRY_POINT_KEY, TriggerUtils.getEntryPoint(t));
        }
        if (t.getActiveProfiles() != null) {
            cfg.put(Constants.Request.ACTIVE_PROFILES_KEY, t.getActiveProfiles());
        }
        Map<String, Object> exclusive = exclusiveResolver.resolve(t);
        if (exclusive != null && !exclusive.isEmpty()) {
            // avoid saving empty objects into the cfg
            cfg.put(Constants.Request.EXCLUSIVE, exclusive);
        }
        if (cfgEnricher != null) {
            cfg = cfgEnricher.enrich(t, cfg);
        }
        try {
            UUID orgId = projectDao.getOrgId(t.getProjectId());
            PartialProcessKey pk = startProcess(event.id(), orgId, t, cfg, initiator);
            log.info("process ['{}'] -> new process ('{}') triggered by {}", event.id(), pk, t);
            return pk;
        } catch (Exception e) {
            log.error("process ['{}', '{}', '{}'] -> error", event.id(), event.name(), t.getId(), e);
            return null;
        }
    });
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) UserEntry(com.walmartlabs.concord.server.user.UserEntry) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException)

Aggregations

PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)27 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)18 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)14 ApiOperation (io.swagger.annotations.ApiOperation)14 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)8 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)4 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)4 UUID (java.util.UUID)3 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)3 Imports (com.walmartlabs.concord.imports.Imports)2 ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 ConfigurationUtils (com.walmartlabs.concord.common.ConfigurationUtils)1 IOUtils (com.walmartlabs.concord.common.IOUtils)1 Form (com.walmartlabs.concord.forms.Form)1 FormField (com.walmartlabs.concord.forms.FormField)1 FormUtils (com.walmartlabs.concord.forms.FormUtils)1 AttachmentsRule (com.walmartlabs.concord.policyengine.AttachmentsRule)1 CheckResult (com.walmartlabs.concord.policyengine.CheckResult)1