Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.capitalone.dashboard.rest.ServiceController Maven / Gradle / Ivy
package com.capitalone.dashboard.rest;
import com.capitalone.dashboard.editors.CaseInsensitiveServiceStatusEditor;
import com.capitalone.dashboard.model.DataResponse;
import com.capitalone.dashboard.model.Service;
import com.capitalone.dashboard.model.ServiceStatus;
import com.capitalone.dashboard.request.ServiceRequest;
import com.capitalone.dashboard.service.ServiceService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;
@RestController
public class ServiceController {
private final ServiceService serviceService;
@Autowired
public ServiceController(ServiceService serviceService) {
this.serviceService = serviceService;
}
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(ServiceStatus.class, new CaseInsensitiveServiceStatusEditor());
}
@RequestMapping(value = "/service", method = GET, produces = APPLICATION_JSON_VALUE)
public Iterable services() {
return serviceService.all();
}
@RequestMapping(value = "/dashboard/{id}/service", method = GET, produces = APPLICATION_JSON_VALUE)
public DataResponse>> dashboardServices(@PathVariable ObjectId id) {
Map> response = new HashMap<>();
response.put("services", serviceService.dashboardServices(id));
response.put("dependencies", serviceService.dashboardDependentServices(id));
return new DataResponse<>(response, System.currentTimeMillis());
}
@RequestMapping(value = "/dashboard/{id}/service", method = POST,
consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
public ResponseEntity createService(@PathVariable ObjectId id, @NotNull @RequestBody ServiceRequest serviceRequest) {
return ResponseEntity
.status(HttpStatus.CREATED)
.body(serviceService.create(id, serviceRequest.getName(), serviceRequest.getUrl()));
}
@RequestMapping(value = "/dashboard/{id}/service/{serviceId}", method = PUT,
consumes = APPLICATION_JSON_VALUE)
public ResponseEntity updateService(@PathVariable ObjectId id,
@PathVariable ObjectId serviceId,
@RequestBody ServiceRequest request) {
return ResponseEntity
.ok()
.body(serviceService.update(id, request.update(serviceService.get(serviceId))));
}
@RequestMapping(value = "/dashboard/{id}/service/{serviceId}", method = GET)
public ResponseEntity refreshService(@PathVariable ObjectId id, @PathVariable ObjectId serviceId) {
serviceService.refreshService(id, serviceId);
return ResponseEntity.noContent().build();
}
@RequestMapping(value = "/dashboard/{id}/service/{serviceId}", method = DELETE)
public ResponseEntity deleteService(@PathVariable ObjectId id, @PathVariable ObjectId serviceId) {
serviceService.delete(id, serviceId);
return ResponseEntity.noContent().build();
}
@RequestMapping(value = "/dashboard/{id}/dependent-service/{serviceId}", method = POST,
produces = APPLICATION_JSON_VALUE)
public ResponseEntity addDependentService(@PathVariable ObjectId id, @PathVariable ObjectId serviceId) {
return ResponseEntity
.status(HttpStatus.CREATED)
.body(serviceService.addDependentService(id, serviceId));
}
@RequestMapping(value = "/dashboard/{id}/dependent-service/{serviceId}", method = DELETE)
public ResponseEntity deleteDependentService(@PathVariable ObjectId id, @PathVariable ObjectId serviceId) {
serviceService.deleteDependentService(id, serviceId);
return ResponseEntity.noContent().build();
}
@RequestMapping(value = "/dashboard/{id}/service/{serviceId}", method = GET,
consumes = APPLICATION_JSON_VALUE)
public ResponseEntity refreshService(@PathVariable ObjectId id,
@PathVariable ObjectId serviceId,
@RequestBody ServiceRequest request) {
return ResponseEntity
.ok()
.body(serviceService.update(id, request.refresh(serviceService.get(serviceId))));
}
}