Search in sources :

Example 11 with ConcordApplicationException

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);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) ApiOperation(io.swagger.annotations.ApiOperation)

Example 12 with ConcordApplicationException

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;
}
Also used : ApiKeyEntry(com.walmartlabs.concord.server.security.apikey.ApiKeyEntry) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) BinaryDataSecret(com.walmartlabs.concord.common.secret.BinaryDataSecret)

Example 13 with ConcordApplicationException

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);
}
Also used : ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) Payload(com.walmartlabs.concord.server.process.Payload) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashMap(java.util.HashMap) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) Inject(javax.inject.Inject) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) Response(javax.ws.rs.core.Response) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Map(java.util.Map) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) Optional(java.util.Optional) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) Named(javax.inject.Named) Path(java.nio.file.Path) InputStream(java.io.InputStream) Path(java.nio.file.Path) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) HashMap(java.util.HashMap) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) HashMap(java.util.HashMap) Map(java.util.Map) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 14 with ConcordApplicationException

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);
}
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 15 with ConcordApplicationException

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

Aggregations

ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)70 ApiOperation (io.swagger.annotations.ApiOperation)28 UUID (java.util.UUID)22 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)21 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)18 IOException (java.io.IOException)14 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)12 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)11 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)11 Validate (org.sonatype.siesta.Validate)11 Path (java.nio.file.Path)10 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)9 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)8 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)6 ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)6 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)6 UserEntry (com.walmartlabs.concord.server.user.UserEntry)5 InputStream (java.io.InputStream)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Form (com.walmartlabs.concord.forms.Form)3