Search in sources :

Example 1 with Workflow

use of edu.harvard.iq.dataverse.workflow.Workflow in project dataverse by IQSS.

the class WorkflowsAdmin method setDefault.

@Path("default/{triggerType}")
@PUT
public Response setDefault(@PathParam("triggerType") String triggerType, String identifier) {
    try {
        long idtf = Long.parseLong(identifier.trim());
        TriggerType tt = TriggerType.valueOf(triggerType);
        Optional<Workflow> wf = workflows.getWorkflow(idtf);
        if (wf.isPresent()) {
            workflows.setDefaultWorkflowId(tt, idtf);
            return ok("Default workflow id for trigger " + tt.name() + " set to " + idtf);
        } else {
            return notFound("Can't find workflow with id " + idtf);
        }
    } catch (NumberFormatException nfe) {
        return badRequest("workflow identifier has to be numeric.");
    } catch (IllegalArgumentException iae) {
        return badRequest("Unknown trigger type '" + triggerType + "'. Available triggers: " + Arrays.toString(TriggerType.values()));
    }
}
Also used : TriggerType(edu.harvard.iq.dataverse.workflow.WorkflowContext.TriggerType) Workflow(edu.harvard.iq.dataverse.workflow.Workflow) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 2 with Workflow

use of edu.harvard.iq.dataverse.workflow.Workflow in project dataverse by IQSS.

the class WorkflowsAdmin method addWorkflow.

@POST
public Response addWorkflow(JsonObject jsonWorkflow) {
    JsonParser jp = new JsonParser();
    try {
        Workflow wf = jp.parseWorkflow(jsonWorkflow);
        Workflow managedWf = workflows.save(wf);
        return created("/admin/workflows/" + managedWf.getId(), json(managedWf));
    } catch (JsonParseException ex) {
        return badRequest("Can't parse Json: " + ex.getMessage());
    }
}
Also used : Workflow(edu.harvard.iq.dataverse.workflow.Workflow) JsonParseException(edu.harvard.iq.dataverse.util.json.JsonParseException) JsonParser(edu.harvard.iq.dataverse.util.json.JsonParser) POST(javax.ws.rs.POST)

Example 3 with Workflow

use of edu.harvard.iq.dataverse.workflow.Workflow in project dataverse by IQSS.

the class BriefJsonPrinterTest method testJson_Workflow.

/**
 * Test of json method, of class BriefJsonPrinter.
 */
@Test
public void testJson_Workflow() {
    Workflow wf = new Workflow();
    wf.setId(1l);
    wf.setName("Name");
    BriefJsonPrinter sut = new BriefJsonPrinter();
    JsonObject res = sut.json(wf).build();
    assertEquals("Name", res.getString("name"));
    assertEquals(1, res.getInt("id"));
    assertEquals(2, res.keySet().size());
}
Also used : Workflow(edu.harvard.iq.dataverse.workflow.Workflow) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 4 with Workflow

use of edu.harvard.iq.dataverse.workflow.Workflow in project dataverse by IQSS.

the class JsonParser method parseWorkflow.

public Workflow parseWorkflow(JsonObject json) throws JsonParseException {
    Workflow retVal = new Workflow();
    validate("", json, "name", ValueType.STRING);
    validate("", json, "steps", ValueType.ARRAY);
    retVal.setName(json.getString("name"));
    JsonArray stepArray = json.getJsonArray("steps");
    List<WorkflowStepData> steps = new ArrayList<>(stepArray.size());
    for (JsonValue jv : stepArray) {
        steps.add(parseStepData((JsonObject) jv));
    }
    retVal.setSteps(steps);
    return retVal;
}
Also used : JsonArray(javax.json.JsonArray) WorkflowStepData(edu.harvard.iq.dataverse.workflow.step.WorkflowStepData) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) Workflow(edu.harvard.iq.dataverse.workflow.Workflow) JsonObject(javax.json.JsonObject)

Aggregations

Workflow (edu.harvard.iq.dataverse.workflow.Workflow)4 JsonObject (javax.json.JsonObject)2 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)1 JsonParser (edu.harvard.iq.dataverse.util.json.JsonParser)1 TriggerType (edu.harvard.iq.dataverse.workflow.WorkflowContext.TriggerType)1 WorkflowStepData (edu.harvard.iq.dataverse.workflow.step.WorkflowStepData)1 ArrayList (java.util.ArrayList)1 JsonArray (javax.json.JsonArray)1 JsonValue (javax.json.JsonValue)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Test (org.junit.Test)1