Example usage for org.apache.commons.collections Predicate Predicate

List of usage examples for org.apache.commons.collections Predicate Predicate

Introduction

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

Prototype

Predicate

Source Link

Usage

From source file:net.sourceforge.fenixedu.domain.accounting.report.GratuityReportQueueJob.java

public static List<GratuityReportQueueJob> retrieveNotGeneratedReports(final ExecutionYear executionYear) {
    List<GratuityReportQueueJob> reports = new ArrayList<GratuityReportQueueJob>();

    CollectionUtils.select(executionYear.getGratuityReportQueueJobsSet(), new Predicate() {

        @Override/*from   ww w  .j  a v  a  2  s . c  o  m*/
        public boolean evaluate(Object arg0) {
            GratuityReportQueueJob gratuityQueueJob = (GratuityReportQueueJob) arg0;

            return !gratuityQueueJob.getDone();
        }

    }, reports);

    return reports;
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.IndividualCandidacy.java

public List<Formation> getNonConcludedFormationList() {
    return new ArrayList<Formation>(CollectionUtils.select(getFormationsSet(), new Predicate() {

        @Override//from ww  w  .j  a  v a  2 s .  c  om
        public boolean evaluate(Object arg0) {
            return !((Formation) arg0).getConcluded();
        }

    }));
}

From source file:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java

@TriggersRemove(cacheName = { "EmployeeCache", "GroupCache",
        "EmployeeKeyedByGroupCache" }, when = When.AFTER_METHOD_INVOCATION, removeAll = true, keyGenerator = @KeyGenerator(name = "HashCodeCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false")))
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class)
public void updateAllEmployee(List<EmployeeBO> employeeListFromLDAP) throws ExceptionWrapper {
    try {/*w  ww . j ava 2s  .  c om*/
        String messageTemplateAdded = "<html>\n" + "<head>\n" + "</head>\n" + "\n"
                + "<body style=\"font:Georgia; font-size:12px;\">\n" + "<p>Dear All,</p>\n" + "<blockquote>\n"
                + "  <p>A new user is added to the system.</p>\n" + "</blockquote>\n" + "<ul>\n"
                + "  <li><strong><em>User Name</em></strong>: <strong>%s</strong></li>\n"
                + "  <li><em><strong>User Short Id</strong></em>: <strong>%s</strong></li>\n"
                + "  <li><em><strong>Employee Id</strong></em>: <strong>%s</strong></li>\n"
                + "  <li><strong><em>User Email-Id</em></strong>:<strong> %s</strong></li>\n"
                + "  <li><em><strong>Mobile Number</strong></em>:<strong> %s</strong></li>\n"
                + "  <li><em><strong>Job Title</strong></em> : <strong>%s</strong></li>\n" + "</ul>\n"
                + "<p>Please take necessary actions.</p>\n" + "<p>Thanks,</p>\n" + "<blockquote>\n"
                + "  <p>Perceptive Kolkata Central</p>\n" + "</blockquote>\n" + "</body>\n" + "</html>";

        String messageTemplateDeleted = "<html>\n" + "<head>\n" + "</head>\n" + "\n"
                + "<body style=\"font:Georgia; font-size:12px;\">\n" + "<p>Dear All,</p>\n" + "<blockquote>\n"
                + "  <p>An  user is removed from the system.</p>\n" + "</blockquote>\n" + "<ul>\n"
                + "  <li><strong><em>User Name</em></strong>: <strong>%s</strong></li>\n"
                + "  <li><em><strong>User Short Id</strong></em>: <strong>%s</strong></li>\n"
                + "  <li><em><strong>Employee Id</strong></em>: <strong>%s</strong></li>\n"
                + "  <li><strong><em>User Email-Id</em></strong>:<strong> %s</strong></li>\n"
                + "  <li><em><strong>Mobile Number</strong></em>:<strong> %s</strong></li>\n"
                + "  <li><em><strong>Job Title</strong></em> : <strong>%s</strong></li>\n" + "</ul>\n"
                + "<p>Please take necessary actions.</p>\n" + "<p>Thanks,</p>\n" + "<blockquote>\n"
                + "  <p>Perceptive Kolkata Central</p>\n" + "</blockquote>\n" + "</body>\n" + "</html>";

        LinkedHashMap<Long, EmployeeBO> employeeLinkedHashMap = employeeDataAccessor.getAllEmployees();
        for (EmployeeBO employeeBO : employeeListFromLDAP) {
            if (!employeeLinkedHashMap.containsKey(Long.valueOf(employeeBO.getEmployeeId()))) {
                //Add a new employee
                Employee employee = new Employee();
                employee.setEmployeeId(Long.parseLong(employeeBO.getEmployeeId()));
                employee.setEmail(employeeBO.getEmail());
                employee.setEmployeeName(employeeBO.getEmployeeName());
                employee.setEmployeeUid(employeeBO.getEmployeeUid());
                employee.setJobTitle(employeeBO.getJobTitle());
                employee.setMobileNumber(employeeBO.getMobileNumber());
                employee.setManager(employeeBO.getManager());
                employee.setManagerEmail(employeeBO.getManagerEmail());
                employee.setExtensionNum(employeeBO.getExtensionNum());
                employee.setWorkspace(employeeBO.getWorkspace());
                employee.setIsActive(true);
                employeeDataAccessor.addEmployee(employee);
                LoggingHelpUtil.printDebug(String.format("Adding user ----> %s with details %s %s",
                        employeeBO.getEmployeeName(), System.getProperty("line.separator"),
                        ReflectionToStringBuilder.toString(employeeBO)));
                //Send the mail
                HtmlEmail emailToSend = new HtmlEmail();
                emailToSend.setHostName(email.getHostName());
                String messageToSend = String.format(messageTemplateAdded, employeeBO.getEmployeeName(),
                        employeeBO.getEmployeeUid(), employeeBO.getEmployeeId().toString(),
                        employeeBO.getEmail(), employeeBO.getMobileNumber(), employeeBO.getJobTitle());

                emailToSend.setHtmlMsg(messageToSend);
                //emailToSend.setTextMsg(StringEscapeUtils.escapeHtml(messageToSend));
                emailToSend.getToAddresses().clear();
                //Send mail to scrum masters and Development Managers Group Id 15
                Collection<EmployeeBO> allEmployeesNeedToGetMail = CollectionUtils.union(
                        getAllEmployeesKeyedByGroupId().get(Integer.valueOf("14")),
                        getAllEmployeesKeyedByGroupId().get(Integer.valueOf("15")));
                for (EmployeeBO item : allEmployeesNeedToGetMail) {
                    emailToSend.addTo(item.getEmail(), item.getEmployeeName());
                }
                emailToSend.addTo(employeeBO.getManagerEmail(), employeeBO.getManager());//Send the mail to manager
                //emailToSend.setFrom("PerceptiveKolkataCentral@perceptivesoftware.com", "Perceptive Kolkata Central");
                emailToSend.setFrom("EnterpriseSoftwareKolkata@lexmark.com", "Enterprise Software Kolkata");
                emailToSend.setSubject(String.format("New employee added : %s", employeeBO.getEmployeeName()));
                emailToSend.send();
                //==========================Mail send ends here===========================================================================================================
                //sendMailToPerceptiveOpsTeam(employeeBO);//Send mail to operations team in Shawnee
            } else {
                //Update a new employee
                employeeDataAccessor.updateEmployee(employeeBO);
                LoggingHelpUtil.printDebug(String.format("Updating user ----> %s with details %s %s",
                        employeeBO.getEmployeeName(), System.getProperty("line.separator"),
                        ReflectionToStringBuilder.toString(employeeBO)));
            }

            //========================================================================================================================================
        }
        //Delete employees if any
        for (Object obj : employeeLinkedHashMap.values()) {
            final EmployeeBO emp = (EmployeeBO) obj;
            if (!CollectionUtils.exists(employeeListFromLDAP, new Predicate() {
                @Override
                public boolean evaluate(Object o) {
                    return emp.getEmployeeId().trim().equalsIgnoreCase(((EmployeeBO) o).getEmployeeId().trim()); //To change body of implemented methods use File | Settings | File Templates.
                }
            })) {
                emp.setActive(false); //Soft delete the Employee
                employeeDataAccessor.updateEmployee(emp);//Rest deletion will be taken care by the Trigger AFTER_EMPLOYEE_UPDATE
                LoggingHelpUtil.printDebug(
                        String.format("Deleting user ----> %s with details %s %s", emp.getEmployeeName(),
                                System.getProperty("line.separator"), ReflectionToStringBuilder.toString(emp)));
                //Send the mail
                HtmlEmail emailToSend = new HtmlEmail();
                emailToSend.setHostName(email.getHostName());

                String messageToSend = String.format(messageTemplateDeleted, emp.getEmployeeName(),
                        emp.getEmployeeUid(), emp.getEmployeeId().toString(), emp.getEmail(),
                        emp.getMobileNumber(), emp.getJobTitle());
                emailToSend.setHtmlMsg(messageToSend);
                //emailToSend.setTextMsg(StringEscapeUtils.escapeHtml(messageToSend));
                emailToSend.getToAddresses().clear();
                //Send mail to scrum masters ==Group ID 14 and Development Managers Group Id 15
                Collection<EmployeeBO> allEmployeesNeedToGetMail = CollectionUtils.union(
                        getAllEmployeesKeyedByGroupId().get(Integer.valueOf("14")),
                        getAllEmployeesKeyedByGroupId().get(Integer.valueOf("15")));
                for (EmployeeBO item : allEmployeesNeedToGetMail) {
                    emailToSend.addTo(item.getEmail(), item.getEmployeeName());
                }
                //emailToSend.setFrom("PerceptiveKolkataCentral@perceptivesoftware.com", "Perceptive Kolkata Central");
                emailToSend.setFrom("EnterpriseSoftwareKolkata@lexmark.com", "Enterprise Software Kolkata");
                emailToSend.setSubject(String.format("Employee removed : %s", emp.getEmployeeName()));
                emailToSend.send();
            }
        }

        luceneUtil.indexUserInfo(getAllEmployees().values());

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.candidate.degree.DegreeCandidacyManagementDispatchAction.java

private Object installmmentPaymentCodes(Collection<PaymentCode> availablePaymentCodes) {
    List<PaymentCode> installmentPaymentCodes = new ArrayList<PaymentCode>();

    CollectionUtils.select(availablePaymentCodes, new Predicate() {

        @Override/*from  w ww.  ja va 2s  .  c  o m*/
        public boolean evaluate(Object arg0) {
            PaymentCode paymentCode = (PaymentCode) arg0;

            if (paymentCode instanceof InstallmentPaymentCode) {
                return true;
            }

            return false;
        }
    }, installmentPaymentCodes);

    Collections.sort(installmentPaymentCodes, new BeanComparator("code"));

    return installmentPaymentCodes;
}

From source file:gov.nih.nci.caarray.application.translation.magetab.MageTabTranslatorTest.java

@Test
public void testSpecificationTermCaseSensitivityDocuments() throws Exception {
    final CaArrayFileSet fileSet = TestMageTabSets
            .getFileSet(TestMageTabSets.MAGE_TAB_SPECIFICATION_CASE_SENSITIVITY_INPUT_SET);
    final MageTabDocumentSet docSet = MageTabParser.INSTANCE
            .parse(TestMageTabSets.MAGE_TAB_SPECIFICATION_CASE_SENSITIVITY_INPUT_SET);
    final CaArrayTranslationResult result = this.translator.translate(docSet, fileSet);
    final Collection<Term> terms = result.getTerms();
    @SuppressWarnings("unchecked")
    final Collection<Term> matchingTerms = CollectionUtils.select(terms, new Predicate() {
        public boolean evaluate(Object o) {
            final Term t = (Term) o;
            return t.getValue().equalsIgnoreCase("fresh_sample");
        }//from   w ww  .ja  v  a 2s .co  m
    });
    assertTrue(matchingTerms.size() >= 1);
    final Term oneMatch = matchingTerms.iterator().next();
    for (final Term eachMatch : matchingTerms) {
        assertTrue(oneMatch == eachMatch);
    }
}

From source file:net.sourceforge.fenixedu.domain.alumni.AlumniReportFile.java

public static List<AlumniReportFile> readDoneJobs() {
    List<AlumniReportFile> reportFileList = new ArrayList<AlumniReportFile>();

    CollectionUtils.select(ExecutionYear.readCurrentExecutionYear().getAlumniReportFilesSet(), new Predicate() {

        @Override//from   w w  w . j  a  v a 2 s . c  o m
        public boolean evaluate(Object arg0) {
            return ((AlumniReportFile) arg0).getDone();
        }
    }, reportFileList);

    return reportFileList;
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.mobility.MobilityApplicationProcess.java

public List<MobilityCoordinator> getErasmusCoordinatorForTeacher(final Teacher teacher) {
    return new ArrayList<MobilityCoordinator>(CollectionUtils.select(getCoordinatorsSet(), new Predicate() {

        @Override//from   w w w .j  ava 2 s  .  co m
        public boolean evaluate(Object arg0) {
            return ((MobilityCoordinator) arg0).getTeacher() == teacher;
        }

    }));
}

From source file:com.perceptive.epm.perkolcentral.action.ajax.EmployeeDetailsAction.java

public String executeEmployeesByLicenseAjax() throws ExceptionWrapper {
    try {/*from  w  w w. ja v  a2 s. c  o m*/
        LoggingHelpUtil.printDebug("Page " + getPage() + " Rows " + getRows() + " Sorting Order " + getSord()
                + " Index Row :" + getSidx());
        LoggingHelpUtil.printDebug("Search :" + searchField + " " + searchOper + " " + searchString);

        // Calcalate until rows ware selected
        int to = (rows * page);

        // Calculate the first row to read
        int from = to - rows;
        LinkedHashMap<Long, EmployeeBO> employeeLinkedHashMap = new LinkedHashMap<Long, EmployeeBO>();
        employeeLinkedHashMap = employeeBL.getAllEmployees();

        ArrayList<EmployeeBO> allEmployees = new ArrayList<EmployeeBO>(employeeLinkedHashMap.values());
        CollectionUtils.filter(allEmployees, new Predicate() {
            @Override
            public boolean evaluate(Object o) {
                EmployeeBO emp = (EmployeeBO) o;
                if (CollectionUtils.exists(emp.getLicenses(), new Predicate() {
                    @Override
                    public boolean evaluate(Object o) {
                        return ((LicenseBO) o).getLicenseTypeName().equalsIgnoreCase(selectedLicenseTypeName); //To change body of implemented methods use File | Settings | File Templates.
                    }
                }))
                    return true;
                else
                    return false;
            }
        });

        //// Handle Order By
        if (sidx != null && !sidx.equals("")) {

            Collections.sort(allEmployees, new Comparator<EmployeeBO>() {
                public int compare(EmployeeBO e1, EmployeeBO e2) {
                    if (sidx.equalsIgnoreCase("employeeName"))
                        return sord.equalsIgnoreCase("asc")
                                ? e1.getEmployeeName().compareTo(e2.getEmployeeName())
                                : e2.getEmployeeName().compareTo(e1.getEmployeeName());
                    else if (sidx.equalsIgnoreCase("jobTitle"))
                        return sord.equalsIgnoreCase("asc") ? e1.getJobTitle().compareTo(e2.getJobTitle())
                                : e2.getJobTitle().compareTo(e1.getJobTitle());
                    else
                        return sord.equalsIgnoreCase("asc")
                                ? e1.getEmployeeName().compareTo(e2.getEmployeeName())
                                : e2.getEmployeeName().compareTo(e1.getEmployeeName());
                }
            });

        }
        //

        records = allEmployees.size();
        total = (int) Math.ceil((double) records / (double) rows);

        gridModel = new ArrayList<EmployeeBO>();
        to = to > records ? records : to;
        for (int iCounter = from; iCounter < to; iCounter++) {
            EmployeeBO employeeBO = allEmployees.get(iCounter);
            //new EmployeeBO((Employee) employeeLinkedHashMap.values().toArray()[iCounter]);
            gridModel.add(employeeBO);
        }

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return SUCCESS;
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.mobility.MobilityApplicationProcess.java

public MobilityCoordinator getCoordinatorForTeacherAndDegree(final Teacher teacher, final Degree degree) {
    List<MobilityCoordinator> coordinators = getErasmusCoordinatorForTeacher(teacher);

    return (MobilityCoordinator) CollectionUtils.find(coordinators, new Predicate() {

        @Override/*from  ww  w.j  a  v  a  2 s. c om*/
        public boolean evaluate(Object arg0) {
            MobilityCoordinator coordinator = (MobilityCoordinator) arg0;
            return coordinator.getDegree() == degree;
        }
    });
}

From source file:edu.kit.dama.staging.services.impl.ingest.IngestInformationServiceLocal.java

private List<StagingProcessor> mergeStagingProcessors(Collection<StagingProcessor> assignedProcessors,
        List<StagingProcessor> defaultProcessors) {
    LOGGER.debug("Checking default staging processors.");
    if (assignedProcessors == null || assignedProcessors.isEmpty()) {
        //return defaultProcessors (can't be null, so we do not have to check result)
        LOGGER.debug("No staging processors assigned, using only default processors.");
        return defaultProcessors;
    }//from   ww w  . j  a  v  a 2s  .co m
    LOGGER.debug("Adding all assigned processors to result list.");
    List<StagingProcessor> result = new ArrayList<>(assignedProcessors);
    if (defaultProcessors == null || defaultProcessors.isEmpty()) {
        //return empty list
        LOGGER.debug("No default processors provided, using only assigned processors.");
        return result;
    }

    LOGGER.debug("Merging {} existing and {} default processor(s)", assignedProcessors.size(),
            defaultProcessors.size());
    for (final StagingProcessor processor : defaultProcessors) {
        LOGGER.debug("Searching for default processor with id {}", processor.getUniqueIdentifier());
        StagingProcessor exists = (StagingProcessor) CollectionUtils.find(assignedProcessors, new Predicate() {

            @Override
            public boolean evaluate(Object o) {
                return Long.compare(((StagingProcessor) o).getId(), processor.getId()) == 0;
            }
        });

        if (exists == null) {
            LOGGER.debug("Default processor with id {} is not assigned, yet. Adding it.", processor.getId());
            //add as it not exists
            result.add(processor);
        }
    }
    return result;
}