Example usage for java.util Collection contains

List of usage examples for java.util Collection contains

Introduction

In this page you can find the example usage for java.util Collection contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this collection contains the specified element.

Usage

From source file:com.flexive.shared.content.FxPermissionUtils.java

/**
 * Permission check for (new) contents//from  w w w.  j  ava 2  s . c  o m
 *
 * @param ticket         calling users ticket
 * @param ownerId        owner of the content to check
 * @param permission     permission to check
 * @param type           used type
 * @param stepACL        step ACL
 * @param contentACLs    content ACL(s)
 * @param throwException should exception be thrown
 * @return access granted
 * @throws FxNoAccessException if not accessible for calling user
 * @since 3.1
 */
public static boolean checkPermission(UserTicket ticket, long ownerId, ACLPermission permission, FxType type,
        long stepACL, Collection<Long> contentACLs, boolean throwException) throws FxNoAccessException {
    if (ticket.isGlobalSupervisor() || !type.isUsePermissions() || FxContext.get().getRunAsSystem())
        return true;
    boolean typeAllowed = !type.isUseTypePermissions();
    boolean stepAllowed = !type.isUseStepPermissions();
    boolean contentAllowed = !type.isUseInstancePermissions();
    final long userId = ticket.getUserId();
    final long typeAclId = type.getACL().getId();
    for (ACLAssignment assignment : ticket.getACLAssignments()) {
        final long assignmentAclId = assignment.getAclId();
        if (!typeAllowed && assignmentAclId == typeAclId)
            typeAllowed = assignment.getPermission(permission, ownerId, userId);
        if (!stepAllowed && assignmentAclId == stepACL)
            stepAllowed = assignment.getPermission(permission, ownerId, userId);
        if (!contentAllowed && contentACLs.contains(assignmentAclId))
            contentAllowed = assignment.getPermission(permission, ownerId, userId);
    }
    if (throwException && !(typeAllowed && stepAllowed && contentAllowed)) {
        Set<String> lacking = new HashSet<String>(3);
        if (!typeAllowed)
            addACLName(lacking, ticket.getLanguage(), typeAclId);
        if (!stepAllowed)
            addACLName(lacking, ticket.getLanguage(), stepACL);
        if (!contentAllowed) {
            for (Long acl : contentACLs) {
                addACLName(lacking, ticket.getLanguage(), acl);
            }
        }
        throw noAccess(permission, lacking);
    }
    return typeAllowed && stepAllowed && contentAllowed;
}

From source file:gov.nih.nci.caintegrator.application.query.QueryManagementServiceImpl.java

private boolean isQueryOnAllGenes(Collection<String> allGeneSymbols) {
    if (allGeneSymbols.contains("")) {
        return true;
    }//from  ww w . j a va  2s  . c  o m
    return false;
}

From source file:org.openmrs.module.odkconnector.web.controller.concept.ManageConceptController.java

@RequestMapping(value = "/module/odkconnector/concept/manageConcept", method = RequestMethod.POST)
public void process(final @RequestParam(value = "conceptUuids", required = true) String conceptUuids,
        final @RequestParam(value = "configurationUuid", required = true) String configurationUuid,
        final Model model, final HttpServletRequest request) {

    ConnectorService service = Context.getService(ConnectorService.class);
    ConceptConfiguration conceptConfiguration = service.getConceptConfigurationByUuid(configurationUuid);

    // the uuids coming from the web page. might contains new uuid and will not contains retired uuid
    Set<String> createdConceptUuidValues = new LinkedHashSet<String>(
            Arrays.asList(StringUtils.split(StringUtils.defaultString(conceptUuids), ",")));
    // the saved uuids. might contains retired uuid and will not contains new uuid
    Set<String> savedConceptUuidValues = new LinkedHashSet<String>();
    for (ConfiguredConcept configuredConcept : conceptConfiguration.getConfiguredConcepts()) {
        if (!configuredConcept.isRetired()) {
            Concept concept = configuredConcept.getConcept();
            savedConceptUuidValues.add(concept.getUuid());
        }//from  w w  w . j a  v  a  2 s.  c  o m
    }

    Collection intersectedUuids = CollectionUtils.intersection(createdConceptUuidValues,
            savedConceptUuidValues);
    Collection retiredConceptUuids = CollectionUtils.subtract(savedConceptUuidValues, intersectedUuids);
    Collection createdConceptUuids = CollectionUtils.subtract(createdConceptUuidValues, intersectedUuids);

    for (ConfiguredConcept configuredConcept : conceptConfiguration.getConfiguredConcepts()) {
        Concept concept = configuredConcept.getConcept();
        if (retiredConceptUuids.contains(concept.getUuid())) {
            configuredConcept.setRetired(Boolean.TRUE);
            configuredConcept.setRetiredBy(Context.getAuthenticatedUser());
            configuredConcept.setDateRetired(new Date());
        }
    }

    for (Object conceptUuid : createdConceptUuids) {
        Concept concept = Context.getConceptService().getConceptByUuid(String.valueOf(conceptUuid));
        if (concept != null) {
            ConfiguredConcept configuredConcept = new ConfiguredConcept();
            configuredConcept.setConcept(concept);
            configuredConcept.setConceptConfiguration(conceptConfiguration);
            conceptConfiguration.addConfiguredConcept(configuredConcept);
        }
    }
    service.saveConceptConfiguration(conceptConfiguration);

    Set<Concept> concepts = ConnectorUtils.getConcepts(conceptConfiguration.getConfiguredConcepts());
    model.addAttribute("configuration", conceptConfiguration);
    model.addAttribute("concepts", concepts);
    model.addAttribute("conceptUuids", ConnectorUtils.convertString(ConnectorUtils.getConceptUuids(concepts)));
}

From source file:com.bluexml.side.Framework.alfresco.dataGenerator.dictionary.AlfrescoModelDictionary.java

/**
 * removes of the model's types types that can't be instantiate, i.e. abstract types 
 * @param types//from  w ww .j  a  va  2 s  . c  om
 * @return the non abstract types, i.e. types that can be instantiate under Alfresco
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 */
private Collection<TypeDefinition> removeAbstractTypes(Collection<TypeDefinition> types)
        throws ParserConfigurationException, SAXException, IOException {
    Collection<TypeDefinition> tempTypes = new ArrayList<TypeDefinition>();
    Collection<QName> notAbstractTypes = getNotAbstractTypes();
    for (TypeDefinition type : types) {
        QName qnamedType = type.getName();
        if (!notAbstractTypes.contains(qnamedType)) {
            tempTypes.add(type);
        }
    }
    types.removeAll(tempTypes);
    return types;
}

From source file:com.vmware.upgrade.progress.impl.SimpleAggregatingProgressReporter.java

/**
 * Sets child progress reporters to monitor and aggregate.
 *
 * @param children// w  w w.  j  av  a  2 s  .co m
 *          a non-empty collection of child progress reporters
 * @throws IllegalArgumentException if {@code children} is {@code null} or empty
 *                  or contains a {@code null} member
 */
public final void setChildren(final Collection<? extends ProgressReporter> children) {
    if (children == null) {
        throw new IllegalArgumentException("children");
    }

    if (children.isEmpty()) {
        throw new IllegalArgumentException("children");
    }

    if (children.contains(null)) {
        throw new IllegalArgumentException("children");
    }

    for (final ProgressReporter child : children) {
        final PropagatingListener childListener = new PropagatingListener(child);
        childListeners.add(childListener);
    }

    startChildListeners();
}

From source file:com.glaf.core.security.LoginContext.java

public boolean hasSystemPermission() {
    if (this.isSystemAdministrator()) {
        return true;
    }/*from   ww w. j a  v  a 2 s. co m*/
    boolean hasPermission = false;
    Collection<Long> roleIds = this.getRoleIds();
    if (roleIds != null) {
        if (roleIds.contains(10000L)) {
            hasPermission = true;
        }
    }
    Collection<String> roles = this.getRoles();
    if (roles != null) {
        if (roles.contains("SystemAdministrator")) {
            hasPermission = true;
        }
    }
    return hasPermission;
}

From source file:com.flexive.chemistry.webdav.ObjectResource.java

/**
 * {@inheritDoc}//ww  w  . jav  a  2s.c om
 */
public boolean authorise(Request request, Request.Method method, Auth auth) {
    final Collection<QName> actions = getConnection().getSPI().getAllowableActions(object);
    switch (method) {
    case GET:
    case PROPFIND:
        return true; // since we already loaded it, we can also read
    case PUT:
        return actions.contains(AllowableAction.CAN_CREATE_DOCUMENT)
                || actions.contains(AllowableAction.CAN_CREATE_FOLDER)
                || actions.contains(AllowableAction.CAN_ADD_OBJECT_TO_FOLDER);
    case POST:
    case PROPPATCH:
        return actions.contains(AllowableAction.CAN_UPDATE_PROPERTIES);
    case DELETE:
        return actions.contains(AllowableAction.CAN_DELETE_OBJECT);
    case LOCK:
        return actions.contains(AllowableAction.CAN_CHECK_OUT);
    case UNLOCK:
        return actions.contains(AllowableAction.CAN_CANCEL_CHECK_OUT)
                || actions.contains(AllowableAction.CAN_CHECK_IN);
    case MOVE:
        return actions.contains(AllowableAction.CAN_MOVE_OBJECT);
    default:
        return true;
    }
}

From source file:com.glaf.jbpm.action.DynamicTaskInstances.java

public void execute(ExecutionContext ctx) {
    logger.debug("-------------------------------------------------------");
    logger.debug("---------------DynamicTaskInstances--------------------");
    logger.debug("-------------------------------------------------------");

    Task task = null;/*  w  ww  .  j a  v  a 2s .  c  om*/

    if (StringUtils.isNotEmpty(taskName)) {
        Node node = ctx.getNode();
        if (node instanceof TaskNode) {
            TaskNode taskNode = (TaskNode) node;
            task = taskNode.getTask(taskName);
        }
    }

    if (task == null) {
        task = ctx.getTask();
    }

    boolean hasActors = false;

    ContextInstance contextInstance = ctx.getContextInstance();

    if (StringUtils.isNotEmpty(dynamicActors)) {
        Token token = ctx.getToken();
        TaskMgmtInstance tmi = ctx.getTaskMgmtInstance();
        String actorIdxy = (String) contextInstance.getVariable(dynamicActors);
        if (StringUtils.isNotEmpty(actorIdxy)) {
            Collection<String> actorIds = new HashSet<String>();
            StringTokenizer st2 = new StringTokenizer(actorIdxy, ",");
            while (st2.hasMoreTokens()) {
                String actorId = st2.nextToken();
                if (StringUtils.isNotEmpty(actorId) && !actorIds.contains(actorId)) {
                    TaskInstance taskInstance = tmi.createTaskInstance(task, token);
                    actorIds.add(actorId);
                    taskInstance.setActorId(actorId);
                    taskInstance.setCreate(new Date());
                    taskInstance.setSignalling(task.isSignalling());
                    hasActors = true;
                }
            }
            if (StringUtils.isNotEmpty(sendMail) && StringUtils.equals(sendMail, "true")) {
                MailBean mailBean = new MailBean();
                mailBean.setContent(content);
                mailBean.setSubject(subject);
                mailBean.setTaskContent(taskContent);
                mailBean.setTaskName(taskName);
                mailBean.setTemplateId(templateId);
                mailBean.execute(ctx, actorIds);
            }
        }
    }

    // ???
    if (!hasActors) {
        if (leaveNodeIfActorNotAvailable) {
            contextInstance.setVariable(Constant.IS_AGREE, "true");
            if (StringUtils.isNotEmpty(transitionName)) {
                ctx.leaveNode(transitionName);
            } else {
                ctx.leaveNode();
            }
        }
    }

}

From source file:de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionServiceIntegrationTest.java

/**
 * Test method for//w  w w.j  a va  2s  .co  m
 * {@link de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionService#grantReadPermission(de.hybris.platform.core.model.media.MediaModel, de.hybris.platform.core.model.security.PrincipalModel)}
 * .
 */
@Test
public void testGrantPermission() {
    final UserModel testUser = modelService.create(UserModel.class);
    testUser.setUid("testGroup");
    testUser.setName("Testgroup");
    modelService.save(testUser);

    final PermissionAssignment testAssignment = new PermissionAssignment(PermissionsConstants.READ, testUser);
    final Collection<PermissionAssignment> permAssignments = permissionManagementService
            .getItemPermissionsForPrincipal(testMediaItem, testUser);

    Assert.assertFalse(permAssignments.contains(testAssignment));

    mediaPermissionService.grantReadPermission(testMediaItem, testUser);
    final PermissionCheckResult checkResult = permissionCheckingService.checkItemPermission(testMediaItem,
            testUser, PermissionsConstants.READ);

    Assert.assertTrue(checkResult.isGranted());
}

From source file:com.glaf.core.security.LoginContext.java

public boolean isSystemAdministrator() {
    boolean isSystemAdministrator = false;
    Collection<Long> roleIds = this.getRoleIds();
    if (roleIds != null) {
        if (roleIds.contains(10000L)) {
            isSystemAdministrator = true;
        }//  ww  w  .  j a  v a 2  s. c  om
    }

    Collection<String> roles = this.getRoles();
    if (roles != null) {
        if (roles.contains("SystemAdministrator")) {
            isSystemAdministrator = true;
        }
    }

    if (user != null && user.isSystemAdministrator()) {
        isSystemAdministrator = true;
    }

    return isSystemAdministrator;
}