use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
the class MangoTestBase method createMockPublisher.
/**
* Create a publisher
*/
public MockPublisherVO createMockPublisher(boolean enabled) {
MockPublisherVO publisherVO = (MockPublisherVO) ModuleRegistry.getPublisherDefinition(MockPublisherDefinition.TYPE_NAME).baseCreatePublisherVO();
publisherVO.setName(UUID.randomUUID().toString());
publisherVO.setEnabled(enabled);
PublisherService publisherService = Common.getBean(PublisherService.class);
try {
return (MockPublisherVO) publisherService.insert(publisherVO);
} catch (ValidationException e) {
fail(e.getValidationErrorMessage(Common.getTranslations()));
return null;
}
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
the class MangoTestBase method createMockPublishedPoint.
/**
* Create a published point
*/
public MockPublishedPointVO createMockPublishedPoint(MockPublisherVO publisher, IDataPoint dataPoint, boolean enabled) {
MockPublishedPointVO pp = publisher.getDefinition().createPublishedPointVO(publisher, dataPoint);
pp.setName(dataPoint.getName());
pp.setEnabled(true);
PublishedPointService publishedPointService = Common.getBean(PublishedPointService.class);
try {
publishedPointService.insert(pp);
} catch (ValidationException e) {
fail(e.getValidationErrorMessage(Common.getTranslations()));
return null;
}
return pp;
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
the class DataPointService method insert.
@Override
public DataPointVO insert(DataPointVO vo) throws PermissionException, ValidationException {
PermissionHolder user = Common.getUser();
// Ensure they can create
ensureCreatePermission(user, vo);
// Ensure id is not set
if (vo.getId() != Common.NEW_ID) {
ProcessResult result = new ProcessResult();
result.addContextualMessage("id", "validate.invalidValue");
throw new ValidationException(result);
}
// Generate an Xid if necessary
if (StringUtils.isEmpty(vo.getXid()))
vo.setXid(dao.generateUniqueXid());
for (DataPointChangeDefinition def : changeDefinitions) {
def.preInsert(vo);
}
ensureValid(vo);
dao.insert(vo);
List<AbstractPointEventDetectorVO> detectors = new ArrayList<>();
for (DataPointChangeDefinition def : changeDefinitions) {
for (var detector : def.postInsert(vo)) {
if (detector.isNew()) {
log.warn("Detector added via postInsert hook was not saved");
} else if (detector.getDataPoint().getId() != vo.getId()) {
log.warn("Detector added via postInsert hook was for a different data point");
} else {
detectors.add(detector);
}
}
}
if (vo.isEnabled()) {
// the data point cannot have detectors if it was just inserted, don't query for detectors
getRuntimeManager().startDataPoint(new DataPointWithEventDetectors(vo, detectors));
}
return vo;
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
the class ImportTask method processUpdatedDetectors.
/**
* Since detectors can be attached to a data point we will import them in bulk here. This will
* remove any fully imported detectors and their container after there are no more detectors to import
* for that point.
*/
private void processUpdatedDetectors(Map<String, DataPointWithEventDetectors> eventDetectorMap) {
Iterator<String> it = eventDetectorMap.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
DataPointWithEventDetectors dp = eventDetectorMap.get(key);
// The content of the event detectors lists may have duplicates and the DataPointVO may be out of date,
// but we can assume that all the event detectors for a point will exist in this list.
ListIterator<AbstractPointEventDetectorVO> listIt = dp.getEventDetectors().listIterator();
while (listIt.hasNext()) {
AbstractPointEventDetectorVO ed = listIt.next();
try {
if (ed.isNew()) {
eventDetectorService.insertAndReload(ed, false);
importContext.addSuccessMessage(true, "emport.eventDetector.prefix", ed.getXid());
} else {
eventDetectorService.updateAndReload(ed.getXid(), ed, false);
importContext.addSuccessMessage(false, "emport.eventDetector.prefix", ed.getXid());
}
// Reload into the RT
dataPointService.reloadDataPoint(dp.getDataPoint().getXid());
} catch (ValidationException e) {
importContext.copyValidationMessages(e.getValidationResult(), "emport.eventDetector.prefix", ed.getXid());
} catch (Exception e) {
addException(e);
LOG.error("Event detector import failed.", e);
} finally {
// To avoid being stuck in the loop, removing the item from the lists even if it caused an issue or not.
listIt.remove();
}
}
if (dp.getEventDetectors().size() == 0) {
it.remove();
}
}
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-modules-public by infiniteautomation.
the class DataPointModel method toVO.
@Override
public DataPointVO toVO() {
DataPointVO point = new DataPointVO();
if (xid != null) {
point.setXid(xid);
}
if (name != null) {
point.setName(name);
}
if (enabled != null) {
point.setEnabled(enabled);
}
if (deviceName != null) {
point.setDeviceName(deviceName);
}
// TODO Use ModelMapper.unmap
if (readPermission != null) {
point.setReadPermission(readPermission.getPermission());
}
// TODO Use ModelMapper.unmap
if (editPermission != null) {
point.setEditPermission(editPermission.getPermission());
}
// TODO Use ModelMapper.unmap
if (setPermission != null) {
point.setSetPermission(setPermission.getPermission());
}
// TODO Use ModelMapper.unmap
if (StringUtils.isNotEmpty(dataSourceXid)) {
DataSourceVO ds = DataSourceDao.getInstance().getByXid(dataSourceXid);
if (ds != null) {
point.setDataSourceId(ds.getId());
point.setDataSourceName(ds.getName());
point.setDataSourceXid(ds.getXid());
point.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
}
}
// TODO Use ModelMapper.unmap
if (point.getDataSourceId() <= 0 && dataSourceId != null && dataSourceId > 0) {
point.setDataSourceId(dataSourceId);
}
if (purgeOverride != null) {
point.setPurgeOverride(purgeOverride);
// Ensure that a purge period must be supplied
if (purgeOverride) {
point.setPurgePeriod(-1);
point.setPurgeType(-1);
}
}
if (purgePeriod != null) {
point.setPurgePeriod(purgePeriod.getPeriods());
point.setPurgeType(Common.TIME_PERIOD_CODES.getId(purgePeriod.getPeriodType()));
}
if (unit != null) {
try {
point.setUnit(JUnitUtil.parseLocal(unit));
} catch (IllegalArgumentException e) {
// TODO unmap
ProcessResult result = new ProcessResult();
result.addContextualMessage("unit", "validate.unitInvalid", e.getMessage());
throw new ValidationException(result);
}
}
if (useIntegralUnit != null) {
point.setUseIntegralUnit(useIntegralUnit);
}
if (integralUnit != null) {
try {
point.setIntegralUnit(JUnitUtil.parseLocal(integralUnit));
} catch (IllegalArgumentException e) {
// TODO unmap
ProcessResult result = new ProcessResult();
result.addContextualMessage("integralUnit", "validate.unitInvalid", e.getMessage());
throw new ValidationException(result);
}
}
if (useRenderedUnit != null) {
point.setUseRenderedUnit(useRenderedUnit);
}
if (this.renderedUnit != null) {
try {
point.setRenderedUnit(JUnitUtil.parseLocal(renderedUnit));
} catch (IllegalArgumentException e) {
// TODO unmap
ProcessResult result = new ProcessResult();
result.addContextualMessage("renderedUnit", "validate.unitInvalid", e.getMessage());
throw new ValidationException(result);
}
}
if (chartColour != null) {
point.setChartColour(chartColour);
}
if (plotType != null) {
point.setPlotType(DataPointVO.PLOT_TYPE_CODES.getId(plotType));
}
if (this.tags != null) {
Map<String, String> existingTags = point.getTags();
if (!this.mergeTags || existingTags == null) {
// existingTags is only null if someone tried to use mergeTags when creating a data point
point.setTags(this.tags);
} else {
Map<String, String> mergedTags = new HashMap<>(existingTags);
for (Entry<String, String> entry : this.tags.entrySet()) {
String tagKey = entry.getKey();
String tagValue = entry.getValue();
if (tagValue == null) {
mergedTags.remove(tagKey);
} else {
mergedTags.put(tagKey, tagValue);
}
}
point.setTags(mergedTags);
}
} else {
// TODO unmap
if (id != null && id > 0) {
point.setTags(DataPointTagsDao.getInstance().getTagsForDataPointId(id));
} else if (xid != null) {
Integer id = DataPointDao.getInstance().getIdByXid(xid);
if (id != null) {
point.setTags(DataPointTagsDao.getInstance().getTagsForDataPointId(id));
}
}
}
if (this.loggingProperties != null) {
loggingProperties.copyPropertiesTo(point);
}
if (this.textRenderer != null) {
point.setTextRenderer(textRenderer.toVO());
}
if (pointLocator != null) {
point.setPointLocator(pointLocator.toVO());
}
if (this.rollup != null) {
point.setRollup(Common.ROLLUP_CODES.getId(this.rollup));
}
if (this.simplifyType != null) {
point.setSimplifyType(DataPointVO.SIMPLIFY_TYPE_CODES.getId(this.simplifyType));
}
if (this.simplifyTolerance != null) {
point.setSimplifyTolerance(simplifyTolerance);
}
if (this.simplifyTarget != null) {
point.setSimplifyTarget(simplifyTarget);
}
if (this.preventSetExtremeValues != null) {
point.setPreventSetExtremeValues(this.preventSetExtremeValues);
}
if (this.setExtremeLowLimit != null) {
point.setSetExtremeLowLimit(this.setExtremeLowLimit);
}
if (this.setExtremeHighLimit != null) {
point.setSetExtremeHighLimit(this.setExtremeHighLimit);
}
if (this.data != null) {
point.setData(data);
}
return point;
}
Aggregations