use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class RepositoryResource method createOrUpdate.
@POST
@ApiOperation("Creates a new repository or updates an existing one")
@Path("/{orgName}/project/{projectName}/repository")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public GenericOperationResult createOrUpdate(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("projectName") @ConcordKey String projectName, @ApiParam @Valid RepositoryEntry entry) {
OrganizationEntry org = orgManager.assertAccess(orgName, true);
UUID projectId = projectDao.getId(org.getId(), projectName);
if (projectId == null) {
throw new ConcordApplicationException("Project not found: " + projectName, Status.NOT_FOUND);
}
projectRepositoryManager.createOrUpdate(projectId, entry);
return new GenericOperationResult(entry.getId() == null ? OperationResult.CREATED : OperationResult.UPDATED);
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class SecretManager method assertApiKey.
public ApiKeyEntry assertApiKey(AccessScope accessScope, UUID orgId, String secretName, String password) {
DecryptedSecret secret = getSecret(accessScope, orgId, secretName, password, SecretType.DATA);
BinaryDataSecret data = (BinaryDataSecret) secret.getSecret();
ApiKeyEntry result = apiKeyDao.find(new String(data.getData()));
if (result == null) {
throw new ConcordApplicationException("Api key from secret '" + secretName + "' not found", Status.NOT_FOUND);
}
return result;
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class PayloadRestoreProcessor method process.
@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> headers = stateManager.get(processKey, "_initial/payload.json", inputStream -> {
Map<String, Object> result = deserialize(inputStream);
return Optional.ofNullable(result);
}).orElseThrow(() -> new ConcordApplicationException("Initial state not found", Response.Status.INTERNAL_SERVER_ERROR));
payload = payload.putHeaders(headers);
Path baseDir = payload.getHeader(Payload.BASE_DIR);
ProcessStateManager.ItemConsumer cp = ProcessStateManager.copyTo(baseDir);
Map<String, Path> attachments = new HashMap<>();
stateManager.exportDirectory(processKey, "_initial/attachments/", (name, unixMode, src) -> {
cp.accept(name, unixMode, src);
attachments.put(name, baseDir.resolve(name));
});
payload = payload.putAttachments(attachments);
return chain.process(payload);
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException 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.ConcordApplicationException 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);
}
Aggregations