List of usage examples for org.apache.commons.collections CollectionUtils exists
public static boolean exists(Collection collection, Predicate predicate)
From source file:net.shopxx.entity.Order.java
@Transient public boolean getIsDelivery() { return CollectionUtils.exists(getOrderItems(), new Predicate() { @Override//www. j a va 2 s.co m public boolean evaluate(Object object) { OrderItem orderItem = (OrderItem) object; return orderItem != null && BooleanUtils.isTrue(orderItem.getIsDelivery()); } }); }
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 {//from w w w. jav a 2 s . 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:com.perceptive.epm.perkolcentral.action.ajax.EmployeeDetailsAction.java
public String executeEmployeesByLicenseAjax() throws ExceptionWrapper { try {/* w w w .ja va 2s.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.shopxx.entity.Goods.java
@Transient public boolean getIsStockAlert() { return CollectionUtils.exists(getProducts(), new Predicate() { public boolean evaluate(Object object) { Product product = (Product) object; return product != null && product.getIsStockAlert(); }/* ww w . jav a 2s.c o m*/ }); }
From source file:net.shopxx.entity.Goods.java
@Transient public boolean getIsOutOfStock() { return CollectionUtils.exists(getProducts(), new Predicate() { public boolean evaluate(Object object) { Product product = (Product) object; return product != null && product.getIsOutOfStock(); }//from w w w . j a v a2 s . c o m }); }
From source file:gov.nih.nci.caarray.dao.ProjectDaoTest.java
@Test public void testOwnerPermissions() throws Exception { CaArrayUsernameHolder.setUser(STANDARD_USER); Transaction tx = this.hibernateHelper.beginTransaction(); saveSupportingObjects();// w ww .j a va2s .com daoObject.save(DUMMY_PROJECT_1); tx.commit(); tx = this.hibernateHelper.beginTransaction(); Project p = searchDao.retrieve(Project.class, DUMMY_PROJECT_1.getId()); assertTrue(SecurityUtils.isOwner(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canWrite(DUMMY_SOURCE, CaArrayUsernameHolder.getCsmUser())); assertNotNull(p.getPublicProfile()); assertEquals(2, p.getFiles().size()); assertNotNull(searchDao.retrieve(CaArrayFile.class, DUMMY_FILE_1.getId())); assertNotNull(searchDao.retrieve(CaArrayFile.class, DUMMY_FILE_2.getId())); assertNotNull(searchDao.retrieve(CaArrayFile.class, DUMMY_DATA_FILE.getId())); List<UserGroupRoleProtectionGroup> list = SecurityUtils.getUserGroupRoleProtectionGroups(p); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.READ_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.WRITE_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.PERMISSIONS_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.BROWSE_ROLE)))); assertTrue(SecurityUtils.canRead(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canWrite(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canFullRead(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canFullWrite(p, CaArrayUsernameHolder.getCsmUser())); assertTrue(SecurityUtils.canModifyPermissions(p, CaArrayUsernameHolder.getCsmUser())); }
From source file:gov.nih.nci.caarray.dao.ProjectDaoTest.java
@Test public void testInitialProjectPermissions() { // create project Transaction tx = this.hibernateHelper.beginTransaction(); saveSupportingObjects();//from w w w . j a va 2 s . c o m this.hibernateHelper.getCurrentSession().save(DUMMY_PROJECT_1); this.hibernateHelper.getCurrentSession().save(DUMMY_ASSAYTYPE_1); this.hibernateHelper.getCurrentSession().save(DUMMY_ASSAYTYPE_2); tx.commit(); // check initial settings.. drafts should be not visible tx = this.hibernateHelper.beginTransaction(); final Project p = searchDao.retrieve(Project.class, DUMMY_PROJECT_1.getId()); List<UserGroupRoleProtectionGroup> list = SecurityUtils.getUserGroupRoleProtectionGroups(p); assertEquals(8, list.size()); // expect the user-only ones only assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.READ_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.WRITE_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.PERMISSIONS_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.BROWSE_ROLE)))); p.getPublicProfile().setSecurityLevel(SecurityLevel.VISIBLE); tx.commit(); // check that after changing to visible, the role is reflected. tx = this.hibernateHelper.beginTransaction(); list = SecurityUtils.getUserGroupRoleProtectionGroups(p); assertEquals(9, list.size()); // expect the user-only ones and the anonymous access one assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.READ_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.WRITE_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.PERMISSIONS_ROLE)))); assertTrue(CollectionUtils.exists(list, new AndPredicate(new IsGroupPredicate(), new HasRolePredicate(SecurityUtils.BROWSE_ROLE)))); tx.commit(); }
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
private boolean enroledShiftsContainsShiftWithSameExecutionCourseAndShiftType(final List<Shift> enroledShifts, final ExecutionCourse executionCourse, final ShiftType shiftType) { return CollectionUtils.exists(enroledShifts, new Predicate() { @Override//from w w w . ja va 2 s.c o m final public boolean evaluate(Object object) { Shift enroledShift = (Shift) object; return enroledShift.getExecutionCourse() == executionCourse && enroledShift.containsType(shiftType); } }); }
From source file:org.andromda.cartridges.gui.metafacades.GuiUseCaseLogicImpl.java
private static boolean isParent(final GuiUseCase useCase1, final GuiUseCase useCase2) { return CollectionUtils.exists(useCase2.getIncludes(), new Predicate() { @Override//w w w . j a v a 2 s. c o m public boolean evaluate(final Object object) { final IncludeFacade include = (IncludeFacade) object; return include.getAddition().equals(useCase1); } }); }
From source file:org.apache.accumulo.core.util.format.ShardedTableDistributionFormatterTest.java
@Test public void testAggregate() { data.put(new Key("t", "~tab", "loc"), new Value("srv1".getBytes(UTF_8))); data.put(new Key("t;19700101", "~tab", "loc", 0), new Value("srv1".getBytes(UTF_8))); data.put(new Key("t;19700101", "~tab", "loc", 1), new Value("srv2".getBytes(UTF_8))); formatter.initialize(data.entrySet(), new FormatterConfig()); String[] resultLines = formatter.next().split("\n"); List<String> results = Arrays.asList(resultLines).subList(2, 4); assertTrue(CollectionUtils.exists(results, new AggregateReportChecker("NULL", 1))); assertTrue(CollectionUtils.exists(results, new AggregateReportChecker("19700101", 2))); assertFalse(formatter.hasNext());// w w w . ja v a2 s .c o m }