Package org.rhq.core.domain.criteria

Examples of org.rhq.core.domain.criteria.BundleGroupCriteria


        } catch (PermissionException e) {
            // expected
        }

        // deny global perm bundleGroup view
        BundleGroupCriteria bgCriteria = new BundleGroupCriteria();
        List<BundleGroup> bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not be able to see unassociated bundle group";

        // allow global perm bundleGroup view
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assertEquals("Should be able to see unassociated bundle group", 1, bundleGroups.size());

        // allow bundle group delete
        bundleManager.deleteBundleGroups(subject, new int[] { bundleGroup.getId() });
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        // deny unassigned bundle create (no global create or view)
        try {
            createBundle(subject, TEST_PREFIX + ".bundle");
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // deny unassigned bundle create (no global view)
        addRolePermissions(role, Permission.CREATE_BUNDLES);
        try {
            createBundle(subject, TEST_PREFIX + ".bundle");
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // deny unassigned bundle create (no global create)
        removeRolePermissions(role, Permission.CREATE_BUNDLES);
        addRolePermissions(role, Permission.VIEW_BUNDLES);
        try {
            createBundle(subject, TEST_PREFIX + ".bundle");
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow unassigned bundle create
        addRolePermissions(role, Permission.CREATE_BUNDLES);
        Bundle bundle = createBundle(subject, TEST_PREFIX + ".bundle");

        // deny unassigned bundle view
        removeRolePermissions(role, Permission.CREATE_BUNDLES, Permission.VIEW_BUNDLES);
        BundleCriteria bCriteria = new BundleCriteria();
        List<Bundle> bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assert bundles.isEmpty() : "Should not be able to see unassigned bundle";

        // allow unassigned bundle view
        addRolePermissions(role, Permission.VIEW_BUNDLES);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see unassigned bundle", 1, bundles.size());

        // deny global perm bundle assign
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        bundleGroup = new BundleGroup(TEST_BUNDLE_GROUP_NAME);
        bundleGroup.setDescription("test");

        bundleGroup = bundleManager.createBundleGroup(subject, bundleGroup);
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle assign via global manage_bundle_groups
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // allow bundle unassign via global manage_bundle_groups
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // allow bundle assign via global create
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        addRolePermissions(role, Permission.CREATE_BUNDLES);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // deny bundle unassign via global create
        try {
            bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle unassign via global delete
        addRolePermissions(role, Permission.DELETE_BUNDLES);
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });
        removeRolePermissions(role, Permission.DELETE_BUNDLES);

        // deny bundle assign with global create but no view
        removeRolePermissions(role, Permission.VIEW_BUNDLES);
        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // go back and again assign via global create and view
        addRolePermissions(role, Permission.VIEW_BUNDLES);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // deny assigned, unassociated-bundle-group bundle view
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        removeRolePermissions(role, Permission.VIEW_BUNDLES);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assert bundles.isEmpty() : "Should not be able to see assigned bundle";

        // allow assigned, associated-bundle-group bundle view
        addRoleBundleGroup(role, bundleGroup);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see assigned bundle", 1, bundles.size());

        // check new bundle criteria options (no match)
        bCriteria.addFilterBundleGroupIds(87678);
        bCriteria.fetchBundleGroups(true);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assert bundles.isEmpty() : "Should not have found anything";

        // check new bundle criteria options (match)
        bCriteria.addFilterBundleGroupIds(bundleGroup.getId());
        bCriteria.fetchBundleGroups(true);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see assigned bundle", 1, bundles.size());
        assertNotNull(bundles.get(0).getBundleGroups());
        assertEquals("Should have fetched bundlegroup", 1, bundles.get(0).getBundleGroups().size());
        assertEquals("Should have fetched expected bundlegroup", bundleGroup, bundles.get(0).getBundleGroups()
            .iterator().next());

        // check new bundle group criteria options (no match)
        bgCriteria.addFilterId(87678);
        bgCriteria.addFilterBundleIds(87678);
        bgCriteria.addFilterRoleIds(87678);
        bgCriteria.fetchBundles(true);
        bgCriteria.fetchRoles(true);
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not have found anything";

        // check new bundle group criteria options (no match)
        bgCriteria.addFilterId(bundleGroup.getId());
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not have found anything";

        // check new bundle group criteria options (no match)
        bgCriteria.addFilterBundleIds(bundle.getId());
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not have found anything";

        // check new bundle group criteria options (match)
        bgCriteria.addFilterRoleIds(role.getId());
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assertEquals("Should be able to see assigned bundle", 1, bundleGroups.size());
        assertNotNull(bundleGroups.get(0).getBundles());
        assertEquals("Should have fetched bundle in bundle group", 1, bundleGroups.get(0).getBundles().size());
View Full Code Here


        String name = bundleGroup.getName();
        if (null == name || "".equals(name.trim())) {
            throw new IllegalArgumentException("Invalid bundleGroupName: " + name);
        }

        BundleGroupCriteria c = new BundleGroupCriteria();
        c.addFilterName(name);
        c.setStrict(true);
        if (!bundleManager.findBundleGroupsByCriteria(subject, c).isEmpty()) {
            throw new IllegalArgumentException("Invalid bundleGroupName, bundle group already exists with name: "
                + name);
        }
View Full Code Here

        Set<Permission> globalPermissions = authorizationManager.getExplicitGlobalPermissions(assigningSubject);
        boolean hasManageBundleGroups = globalPermissions.contains(Permission.MANAGE_BUNDLE_GROUPS);

        // can assign any bundle anywhere, or leave unassigned
        if (hasManageBundleGroups) {
            BundleGroupCriteria criteria = new BundleGroupCriteria();
            // just get all the bundle groups by using overlord and no filters
            List<BundleGroup> bundleGroups = findBundleGroupsByCriteria(subjectManager.getOverlord(), criteria);
            result.setCanBeUnassigned(true);
            result.setBundleGroupMap(populateBundleGroupMap(bundleGroups, bundle));
            return result;
        }

        boolean hasViewBundles = globalPermissions.contains(Permission.VIEW_BUNDLES);
        boolean hasCreateBundles = globalPermissions.contains(Permission.CREATE_BUNDLES);
        boolean isNewBundle = (null == bundle);
        ArrayList<Permission> permFilter = new ArrayList<Permission>(1);

        if (isNewBundle) {
            // set whether can leave unassigned
            result.setCanBeUnassigned(hasCreateBundles && hasViewBundles);
            // can assign to bundle groups for which he has create_bundles_in_group
            permFilter.add(Permission.CREATE_BUNDLES_IN_GROUP);

        } else {
            // if necessary, make sure the bundle is viewable
            if (!hasViewBundles && !authorizationManager.canViewBundle(assigningSubject, bundleId)) {
                throw new PermissionException("Bundle ID [" + bundleId + "] is not viewable by subject ["
                    + assigningSubject.getName() + "]");
            }

            // can assign to bundle groups for which he has create_bundles_in_group or assign_bundles_to_group
            permFilter.add(Permission.CREATE_BUNDLES_IN_GROUP);
            permFilter.add(Permission.ASSIGN_BUNDLES_TO_GROUP);
        }

        List<BundleGroup> bundleGroups;
        if (hasCreateBundles) {
            // can assign to any viewable bundle group
            // get all the viewable bundle groups for the subject, no filters
            BundleGroupCriteria criteria = new BundleGroupCriteria();
            bundleGroups = findBundleGroupsByCriteria(assigningSubject, criteria);

        } else {
            // can only assign to bundle groups for which he has the necessary permissions
            RoleCriteria criteria = new RoleCriteria();
            criteria.addFilterSubjectId(assigningSubject.getId());
            criteria.addFilterPermissions(permFilter);
            criteria.fetchBundleGroups(true);
            List<Role> roles = LookupUtil.getRoleManager().findRolesByCriteria(subjectManager.getOverlord(), criteria);
            bundleGroups = new ArrayList<BundleGroup>();
            for (Role role : roles) {
                for (BundleGroup bundleGroup : role.getBundleGroups()) {
                    if (!bundleGroups.contains(bundleGroup)) {
View Full Code Here

        });
    }

    @Override
    protected BundleGroupCriteria getFetchCriteria(final DSRequest request) {
        BundleGroupCriteria criteria = new BundleGroupCriteria();

        // may support tags in future, but not in rev1
        //criteria.addFilterTagNamespace(getFilter(request, "tagNamespace", String.class));
        //criteria.addFilterTagSemantic(getFilter(request, "tagSemantic", String.class));
        //criteria.addFilterTagName(getFilter(request, "tagName", String.class));      
        //criteria.addFilterTagSemantic(getFilter(request, "tagSemantic", String.class));

        criteria.addFilterId(getFilter(request, FIELD_ID, Integer.class));
        criteria.addFilterName(getFilter(request, "search", String.class));
        criteria.addFilterBundleIds(getArrayFilter(request, "bundleIds", Integer.class));
        criteria.fetchBundles(true);

        return criteria;
    }
View Full Code Here

    }

    public class SelectedBundleGroupsDataSource extends BundleGroupsDataSource {
        @Override
        protected BundleGroupCriteria getFetchCriteria(final DSRequest request) {
            BundleGroupCriteria result = super.getFetchCriteria(request);
            if (null != result) {
                result.setStrict(false);
            }
            if (null != idsFilter) {
                result.addFilterIds(idsFilter);
            }
            return result;
        }
View Full Code Here

                    final ArrayList<BundleGroup> allVisibleBundleGroups = new ArrayList<BundleGroup>(visibleBundleGroups.values());
                    if (!unassignedBundleGroup.getBundles().isEmpty()) {
                        allVisibleBundleGroups.add(unassignedBundleGroup);
                    }

                    BundleGroupCriteria bundleGroupCriteria = new BundleGroupCriteria();
                    bundleGroupCriteria.addFilterIds(visibleBundleGroups.keySet().toArray(new Integer[0]));
                    bundleService.findBundleGroupsByCriteria(bundleGroupCriteria, new AsyncCallback<PageList<BundleGroup>>() {
                        public void onFailure(Throwable caught) {
                            // just log a message, but keep going, this just means we can't show lock icons where applicable
                            CoreGUI.getErrorHandler().handleError(MSG.view_bundle_tree_loadFailure(), caught);
                        }
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.criteria.BundleGroupCriteria

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.