@Test void testAddType() { EntityType entityType = mock(EntityType.class); when(entityType.getId()).thenReturn("typeId"); Attribute attribute = mock(Attribute.class); when(entityType.getIdAttribute()).thenReturn(attribute); when(attribute.getDataType()).thenReturn(AttributeType.STRING); when(dataService.getEntityType("typeId")).thenReturn(entityType); Entity entity1 = mock(Entity.class); when(entity1.getEntityType()).thenReturn(entityType); when(entity1.getIdValue()).thenReturn("1"); Entity entity2 = mock(Entity.class); when(entity2.getIdValue()).thenReturn("2"); when(entity2.getEntityType()).thenReturn(entityType); when(dataService.findAll("typeId")).thenReturn(Stream.of(entity1, entity2)); when(entityHelper.getEntityTypeIdFromType("entity-typeId")).thenReturn("typeId"); permissionsApiService.addType("entity-typeId"); verify(mutableAclClassService).createAclClass("entity-typeId", String.class); verify(mutableAclService).createAcl(new EntityIdentity("typeId", "1")); verify(mutableAclService).createAcl(new EntityIdentity("typeId", "2")); }
@Override @Transactional public void addType(String typeId) { entityHelper.checkEntityTypeExists(typeId); entityHelper.checkIsNotSystem(typeId); EntityType entityType = dataService.getEntityType(entityHelper.getEntityTypeIdFromType(typeId)); if (mutableAclClassService.getAclClassTypes().contains(typeId)) { throw new AclClassAlreadyExistsException(typeId); } mutableAclClassService.createAclClass(typeId, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach( entity -> { try { mutableAclService.createAcl(new EntityIdentity(entity)); } catch (AlreadyExistsException e) { throw new AclAlreadyExistsException(typeId, entityType.getId()); } }); }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void addType(String typeId) { entityHelper.checkEntityTypeExists(typeId); entityHelper.checkIsNotSystem(typeId); EntityType entityType = dataService.getEntityType(entityHelper.getEntityTypeIdFromType(typeId)); if (mutableAclClassService.getAclClassTypes().contains(typeId)) { throw new AclClassAlreadyExistsException(typeId); } mutableAclClassService.createAclClass(typeId, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach( entity -> { try { mutableAclService.createAcl(new EntityIdentity(entity)); } catch (AlreadyExistsException e) { throw new AclAlreadyExistsException(typeId, entityType.getId()); } }); } }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void addType(String typeId) { entityHelper.checkEntityTypeExists(typeId); entityHelper.checkIsNotSystem(typeId); EntityType entityType = dataService.getEntityType(entityHelper.getEntityTypeIdFromType(typeId)); if (mutableAclClassService.getAclClassTypes().contains(typeId)) { throw new AclClassAlreadyExistsException(typeId); } mutableAclClassService.createAclClass(typeId, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach( entity -> { try { mutableAclService.createAcl(new EntityIdentity(entity)); } catch (AlreadyExistsException e) { throw new AclAlreadyExistsException(typeId, entityType.getId()); } }); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void addType(String typeId) { entityHelper.checkEntityTypeExists(typeId); entityHelper.checkIsNotSystem(typeId); EntityType entityType = dataService.getEntityType(entityHelper.getEntityTypeIdFromType(typeId)); if (mutableAclClassService.getAclClassTypes().contains(typeId)) { throw new AclClassAlreadyExistsException(typeId); } mutableAclClassService.createAclClass(typeId, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach( entity -> { try { mutableAclService.createAcl(new EntityIdentity(entity)); } catch (AlreadyExistsException e) { throw new AclAlreadyExistsException(typeId, entityType.getId()); } }); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); @Override Set<LabelledType> getLabelledTypes(); @Override Set<LabelledObject> getObjects(String typeId, int page, int pageSize); @Override Set<PermissionSet> getSuitablePermissionsForType(String typeId); @Override Set<LabelledPermission> getPermissionsForObject(
      ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions); @Override Set<LabelledPermission> getPermissions(Set<Sid> sids, boolean isReturnInherited); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, int page, int pageSize); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, boolean isReturnInherited); @Override @Transactional void createAcl(ObjectIdentity objectIdentity); @Override @Transactional void createPermission(Permission permission); @Override @Transactional void createPermissions(Set<Permission> permissions); @Override @Transactional void updatePermission(Permission permission); @Override @Transactional void updatePermissions(Set<Permission> permissions); @Override @Transactional void deletePermission(Sid sid, ObjectIdentity objectIdentity); @Override @Transactional void addType(String typeId); @Override @Transactional void deleteType(String typeId); @Override boolean exists(ObjectIdentity objectIdentity, Sid sid); }
PermissionServiceImpl implements PermissionService { @Override @Transactional public void addType(String typeId) { entityHelper.checkEntityTypeExists(typeId); entityHelper.checkIsNotSystem(typeId); EntityType entityType = dataService.getEntityType(entityHelper.getEntityTypeIdFromType(typeId)); if (mutableAclClassService.getAclClassTypes().contains(typeId)) { throw new AclClassAlreadyExistsException(typeId); } mutableAclClassService.createAclClass(typeId, EntityIdentityUtils.toIdType(entityType)); dataService .findAll(entityType.getId()) .forEach( entity -> { try { mutableAclService.createAcl(new EntityIdentity(entity)); } catch (AlreadyExistsException e) { throw new AclAlreadyExistsException(typeId, entityType.getId()); } }); } PermissionServiceImpl(
      MutableAclService mutableAclService,
      PermissionInheritanceResolver inheritanceResolver,
      ObjectIdentityService objectIdentityService,
      DataService dataService,
      MutableAclClassService mutableAclClassService,
      UserRoleTools userRoleTools,
      EntityHelper entityHelper,
      UserPermissionEvaluator userPermissionEvaluator); @Override Set<LabelledType> getLabelledTypes(); @Override Set<LabelledObject> getObjects(String typeId, int page, int pageSize); @Override Set<PermissionSet> getSuitablePermissionsForType(String typeId); @Override Set<LabelledPermission> getPermissionsForObject(
      ObjectIdentity objectIdentity, Set<Sid> sids, boolean isReturnInheritedPermissions); @Override Set<LabelledPermission> getPermissions(Set<Sid> sids, boolean isReturnInherited); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, int page, int pageSize); @Override Map<String, Set<LabelledPermission>> getPermissionsForType(
      String typeId, Set<Sid> sids, boolean isReturnInherited); @Override @Transactional void createAcl(ObjectIdentity objectIdentity); @Override @Transactional void createPermission(Permission permission); @Override @Transactional void createPermissions(Set<Permission> permissions); @Override @Transactional void updatePermission(Permission permission); @Override @Transactional void updatePermissions(Set<Permission> permissions); @Override @Transactional void deletePermission(Sid sid, ObjectIdentity objectIdentity); @Override @Transactional void addType(String typeId); @Override @Transactional void deleteType(String typeId); @Override boolean exists(ObjectIdentity objectIdentity, Sid sid);  }