Search in sources :

Example 1 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project spring-framework by spring-projects.

the class ServletInvocableHandlerMethod method initResponseStatus.

private void initResponseStatus() {
    ResponseStatus annotation = getMethodAnnotation(ResponseStatus.class);
    if (annotation == null) {
        annotation = AnnotatedElementUtils.findMergedAnnotation(getBeanType(), ResponseStatus.class);
    }
    if (annotation != null) {
        this.responseStatus = annotation.code();
        this.responseReason = annotation.reason();
    }
}
Also used : ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 2 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project symmetric-ds by JumpMind.

the class RestService method getSnapshot.

/**
     * Takes a snapshot for the specified engine and streams it to the client.
     */
@ApiOperation(value = "Take a diagnostic snapshot for the specified engine")
@RequestMapping(value = "engine/{engine}/snapshot", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final void getSnapshot(@PathVariable("engine") String engineName, HttpServletResponse resp) {
    BufferedInputStream bis = null;
    try {
        ISymmetricEngine engine = getSymmetricEngine(engineName);
        File file = engine.snapshot();
        resp.setHeader("Content-Disposition", String.format("attachment; filename=%s", file.getName()));
        bis = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(bis, resp.getOutputStream());
    } catch (IOException e) {
        throw new IoException(e);
    } finally {
        IOUtils.closeQuietly(bis);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project symmetric-ds by JumpMind.

the class RestService method getOutgoingBatchSummary.

@ApiOperation(value = "Outgoing summary of batches and data counts waiting for a node")
@RequestMapping(value = "/engine/{engine}/outgoingBatchSummary", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final BatchSummaries getOutgoingBatchSummary(@PathVariable("engine") String engineName, @RequestParam(value = WebConstants.NODE_ID) String nodeId, @ApiParam(value = "This the password for the nodeId being passed in.  The password is stored in the node_security table.") @RequestParam(value = WebConstants.SECURITY_TOKEN) String securityToken) {
    ISymmetricEngine engine = getSymmetricEngine(engineName);
    if (securityVerified(nodeId, engine, securityToken)) {
        BatchSummaries summaries = new BatchSummaries();
        summaries.setNodeId(nodeId);
        IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
        List<OutgoingBatchSummary> list = outgoingBatchService.findOutgoingBatchSummary(OutgoingBatch.Status.RQ, OutgoingBatch.Status.QY, OutgoingBatch.Status.NE, OutgoingBatch.Status.SE, OutgoingBatch.Status.LD, OutgoingBatch.Status.ER);
        for (OutgoingBatchSummary sum : list) {
            if (sum.getNodeId().equals(nodeId)) {
                BatchSummary summary = new BatchSummary();
                summary.setBatchCount(sum.getBatchCount());
                summary.setDataCount(sum.getDataCount());
                summary.setOldestBatchCreateTime(sum.getOldestBatchCreateTime());
                summary.setStatus(sum.getStatus().name());
                summaries.getBatchSummaries().add(summary);
            }
        }
        return summaries;
    } else {
        throw new NotAllowedException();
    }
}
Also used : BatchSummary(org.jumpmind.symmetric.web.rest.model.BatchSummary) OutgoingBatchSummary(org.jumpmind.symmetric.model.OutgoingBatchSummary) OutgoingBatchSummary(org.jumpmind.symmetric.model.OutgoingBatchSummary) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) BatchSummaries(org.jumpmind.symmetric.web.rest.model.BatchSummaries) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project symmetric-ds by JumpMind.

the class RestService method postInstall.

/**
     * Installs and starts a new node
     * 
     * @param file
     *            A file stream that contains the node's properties.
     */
@ApiOperation(value = "Load a configuration file to the single engine")
@RequestMapping(value = "engine/install", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public final void postInstall(@RequestParam MultipartFile file) {
    try {
        Properties properties = new Properties();
        properties.load(file.getInputStream());
        getSymmetricEngineHolder().install(properties);
    } catch (RuntimeException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : Properties(java.util.Properties) IOException(java.io.IOException) IoException(org.jumpmind.exception.IoException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project symmetric-ds by JumpMind.

the class RestService method postRequestInitialLoad.

/**
     * Requests an initial load from the server for the node id provided. The
     * initial load requst directs the server to queue up initial load data for
     * the client node. Data is obtained for the initial load by the client
     * calling the pull method.
     * 
     * @param nodeID
     */
@ApiOperation(value = "Request an initial load for the specified node for the specified engine")
@RequestMapping(value = "/engine/{engine}/requestinitialload", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public final void postRequestInitialLoad(@PathVariable("engine") String engineName, @RequestParam(value = "nodeId") String nodeId) {
    ISymmetricEngine engine = getSymmetricEngine(engineName);
    INodeService nodeService = engine.getNodeService();
    nodeService.setInitialLoadEnabled(nodeId, true, false, -1, "restapi");
}
Also used : INodeService(org.jumpmind.symmetric.service.INodeService) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)93 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)69 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)35 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)26 GetMapping (org.springframework.web.bind.annotation.GetMapping)17 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)16 User (org.hisp.dhis.user.User)14 Date (java.util.Date)13 Configuration (org.hisp.dhis.configuration.Configuration)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Period (org.hisp.dhis.period.Period)11 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)9 Calendar (java.util.Calendar)9 DataSet (org.hisp.dhis.dataset.DataSet)7 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)7 ArrayList (java.util.ArrayList)6 DataApproval (org.hisp.dhis.dataapproval.DataApproval)6 DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)6 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)6 Proveedor (sic.modelo.Proveedor)6