Search in sources :

Example 1 with MaintenanceEventModel

use of com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsRestController method update.

@ApiOperation(value = "Update an existing maintenance event")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}")
public ResponseEntity<MaintenanceEventModel> update(@PathVariable String xid, @ApiParam(value = "Updated maintenance event", required = true) @RequestBody(required = true) MaintenanceEventModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    MaintenanceEventVO vo = service.update(xid, model.toVO());
    URI location = builder.path("/maintenance-events/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(new MaintenanceEventModel(vo), headers, HttpStatus.OK);
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) HttpHeaders(org.springframework.http.HttpHeaders) MaintenanceEventModel(com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with MaintenanceEventModel

use of com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsRestController method create.

@ApiOperation(value = "Create new maintenance event", notes = "User must have global data source permission")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<MaintenanceEventModel> create(@ApiParam(value = "Updated maintenance event", required = true) @RequestBody(required = true) MaintenanceEventModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    MaintenanceEventVO vo = service.insert(model.toVO());
    URI location = builder.path("/maintenance-events/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(new MaintenanceEventModel(vo), headers, HttpStatus.OK);
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) HttpHeaders(org.springframework.http.HttpHeaders) MaintenanceEventModel(com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with MaintenanceEventModel

use of com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsRestController method getForPointsByIds.

@ApiOperation(value = "Find Maintenance Events linked to data points by point IDs", notes = "Returns a map of point ids to a list of events that have this data point in their list OR the its data source in the list", response = Map.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, value = "/query/get-for-points-by-ids/{pointIds}")
public Map<Integer, List<MaintenanceEventModel>> getForPointsByIds(@PathVariable(required = true) List<Integer> pointIds, HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
    Map<Integer, List<MaintenanceEventModel>> map = new HashMap<>();
    for (Integer id : pointIds) {
        List<MaintenanceEventModel> models = new ArrayList<>();
        map.put(id, models);
        dao.getForDataPoint(id, new Consumer<MaintenanceEventVO>() {

            @Override
            public void accept(MaintenanceEventVO vo) {
                MaintenanceEventModel model = new MaintenanceEventModel(vo);
                fillDataPoints(model);
                fillDataSources(model);
                models.add(model);
            }
        });
    }
    return map;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) MaintenanceEventModel(com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with MaintenanceEventModel

use of com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsRestController method getForPointsByXid.

@ApiOperation(value = "Find Maintenance Events linked to data points by point XIDs", notes = "Returns a map of point xids to a list of events that have this data point in their list OR the its data source in the list", response = Map.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, value = "/query/get-for-points-by-xids/{pointXids}")
public Map<String, List<MaintenanceEventModel>> getForPointsByXid(@PathVariable(required = true) List<String> pointXids, HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
    Map<String, List<MaintenanceEventModel>> map = new HashMap<>();
    for (String xid : pointXids) {
        List<MaintenanceEventModel> models = new ArrayList<>();
        map.put(xid, models);
        dao.getForDataPoint(xid, new Consumer<MaintenanceEventVO>() {

            @Override
            public void accept(MaintenanceEventVO vo) {
                MaintenanceEventModel model = new MaintenanceEventModel(vo);
                fillDataPoints(model);
                fillDataSources(model);
                models.add(model);
            }
        });
    }
    return map;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) MaintenanceEventModel(com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with MaintenanceEventModel

use of com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsRestController method partialUpdate.

@ApiOperation(value = "Partially update an existing maintenance event")
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<MaintenanceEventModel> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated maintenance event", required = true) @PatchVORequestBody(service = MaintenanceEventsService.class, modelClass = MaintenanceEventModel.class) MaintenanceEventModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    MaintenanceEventVO vo = service.update(xid, model.toVO());
    URI location = builder.path("/maintenance-events/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(new MaintenanceEventModel(vo), headers, HttpStatus.OK);
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) HttpHeaders(org.springframework.http.HttpHeaders) MaintenanceEventModel(com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MaintenanceEventModel (com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel)7 MaintenanceEventVO (com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO)7 ApiOperation (io.swagger.annotations.ApiOperation)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 URI (java.net.URI)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ResponseEntity (org.springframework.http.ResponseEntity)3