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);
}
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);
}
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;
}
}
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);
}
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;
}
});
}
Aggregations