List of usage examples for org.apache.commons.lang3 BooleanUtils isFalse
public static boolean isFalse(final Boolean bool)
Checks if a Boolean value is false , handling null by returning false .
BooleanUtils.isFalse(Boolean.TRUE) = false BooleanUtils.isFalse(Boolean.FALSE) = true BooleanUtils.isFalse(null) = false
From source file:org.finra.herd.dao.impl.TagDaoImpl.java
@Override public List<TagEntity> getTagsByTagTypeEntityAndParentTagCode(TagTypeEntity tagTypeEntity, String parentTagCode, Boolean isParentTagNull) { // Create the criteria builder and the criteria. CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<TagEntity> criteria = builder.createQuery(TagEntity.class); // The criteria root is the tag entity. Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class); // Get the columns. Path<String> displayNameColumn = tagEntityRoot.get(TagEntity_.displayName); // Create the standard restrictions (i.e. the standard where clauses). List<Predicate> predicates = new ArrayList<>(); predicates.add(builder.equal(tagEntityRoot.get(TagEntity_.tagType), tagTypeEntity)); if (StringUtils.isNotBlank(parentTagCode)) { // Return all tags that are immediate children of the specified parent tag. predicates.add(builder.equal(//from w ww . ja v a 2s. co m builder.upper(tagEntityRoot.get(TagEntity_.parentTagEntity).get(TagEntity_.tagCode)), parentTagCode.toUpperCase())); } else if (BooleanUtils.isTrue(isParentTagNull)) { // The flag is non-null and true, return all tags with no parents, i.e. root tags. predicates.add(builder.isNull(tagEntityRoot.get(TagEntity_.parentTagEntity))); } else if (BooleanUtils.isFalse(isParentTagNull)) { // The flag is non-null and false, return all tags with parents. predicates.add(builder.isNotNull(tagEntityRoot.get(TagEntity_.parentTagEntity))); } // Add all clauses to the query. criteria.select(tagEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))) .orderBy(builder.asc(displayNameColumn)); // Run the query to get the results. return entityManager.createQuery(criteria).getResultList(); }
From source file:org.optaplanner.benchmark.impl.result.PlannerBenchmarkResult.java
public void initBenchmarkReportDirectory(File benchmarkDirectory) { String timestamp = new SimpleDateFormat("yyyy-MM-dd_HHmmss").format(startingTimestamp); if (StringUtils.isEmpty(name)) { name = timestamp;/*ww w . j a va2 s. c o m*/ } if (!benchmarkDirectory.mkdirs()) { if (!benchmarkDirectory.isDirectory()) { throw new IllegalArgumentException("The benchmarkDirectory (" + benchmarkDirectory + ") already exists, but is not a directory."); } if (!benchmarkDirectory.canWrite()) { throw new IllegalArgumentException( "The benchmarkDirectory (" + benchmarkDirectory + ") already exists, but is not writable."); } } int duplicationIndex = 0; do { String directoryName = timestamp + (duplicationIndex == 0 ? "" : "_" + duplicationIndex); duplicationIndex++; benchmarkReportDirectory = new File(benchmarkDirectory, BooleanUtils.isFalse(aggregation) ? directoryName : directoryName + "_aggregation"); } while (!benchmarkReportDirectory.mkdir()); for (ProblemBenchmarkResult problemBenchmarkResult : unifiedProblemBenchmarkResultList) { problemBenchmarkResult.makeDirs(); } }
From source file:org.sakaiproject.evaluation.logic.EvalCommonLogicImpl.java
public Set<String> getUserIdsForEvalGroup(String evalGroupID, String permission, Boolean sectionAware) { Set<String> userIDs = new HashSet<>(); if (BooleanUtils.isTrue(sectionAware)) { userIDs.addAll(externalLogic.getUserIdsForEvalGroup(evalGroupID, permission, sectionAware)); }/*from ww w. j av a 2 s . c om*/ // If it's not section aware, or if we didn't find anything from external logic, do the normal lookup call if (BooleanUtils.isFalse(sectionAware) || userIDs.isEmpty()) { // Strip out the '/section/<section_id>' part of the evalGroupID if its there if (BooleanUtils.isFalse(sectionAware) && evalGroupID.contains(EvalConstants.GROUP_ID_SECTION_PREFIX)) { evalGroupID = evalGroupID.substring(0, evalGroupID.indexOf(EvalConstants.GROUP_ID_SECTION_PREFIX)); } /* NOTE: we are assuming there is not much chance that there will be some users stored in * multiple data stores for the same group id so we only check until we find at least one user, * this means checks for user in groups with no users in them end up being really costly */ // Check external userIDs.addAll(externalLogic.getUserIdsForEvalGroup(evalGroupID, permission, sectionAware)); // Only go on to check the internal adhocs if nothing was found if (userIDs.isEmpty()) { // Check internal adhoc groups if (EvalConstants.PERM_BE_EVALUATED.equals(permission) || EvalConstants.PERM_TAKE_EVALUATION.equals(permission)) { Long id = EvalAdhocGroup.getIdFromAdhocEvalGroupId(evalGroupID); if (id != null) { EvalAdhocGroup adhocGroup = adhocSupportLogic.getAdhocGroupById(id); if (adhocGroup != null) { List<String> ids = null; if (EvalConstants.PERM_BE_EVALUATED.equals(permission)) { ids = adhocGroup.getEvaluateeIds(); } else if (EvalConstants.PERM_TAKE_EVALUATION.equals(permission)) { ids = adhocGroup.getParticipantIds(); } if (ids != null) { userIDs.addAll(ids); } } } } } // Check the provider if we still found nothing if (userIDs.isEmpty()) { // Also check provider if (evalGroupsProvider != null) { if (EvalConstants.PERM_BE_EVALUATED.equals(permission) || EvalConstants.PERM_TAKE_EVALUATION.equals(permission) || EvalConstants.PERM_ASSISTANT_ROLE.equals(permission)) { LOG.debug("Using eval groups provider: evalGroupId: " + evalGroupID + ", permission: " + permission); userIDs.addAll(evalGroupsProvider.getUserIdsForEvalGroups(new String[] { evalGroupID }, EvalExternalLogicImpl.translatePermission(permission))); } } } } return userIDs; }
From source file:org.sakaiproject.evaluation.logic.externals.EvalExternalLogicImpl.java
public Set<String> getUserIdsForEvalGroup(String evalGroupID, String permission, Boolean sectionAware) { // Parse out the section and site IDs from the group ID ParsedEvalGroupID groupID = new ParsedEvalGroupID(evalGroupID); // If it's not section aware... Set<String> userIDs = new HashSet<>(); if (BooleanUtils.isFalse(sectionAware)) { // Get the list normally List<String> azGroups = new ArrayList<>(); String azGroup = EvalConstants.GROUP_ID_SITE_PREFIX + groupID.getSiteID(); if (groupID.hasGroup()) { azGroup += EvalConstants.GROUP_ID_GROUP_PREFIX + groupID.getGroupID(); }//from w w w .j a va2 s.c o m azGroups.add(azGroup); userIDs.addAll(authzGroupService.getUsersIsAllowed(permission, azGroups)); if (userIDs.contains(ADMIN_USER_ID)) { userIDs.remove(ADMIN_USER_ID); } } // Otherwise, it's section aware but we only need to run the following if the sectin prefix is present in the evalGroupID else if (groupID.hasSection()) { try { // Get all roles for the site Site site = siteService.getSite(groupID.getSiteID()); Set<Role> siteRoles = site.getRoles(); List<String> siteRolesWithPerm = new ArrayList<>(siteRoles.size()); // Determine which roles have the given permission for (Role role : siteRoles) { if (role.getAllowedFunctions().contains(permission)) { siteRolesWithPerm.add(role.getId()); } } // Get the section and the user role map for the section Section section = courseManagementService.getSection(groupID.getSectionID()); Map<String, String> userRoleMap = sectionRoleResolver.getUserRoles(courseManagementService, section); // Loop through the user role map; if the user's section role is in the list of site roles with the permission, add the user to the list for (Entry<String, String> userRoleEntry : userRoleMap.entrySet()) { if (siteRolesWithPerm.contains(userRoleEntry.getValue())) { String userEID; try { userEID = userDirectoryService.getUserId(userRoleEntry.getKey()); } catch (UserNotDefinedException e) { LOG.info("Cant find userID for user = " + userRoleEntry.getKey(), e); continue; } userIDs.add(userEID); } } } catch (IdUnusedException ex) { LOG.warn("Could not find site with ID = " + groupID.getSiteID(), ex); } catch (IdNotFoundException ex) { LOG.warn("Could not find section with ID = " + groupID.getSectionID(), ex); } } // Return the user IDs return userIDs; }
From source file:org.sakaiproject.evaluation.tool.renderers.HierarchyTreeNodeSelectRenderer.java
/** * Performs the recursive rendering logic for a single hierarchy node. * /*from w w w . j a va 2s .co m*/ * @param tofill * @param node * @param level */ private void renderSelectHierarchyNode(UIContainer tofill, EvalHierarchyNode node, int level, EvalViewParameters evalViewParams, Set<String> accessNodeIds, Set<String> parentNodeIds, List<String> selectedNodes, List<String> selectedGroups) { //a null "accessNodeIds varaible means the user is admin if (parentNodeIds == null || parentNodeIds.contains(node.id) || accessNodeIds.contains(node.id)) { boolean expanded = renderRow(tofill, "hierarchy-level-row:", level, node, evalViewParams, accessNodeIds, null, false); selectedNodes.remove("" + node.id); if (expanded) { Set<String> groupIDs = hierarchyLogic.getEvalGroupsForNode(node.id); for (String groupID : groupIDs) { Set<String> currentNodeParents = node.parentNodeIds; currentNodeParents.add(node.id); selectedGroups.remove(groupID); if (BooleanUtils.isFalse(sectionAware)) { EvalGroup evalGroup = commonLogic.makeEvalGroupObject(groupID); renderRow(tofill, "hierarchy-level-row:", level + 1, evalGroup, evalViewParams, accessNodeIds, currentNodeParents, false); } else { // Get the eval groups (child sections) under this group ID (parent site), and render a row for each List<EvalGroup> evalGroups = commonLogic.makeEvalGroupObjectsForSectionAwareness(groupID); for (EvalGroup evalGroup : evalGroups) { renderRow(tofill, "hierarchy-level-row:", level + 1, evalGroup, evalViewParams, accessNodeIds, currentNodeParents, false); } } } for (EvalHierarchyNode childHierNode : hierarchyLogic.getChildNodes(node.id, true)) { renderSelectHierarchyNode(tofill, childHierNode, level + 1, evalViewParams, accessNodeIds, parentNodeIds, selectedNodes, selectedGroups); } } } }
From source file:org.settings4j.connector.JNDIConnector.java
/** * @param key the JNDI-Key (will NOT be normalized). * @param value the JNDI-Value./*w w w. ja v a 2s . com*/ * @return Constants.SETTING_NOT_POSSIBLE if the JNDI Context ist readonly. */ public int rebindToContext(final String key, final Object value) { // don't do a check, but use the result if a check was done. if (BooleanUtils.isFalse(this.isJNDIAvailable)) { // only if isJNDIAvailable() was called an evaluated to false. return Constants.SETTING_NOT_POSSIBLE; } LOG.debug("Try to rebind Key '{}' with value: {}", key, value); InitialContext ctx = null; int result = Constants.SETTING_NOT_POSSIBLE; try { ctx = getJNDIContext(); createParentContext(ctx, key); ctx.rebind(key, value); result = Constants.SETTING_SUCCESS; } catch (final NoInitialContextException e) { logInfoButExceptionDebug(String.format("Maybe no JNDI-Context available. %s", e.getMessage()), e); } catch (final NamingException e) { // the JNDI-Context from TOMCAT is readonly // if you try to write it, The following Exception will be thrown: // javax.naming.NamingException: Context is read only logInfoButExceptionDebug(String.format("cannot bind key: '%s'. %s", key, e.getMessage()), e); } finally { closeQuietly(ctx); } return result; }
From source file:org.sigmah.server.security.impl.AuthenticationSecureSessionValidator.java
/** * Returns the grant access to the given {@code resourceToken} for the {@code user}. * //from w w w.j ava2 s. c om * @param user * The user. * @param resourceToken * The resource token to secure. * @param originPageToken * The origin page token, may be {@code null}. * @return {@code true} if the {@code user} is granted to access {@code resourceToken}, {@code false} otherwise. */ private boolean isUserGranted(final User user, final String resourceToken, final String originPageToken) { if (user != null && BooleanUtils.isFalse(user.getActive())) { if (LOG.isWarnEnabled()) { LOG.warn("User '{}' cannot access resource '{}' because it is no longer active.", user, resourceToken); } return false; } return AccessRights.isGranted(user, resourceToken, originPageToken, mapper); }
From source file:org.sigmah.server.service.ReminderService.java
/** * {@inheritDoc}//from w w w. j a v a 2s .c o m */ @Override public Reminder update(final Integer entityId, final PropertyMap changes, final UserExecutionContext context) throws CommandException { final Reminder reminderToUpdate = reminderDAO.findById(entityId); if (reminderToUpdate == null) { throw new CommandException("Cannot find Reminder with id #" + entityId + "."); } final User user = context.getUser(); final boolean date_modified = !(new Date((Long) changes.get(ReminderDTO.EXPECTED_DATE)) .equals(reminderToUpdate.getExpectedDate())); final boolean label_modified = !((String) changes.get(ReminderDTO.LABEL)) .equals(reminderToUpdate.getLabel()); // Update 3 properties: ExpectedDate,Label,Deleted reminderToUpdate.setExpectedDate(new Date((Long) changes.get(ReminderDTO.EXPECTED_DATE))); reminderToUpdate.setLabel((String) changes.get(ReminderDTO.LABEL)); final Boolean deleted = (Boolean) changes.get(ReminderDTO.DELETED); if (deleted != null) { reminderToUpdate.setDeleted(deleted); } if (BooleanUtils.isFalse(reminderToUpdate.getDeleted())) { if (date_modified) { final ReminderHistory hist = new ReminderHistory(); hist.setDate(new Date()); hist.setType(ReminderChangeType.DATE_MODIFIED); hist.setUserId(user.getId()); hist.setValue(user.getName() + ", " + user.getFirstName() + " <" + user.getEmail() + ">"); reminderToUpdate.addHistory(hist); } if (label_modified) { final ReminderHistory hist = new ReminderHistory(); hist.setDate(new Date()); hist.setType(ReminderChangeType.LABEL_MODIFIED); hist.setUserId(user.getId()); hist.setValue(user.getName() + ", " + user.getFirstName() + " <" + user.getEmail() + ">"); reminderToUpdate.addHistory(hist); } } else { final ReminderHistory hist = new ReminderHistory(); hist.setDate(new Date()); hist.setType(ReminderChangeType.DELETED); hist.setUserId(user.getId()); hist.setValue(user.getName() + ", " + user.getFirstName() + " <" + user.getEmail() + ">"); reminderToUpdate.addHistory(hist); } return reminderDAO.persist(reminderToUpdate, user); }
From source file:yoyo.framework.standard.shared.commons.lang.BooleanUtilsTest.java
@Test public void test() { assertThat(BooleanUtils.and(new boolean[] { true }), is(true)); assertThat(BooleanUtils.and(new boolean[] { true, false }), is(false)); assertThat(BooleanUtils.isFalse(false), is(true)); assertThat(BooleanUtils.isNotFalse(false), is(false)); assertThat(BooleanUtils.isNotTrue(true), is(false)); assertThat(BooleanUtils.isTrue(true), is(true)); assertThat(BooleanUtils.negate(Boolean.FALSE), is(true)); assertThat(BooleanUtils.or(new boolean[] { true }), is(true)); assertThat(BooleanUtils.or(new boolean[] { true, false }), is(true)); assertThat(BooleanUtils.toBoolean(Boolean.TRUE), is(true)); assertThat(BooleanUtils.toBoolean(0), is(false)); assertThat(BooleanUtils.toBoolean(1), is(true)); assertThat(BooleanUtils.toBoolean((String) null), is(false)); assertThat(BooleanUtils.toBoolean("true"), is(true)); assertThat(BooleanUtils.toBoolean("hoge"), is(false)); assertThat(BooleanUtils.toBooleanDefaultIfNull(null, false), is(false)); assertThat(BooleanUtils.toBooleanObject(0), is(Boolean.FALSE)); assertThat(BooleanUtils.toBooleanObject(1), is(Boolean.TRUE)); assertThat(BooleanUtils.toInteger(true), is(1)); assertThat(BooleanUtils.toInteger(false), is(0)); assertThat(BooleanUtils.toIntegerObject(true), is(Integer.valueOf(1))); assertThat(BooleanUtils.toIntegerObject(false), is(Integer.valueOf(0))); assertThat(BooleanUtils.toString(true, "true", "false"), is("true")); assertThat(BooleanUtils.toString(false, "true", "false"), is("false")); assertThat(BooleanUtils.toStringOnOff(true), is("on")); assertThat(BooleanUtils.toStringOnOff(false), is("off")); assertThat(BooleanUtils.toStringTrueFalse(true), is("true")); assertThat(BooleanUtils.toStringTrueFalse(false), is("false")); assertThat(BooleanUtils.toStringYesNo(true), is("yes")); assertThat(BooleanUtils.toStringYesNo(false), is("no")); assertThat(BooleanUtils.xor(new boolean[] { true }), is(true)); assertThat(BooleanUtils.xor(new boolean[] { true, false }), is(true)); assertThat(BooleanUtils.xor(new boolean[] { true, true }), is(false)); }