List of usage examples for org.springframework.http HttpStatus CREATED
HttpStatus CREATED
To view the source code for org.springframework.http HttpStatus CREATED.
Click Source Link
From source file:de.thm.arsnova.controller.SessionController.java
@RequestMapping(value = "/", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public Session postNewSession(@RequestBody final Session session, final HttpServletResponse response) { if (session != null && session.isCourseSession()) { final List<Course> courses = new ArrayList<Course>(); final Course course = new Course(); course.setId(session.getCourseId()); courses.add(course);//from ww w.j av a 2 s. co m final int sessionCount = sessionService.countSessions(courses); if (sessionCount > 0) { final String appendix = " (" + (sessionCount + 1) + ")"; session.setName(session.getName() + appendix); session.setShortName(session.getShortName() + appendix); } } final Session newSession = sessionService.saveSession(session); if (newSession == null) { response.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); return null; } return newSession; }
From source file:org.avidj.zuul.rs.ZuulTest.java
@Test public void itShallCreateShallowReadLock() { final Zuul zuul = createZuul(); given().standaloneSetup(zuul).param("t", "r").param("s", "s").when().put("/s/1/a").then() .statusCode(HttpStatus.CREATED.value()); given().standaloneSetup(zuul).when().get("/s/1/a").then().statusCode(HttpStatus.OK.value()).and() .body("key", hasItem(Arrays.asList("a"))).and().body("session", hasItem("1")).and() .body("type", hasItem("READ")).and().body("scope", hasItem("SHALLOW")).and() .body("count", hasItem(1)); }
From source file:com.marklogic.samplestack.web.QnADocumentController.java
/** * Exposes endpoint for asking a question. * @param sparseQuestion A POJO constructed from the request body. * @return The newly-created QnADocument's JSON node. *///from www . jav a2 s . c o m @RequestMapping(value = "questions", method = RequestMethod.POST) public @ResponseBody @PreAuthorize("hasRole('ROLE_CONTRIBUTORS')") @ResponseStatus(HttpStatus.CREATED) JsonNode ask( @RequestBody InitialQuestion sparseQuestion) { QnADocument qnaDoc = new QnADocument(mapper, sparseQuestion.getTitle(), sparseQuestion.getText(), sparseQuestion.getTags()); QnADocument answered = qnaService.ask(ClientRole.securityContextUserName(), qnaDoc); return answered.getJson(); }
From source file:de.zib.gndms.gndmc.gorfx.Test.TaskFlowClientTest.java
@Test(groups = { "TaskFlowClientTest" }) public void createTaskFlow() { FailureOrder order = new FailureOrder(); order.setMessage("TESTING TaskFlow creation"); order.setWhere(FailureOrder.FailurePlace.NOWHERE); ResponseEntity<Specifier<Facets>> responseEntity = gorfxClient.createTaskFlow( FailureTaskFlowMeta.TASK_FLOW_TYPE_KEY, order, admindn, TASKFLOW_WID, new LinkedMultiValueMap<String, String>()); Assert.assertNotNull(responseEntity); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.CREATED); taskFlowId = responseEntity.getBody().getUriMap().get(UriFactory.TASKFLOW_ID); }
From source file:io.github.cdelmas.spike.springboot.car.CarsController.java
@RequestMapping(method = RequestMethod.POST, consumes = "application/json") public ResponseEntity<CarRepresentation> create(@RequestBody Car car) { carRepository.save(car);/*from ww w.j av a 2 s . co m*/ HttpHeaders responseHeaders = new HttpHeaders(); Link link = linkTo(methodOn(CarsController.class).byId(String.valueOf(car.getId()))).withSelfRel(); responseHeaders.set("Location", link.getHref()); return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED); }
From source file:de.hska.ld.content.controller.TagControllerIntegrationTest.java
@Test public void testEditTagUsesHttpOkOnPersist() throws Exception { HttpResponse response = UserSession.user().post(RESOURCE_TAG, tag); Assert.assertEquals(HttpStatus.CREATED, ResponseHelper.getStatusCode(response)); Tag tag = ResponseHelper.getBody(response, Tag.class); Assert.assertNotNull(tag);/*from ww w . j a v a 2 s .c o m*/ Assert.assertNotNull(tag.getId()); String updatedName = "updatedName"; tag.setName(updatedName); HttpResponse response2 = UserSession.user().put(RESOURCE_TAG + "/" + tag.getId(), tag); Assert.assertEquals(HttpStatus.OK, ResponseHelper.getStatusCode(response2)); Tag tag2 = ResponseHelper.getBody(response2, Tag.class); Assert.assertNotNull(tag2); Assert.assertNotNull(tag2.getId()); Assert.assertEquals(updatedName, tag2.getName()); }
From source file:com.envision.envservice.rest.EvaluationResource.java
/** * ?/* ww w .j ava 2 s.c o m*/ * * */ @POST @Path("/addNullEvaluationForUser") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response addNullEvaluationForUser(EvaluationBo evaluationBo) throws Exception { HttpStatus status = HttpStatus.CREATED; String response = StringUtils.EMPTY; if (!checkParamForUser(evaluationBo)) { status = HttpStatus.BAD_REQUEST; response = FailResult.toJson(Code.PARAM_ERROR, "?"); } else { response = evaluationService.addNullEvaluationForUser(evaluationBo).toJSONString(); } return Response.status(status.value()).entity(response).build(); }
From source file:com.epam.ta.reportportal.ws.controller.impl.UserFilterController.java
@Override @RequestMapping(method = RequestMethod.POST) @ResponseBody//from w w w. j a v a 2 s . co m @ResponseStatus(HttpStatus.CREATED) @ApiOperation("Create user filter") public List<EntryCreatedRS> createFilter(@PathVariable String projectName, @RequestBody @Validated CollectionsRQ<CreateUserFilterRQ> createFilterRQ, Principal principal) { return createFilterHandler.createFilter(principal.getName(), EntityUtils.normalizeProjectName(projectName), createFilterRQ); }
From source file:com.swcguild.blacksmithblogcapstone.controller.BlackSmithController.java
@Valid @RequestMapping(value = "/blogEntry", method = RequestMethod.POST) @ResponseBody/* w w w .j a v a 2 s. c om*/ @ResponseStatus(HttpStatus.CREATED) public BlogEntry addBlogEntry(@Valid @RequestBody BlogEntry blogEntry) { return dao.addBlogEntry(blogEntry); }
From source file:reconf.server.services.security.UpsertUserService.java
private HttpStatus upsert(Client client, List<GrantedAuthority> authorities) { HttpStatus status;//from ww w .j a v a2 s . c o m User user = new User(client.getUsername(), client.getPassword(), authorities); if (userDetailsManager.userExists(client.getUsername())) { userDetailsManager.updateUser(user); status = HttpStatus.OK; } else { userDetailsManager.createUser(user); status = HttpStatus.CREATED; } return status; }