Search in sources :

Example 51 with PublishedPointVO

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

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 52 with PublishedPointVO

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

the class RuntimeManagerImpl method startPublisher.

@Override
public void startPublisher(PublisherVO vo) {
    // Ensure that the publisher is saved and enabled.
    Assert.isTrue(vo.getId() > 0, "Publisher must be saved");
    Assert.isTrue(vo.isEnabled(), "Publisher must be enabled");
    ensureState(ILifecycleState.INITIALIZING, ILifecycleState.RUNNING);
    PublisherRT<? extends PublisherVO, ? extends PublishedPointVO, ? extends SendThread> publisher = runningPublishers.computeIfAbsent(vo.getId(), k -> vo.createPublisherRT());
    long startTime = System.nanoTime();
    // Initialize the runtime of the publisher.
    publisher.initialize(false);
    long duration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
    stateMessage = new TranslatableMessage("runtimeManager.initialize.publisher", vo.getName(), duration);
    LOG.info(String.format("%s took %dms to start", publisher.readableIdentifier(), duration));
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 53 with PublishedPointVO

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

the class RuntimeManagerImpl method startPublishedPoint.

@Override
public void startPublishedPoint(PublishedPointVO vo) {
    // Ensure that the published point is saved and enabled.
    Assert.isTrue(vo.getId() > 0, "Published point must be saved");
    Assert.isTrue(vo.isEnabled(), "Published point not enabled");
    ensureState(ILifecycleState.INITIALIZING, ILifecycleState.RUNNING);
    // Only add the published point if its publisher is enabled.
    PublisherRT<? extends PublisherVO, ? extends PublishedPointVO, ? extends SendThread> pub = runningPublishers.get(vo.getPublisherId());
    if (pub != null) {
        PublishedPointRT point = publishedPointCache.computeIfAbsent(vo.getId(), k -> new PublishedPointRT(vo, pub));
        // Initialize it, will fail if published point is already initializing or running
        point.initialize(false);
    }
}
Also used : PublishedPointRT(com.serotonin.m2m2.rt.publish.PublishedPointRT)

Example 54 with PublishedPointVO

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

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 55 with PublishedPointVO

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

the class PublisherDefinition method createPublishedPointVO.

/**
 * Create a point with the publisher id, type and data point id set
 */
@NonNull
public <T extends PublishedPointVO> T createPublishedPointVO(int publisherId, int dataPointId) {
    T vo = newPublishedPointVO();
    vo.setPublisherId(publisherId);
    vo.setDataPointId(dataPointId);
    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