use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
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 MangoAutomation.
the class SystemPermissionService method update.
/**
*/
public void update(MangoPermission permission, PermissionDefinition def) throws ValidationException {
Objects.requireNonNull(def, "Permission definition cannot be null");
permissionService.ensureAdminRole(Common.getUser());
ProcessResult validation = new ProcessResult();
if (permission == null) {
validation.addContextualMessage("permission", "validate.required");
throw new ValidationException(validation);
}
permission.getRoles().stream().flatMap(Collection::stream).forEach(role -> {
try {
roleService.get(role.getXid());
} catch (NotFoundException e) {
validation.addGenericMessage("validate.role.notFound", role.getXid());
}
});
if (validation.getHasMessages()) {
throw new ValidationException(validation);
}
// Execute in transaction as def.setPermission may make database calls
dao.doInTransaction(tx -> {
dao.update(def.getPermissionTypeName(), def.getPermission(), permission);
def.setPermission(permission);
});
this.eventPublisher.publishEvent(new SystemPermissionUpdated(def));
}
use of com.infiniteautomation.mango.util.exception.ValidationException in project ma-core-public by MangoAutomation.
the class MangoTestBase method createMockDataSource.
protected MockDataSourceVO createMockDataSource(String name, String xid, boolean enabled, MangoPermission readPermission, MangoPermission editPermission) {
DataSourceService service = Common.getBean(DataSourceService.class);
MockDataSourceVO vo = (MockDataSourceVO) ModuleRegistry.getDataSourceDefinition(MockDataSourceDefinition.TYPE_NAME).baseCreateDataSourceVO();
vo.setXid(name);
vo.setName(xid);
vo.setEnabled(enabled);
vo.setReadPermission(readPermission);
vo.setEditPermission(editPermission);
try {
return (MockDataSourceVO) service.insert(vo);
} 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 createMockDataPoint.
protected DataPointVO createMockDataPoint(MockDataSourceVO ds, Consumer<DataPointVO> customizer) {
DataPointService service = Common.getBean(DataPointService.class);
DataPointVO dp = new DataPointVO();
dp.setName(UUID.randomUUID().toString());
dp.setDeviceName(ds.getName());
dp.setPointLocator(new MockPointLocatorVO(DataType.NUMERIC, true));
dp.setDataSourceId(ds.getId());
customizer.accept(dp);
try {
return service.insert(dp);
} 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 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