Example usage for org.apache.commons.collections CollectionUtils filter

List of usage examples for org.apache.commons.collections CollectionUtils filter

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils filter.

Prototype

public static void filter(Collection collection, Predicate predicate) 

Source Link

Document

Filter the collection by applying a Predicate to each element.

Usage

From source file:org.openmrs.api.db.hibernate.HibernateVisitDAO.java

/**
 * @see org.openmrs.api.db.VisitDAO#getVisits(java.util.Collection, java.util.Collection,
 *      java.util.Collection, java.util.Collection, java.util.Date, java.util.Date,
 *      java.util.Date, java.util.Date, java.util.Map, boolean, boolean)
 *///from w ww. j  av  a2  s  . c  o m
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public List<Visit> getVisits(Collection<VisitType> visitTypes, Collection<Patient> patients,
        Collection<Location> locations, Collection<Concept> indications, Date minStartDatetime,
        Date maxStartDatetime, Date minEndDatetime, Date maxEndDatetime,
        final Map<VisitAttributeType, String> serializedAttributeValues, boolean includeInactive,
        boolean includeVoided) throws DAOException {

    Criteria criteria = getCurrentSession().createCriteria(Visit.class);

    if (visitTypes != null) {
        criteria.add(Restrictions.in("visitType", visitTypes));
    }
    if (patients != null) {
        criteria.add(Restrictions.in("patient", patients));
    }
    if (locations != null) {
        criteria.add(Restrictions.in("location", locations));
    }
    if (indications != null) {
        criteria.add(Restrictions.in("indication", indications));
    }

    if (minStartDatetime != null) {
        criteria.add(Restrictions.ge("startDatetime", minStartDatetime));
    }
    if (maxStartDatetime != null) {
        criteria.add(Restrictions.le("startDatetime", maxStartDatetime));
    }

    // active visits have null end date, so it doesn't make sense to search against it if include inactive is set to false
    if (!includeInactive) {
        // the user only asked for currently active visits, so stop time needs to be null or after right now
        criteria.add(Restrictions.or(Restrictions.isNull("stopDatetime"),
                Restrictions.gt("stopDatetime", new Date())));
    } else {
        if (minEndDatetime != null) {
            criteria.add(Restrictions.or(Restrictions.isNull("stopDatetime"),
                    Restrictions.ge("stopDatetime", minEndDatetime)));
        }
        if (maxEndDatetime != null) {
            criteria.add(Restrictions.le("stopDatetime", maxEndDatetime));
        }
    }

    if (!includeVoided) {
        criteria.add(Restrictions.eq("voided", false));
    }

    criteria.addOrder(Order.desc("startDatetime"));
    criteria.addOrder(Order.desc("visitId"));

    List<Visit> visits = criteria.list();

    if (serializedAttributeValues != null) {
        CollectionUtils.filter(visits,
                new AttributeMatcherPredicate<Visit, VisitAttributeType>(serializedAttributeValues));
    }

    return visits;
}

From source file:org.openmrs.module.kenyaemr.fragment.controller.report.ReportUtilsFragmentController.java

/**
 * Gets the queued requests for the given report
 * @param reportUuid the report definition UUID
 * @param ui the UI utils//from  w  w  w  .j  a  va2 s  .  c o  m
 * @param reportService the report service
 * @return the simplified requests
 */
public SimpleObject[] getQueuedRequests(@RequestParam(value = "reportUuid", required = false) String reportUuid,
        UiUtils ui, @SpringBean ReportService reportService) {

    List<ReportRequest> requests = fetchRequests(reportUuid, false, reportService);

    // Filter out finished requests
    CollectionUtils.filter(requests, new Predicate() {
        @Override
        public boolean evaluate(Object obj) {
            ReportRequest request = (ReportRequest) obj;
            return !(ReportRequest.Status.COMPLETED.equals(request.getStatus())
                    || ReportRequest.Status.FAILED.equals(request.getStatus()));
        }
    });

    return ui.simplifyCollection(requests);
}

From source file:org.openmrs.module.providermanagement.ProviderManagementUtils.java

/**
 * Filters retired providers out of the list of passed providers
 * //from   w  ww. j  ava2s.  c o m
 * @param providers
 */
public static void filterRetired(Collection<Provider> providers) {
    CollectionUtils.filter(providers, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return !((Provider) o).isRetired();
        }
    });
}

From source file:org.openmrs.module.providermanagement.ProviderManagementUtils.java

/**
 * Filters out all relationship types that are not associated with a provider role
 * (Does not filter out retired relationship types associated with a provider role)
 *
 * @param relationships/*from   w  w w  .  j a v a2 s  .c  o m*/
 */
public static void filterNonProviderRelationships(Collection<Relationship> relationships) {
    final List<RelationshipType> providerRelationshipTypes = Context.getService(ProviderManagementService.class)
            .getAllProviderRoleRelationshipTypes(true);
    CollectionUtils.filter(relationships, new Predicate() {
        @Override
        public boolean evaluate(Object o) {
            return providerRelationshipTypes.contains(((Relationship) o).getRelationshipType());
        }
    });

}

From source file:org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10.OrderUtil.java

private static void removeActiveOrders(List<Order> orders, final Date asOfDate) {

    CollectionUtils.filter(orders, new Predicate() {

        @Override//from  w  w w  . j a va 2 s .  c o  m
        public boolean evaluate(Object object) {
            Order order = (Order) object;
            return order.isDiscontinued(asOfDate) || order.isExpired(asOfDate);
        }

    });
}

From source file:org.ovirt.engine.api.restapi.resource.openstack.BackendOpenStackVolumeTypeResource.java

@Override
public OpenStackVolumeType get() {
    Guid storageDomainId = BackendOpenStackStorageProviderHelper.getStorageDomainId(this, providerId);
    IdQueryParameters parameters = new IdQueryParameters(storageDomainId);
    List<CinderVolumeType> volumeTypes = getBackendCollection(CinderVolumeType.class,
            VdcQueryType.GetCinderVolumeTypesByStorageDomainId, parameters);
    CollectionUtils.filter(volumeTypes, new Predicate() {
        @Override/*from  w w  w  .j a v a2 s.  co m*/
        public boolean evaluate(Object o) {
            return ((CinderVolumeType) o).getId().equals(id);
        }
    });

    if (volumeTypes.isEmpty()) {
        return notFound();
    }

    return addLinks(populate(map(volumeTypes.get(0)), volumeTypes.get(0)));
}

From source file:org.pentaho.marketplace.domain.services.BaPluginService.java

@Override
public Map<String, IPlugin> getPlugins() {
    Map<String, IPlugin> plugins = super.getPlugins();

    // remove non BA plugins
    CollectionUtils.filter(plugins.entrySet(), new Predicate() {
        @Override//ww w  . j  a v  a 2 s  .c  o m
        public boolean evaluate(Object mapEntry) {
            Map.Entry<String, IPlugin> mapEntryCasted = (Map.Entry<String, IPlugin>) mapEntry;
            return mapEntryCasted.getValue().getType() == MarketEntryType.Platform;
        }
    });

    return plugins;
}

From source file:org.pentaho.marketplace.domain.services.DiPluginService.java

@Override
public Map<String, IPlugin> getPlugins() {
    Map<String, IPlugin> plugins = super.getPlugins();

    // remove non PDI plugins
    CollectionUtils.filter(plugins.entrySet(), new Predicate() {
        @SuppressWarnings("unchecked")
        @Override//from  w w  w.java 2s .  c o m
        public boolean evaluate(Object mapEntry) {
            Map.Entry<String, IPlugin> mapEntryCasted = (Map.Entry<String, IPlugin>) mapEntry;
            return mapEntryCasted.getValue().getType() != MarketEntryType.Platform;
        }
    });

    return plugins;
}

From source file:org.projectforge.business.fibu.AuftragDao.java

private List<AuftragDO> getList(final BaseSearchFilter filter, final boolean checkAccess) {
    final AuftragFilter myFilter;
    if (filter instanceof AuftragFilter) {
        myFilter = (AuftragFilter) filter;
    } else {/*  w w  w.ja  v a2  s  .c o  m*/
        myFilter = new AuftragFilter(filter);
    }
    final QueryFilter queryFilter = new QueryFilter(myFilter);
    Boolean vollstaendigFakturiert = null;
    if (myFilter.isShowBeauftragtNochNichtVollstaendigFakturiert() == true) {
        queryFilter.add(Restrictions.not(Restrictions.in("auftragsStatus",
                new AuftragsStatus[] { AuftragsStatus.ABGELEHNT, AuftragsStatus.ERSETZT, AuftragsStatus.GELEGT,
                        AuftragsStatus.GROB_KALKULATION, AuftragsStatus.IN_ERSTELLUNG })));
        vollstaendigFakturiert = false;
    } else if (myFilter.isShowNochNichtVollstaendigFakturiert() == true) {
        queryFilter.add(Restrictions.not(Restrictions.in("auftragsStatus",
                new AuftragsStatus[] { AuftragsStatus.ABGELEHNT, AuftragsStatus.ERSETZT })));
        vollstaendigFakturiert = false;
    } else if (myFilter.isShowVollstaendigFakturiert() == true) {
        vollstaendigFakturiert = true;
    } else if (myFilter.isShowAbgelehnt() == true) {
        queryFilter.add(Restrictions.eq("auftragsStatus", AuftragsStatus.ABGELEHNT));
    } else if (myFilter.isShowAbgeschlossenNichtFakturiert() == true) {
        queryFilter.createAlias("positionen", "position")
                .createAlias("paymentSchedules", "paymentSchedule", Criteria.FULL_JOIN).add(
                        Restrictions.or(
                                Restrictions.or(Restrictions.eq("auftragsStatus", AuftragsStatus.ABGESCHLOSSEN),
                                        Restrictions.eq("position.status",
                                                AuftragsPositionsStatus.ABGESCHLOSSEN)),
                                Restrictions.eq("paymentSchedule.reached", true)));
        vollstaendigFakturiert = false;
    } else if (myFilter.isShowAkquise() == true) {
        queryFilter.add(Restrictions.in("auftragsStatus", new AuftragsStatus[] { AuftragsStatus.GELEGT,
                AuftragsStatus.IN_ERSTELLUNG, AuftragsStatus.GROB_KALKULATION }));
    } else if (myFilter.isShowBeauftragt() == true) {
        queryFilter.add(Restrictions.in("auftragsStatus", new AuftragsStatus[] { AuftragsStatus.BEAUFTRAGT,
                AuftragsStatus.LOI, AuftragsStatus.ESKALATION }));
    } else if (myFilter.isShowErsetzt() == true) {
        queryFilter.add(Restrictions.eq("auftragsStatus", AuftragsStatus.ERSETZT));
    }
    if (myFilter.getYear() > 1900) {
        final Calendar cal = DateHelper.getUTCCalendar();
        cal.set(Calendar.YEAR, myFilter.getYear());
        java.sql.Date lo = null;
        java.sql.Date hi = null;
        cal.set(Calendar.DAY_OF_YEAR, 1);
        lo = new java.sql.Date(cal.getTimeInMillis());
        final int lastDayOfYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
        cal.set(Calendar.DAY_OF_YEAR, lastDayOfYear);
        hi = new java.sql.Date(cal.getTimeInMillis());
        queryFilter.add(Restrictions.between("angebotsDatum", lo, hi));
    }
    queryFilter.addOrder(Order.desc("nummer"));
    final List<AuftragDO> list;
    if (checkAccess == true) {
        list = getList(queryFilter);
    } else {
        list = internalGetList(queryFilter);
    }
    if (vollstaendigFakturiert != null) {
        final Boolean invoiced = vollstaendigFakturiert;
        CollectionUtils.filter(list, new Predicate() {
            @Override
            public boolean evaluate(final Object object) {
                final AuftragDO auftrag = (AuftragDO) object;
                final boolean orderIsCompletelyInvoiced = auftrag.isVollstaendigFakturiert();
                if (HibernateUtils.getDialect() != DatabaseDialect.HSQL
                        && myFilter.isShowAbgeschlossenNichtFakturiert() == true) {
                    // if order is completed and not all positions are completely invoiced
                    if (auftrag.getAuftragsStatus() == AuftragsStatus.ABGESCHLOSSEN
                            && orderIsCompletelyInvoiced == false) {
                        return true;
                    }
                    // if order is completed and not completely invoiced
                    if (auftrag.getPositionen() != null) {
                        for (final AuftragsPositionDO pos : auftrag.getPositionen()) {
                            if (pos.isAbgeschlossenUndNichtVollstaendigFakturiert() == true) {
                                return true;
                            }
                        }
                    }
                    if (auftrag.getPaymentSchedules() != null) {
                        for (final PaymentScheduleDO schedule : auftrag.getPaymentSchedules()) {
                            if (schedule.isReached() == true && schedule.isVollstaendigFakturiert() == false) {
                                return true;
                            }
                        }
                    }
                    return false;
                }
                return orderIsCompletelyInvoiced == invoiced;
            }
        });
    }
    if (myFilter.getAuftragsPositionsArt() != null) {
        final AuftragFilter fil = myFilter;
        CollectionUtils.filter(list, new Predicate() {
            @Override
            public boolean evaluate(final Object object) {
                final AuftragDO auftrag = (AuftragDO) object;
                boolean match = false;
                if (fil.getAuftragsPositionsArt() != null) {
                    if (CollectionUtils.isNotEmpty(auftrag.getPositionen()) == true) {
                        for (final AuftragsPositionDO position : auftrag.getPositionen()) {
                            if (fil.getAuftragsPositionsArt() == position.getArt()) {
                                match = true;
                                break;
                            }
                        }
                    }
                }
                return match;
            }
        });
    }
    return list;
}

From source file:org.projectforge.business.fibu.EmployeeDao.java

@Override
public List<EmployeeDO> getList(final BaseSearchFilter filter) {
    final EmployeeFilter myFilter;
    if (filter instanceof EmployeeFilter) {
        myFilter = (EmployeeFilter) filter;
    } else {/* w ww.j a va 2  s.  c o  m*/
        myFilter = new EmployeeFilter(filter);
    }
    final QueryFilter queryFilter = new QueryFilter(myFilter);
    final List<EmployeeDO> list = getList(queryFilter);
    final Date now = new Date();
    if (myFilter.isShowOnlyActiveEntries() == true) {
        CollectionUtils.filter(list, new Predicate() {
            @Override
            public boolean evaluate(final Object object) {
                final EmployeeDO employee = (EmployeeDO) object;
                if (employee.getEintrittsDatum() != null && now.before(employee.getEintrittsDatum()) == true) {
                    return false;
                } else if (employee.getAustrittsDatum() != null
                        && now.after(employee.getAustrittsDatum()) == true) {
                    return false;
                }
                return true;
            }
        });
    }
    return list;
}