use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsServiceTest method testAddReadRoleUserDoesNotHave.
@Test
@Override
public void testAddReadRoleUserDoesNotHave() {
validation.expectValidationException(getReadPermissionContextKey());
MaintenanceEventVO vo = newVO(readUser);
setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
service.insert(vo);
runAs.runAs(readUser, () -> {
MaintenanceEventVO fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
fromDb.setTogglePermission(MangoPermission.superadminOnly());
service.update(fromDb.getId(), fromDb);
});
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsServiceTest method testCannotRemoveToggleAccess.
@Test
@ExpectValidationException("togglePermission")
public void testCannotRemoveToggleAccess() {
MaintenanceEventVO vo = newVO(editUser);
setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
service.insert(vo);
runAs.runAs(readUser, () -> {
MaintenanceEventVO fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
fromDb.setTogglePermission(MangoPermission.superadminOnly());
service.update(fromDb.getId(), fromDb);
});
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO in project ma-modules-public by infiniteautomation.
the class MaintenanceEventsServiceTest method assertVoEqual.
@Override
void assertVoEqual(MaintenanceEventVO expected, MaintenanceEventVO actual) {
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getXid(), actual.getXid());
assertEquals(expected.getName(), actual.getName());
List<Integer> actualPoints = actual.getDataPoints();
List<Integer> expectedPoints = expected.getDataPoints();
assertEquals(expectedPoints.size(), actualPoints.size());
for (int i = 0; i < expectedPoints.size(); i++) {
assertEquals(expectedPoints.get(i), actualPoints.get(i));
}
List<String> actualPointXids = new ArrayList<>();
List<String> expectedPointXids = new ArrayList<>();
dao.getPointXids(actual.getId(), actualPointXids::add);
dao.getPointXids(expected.getId(), expectedPointXids::add);
assertEquals(expectedPointXids.size(), actualPointXids.size());
for (int i = 0; i < expectedPointXids.size(); i++) {
assertEquals(expectedPointXids.get(i), actualPointXids.get(i));
}
List<Integer> actualDataSources = actual.getDataSources();
List<Integer> expectedDataSources = expected.getDataSources();
assertEquals(expectedDataSources.size(), actualDataSources.size());
for (int i = 0; i < expectedDataSources.size(); i++) {
assertEquals(expectedDataSources.get(i), actualDataSources.get(i));
}
List<String> actualDataSourceXids = new ArrayList<>();
List<String> expectedDataSourceXids = new ArrayList<>();
dao.getSourceXids(actual.getId(), actualDataSourceXids::add);
dao.getSourceXids(expected.getId(), expectedDataSourceXids::add);
assertEquals(expectedDataSourceXids.size(), actualDataSourceXids.size());
for (int i = 0; i < expectedDataSourceXids.size(); i++) {
assertEquals(expectedDataSourceXids.get(i), actualDataSourceXids.get(i));
}
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO 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;
}
use of com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO 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);
}
Aggregations