Search in sources :

Example 21 with MaintenanceEventVO

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);
    });
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) Test(org.junit.Test)

Example 22 with MaintenanceEventVO

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);
    });
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 23 with MaintenanceEventVO

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));
    }
}
Also used : ArrayList(java.util.ArrayList) IDataPoint(com.serotonin.m2m2.vo.IDataPoint)

Example 24 with MaintenanceEventVO

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;
}
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 25 with MaintenanceEventVO

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);
}
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

MaintenanceEventVO (com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO)17 ArrayList (java.util.ArrayList)9 ApiOperation (io.swagger.annotations.ApiOperation)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 MaintenanceEventModel (com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel)7 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)7 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)5 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)5 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)5 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)4 HashMap (java.util.HashMap)4 List (java.util.List)4 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)3 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)3 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)3 URI (java.net.URI)3 HashSet (java.util.HashSet)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ResponseEntity (org.springframework.http.ResponseEntity)3 MaintenanceEventsService (com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService)2