private void fillSpreadSheet( final Collection<CerimonyInquiryPerson> requests, final StyledExcelSpreadsheet sheet) { setHeaders(sheet); for (CerimonyInquiryPerson inquiryPerson : requests) { final Person person = inquiryPerson.getPerson(); final CerimonyInquiryAnswer inquiryAnswer = inquiryPerson.getCerimonyInquiryAnswer(); sheet.newRow(); sheet.addCell(person.getUsername()); sheet.addCell(person.getName()); sheet.addCell(person.getEmail()); final StringBuilder contacts = new StringBuilder(); for (final PartyContact partyContact : person.getPartyContactsSet()) { if (partyContact instanceof Phone || partyContact instanceof MobilePhone) { if (contacts.length() > 0) { contacts.append(", "); } contacts.append(partyContact.getPresentationValue()); } } sheet.addCell(contacts.toString()); sheet.addCell((inquiryAnswer != null ? inquiryAnswer.getText() : new String("-"))); sheet.addCell(getDegrees(person)); sheet.addCell(inquiryPerson.getComment()); } }
protected List<PartyContact> getSortedFilteredContacts( Collection<? extends PartyContact> unfiltered, PartyContactType... types) { List<PartyContactType> typeList; if (types.length == 0) { typeList = Arrays.asList(PartyContactType.values()); } else { typeList = Arrays.asList(types); } List<PartyContact> contacts = new ArrayList<PartyContact>(); for (PartyContact contact : unfiltered) { if (isVisible(contact) && typeList.contains(contact.getType())) { contacts.add(contact); } } Collections.sort( contacts, new Comparator<PartyContact>() { @Override public int compare(PartyContact contact1, PartyContact contact2) { if (contact1.getType().ordinal() > contact2.getType().ordinal()) { return -1; } else if (contact1.getType().ordinal() < contact2.getType().ordinal()) { return 1; } else if (contact1.getDefaultContact().booleanValue()) { return -1; } else if (contact2.getDefaultContact().booleanValue()) { return 1; } else { return contact1.getPresentationValue().compareTo(contact2.getPresentationValue()); } } }); return contacts; }
private boolean isVisible(PartyContact contact) { boolean publicSpace = true; // because this is a homepage. When this logic is exported to a more proper place // remember to pass this as an argument. if (!Authenticate.isLogged() && publicSpace && contact.getVisibleToPublic().booleanValue()) { return true; } if (Authenticate.isLogged()) { User user = Authenticate.getUser(); Person reader = user.getPerson(); if (reader.hasRole(RoleType.CONTACT_ADMIN).booleanValue() || reader.hasRole(RoleType.MANAGER).booleanValue() || reader.hasRole(RoleType.DIRECTIVE_COUNCIL).booleanValue()) { return true; } if (reader.hasRole(RoleType.EMPLOYEE).booleanValue() && contact.getVisibleToEmployees().booleanValue()) { return true; } if (reader.hasRole(RoleType.TEACHER).booleanValue() && contact.getVisibleToTeachers().booleanValue()) { return true; } if (reader.hasRole(RoleType.STUDENT).booleanValue() && contact.getVisibleToStudents().booleanValue()) { return true; } if (reader.hasRole(RoleType.ALUMNI).booleanValue() && contact.getVisibleToAlumni().booleanValue()) { return true; } if (contact.getVisibleToPublic()) { return true; } } return false; }
@Override public boolean evaluate(PartyContact contact) { final Person contactPerson = (Person) contact.getParty(); return eval(contactPerson); };