Example usage for org.springframework.http ResponseEntity ok

List of usage examples for org.springframework.http ResponseEntity ok

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity ok.

Prototype

public static BodyBuilder ok() 

Source Link

Document

Create a builder with the status set to HttpStatus#OK OK .

Usage

From source file:org.ow2.proactive.workflow_catalog.rest.controller.WorkflowController.java

@ApiOperation(value = "Gets a workflow's metadata by IDs", notes = "Returns metadata associated to the latest revision of the workflow.")
@ApiResponses(value = @ApiResponse(code = 404, message = "Bucket or workflow not found"))
@RequestMapping(value = "/buckets/{bucketId}/workflows/{idList}", method = GET)
public ResponseEntity<?> get(@PathVariable Long bucketId, @PathVariable List<Long> idList,
        @ApiParam(value = "Force response to return workflow XML content when set to 'xml'. Or extract workflows as ZIP when set to 'zip'.") @RequestParam(required = false) Optional<String> alt,
        HttpServletResponse response) throws MalformedURLException {
    if (alt.isPresent() && ZIP_EXTENSION.equals(alt.get())) {
        byte[] zip = workflowService.getWorkflowsAsArchive(bucketId, idList);

        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("application/zip");
        response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"archive.zip\"");
        response.addHeader(HttpHeaders.CONTENT_ENCODING, "binary");
        try {//from www .j av  a  2  s . c o m
            response.getOutputStream().write(zip);
            response.getOutputStream().flush();
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
        return ResponseEntity.ok().build();
    } else {
        if (idList.size() == 1) {
            return workflowService.getWorkflowMetadata(bucketId, idList.get(0), alt);
        } else {
            return ResponseEntity.badRequest().build();
        }
    }
}

From source file:de.unimannheim.spa.process.rest.ProjectRestController.java

@RequestMapping(value = "/{projectID}", method = RequestMethod.DELETE)
public ResponseEntity<Void> removeProject(@PathVariable String projectID) {
    ResponseEntity<Void> response = null;
    final Optional<Project> projectToRemove = spaService.findProjectById(PROJECT_BASE_URL + projectID);
    if (projectToRemove.isPresent()) {
        spaService.deleteProject(projectToRemove.get());
        response = ResponseEntity.ok().build();
    } else {/*from  ww w .ja  v a  2 s. c  o m*/
        response = ResponseEntity.notFound().build();
    }
    return response;
}

From source file:me.j360.trace.server.ZipkinQueryApiV1.java

/**
 * We cache names if there are more than 3 services. This helps people getting started: if we
 * cache empty results, users have more questions. We assume caching becomes a concern when zipkin
 * is in active use, and active use usually implies more than 3 services.
 *//*from ww w.java  2  s . c  o m*/
ResponseEntity<List<String>> maybeCacheNames(List<String> names) {
    ResponseEntity.BodyBuilder response = ResponseEntity.ok();
    if (serviceCount > 3) {
        response.cacheControl(CacheControl.maxAge(namesMaxAge, TimeUnit.SECONDS).mustRevalidate());
    }
    return response.body(names);
}

From source file:com.anuz.dummyapi.controller.ClientController.java

@RequestMapping(value = "/contents_file/{id}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> downloadFiles(@PathVariable("id") int id) throws IOException {

    List<Content> contentList = contentUpdateService.getUnsynchronizedContentList(id);
    if (!contentList.isEmpty()) {
        String fileName = "zipFile" + new Date().getTime() + ".zip";
        ZipUtil zipFile = new ZipUtil();
        for (Content content : contentList) {
            System.out.println(CONSTANTS.CONTENTS + content.getContentLocation());
            zipFile.generateFileList(new File(CONSTANTS.CONTENTS + content.getContentLocation()));
        }//from w  w  w  . j  ava  2s  .c o  m
        String finalZip = zipFile.zipIt(CONSTANTS.CONTENTS + fileName);
        //            System.out.println(finalZip);
        //            if(finalZip!=null){
        //                contentUpdateService.updateContentStatus(id,Boolean.FALSE);
        //            }

        FileSystemResource file = new FileSystemResource(finalZip);

        //            return ResponseEntity.ok().contentLength(file.contentLength())
        //                    .contentType(MediaType.parseMediaType("application/octet-stream"))
        //                    .header("Content-Disposition", "attachment; filename=" + fileName)
        //                    .body(new InputStreamResource(file.getInputStream()));

        return ResponseEntity.ok().contentLength(file.contentLength())
                .contentType(MediaType.parseMediaType("application/zip"))
                .header("Content-Disposition", "attachment; filename=" + fileName)
                .body(new InputStreamResource(file.getInputStream()));

    }
    return ResponseEntity.ok().body(null);

}

From source file:org.appverse.web.framework.backend.frontfacade.mvc.schema.services.presentation.SchemaGeneratorServiceImpl.java

@RequestMapping(value = "/entity/{entity}.schema.json", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<JsonSchema> generateSchemaByEntityName2(@PathVariable("entity") String entity) {
    JsonSchema schema = null;/* w  w  w . ja v a 2  s  .  c  o m*/
    if (StringUtils.isEmpty(entity)) {
        throw new PresentationException("invalid content");
    }
    try {
        Class<?> clazz = Class.forName(entity);
        schema = entityConverter.convert(clazz, TypeDescriptor.valueOf(String.class),
                TypeDescriptor.valueOf(JsonSchema.class));

    } catch (ClassNotFoundException nsme) {
        throw new PresentationException("invalid class:" + entity, nsme);
    } catch (NullPointerException npe) {
        // workarround where entity have a setter without getter it fails to parse
        throw new PresentationException("entity have setter without getter", npe);
    }
    return ResponseEntity.ok().contentType(APPLICATION_SCHEMA_JSON).body(schema);
}

From source file:com.erudika.scoold.controllers.SearchController.java

@ResponseBody
@GetMapping("/opensearch.xml")
public ResponseEntity<String> openSearch() {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
            + "<OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\" "
            + "  xmlns:moz=\"http://www.mozilla.org/2006/browser/search/\">\n" + "  <ShortName>"
            + Config.APP_NAME + "</ShortName>\n"
            + "  <Description>Search for questions and answers</Description>\n"
            + "  <InputEncoding>UTF-8</InputEncoding>\n"
            + "  <Image width=\"16\" height=\"16\" type=\"image/x-icon\">http://scoold.com/favicon.ico</Image>\n"
            + "  <Url type=\"text/html\" method=\"get\" template=\"" + ScooldServer.getServerURL()
            + "/search?q={searchTerms}\"></Url>\n" + "</OpenSearchDescription>";
    return ResponseEntity.ok().contentType(MediaType.APPLICATION_XML)
            .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)).eTag(Utils.md5(xml)).body(xml);
}

From source file:de.unimannheim.spa.process.rest.ProjectRestController.java

@RequestMapping(value = "/{projectID}/processes", method = RequestMethod.GET)
public ResponseEntity<Map<String, Object>> getAllProcesses(@PathVariable String projectID) {
    return spaService.findProjectById(PROJECT_BASE_URL + projectID).map(project -> project.getDataPools())
            .map(processes -> {/*from   ww  w .  j  av  a 2  s. c  om*/
                return ResponseEntity.ok().contentType(JSON_CONTENT_TYPE)
                        .body(serializeDataPool(processes.get(0).getDataBuckets()));
            }).orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(JSON_CONTENT_TYPE)
                    .body(Collections.emptyMap()));
}

From source file:com.erudika.scoold.controllers.SearchController.java

@ResponseBody
@GetMapping("/feed.xml")
public ResponseEntity<String> feed() {
    String feed = "";
    try {//  w  w w  .j  a  v a2  s .  c om
        feed = new SyndFeedOutput().outputString(getFeed());
    } catch (Exception ex) {
        logger.error("Could not generate feed", ex);
    }
    return ResponseEntity.ok().contentType(MediaType.APPLICATION_ATOM_XML)
            .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)).eTag(Utils.md5(feed)).body(feed);
}

From source file:com.couchbase.trombi.controllers.CoworkerController.java

@RequestMapping(value = "/{coworkerId}", method = RequestMethod.PATCH)
public ResponseEntity<?> patchCoworker(@PathVariable("coworkerId") int id,
        @RequestBody Map<String, Object> body) {
    String fullId = CoworkerRepository.PREFIX + id;
    if (!bucket.exists(fullId)) {
        return ResponseEntity.notFound().build();
    }//from www .j  a  va 2 s  .  com

    MutateInBuilder builder = bucket.mutateIn(fullId);

    if (body.containsKey("name")) {
        builder.upsert("name", body.get("name"), false);
    }

    if (body.containsKey("description")) {
        builder.upsert("description", body.get("description"), false);
    }

    if (body.containsKey("team")) {
        builder.upsert("team", body.get("team"), false);
    }

    if (body.containsKey("skills")) {
        Iterable<Object> skills = (Iterable<Object>) body.get("skills");
        for (Object skill : skills) {
            builder.arrayAddUnique("skills", skill, false);
        }
    }

    if (body.containsKey("imHandles")) {
        Map<String, Object> imHandles = (Map<String, Object>) body.get("imHandles");
        for (Map.Entry<String, Object> entry : imHandles.entrySet()) {
            builder.upsert("imHandles." + entry.getKey(), entry.getValue(), true);
        }
    }

    if (body.containsKey("mainLocation")) {
        Map<String, Object> mainLocation = (Map<String, Object>) body.get("mainLocation");
        if (mainLocation.containsKey("name")) {
            builder.replace("mainLocation.name", mainLocation.get("name"));
        }
        if (mainLocation.containsKey("description")) {
            builder.replace("mainLocation.description", mainLocation.get("description"));
        }

        //disallow anything else (coordinates and timezone)
        if (!mainLocation.containsKey("name") && !mainLocation.containsKey("description")) {
            return ResponseEntity.badRequest().body("Main location can only have name and description updated, "
                    + "use a different API to switch to a whole new location");
        }
    }

    if (body.containsKey("lastCheckin")) {
        return ResponseEntity.badRequest().body("Checkin can only be performed through the dedicated API");
    }

    builder.execute();
    Coworker result = repository.findOne(fullId);
    return ResponseEntity.ok().body(result);
}