use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by MangoAutomation.
the class MockMango method createDataPoints.
/**
* Create points asynchronously and wait for all to be created
*/
public List<DataPointVO> createDataPoints(int count, Map<String, String> tags) throws ExecutionException, InterruptedException {
MockDataSourceVO ds = createMockDataSource();
DataPointService service = Common.getBean(DataPointService.class);
List<CompletableFuture<DataPointVO>> points = new ArrayList<>();
for (int i = 0; i < count; i++) {
DataPointVO dp = new DataPointVO();
dp.setName(UUID.randomUUID().toString());
dp.setDeviceName(ds.getName());
dp.setPointLocator(new MockPointLocatorVO(DataType.NUMERIC, true));
dp.setDataSourceId(ds.getId());
dp.setTags(tags);
points.add(service.insertAsync(dp).toCompletableFuture());
}
return CompletableFuture.allOf(points.toArray(new CompletableFuture[0])).thenApply(ignored -> points.stream().map(CompletableFuture::join).collect(Collectors.toList())).get();
}
use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by MangoAutomation.
the class DataPointPermissionTest method testDeleteDataPoint.
/**
* Test to ensure an un-used permission is deleted
*/
@Test
public void testDeleteDataPoint() {
// Insert some data points
Set<Role> readRoles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
List<IDataPoint> points = this.createMockDataPoints(1, false, MangoPermission.requireAnyRole(readRoles), new MangoPermission());
DataPointService service = Common.getBean(DataPointService.class);
runAs.runAs(new PermissionHolder() {
@Override
public String getPermissionHolderName() {
return "Test";
}
@Override
public boolean isPermissionHolderDisabled() {
return false;
}
@Override
public Set<Role> getRoles() {
return readRoles;
}
}, () -> {
List<Integer> ids = points.stream().map(dp -> dp.getId()).collect(Collectors.toList());
QueryBuilder<DataPointVO> query = service.buildQuery().in("id", ids.toArray());
List<DataPointVO> vos = query.query();
assertEquals(points.size(), vos.size());
for (DataPointVO vo : vos) {
assertTrue(points.contains(vo));
}
List<Integer> existing = getPermissionIds(null);
// Delete the source and point
DataSourceDao.getInstance().delete(vos.get(0).getDataSourceId());
// We should have removed 1 permission
assertEquals(existing.size() - 1, getPermissionIds(null).size());
});
}
use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by MangoAutomation.
the class DataPointPermissionTest method testDeleteDataPoints.
@Test
public void testDeleteDataPoints() {
// Insert some data points
Set<Role> readRoles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
List<IDataPoint> points = this.createMockDataPoints(2, false, MangoPermission.requireAnyRole(readRoles), new MangoPermission());
DataPointService service = Common.getBean(DataPointService.class);
runAs.runAs(new PermissionHolder() {
@Override
public String getPermissionHolderName() {
return "Test";
}
@Override
public boolean isPermissionHolderDisabled() {
return false;
}
@Override
public Set<Role> getRoles() {
return readRoles;
}
}, () -> {
List<Integer> ids = points.stream().map(dp -> dp.getId()).collect(Collectors.toList());
QueryBuilder<DataPointVO> query = service.buildQuery().in("id", ids.toArray());
List<DataPointVO> vos = query.query();
assertEquals(points.size(), vos.size());
for (DataPointVO vo : vos) {
assertTrue(points.contains(vo));
}
List<Integer> existing = getPermissionIds(null);
// Delete a point
DataPointDao.getInstance().delete(vos.get(0));
// The set and read permission for point 2 still exist
assertEquals(existing.size(), getPermissionIds(null).size());
// ensure all minterms ect still exist for the un-deleted point
vos = query.query();
assertEquals(1, vos.size());
for (DataPointVO vo : vos) {
assertTrue(points.contains(vo));
}
});
}
use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by MangoAutomation.
the class DataPointQueryPermissionTest method testDeleteSingleRoleFromOrSet.
@Test
public void testDeleteSingleRoleFromOrSet() {
// Insert some data points
Set<Role> readRoles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
List<IDataPoint> points = this.createMockDataPoints(5, false, MangoPermission.requireAnyRole(readRoles), new MangoPermission());
List<IDataPoint> unreadable = this.createMockDataPoints(5, false, new MangoPermission(), new MangoPermission());
Role role = readRoles.iterator().next();
Common.getBean(RoleDao.class).delete(role.getId());
readRoles.remove(role);
DataPointService service = Common.getBean(DataPointService.class);
runAs.runAs(new PermissionHolder() {
@Override
public String getPermissionHolderName() {
return "Test";
}
@Override
public boolean isPermissionHolderDisabled() {
return false;
}
@Override
public Set<Role> getRoles() {
return readRoles;
}
}, () -> {
List<Integer> ids = points.stream().map(dp -> dp.getId()).collect(Collectors.toList());
ids.addAll(unreadable.stream().map(dp -> dp.getId()).collect(Collectors.toList()));
QueryBuilder<DataPointVO> query = service.buildQuery().in("id", ids.toArray());
List<DataPointVO> vos = query.query();
assertEquals(points.size(), vos.size());
for (DataPointVO vo : vos) {
assertTrue(points.contains(vo));
}
});
}
use of com.infiniteautomation.mango.spring.service.DataPointService 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;
}
}
Aggregations