@Test public void testGetResources() throws Exception { List<PermissionEntity> permissionEntities = new LinkedList<PermissionEntity>(); PermissionEntity permissionEntity = createNiceMock(PermissionEntity.class); PermissionEntity viewUsePermissionEntity = createNiceMock(PermissionEntity.class); ResourceTypeEntity resourceTypeEntity = createNiceMock(ResourceTypeEntity.class); ViewEntity viewEntity = createMock(ViewEntity.class); permissionEntities.add(permissionEntity); expect(dao.findViewUsePermission()).andReturn(viewUsePermissionEntity); expect(dao.findAll()).andReturn(Collections.singletonList(permissionEntity)); expect(permissionEntity.getId()).andReturn(99); expect(permissionEntity.getPermissionName()).andReturn("P1"); expect(permissionEntity.getResourceType()).andReturn(resourceTypeEntity); expect(resourceTypeEntity.getName()).andReturn("V1"); expect(viewEntity.isDeployed()).andReturn(true).anyTimes(); expect(viewEntity.getCommonName()).andReturn("V1").anyTimes(); expect(viewEntity.getVersion()).andReturn("1.0.0").anyTimes(); expect(viewRegistry.getDefinition(resourceTypeEntity)).andReturn(viewEntity); replay(dao, permissionEntity, viewUsePermissionEntity, resourceTypeEntity, viewEntity, viewRegistry); ViewPermissionResourceProvider provider = new ViewPermissionResourceProvider(); Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(), null); Assert.assertEquals(1, resources.size()); Resource resource = resources.iterator().next(); Assert.assertEquals(99, resource.getPropertyValue(PermissionResourceProvider.PERMISSION_ID_PROPERTY_ID)); Assert.assertEquals("P1", resource.getPropertyValue(PermissionResourceProvider.PERMISSION_NAME_PROPERTY_ID)); Assert.assertEquals("V1", resource.getPropertyValue(PermissionResourceProvider.RESOURCE_NAME_PROPERTY_ID)); verify(dao, permissionEntity, viewUsePermissionEntity, resourceTypeEntity, viewEntity, viewRegistry); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { ViewRegistry viewRegistry = ViewRegistry.getInstance(); Set<Resource> resources = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); PermissionEntity viewUsePermission = permissionDAO.findViewUsePermission(); for (Map<String, Object> propertyMap: getPropertyMaps(predicate)) { Object viewName = propertyMap.get(VIEW_NAME_PROPERTY_ID); Object viewVersion = propertyMap.get(VIEW_VERSION_PROPERTY_ID); if (viewName != null && viewVersion != null) { ViewEntity viewEntity = viewRegistry.getDefinition(viewName.toString(), viewVersion.toString()); if (viewEntity.isDeployed()) { resources.add(toResource(viewUsePermission, viewEntity.getResourceType(), viewEntity, requestedIds)); } } } for(PermissionEntity permissionEntity : permissionDAO.findAll()){ ResourceTypeEntity resourceType = permissionEntity.getResourceType(); ViewEntity viewEntity = viewRegistry.getDefinition(resourceType); if (viewEntity != null && viewEntity.isDeployed()) { resources.add(toResource(permissionEntity, resourceType, viewEntity, requestedIds)); } } return resources; }
ViewPermissionResourceProvider extends AbstractResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { ViewRegistry viewRegistry = ViewRegistry.getInstance(); Set<Resource> resources = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); PermissionEntity viewUsePermission = permissionDAO.findViewUsePermission(); for (Map<String, Object> propertyMap: getPropertyMaps(predicate)) { Object viewName = propertyMap.get(VIEW_NAME_PROPERTY_ID); Object viewVersion = propertyMap.get(VIEW_VERSION_PROPERTY_ID); if (viewName != null && viewVersion != null) { ViewEntity viewEntity = viewRegistry.getDefinition(viewName.toString(), viewVersion.toString()); if (viewEntity.isDeployed()) { resources.add(toResource(viewUsePermission, viewEntity.getResourceType(), viewEntity, requestedIds)); } } } for(PermissionEntity permissionEntity : permissionDAO.findAll()){ ResourceTypeEntity resourceType = permissionEntity.getResourceType(); ViewEntity viewEntity = viewRegistry.getDefinition(resourceType); if (viewEntity != null && viewEntity.isDeployed()) { resources.add(toResource(permissionEntity, resourceType, viewEntity, requestedIds)); } } return resources; } }
ViewPermissionResourceProvider extends AbstractResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { ViewRegistry viewRegistry = ViewRegistry.getInstance(); Set<Resource> resources = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); PermissionEntity viewUsePermission = permissionDAO.findViewUsePermission(); for (Map<String, Object> propertyMap: getPropertyMaps(predicate)) { Object viewName = propertyMap.get(VIEW_NAME_PROPERTY_ID); Object viewVersion = propertyMap.get(VIEW_VERSION_PROPERTY_ID); if (viewName != null && viewVersion != null) { ViewEntity viewEntity = viewRegistry.getDefinition(viewName.toString(), viewVersion.toString()); if (viewEntity.isDeployed()) { resources.add(toResource(viewUsePermission, viewEntity.getResourceType(), viewEntity, requestedIds)); } } } for(PermissionEntity permissionEntity : permissionDAO.findAll()){ ResourceTypeEntity resourceType = permissionEntity.getResourceType(); ViewEntity viewEntity = viewRegistry.getDefinition(resourceType); if (viewEntity != null && viewEntity.isDeployed()) { resources.add(toResource(permissionEntity, resourceType, viewEntity, requestedIds)); } } return resources; } ViewPermissionResourceProvider(); }
ViewPermissionResourceProvider extends AbstractResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { ViewRegistry viewRegistry = ViewRegistry.getInstance(); Set<Resource> resources = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); PermissionEntity viewUsePermission = permissionDAO.findViewUsePermission(); for (Map<String, Object> propertyMap: getPropertyMaps(predicate)) { Object viewName = propertyMap.get(VIEW_NAME_PROPERTY_ID); Object viewVersion = propertyMap.get(VIEW_VERSION_PROPERTY_ID); if (viewName != null && viewVersion != null) { ViewEntity viewEntity = viewRegistry.getDefinition(viewName.toString(), viewVersion.toString()); if (viewEntity.isDeployed()) { resources.add(toResource(viewUsePermission, viewEntity.getResourceType(), viewEntity, requestedIds)); } } } for(PermissionEntity permissionEntity : permissionDAO.findAll()){ ResourceTypeEntity resourceType = permissionEntity.getResourceType(); ViewEntity viewEntity = viewRegistry.getDefinition(resourceType); if (viewEntity != null && viewEntity.isDeployed()) { resources.add(toResource(permissionEntity, resourceType, viewEntity, requestedIds)); } } return resources; } ViewPermissionResourceProvider(); static void init(PermissionDAO dao); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Map<Resource.Type, String> getKeyPropertyIds(); }
ViewPermissionResourceProvider extends AbstractResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { ViewRegistry viewRegistry = ViewRegistry.getInstance(); Set<Resource> resources = new HashSet<Resource>(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); PermissionEntity viewUsePermission = permissionDAO.findViewUsePermission(); for (Map<String, Object> propertyMap: getPropertyMaps(predicate)) { Object viewName = propertyMap.get(VIEW_NAME_PROPERTY_ID); Object viewVersion = propertyMap.get(VIEW_VERSION_PROPERTY_ID); if (viewName != null && viewVersion != null) { ViewEntity viewEntity = viewRegistry.getDefinition(viewName.toString(), viewVersion.toString()); if (viewEntity.isDeployed()) { resources.add(toResource(viewUsePermission, viewEntity.getResourceType(), viewEntity, requestedIds)); } } } for(PermissionEntity permissionEntity : permissionDAO.findAll()){ ResourceTypeEntity resourceType = permissionEntity.getResourceType(); ViewEntity viewEntity = viewRegistry.getDefinition(resourceType); if (viewEntity != null && viewEntity.isDeployed()) { resources.add(toResource(permissionEntity, resourceType, viewEntity, requestedIds)); } } return resources; } ViewPermissionResourceProvider(); static void init(PermissionDAO dao); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Map<Resource.Type, String> getKeyPropertyIds(); static final String VIEW_NAME_PROPERTY_ID; static final String VIEW_VERSION_PROPERTY_ID; static final String PERMISSION_ID_PROPERTY_ID; static final String PERMISSION_NAME_PROPERTY_ID; static final String RESOURCE_NAME_PROPERTY_ID; }