Example usage for org.springframework.http ResponseEntity created

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

Introduction

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

Prototype

public static BodyBuilder created(URI location) 

Source Link

Document

Create a new builder with a HttpStatus#CREATED CREATED status and a location header set to the given URI.

Usage

From source file:io.pivotal.strepsirrhini.chaosloris.web.ApplicationController.java

@Transactional
@RequestMapping(method = POST, value = "", consumes = APPLICATION_JSON_VALUE)
public ResponseEntity create(@Valid @RequestBody ApplicationCreateInput input) {
    Application application = new Application(input.getApplicationId());
    this.applicationRepository.saveAndFlush(application);

    return ResponseEntity
            .created(linkTo(methodOn(ApplicationController.class).read(application.getId())).toUri()).build();
}

From source file:com.todo.backend.web.rest.TodoApi.java

@RequestMapping(value = "/todo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed//from   w ww  .j a  va 2  s.c  o m
@Transactional
public ResponseEntity<CreateTodoResponse> createTodo(@Valid @RequestBody CreateTodoRequest request)
        throws URISyntaxException {
    log.debug("POST /todo {}", request);
    final Todo todo = convertToTodo(request);
    final Todo result = todoRepository.save(todo);
    return ResponseEntity.created(new URI("/todo/" + result.getId())).body(convertToCreateTodoResponse(result));
}

From source file:com.todo.backend.web.rest.UserApi.java

@RequestMapping(value = "/user", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed/*  w  ww  .j  av a2 s.co  m*/
@Transactional
@PreAuthorize("hasAuthority('ADMIN')")
public ResponseEntity<CreateUserResponse> createUser(@Valid @RequestBody CreateUserRequest request)
        throws URISyntaxException {
    log.debug("POST /user {}", request);
    final User user = convertToUser(request);
    final User result = userRepository.save(user);
    return ResponseEntity.created(new URI("/user/" + result.getId())).body(convertToCreateUserResponse(result));
}

From source file:com.orange.clara.pivotaltrackermirror.controllers.MirrorReferenceController.java

@ApiOperation(value = "Register a mirror reference", response = MirrorReference.class)
@RequestMapping(method = RequestMethod.POST, value = "", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> register(@RequestBody MirrorReferenceRequest mirrorReferenceRequest)
        throws ConvertException, CannotFindConverterException, SchedulerException {
    MirrorReference mirrorReference = mirrorReferenceRequest.toMirrorReference();
    mirrorReference.setUpdatedAt(null);/*  w  ww  .jav a 2  s  .  c  o m*/
    mirrorReference = this.mirrorReferenceRepo.save(mirrorReference);
    JobDetail job = JobBuilder.newJob(MirrorJob.class)
            .withIdentity(MirrorJob.JOB_KEY_NAME + mirrorReference.getId(), MirrorJob.JOB_KEY_GROUP)
            .usingJobData(MirrorJob.JOB_MIRROR_REFERENCE_ID_KEY, String.valueOf(mirrorReference.getId()))
            .usingJobData(MirrorJob.JOB_MIRROR_TOKEN_KEY, mirrorReferenceRequest.getToken()).build();
    Trigger trigger = TriggerBuilder.newTrigger()
            .withIdentity(MirrorJob.TRIGGER_KEY_NAME + mirrorReference.getId(), MirrorJob.TRIGGER_KEY_GROUP)
            .startNow().withSchedule(SimpleScheduleBuilder.simpleSchedule()
                    .withIntervalInMinutes(refreshMirrorMinutes).repeatForever())
            .build();
    scheduler.scheduleJob(job, trigger);
    return ResponseEntity.created(URI.create(appUrl + "/api/task/" + mirrorReference.getId() + "/status"))
            .body(mirrorReference);
}

From source file:org.farrukh.template.rest.inbound.RestInboundGateway.java

@RequestMapping(method = RequestMethod.POST, consumes = CustomMediaTypeHolder.JSON_MIME_TYPE)
public ResponseEntity<LibraryResource> createLibrary(@RequestBody final Library library) {
    try {/* www  .  j a v  a 2  s . c o  m*/
        Library createdLibrary = coreService.create(library);
        URI location = ServletUriComponentsBuilder.fromCurrentRequestUri().build().toUri();
        LibraryResource libraryResource = assembler.toResource(createdLibrary);
        return ResponseEntity.created(location).body(libraryResource);
    } catch (Exception e) {
        throw new LibraryCreationError(RestFeedbackContext.SOME_FEEDBACK, e);
    }
}

From source file:doge.controller.UsersRestController.java

@RequestMapping(method = RequestMethod.POST, value = "{userId}/doge")
public ResponseEntity<?> postDogePhoto(@PathVariable String userId, @RequestParam MultipartFile file,
        UriComponentsBuilder uriBuilder) throws IOException {
    Photo photo = file::getInputStream;/*from w  ww .j a  v a 2  s .c om*/
    User user = this.userRepository.findOne(userId);
    DogePhoto doge = this.dogeService.addDogePhoto(user, photo);
    URI uri = uriBuilder.path("/users/{userId}/doge/{dogeId}").buildAndExpand(userId, doge.getId()).toUri();
    sendMessage(user, uri);
    return ResponseEntity.created(uri).build();
}

From source file:de.lgblaumeiser.ptm.rest.BookingRestController.java

@RequestMapping(method = RequestMethod.POST, value = "/{dayString}")
public ResponseEntity<?> addBooking(@PathVariable String dayString, @RequestBody BookingBody newData) {
    LocalDate day = LocalDate.parse(dayString);
    Activity activity = services.activityStore().retrieveById(valueOf(newData.activityId))
            .orElseThrow(IllegalStateException::new);
    Booking newBooking = services.bookingService().addBooking(day, newData.user, activity,
            parse(newData.starttime), newData.comment);
    if (newData.endtime != null) {
        newBooking = services.bookingService().endBooking(newBooking, parse(newData.endtime));
    }/*from  w ww .j  a  va 2 s .  c om*/
    URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{day}/{id}")
            .buildAndExpand(day.format(ISO_LOCAL_DATE), newBooking.getId()).toUri();
    return ResponseEntity.created(location).build();
}

From source file:org.moserp.environment.rest.ValueListController.java

@RequestMapping(method = RequestMethod.POST, value = "/valueLists/{key}/values")
public ResponseEntity<Void> addValueForKey(@PathVariable String key, ValueListItem item)
        throws URISyntaxException {
    ValueList valueList = valueListRepository.findByKey(key);
    if (valueList == null) {
        valueList = new ValueList(key);
        valueList = valueListRepository.save(valueList);
    }/*w ww .java  2 s . co  m*/
    valueList.addValue(item);
    URI location = new URI(entityLinks.linkToSingleResource(valueList).getHref());
    return ResponseEntity.created(location).build();
}

From source file:com.fns.grivet.controller.NamedQueryController.java

@PreAuthorize("hasAuthority('write:query')")
@PostMapping("/api/v1/query")
public ResponseEntity<?> createNamedQuery(@RequestBody NamedQuery query) {
    ResponseEntity<?> result = ResponseEntity.unprocessableEntity().build();
    Assert.isTrue(StringUtils.isNotBlank(query.getName()), "Query name must not be null, empty or blank.");
    Assert.notNull(query.getQuery(), "Query string must not be null!");
    Assert.isTrue(isSupportedQuery(query), "Query must start with either CALL or SELECT");
    // check for named parameters; but only if they exist
    if (!query.getParams().isEmpty()) {
        query.getParams().keySet()/*  w  w  w  .j  a v  a  2  s. co m*/
                .forEach(k -> Assert.isTrue(query.getQuery().contains(String.format(":%s", k)),
                        String.format("Query must contain named parameter [%s]", k)));
    }
    namedQueryService.create(query);
    log.info("Named Query \n\n{}\n\n successfully registered!", query);
    UriComponentsBuilder ucb = UriComponentsBuilder.newInstance();
    if (query.getParams().isEmpty()) {
        result = ResponseEntity
                .created(ucb.path("/api/v1/query/{name}").buildAndExpand(query.getName()).toUri()).build();
    } else {
        result = ResponseEntity.noContent().build();
    }
    return result;
}

From source file:io.pivotal.strepsirrhini.chaosloris.web.ScheduleController.java

@Transactional
@RequestMapping(method = POST, value = "", consumes = APPLICATION_JSON_VALUE)
public ResponseEntity create(@Valid @RequestBody ScheduleCreateInput input) {
    Schedule schedule = new Schedule(input.getExpression(), input.getName());
    this.scheduleRepository.saveAndFlush(schedule);
    this.applicationEventPublisher.publishEvent(new ScheduleCreatedEvent(this, schedule));

    return ResponseEntity.created(linkTo(methodOn(ScheduleController.class).read(schedule.getId())).toUri())
            .build();//from  ww w  .  ja  v a 2  s  . c o  m
}