Search in sources :

Example 31 with PublishedPointVO

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

the class PublishedPointServiceTest method testEmport.

@Test
public void testEmport() {
    // Create publisher and publishedPoints
    MockPublisherVO publisher = createMockPublisher(false);
    List<IDataPoint> dps = createMockDataPoints(5);
    List<PublishedPointVO> pps = new ArrayList<>();
    for (IDataPoint dp : dps) {
        MockPublishedPointVO pp = publisher.getDefinition().createPublishedPointVO(publisher, dp);
        pp.setName(dp.getName());
        pp.setEnabled(true);
        pps.add(service.insert(pp));
    }
    // Export publishedPoints
    String[] exportElements = new String[] { "publishedPoints" };
    Map<String, Object> data = ConfigurationExportData.createExportDataMap(exportElements);
    JsonObject json = null;
    try {
        json = JsonSerializableUtility.convertMapToJsonObject(data);
    } catch (JsonException e) {
        fail(e.getMessage());
    }
    // Ensure publishedPoints
    assertEquals(5, json.getJsonArray("publishedPoints").size());
    // Import publishedPoints for update
    loadConfiguration(json);
    assertEquals(5, service.count());
    // Remove publishedPoints
    pps.forEach(p -> service.delete(p));
    assertEquals(0, service.count());
    // Import publishedPoints for create
    loadConfiguration(json);
    assertEquals(5, service.count());
}
Also used : JsonException(com.serotonin.json.JsonException) MockPublisherVO(com.serotonin.m2m2.vo.publish.mock.MockPublisherVO) ArrayList(java.util.ArrayList) JsonObject(com.serotonin.json.type.JsonObject) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) JsonObject(com.serotonin.json.type.JsonObject) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) Test(org.junit.Test)

Example 32 with PublishedPointVO

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

the class PublishedPointServiceTest method testDeletePoint.

@Test(expected = NotFoundException.class)
public void testDeletePoint() {
    IDataPoint dp = createMockDataPoints(1).get(0);
    MockPublisherVO publisher = createMockPublisher(true);
    MockPublishedPointVO pp = publisher.getDefinition().createPublishedPointVO(publisher, dp);
    pp.setName(dp.getName());
    pp.setEnabled(true);
    PublishedPointVO vo = service.insert(pp);
    // Ensure it is running
    assertNotNull(getRuntimeManager().getPublishedPoint(vo.getId()));
    DataPointVO point = dataPointService.get(dp.getId());
    // Delete datapoint
    dataPointService.delete(point);
    // Ensure published point deleted
    service.get(pp.getId());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) MockPublisherVO(com.serotonin.m2m2.vo.publish.mock.MockPublisherVO) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) MockPublishedPointVO(com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO) PublishedPointVO(com.serotonin.m2m2.vo.publish.PublishedPointVO) Test(org.junit.Test)

Example 33 with PublishedPointVO

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

the class PublisherEditController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = Common.getUser(request);
    Permissions.ensureAdmin(user);
    PublisherVO<? extends PublishedPointVO> publisherVO;
    // Get the id.
    String idStr = request.getParameter("pid");
    if (idStr == null) {
        // Adding a new data source? Get the type id.
        String typeId = request.getParameter("typeId");
        if (StringUtils.isBlank(typeId))
            return new ModelAndView(new RedirectView(errorViewName));
        // A new publisher
        PublisherDefinition def = ModuleRegistry.getPublisherDefinition(typeId);
        if (def == null)
            return new ModelAndView(new RedirectView(errorViewName));
        publisherVO = def.baseCreatePublisherVO();
        publisherVO.setXid(PublisherDao.instance.generateUniqueXid());
    } else {
        // An existing configuration.
        int id = Integer.parseInt(idStr);
        publisherVO = Common.runtimeManager.getPublisher(id);
        if (publisherVO == null)
            return new ModelAndView(new RedirectView(errorViewName));
    }
    // Set the id of the data source in the user object for the DWR.
    user.setEditPublisher(publisherVO);
    // Create the model.
    Map<String, Object> model = new HashMap<>();
    model.put("publisher", publisherVO);
    if (publisherVO.getId() != Common.NEW_ID) {
        List<EventInstance> events = EventDao.instance.getPendingEventsForPublisher(publisherVO.getId(), user.getId());
        List<EventInstanceBean> beans = new ArrayList<>();
        if (events != null) {
            Translations translations = ControllerUtils.getTranslations(request);
            for (EventInstance event : events) beans.add(new EventInstanceBean(event.isActive(), event.getAlarmLevel(), Functions.getTime(event.getActiveTimestamp()), event.getMessage().translate(translations)));
        }
        model.put("publisherEvents", beans);
    }
    publisherVO.addEditContext(model);
    return new ModelAndView(getViewName(), model);
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) PublisherDefinition(com.serotonin.m2m2.module.PublisherDefinition) EventInstanceBean(com.serotonin.m2m2.web.dwr.beans.EventInstanceBean) RedirectView(org.springframework.web.servlet.view.RedirectView) Translations(com.serotonin.m2m2.i18n.Translations)

Example 34 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 35 with PublishedPointVO

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

the class PublishedPointsRestController method update.

@ApiOperation(value = "Update published point")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}")
public ResponseEntity<AbstractPublishedPointModel<?>> update(@PathVariable String xid, @RequestBody() AbstractPublishedPointModel<?> model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    PublishedPointVO vo = this.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)

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