use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by infiniteautomation.
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 infiniteautomation.
the class DataPointQueryPermissionTest method testEmptyPermission.
@Test
public void testEmptyPermission() {
// Insert some data points
Set<Role> readRoles = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
List<IDataPoint> unreadable = this.createMockDataPoints(5, false, new MangoPermission(), 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 = unreadable.stream().map(dp -> dp.getId()).collect(Collectors.toList());
QueryBuilder<DataPointVO> query = service.buildQuery().in("id", ids.toArray());
List<DataPointVO> vos = query.query();
assertEquals(0, vos.size());
});
}
use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by infiniteautomation.
the class DataPointQueryPermissionTest method testDeleteAllRoles.
@Test
public void testDeleteAllRoles() {
// 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.requireAllRoles(readRoles), new MangoPermission());
List<IDataPoint> unreadable = this.createMockDataPoints(5, false, new MangoPermission(), new MangoPermission());
RoleDao roleDao = Common.getBean(RoleDao.class);
for (Role role : readRoles) {
roleDao.delete(role.getId());
}
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() {
// This is odd as these roles should not be on a user either, but wanted to t
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(0, vos.size());
});
}
use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by infiniteautomation.
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 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;
}
Aggregations