List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty
public static boolean isEmpty(final Collection<?> coll)
From source file:org.phenotips.vocabulary.internal.solr.AbstractSolrVocabularyTerm.java
/** * Retrieves the first value corresponding to the target key. This may be the only value set for a simple field, or * the first in a collection of values for a multi-valued field. * * @param key the name of the field to retrieve * @return the first value, or {@code null} if there's no value set for the target key *///from w ww. ja va 2 s.com protected Object getFirstValue(String key) { Collection<Object> values = getValues(key); if (CollectionUtils.isEmpty(values)) { return null; } return IterableUtils.get(values, 0); }
From source file:org.sakaiproject.poll.logic.impl.PollOrderOptionBackFillJob.java
/** * This is the method that is fired when the job is 'triggered'. * * @param jobExecutionContext - the context of the job execution * @throws JobExecutionException//from www . j a va2 s.co m */ @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { log.info("Attempting to back-fill all existing Poll option orders..."); int modifiedCount = 0; // Iterate over sites in the system, ordered by creation date... List<Site> sites = siteService.getSites(SelectionType.ANY, null, null, null, SortType.CREATED_ON_DESC, null); if (!CollectionUtils.isEmpty(sites)) { for (Site site : sites) { String siteID = site.getId(); List<Poll> pollsForSite = pollService.findAllPolls(siteID); if (!CollectionUtils.isEmpty(pollsForSite)) { // Iterate over the polls for the site... for (Poll poll : pollsForSite) { try { // Iterate over Options in the poll... securityService.pushAdvisor(YES_MAN); List<Option> pollOptions = pollService.getOptionsForPoll(poll); if (!CollectionUtils.isEmpty(pollOptions)) { // Check if any options have a null order boolean hasNullOptionOrder = false; for (Option option : pollOptions) { if (option.getOptionOrder() == null) { hasNullOptionOrder = true; break; } } // If any of the option's order is null, we need to back-fill them if (hasNullOptionOrder) { log.info("Poll ID {} has options with null order, processing...", poll.getId()); // Order the list by ID pollOptions.sort(Comparator.comparingLong(Option::getOptionId)); // Iterate over the list for (int i = 0; i < pollOptions.size(); i++) { // Add order based on ID Option option = pollOptions.get(i); option.setOptionOrder(i); pollService.saveOption(option); modifiedCount++; log.info("Option {} ---> new order == {}", option.getId(), i); } } } } catch (Exception ex) { log.error("Unexcepted exception", ex); } finally { securityService.popAdvisor(YES_MAN); } } } } } log.info("Processing finished, modified {} poll options", modifiedCount); }
From source file:org.sigmah.server.dao.impl.FileHibernateDAO.java
/** * {@inheritDoc}/*ww w. j av a 2s . c o m*/ */ @Override public List<FileVersion> findVersions(final Collection<Integer> filesIds, LoadingScope loadingScope) { if (CollectionUtils.isEmpty(filesIds)) { throw new IllegalArgumentException("Invalid files ids collection."); } if (loadingScope == null) { loadingScope = LoadingScope.LAST_VERSION; } // NOTE : StringBuilder has been removed here since all the strings used here are constants. final String request; switch (loadingScope) { case ALL_VERSIONS: // Retrieves all versions of each file. request = "SELECT " + " fv " + "FROM " + " File f INNER JOIN f.versions fv " + "WHERE " + " f.id IN (:filesIds)"; break; case LAST_VERSION: // Retrieves only the last version of each file. request = "SELECT " + " fv " + "FROM " + " File f INNER JOIN f.versions fv " + "WHERE " + " f.id IN (:filesIds) " + " AND fv.versionNumber IN (" + " SELECT max(fv2.versionNumber) FROM FileVersion fv2 WHERE fv2.parentFile = f" + " )"; break; case LAST_VERSION_FROM_NOT_DELETED_FILES: // Retrieves only the last version of each file if the file has not been deleted. request = "SELECT " + " fv " + "FROM " + " File f INNER JOIN f.versions fv " + "WHERE " + " f.id IN (:filesIds) " + " AND f.dateDeleted IS NULL " + " AND fv.versionNumber IN (" + " SELECT max(fv2.versionNumber) FROM FileVersion fv2 WHERE fv2.parentFile = f" + " )"; break; default: throw new IllegalArgumentException("Invalid file versions loading mode."); } final TypedQuery<FileVersion> query = em().createQuery(request, FileVersion.class); query.setParameter("filesIds", filesIds); return query.getResultList(); }
From source file:org.sigmah.server.dao.impl.ValueHibernateDAO.java
/** * {@inheritDoc}//from ww w . j a v a 2 s . c o m */ @Override public List<Value> findValuesForOrgUnits(final Collection<OrgUnit> orgUnits) { if (CollectionUtils.isEmpty(orgUnits)) { throw new IllegalArgumentException("Invalid OrgUnits collection."); } final StringBuilder builder = new StringBuilder(); builder.append("SELECT v "); builder.append(" FROM Value v "); builder.append(" WHERE v.containerId IN ("); builder.append(" SELECT "); builder.append(" ud.id "); builder.append(" FROM "); builder.append(" OrgUnit o"); builder.append(" INNER JOIN o.databases ud "); builder.append(" WHERE o IN (:orgUnits)"); builder.append(" )"); builder.append(" OR v.containerId IN (:orgUnits)"); final TypedQuery<Value> query = em().createQuery(builder.toString(), Value.class); query.setParameter("orgUnits", orgUnits); return query.getResultList(); }
From source file:org.sigmah.server.handler.DeactivateUsersHandler.java
/** * {@inheritDoc}//ww w .j a va2s . c o m */ @Override public VoidResult execute(final DeactivateUsers cmd, final UserExecutionContext context) throws CommandException { if (CollectionUtils.isEmpty(cmd.getUsers())) { return new VoidResult(); } performDeactivation(cmd.getUsers(), context); return new VoidResult(); }
From source file:org.sigmah.server.handler.DeletePrivacyGroupsHandler.java
/** * {@inheritDoc}// w ww.j av a2 s .co m */ @Override public DeleteResult<PrivacyGroupDTO> execute(final DeletePrivacyGroups cmd, final UserExecutionContext context) throws CommandException { final List<Integer> privacyGroupIds = cmd.getPrivacyGroupIds(); // Result that may contain detected error(s). final DeleteResult<PrivacyGroupDTO> result = new DeleteResult<PrivacyGroupDTO>(); if (CollectionUtils.isEmpty(privacyGroupIds)) { // Nothing to delete. return result; } performDelete(privacyGroupIds, context, result); return result; }
From source file:org.sigmah.server.handler.DeleteProfilesHandler.java
/** * {@inheritDoc}//from w ww . j ava 2 s.c om */ @Override public DeleteResult<ProfileDTO> execute(final DeleteProfiles cmd, final UserExecutionContext context) throws CommandException { // Profiles to delete. final List<ProfileDTO> profiles = cmd.getProfiles(); // Result that may contain detected error(s). final DeleteResult<ProfileDTO> result = new DeleteResult<ProfileDTO>(); if (CollectionUtils.isEmpty(profiles)) { return result; } // Delete the profiles performDelete(profiles, result, context); return result; }
From source file:org.sigmah.server.handler.util.Handlers.java
/** * <p>/*from w ww . jav a2 s. c om*/ * Aggregates the list of profiles of a {@code user}. * </p> * <p> * The {@link User} may have several profiles which link it to its {@link OrgUnit}.<br/> * This handler merges also all the profiles in one <em>aggregated profile</em>. * </p> * * @param user * The user. * @param mapper * The mapper service. * @return The aggregated profile DTO. */ public static ProfileDTO aggregateProfiles(final User user, final Mapper mapper) { final ProfileDTO aggretatedProfileDTO = new ProfileDTO(); aggretatedProfileDTO.setName("AGGREGATED_PROFILE"); aggretatedProfileDTO.setGlobalPermissions(new HashSet<GlobalPermissionEnum>()); aggretatedProfileDTO.setPrivacyGroups(new HashMap<PrivacyGroupDTO, PrivacyGroupPermissionEnum>()); if (user == null || user.getOrgUnitWithProfiles() == null || CollectionUtils.isEmpty(user.getOrgUnitWithProfiles().getProfiles())) { return aggretatedProfileDTO; } // For each profile. for (final Profile profile : user.getOrgUnitWithProfiles().getProfiles()) { // Global permissions. if (profile.getGlobalPermissions() != null) { for (final GlobalPermission p : profile.getGlobalPermissions()) { // Aggregates global permissions among profiles. aggretatedProfileDTO.getGlobalPermissions().add(p.getPermission()); } } // Privacy groups. if (profile.getPrivacyGroupPermissions() != null) { for (final PrivacyGroupPermission p : profile.getPrivacyGroupPermissions()) { final PrivacyGroupDTO groupDTO = mapper.map(p.getPrivacyGroup(), new PrivacyGroupDTO()); // Aggregates privacy groups among profiles. if (aggretatedProfileDTO.getPrivacyGroups().get(groupDTO) != PrivacyGroupPermissionEnum.WRITE) { aggretatedProfileDTO.getPrivacyGroups().put(groupDTO, p.getPermission()); } } } } return aggretatedProfileDTO; }
From source file:org.sigmah.server.servlet.util.Servlets.java
/** * Returns the given {@code violations} corresponding <em>loggable</em> string. * //from w ww . j av a2 s . c o m * @param violations * The constraint violations collection. * @return The given {@code violations} corresponding <em>loggable</em> string. */ public static String logConstraints(final Collection<ConstraintViolation<?>> violations) { final StringBuilder sb = new StringBuilder(); if (CollectionUtils.isEmpty(violations)) { return sb.toString(); } for (final ConstraintViolation<?> violation : violations) { sb.append("Constraint violation["); sb.append("Class: "); sb.append(violation.getRootBeanClass().getCanonicalName()); sb.append(" ; "); sb.append("Property: "); sb.append(violation.getPropertyPath().iterator().next().getName()); sb.append(" ; "); sb.append("Message: "); sb.append(violation.getMessage()); sb.append(" ; "); sb.append("Invalid value: "); sb.append(String.valueOf(violation.getInvalidValue())); sb.append("]\n"); } return sb.toString(); }
From source file:org.tdar.core.bean.resource.InformationResource.java
@XmlTransient public InformationResourceFileVersion getLatestUploadedVersion() { Collection<InformationResourceFileVersion> latestUploadedVersions = getLatestUploadedVersions(); if (CollectionUtils.isEmpty(latestUploadedVersions)) { logger.warn("No latest uploaded version for {}", this); return null; }/*from ww w. j ava 2 s. c om*/ return getLatestUploadedVersions().iterator().next(); }