Java Code Examples for org.springframework.http.MediaType#TEXT_XML_VALUE

The following examples show how to use org.springframework.http.MediaType#TEXT_XML_VALUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestController.java    From telekom-workflow-engine with MIT License 6 votes vote down vote up
/**
 * (Un)assigns a human task to a user or submits its result.
 * 
 * In order to unassign a human task from a user, set an empty user name.
 * 
 * Technically, assigning means updating the user field while submitting means to update the status field to EXECUTED and setting the result value.
 * 
 * <pre>
 * Request:  POST /workflowInstance/1/humanTask/2 {result: {resolution: "completed"}}
 * Response: OK, {refNum:3, woinRefNum:1, tokenId:2, status:EXECUTED, role:"auditor", user:"hans", arguments:{task:"audit customer 500"}, result: {resolution: "completed"}}
 * Response: NOT_FOUND, if no such human task exists
 * Response: CONFLICT, if the human task's status does not allow the requested status transition
 * </pre>
 */
@RequestMapping(method = RequestMethod.POST, value = "/workflowInstance/{woinRefNum}/humanTask/{tokenId}",
        produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE})
public ResponseEntity<HumanTaskModel> updateHumanTask( @PathVariable long woinRefNum, @PathVariable int tokenId, @RequestBody String body ){
    WorkItemState woit = facade.findActiveWorkItemByTokenId( woinRefNum, tokenId );
    if( woit == null ){
        return new ResponseEntity<>( HttpStatus.NOT_FOUND );
    }
    try{
        JsonObject root = JsonParserUtil.parseJson( body );
        String user = JsonParserUtil.getAsNullSafeString( root, "user" );
        if( user != null ){
            String userName = user.trim().isEmpty() ? null : user.trim();
            facade.assignHumanTask( woit.getRefNum(), userName );
        }
        else{
            facade.submitHumanTask( woit.getRefNum(), JsonUtil.deserialize( JsonParserUtil.toNullSafeJsonString( root, "result" ) ) );
        }
    }
    catch( UnexpectedStatusException e ){
        return new ResponseEntity<>( HttpStatus.CONFLICT );
    }
    woit = facade.findWorkItem( woit.getRefNum(), true );
    return new ResponseEntity<>( createHumanTaskModel( woit ), HttpStatus.OK );
}
 
Example 2
Source File: ChartFacadeController.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE } )
public void putXmlObject( @PathVariable( "uid" ) String pvUid, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
    List<Visualization> objects = (List<Visualization>) getEntity( pvUid );

    if ( objects.isEmpty() )
    {
        throw new WebMessageException( WebMessageUtils.notFound( Chart.class, pvUid ) );
    }

    User user = currentUserService.getCurrentUser();

    if ( !aclService.canUpdate( user, objects.get( 0 ) ) )
    {
        throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
    }

    Chart parsed = deserializeXmlEntity( request, response );
    parsed.setUid( pvUid );

    final Visualization visualization = convertToVisualization( parsed );

    MetadataImportParams params = importService.getParamsFromMap( contextService.getParameterValuesMap() )
        .setImportReportMode( ImportReportMode.FULL )
        .setUser( user )
        .setImportStrategy( ImportStrategy.UPDATE )
        .addObject( visualization );

    ImportReport importReport = importService.importMetadata( params );
    WebMessage webMessage = WebMessageUtils.objectReport( importReport );

    if ( importReport.getStatus() != Status.OK )
    {
        webMessage.setStatus( Status.ERROR );
    }

    webMessageService.send( webMessage, response, request );
}
 
Example 3
Source File: ReportTableFacadeController.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE } )
public void putXmlObject( @PathVariable( "uid" ) String pvUid, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
    List<Visualization> objects = (List<Visualization>) getEntity( pvUid );

    if ( objects.isEmpty() )
    {
        throw new WebMessageException( WebMessageUtils.notFound( ReportTable.class, pvUid ) );
    }

    User user = currentUserService.getCurrentUser();

    if ( !aclService.canUpdate( user, objects.get( 0 ) ) )
    {
        throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
    }

    ReportTable parsed = deserializeXmlEntity( request, response );
    parsed.setUid( pvUid );

    final Visualization visualization = convertToVisualization( parsed );

    MetadataImportParams params = importService.getParamsFromMap( contextService.getParameterValuesMap() )
        .setImportReportMode( ImportReportMode.FULL )
        .setUser( user )
        .setImportStrategy( ImportStrategy.UPDATE )
        .addObject( visualization );

    ImportReport importReport = importService.importMetadata( params );
    WebMessage webMessage = WebMessageUtils.objectReport( importReport );

    if ( importReport.getStatus() != Status.OK )
    {
        webMessage.setStatus( Status.ERROR );
    }

    webMessageService.send( webMessage, response, request );
}
 
Example 4
Source File: RestController.java    From telekom-workflow-engine with MIT License 5 votes vote down vote up
/**
 * Creates a new workflow instance.
 * 
 * <pre>
 * Request:  POST /workflowInstance {workflowName: "credit.step1", workflowVersion: null, arguments: {"arg1":{"refNum":1, "date":"22.09.2014"}, "arg2":[true, 1, "text"]}, label1: "one", label2: null }
 * Response: OK, {refNum: 1, workflowName: "credit.step1", workflowVersion: null, label1: "one", label2: null, status: NEW}
 * </pre>
 */
@RequestMapping(method = RequestMethod.POST, value = "/workflowInstance", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE})
public ResponseEntity<WorkflowInstanceRestModel> create( @RequestBody String body ){
    JsonObject root = JsonParserUtil.parseJson( body );
    CreateWorkflowInstance request = new CreateWorkflowInstance();
    request.setWorkflowName( JsonParserUtil.getAsNullSafeString( root, "workflowName" ) );
    request.setWorkflowVersion( JsonParserUtil.getAsNullSafeInteger( root, "workflowVersion" ) );
    request.setLabel1( JsonParserUtil.getAsNullSafeString( root, "label1" ) );
    request.setLabel2( JsonParserUtil.getAsNullSafeString( root, "label2" ) );
    request.setArguments( JsonUtil.deserializeHashMap( JsonParserUtil.toNullSafeJsonString( root, "arguments" ), String.class, Object.class ) );

    facade.createWorkflowInstance( request );
    WorkflowInstanceState woin = facade.findWorkflowInstance( request.getRefNum(), true );
    return new ResponseEntity<>( createInstanceModel( woin ), HttpStatus.OK );
}
 
Example 5
Source File: RestController.java    From telekom-workflow-engine with MIT License 5 votes vote down vote up
/**
 * Finds a workflow instance.
 * 
 * <pre>
 * Request:  GET /workflowInstance/1
 * Response: OK {refNum: 1, workflowName: "credit.step1", workflowVersion: null, label1: "one", label2: null, status: NEW}
 * Response: NOT_FOUND, if no such workflow instance exists
 * </pre>
 */
@RequestMapping(method = RequestMethod.GET, value = "/workflowInstance/{woinRefNum}",
        produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE})
public ResponseEntity<WorkflowInstanceRestModel> find( @PathVariable long woinRefNum ){
    WorkflowInstanceState woin = facade.findWorkflowInstance( woinRefNum, null );
    if( woin == null ){
        return new ResponseEntity<>( HttpStatus.NOT_FOUND );
    }
    else{
        return new ResponseEntity<>( createInstanceModel( woin ), HttpStatus.OK );
    }
}
 
Example 6
Source File: RestController.java    From telekom-workflow-engine with MIT License 5 votes vote down vote up
/**
 * Aborts, suspends or resumes a workflow instance.
 * 
 * <pre>
 * Request:  POST /workflowInstance/{woinRefNum} {status: "ABORT"}
 * Response: OK, {refNum: 1, workflowName: "credit.step1", workflowVersion: null, label1: "one", label2: null, status: ABORT}
 * Response: NOT_FOUND, if no such workflow instance exists
 * Response: CONFLICT, if the workflow's current status does not allow the requested status transition
 * Response: BAD_REQUEST, if the new status is not allowed.
 * </pre>
 */
@RequestMapping(method = RequestMethod.POST, value = "/workflowInstance/{woinRefNum}",
        produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE})
public ResponseEntity<WorkflowInstanceRestModel> updateIntance( @PathVariable long woinRefNum, @RequestBody UpdateInstanceStatusForm form ){
    WorkflowInstanceState woin = facade.findWorkflowInstance( woinRefNum, true );
    if( woin == null ){
        return new ResponseEntity<>( HttpStatus.NOT_FOUND );
    }
    try{
        if( WorkflowInstanceStatus.ABORT.name().equals( form.getStatus() ) ){
            facade.abortWorkflowInstance( woinRefNum );
        }
        else if( WorkflowInstanceStatus.SUSPENDED.name().equals( form.getStatus() ) ){
            facade.suspendWorkflowInstance( woinRefNum );
        }
        else if( WorkflowInstanceStatus.EXECUTING.name().equals( form.getStatus() ) ){
            facade.resumeWorkflowInstance( woinRefNum );
        }
        else{
            return new ResponseEntity<>( HttpStatus.BAD_REQUEST );
        }
    }
    catch( UnexpectedStatusException e ){
        return new ResponseEntity<>( HttpStatus.CONFLICT );
    }
    woin = facade.findWorkflowInstance( woinRefNum, true );
    return new ResponseEntity<>( createInstanceModel( woin ), HttpStatus.OK );
}
 
Example 7
Source File: RestController.java    From telekom-workflow-engine with MIT License 5 votes vote down vote up
/**
 * Searches workflow instance's that match the given criteria.
 * 
 * <pre>
 * Request:  GET /workflowInstance/search?label1=aClientId
 * Response: OK, [{refNum: 1, workflowName: "credit.step1", workflowVersion: null, label1: "aClientId", label2: null, status: NEW}, {refNum: 2, workflowName: "credit.client.step1", workflowVersion: null, label1: "aClientId", label2: "anotherIdentificator", status: NEW}]
 * </pre>
 */
@RequestMapping(method = RequestMethod.GET, value = "/workflowInstance/search",
        produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE})
public ResponseEntity<List<WorkflowInstanceRestModel>> findInstances( @RequestParam(required = false) String label1,
                                                                      @RequestParam(required = false) String label2,
                                                                      @RequestParam(required = false) Boolean activeOnly ){
    if( activeOnly == null ){
        activeOnly = true;
    }
    label1 = StringUtils.trimToNull( label1 );
    label2 = StringUtils.trimToNull( label2 );
    List<WorkflowInstanceState> woins = facade.findWorkflowInstancesByLabels( label1, label2, activeOnly );
    return new ResponseEntity<>( createInstancesModel( woins ), HttpStatus.OK );
}
 
Example 8
Source File: RestController.java    From telekom-workflow-engine with MIT License 5 votes vote down vote up
/**
 * Searches active human tasks by role and/or user.
 * 
 * <pre>
 * Request:  GET /humanTask/search?role=auditor&user=hans
 * Response: OK, [{refNum:3, woinRefNum:1, tokenId:2, status:EXECUTED, role:"auditor", user:"hans", arguments:{task:"audit customer 500"}}]
 * </pre>
 */
@RequestMapping(method = RequestMethod.GET, value = "/humanTask/search",
        produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE})
public ResponseEntity<List<HumanTaskModel>> findActiveHumanTasks( @RequestParam(required = false) String role,
                                                                  @RequestParam(required = false) String user ){
    if( StringUtils.isBlank( role ) && StringUtils.isBlank( user ) ){
        return new ResponseEntity<>( HttpStatus.BAD_REQUEST );
    }
    List<WorkItemState> woits = facade.findActiveHumanTasksByRoleAndUser( role, user );
    return new ResponseEntity<>( createHumanTasksModel( woits ), HttpStatus.OK );
}
 
Example 9
Source File: ContentTypeNegotiationMessageRendererTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@ValueSource(strings = {MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE})
void shouldGenerateXMLResponseMessageForContentType(String contentType) {
    final MockHttpServletRequest request = HttpRequestBuilder.GET("/")
            .withHeader("Accept", contentType)
            .build();

    final ContentTypeAwareResponse response = new ContentTypeNegotiationMessageRenderer().getResponse(request);

    assertThat(response.getContentType().toString()).isEqualTo(contentType);
    assertThat(response.getFormattedMessage("foo")).isEqualTo("<access-denied>\n  <message>foo</message>\n</access-denied>\n");
}
 
Example 10
Source File: AbstractCrudController.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE } )
public void putXmlObject( @PathVariable( "uid" ) String pvUid, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
    List<T> objects = getEntity( pvUid );

    if ( objects.isEmpty() )
    {
        throw new WebMessageException( WebMessageUtils.notFound( getEntityClass(), pvUid ) );
    }

    User user = currentUserService.getCurrentUser();

    if ( !aclService.canUpdate( user, objects.get( 0 ) ) )
    {
        throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
    }

    T parsed = deserializeXmlEntity( request );
    ((BaseIdentifiableObject) parsed).setUid( pvUid );

    preUpdateEntity( objects.get( 0 ), parsed );

    MetadataImportParams params = importService.getParamsFromMap( contextService.getParameterValuesMap() )
        .setImportReportMode( ImportReportMode.FULL )
        .setUser( user )
        .setImportStrategy( ImportStrategy.UPDATE )
        .addObject( parsed );

    ImportReport importReport = importService.importMetadata( params );
    WebMessage webMessage = WebMessageUtils.objectReport( importReport );

    if ( importReport.getStatus() == Status.OK )
    {
        T entity = manager.get( getEntityClass(), pvUid );
        postUpdateEntity( entity );
    }
    else
    {
        webMessage.setStatus( Status.ERROR );
    }

    webMessageService.send( webMessage, response, request );
}
 
Example 11
Source File: RestController.java    From telekom-workflow-engine with MIT License 3 votes vote down vote up
/**
 * Notifies all waiting signal work items of the given workflow instance and the given signal name.
 * 
 * Technically, sets the work item's result value and updates the status to EXECUTED.
 * 
 * <pre>
 * Request:  POST /workflowInstance/1/signal/invoice {argument: {refNum:3, invoiceAmount: "10 Euro"}}
 * Response: NO_CONTENT
 * </pre>
 */
@RequestMapping(method = RequestMethod.POST, value = "/workflowInstance/{woinRefNum}/signal/{signal}",
        produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE})
public ResponseEntity<Void> sendSignal( @PathVariable long woinRefNum, @PathVariable String signal, @RequestBody String argument ){
    facade.sendSignalToWorkflowInstance( woinRefNum, signal, JsonUtil.deserialize( argument ) );
    return new ResponseEntity<>( HttpStatus.NO_CONTENT );
}