Search in sources :

Example 36 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-modules-public by infiniteautomation.

the class PublishedPointsRestController method partialUpdate.

@ApiOperation(value = "Partially update a published point", notes = "Requires edit permission")
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<AbstractPublishedPointModel<?>> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated published point", required = true) @PatchVORequestBody(service = PublishedPointService.class, modelClass = AbstractPublishedPointModel.class) AbstractPublishedPointModel<?> model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    PublishedPointVO vo = service.update(xid, unmap.apply(model, user));
    URI location = builder.path("/published-points/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(map.apply(vo, user), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublishedPointServiceTest method testNonAdminDelete.

@Test(expected = PermissionException.class)
public void testNonAdminDelete() {
    PublishedPointVO vo = insertNewVO(readUser);
    PublishedPointVO fromDb = service.get(vo.getId());
    assertVoEqual(vo, fromDb);
    runAs.runAs(readUser, () -> {
        service.delete(vo);
    });
}
Also used : MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) Test(org.junit.Test)

Example 38 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublishedPointService method delete.

@Override
protected PublishedPointVO delete(PublishedPointVO vo) throws PermissionException, NotFoundException {
    PermissionHolder user = Common.getUser();
    ensureDeletePermission(user, vo);
    getRuntimeManager().stopPublishedPoint(vo.getId());
    dao.delete(vo);
    return vo;
}
Also used : PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 39 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublishedPointService method update.

@Override
protected PublishedPointVO update(PublishedPointVO existing, PublishedPointVO vo) throws PermissionException, ValidationException {
    PermissionHolder user = Common.getUser();
    ensureEditPermission(user, existing);
    vo.setId(existing.getId());
    ensureValid(existing, vo);
    getRuntimeManager().stopPublishedPoint(vo.getId());
    dao.update(existing, vo);
    if (vo.isEnabled()) {
        getRuntimeManager().startPublishedPoint(vo);
    }
    return vo;
}
Also used : PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 40 with PublishedPointVO

use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.

the class PublisherDefinition method createPublishedPointVO.

/**
 * Create a new published point vo with all base field initialized
 */
@NonNull
public <T extends PublishedPointVO> T createPublishedPointVO(PUB publisher, IDataPoint dataPoint) {
    T vo = newPublishedPointVO();
    vo.setPublisherId(publisher.getId());
    vo.setPublisherXid(publisher.getXid());
    vo.setDataPointId(dataPoint.getId());
    vo.setDataPointXid(dataPoint.getXid());
    vo.setPublisherTypeName(getPublisherTypeName());
    return vo;
}
Also used : PublisherRT(com.serotonin.m2m2.rt.publish.PublisherRT) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Aggregations

PublishedPointVO (com.serotonin.m2m2.vo.publish.PublishedPointVO)34 MockPublishedPointVO (com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO)16 Test (org.junit.Test)12 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)9 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)8 MockPublisherVO (com.serotonin.m2m2.vo.publish.mock.MockPublisherVO)8 JsonException (com.serotonin.json.JsonException)6 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)6 PublisherVO (com.serotonin.m2m2.vo.publish.PublisherVO)6 NonNull (org.checkerframework.checker.nullness.qual.NonNull)6 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)4 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 PublisherRT (com.serotonin.m2m2.rt.publish.PublisherRT)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ArrayList (java.util.ArrayList)4 URI (java.net.URI)3 HttpHeaders (org.springframework.http.HttpHeaders)3