use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-modules-public by infiniteautomation.
the class WatchListEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext, PermissionHolder importer) throws JsonException {
JsonObject watchListJson = jsonValue.toJsonObject();
String xid = watchListJson.getString("xid");
WatchListVO vo = null;
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
vo = service.get(xid);
} catch (NotFoundException e) {
}
}
if (vo == null) {
vo = new WatchListVO();
vo.setXid(xid);
}
try {
importContext.getReader().readInto(vo, watchListJson);
// Ensure we have a default permission since null is valid in Mango 3.x
if (vo.getReadPermission() == null) {
vo.setReadPermission(new MangoPermission());
}
if (vo.getEditPermission() == null) {
vo.setEditPermission(new MangoPermission());
}
boolean isnew = vo.getId() == Common.NEW_ID;
if (isnew) {
service.insert(vo);
} else {
service.update(vo.getId(), vo);
}
importContext.addSuccessMessage(isnew, "emport.watchList.prefix", xid);
} catch (ValidationException e) {
importContext.copyValidationMessages(e.getValidationResult(), "emport.watchList.prefix", xid);
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.watchList.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.watchList.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by infiniteautomation.
the class PermissionServiceTest method validatePermission.
private void validatePermission(MangoPermission oldPermission, MangoPermission newPermission) {
ProcessResult result = new ProcessResult();
permissionService.validatePermission(result, "permission", Common.getUser(), oldPermission, newPermission);
if (!result.isValid()) {
throw new ValidationException(result);
}
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by infiniteautomation.
the class DataPointServiceTest method testDataTypeValidation.
@Test
public void testDataTypeValidation() {
DataPointVO vo = newVO(editUser);
vo.setPointLocator(new MockPointLocatorVO(DataType.fromName("UNKNOWN"), false));
try {
service.insert(vo);
fail("Should throw " + ValidationException.class.getSimpleName());
} catch (ValidationException e) {
Assert.assertTrue(e.getValidationResult().hasContextualMessage("dataType"));
}
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by infiniteautomation.
the class NumericPointValueWithDifferentSeriesIdTest method createMockDataPoints.
@Override
protected List<IDataPoint> createMockDataPoints(int count) {
List<IDataPoint> points = super.createMockDataPoints(count);
// Change series id
DataPointService service = Common.getBean(DataPointService.class);
DataPointDao dao = Common.getBean(DataPointDao.class);
for (IDataPoint point : points) {
DataPointVO vo = (DataPointVO) point;
vo.setSeriesId(dao.insertNewTimeSeries());
try {
service.update(vo.getId(), vo);
} catch (ValidationException e) {
String failureMessage = "";
for (ProcessMessage m : e.getValidationResult().getMessages()) {
String messagePart = m.getContextKey() + " -> " + m.getContextualMessage().translate(Common.getTranslations()) + "\n";
failureMessage += messagePart;
}
fail(failureMessage);
}
}
return points;
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by infiniteautomation.
the class MangoTestBase method createMockPublisher.
/**
* Create a publisher with points
*/
public MockPublisherVO createMockPublisher(boolean enabled, List<MockPublishedPointVO> points) {
MockPublisherVO publisherVO = (MockPublisherVO) ModuleRegistry.getPublisherDefinition(MockPublisherDefinition.TYPE_NAME).baseCreatePublisherVO();
publisherVO.setName(UUID.randomUUID().toString());
publisherVO.setEnabled(enabled);
PublisherService publisherService = Common.getBean(PublisherService.class);
try {
MockPublisherVO pub = (MockPublisherVO) publisherService.insert(publisherVO);
PublishedPointService publishedPointService = Common.getBean(PublishedPointService.class);
for (MockPublishedPointVO point : points) {
publishedPointService.insert(point);
}
return pub;
} catch (ValidationException e) {
fail(e.getValidationErrorMessage(Common.getTranslations()));
return null;
}
}
Aggregations