Search in sources :

Example 21 with DataPointService

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));
        }
    });
}
Also used : RunAs(com.infiniteautomation.mango.spring.components.RunAs) Role(com.serotonin.m2m2.vo.role.Role) Common(com.serotonin.m2m2.Common) DataSourceDao(com.serotonin.m2m2.db.dao.DataSourceDao) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy) Permissions(com.infiniteautomation.mango.db.tables.Permissions) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Collectors(java.util.stream.Collectors) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) QueryBuilder(com.serotonin.m2m2.db.dao.QueryBuilder) List(java.util.List) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) MangoTestBase(com.serotonin.m2m2.MangoTestBase) DSLContext(org.jooq.DSLContext) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) Assert.assertEquals(org.junit.Assert.assertEquals) PermissionsMinterms(com.infiniteautomation.mango.db.tables.PermissionsMinterms) Before(org.junit.Before) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) Set(java.util.Set) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Role(com.serotonin.m2m2.vo.role.Role) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) Test(org.junit.Test)

Example 22 with DataPointService

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());
    });
}
Also used : RunAs(com.infiniteautomation.mango.spring.components.RunAs) Role(com.serotonin.m2m2.vo.role.Role) Common(com.serotonin.m2m2.Common) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) RoleDao(com.serotonin.m2m2.db.dao.RoleDao) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Collectors(java.util.stream.Collectors) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) QueryBuilder(com.serotonin.m2m2.db.dao.QueryBuilder) List(java.util.List) MangoTestBase(com.serotonin.m2m2.MangoTestBase) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) Set(java.util.Set) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Role(com.serotonin.m2m2.vo.role.Role) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) Test(org.junit.Test)

Example 23 with DataPointService

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());
    });
}
Also used : RunAs(com.infiniteautomation.mango.spring.components.RunAs) Role(com.serotonin.m2m2.vo.role.Role) Common(com.serotonin.m2m2.Common) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) RoleDao(com.serotonin.m2m2.db.dao.RoleDao) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Collectors(java.util.stream.Collectors) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) QueryBuilder(com.serotonin.m2m2.db.dao.QueryBuilder) List(java.util.List) MangoTestBase(com.serotonin.m2m2.MangoTestBase) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) Set(java.util.Set) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Role(com.serotonin.m2m2.vo.role.Role) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) RoleDao(com.serotonin.m2m2.db.dao.RoleDao) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) Test(org.junit.Test)

Example 24 with DataPointService

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));
        }
    });
}
Also used : RunAs(com.infiniteautomation.mango.spring.components.RunAs) Role(com.serotonin.m2m2.vo.role.Role) Common(com.serotonin.m2m2.Common) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) RoleDao(com.serotonin.m2m2.db.dao.RoleDao) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Collectors(java.util.stream.Collectors) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) QueryBuilder(com.serotonin.m2m2.db.dao.QueryBuilder) List(java.util.List) MangoTestBase(com.serotonin.m2m2.MangoTestBase) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) Set(java.util.Set) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Role(com.serotonin.m2m2.vo.role.Role) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) RoleDao(com.serotonin.m2m2.db.dao.RoleDao) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) Test(org.junit.Test)

Example 25 with DataPointService

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;
}
Also used : DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage)

Aggregations

DataPointService (com.infiniteautomation.mango.spring.service.DataPointService)33 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)31 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)20 List (java.util.List)20 Common (com.serotonin.m2m2.Common)19 Collectors (java.util.stream.Collectors)19 MangoTestBase (com.serotonin.m2m2.MangoTestBase)18 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)18 Test (org.junit.Test)18 Role (com.serotonin.m2m2.vo.role.Role)17 Set (java.util.Set)17 RunAs (com.infiniteautomation.mango.spring.components.RunAs)16 QueryBuilder (com.serotonin.m2m2.db.dao.QueryBuilder)16 Assert.assertEquals (org.junit.Assert.assertEquals)16 Assert.assertTrue (org.junit.Assert.assertTrue)16 Before (org.junit.Before)16 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)12 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)10 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)6 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)6