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