use of edu.stanford.muse.AddressBookManager.AddressBook in project epadd by ePADD.
the class SearchResult method filterForMailingListState.
/**
* returns only the docs matching per params[mailingListState].
* If this value is either, no filtering is done.
* if set to yes, only docs with at least one address matching a mailing list are returned.
*/
private static SearchResult filterForMailingListState(SearchResult inputSet) {
String mailingListState = JSPHelper.getParam(inputSet.queryParams, "mailingListState");
AddressBook ab = inputSet.archive.addressBook;
if ("either".equals(mailingListState) || Util.nullOrEmpty(mailingListState))
return inputSet;
// keep on removing those documents from allDocs which do not satisfy the filter conditions.
inputSet.matchedDocs = inputSet.matchedDocs.entrySet().stream().filter(k -> {
EmailDocument ed = (EmailDocument) k.getKey();
Collection<Contact> contactsInMessage = EmailUtils.getContactsForMessage(ab, ed);
// is any of these addresses a ML?
boolean atLeastOneML = false;
for (Contact c : contactsInMessage) {
boolean isMailingList = (c.mailingListState & MailingList.SUPER_DEFINITE) != 0 || (c.mailingListState & MailingList.USER_ASSIGNED) != 0;
if (isMailingList && "no".equals(mailingListState))
// continue outer; // we don't want mailing lists, but found one associated with this message. therefore this message fails search.
return false;
if (isMailingList)
// mark this message as having at least one ML
atLeastOneML = true;
}
if (!atLeastOneML && "yes".equals(mailingListState))
// continue outer; // no ML, but search criteria need ML, so ignore this ed
return false;
// result.add(ed);
return true;
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return inputSet;
}
use of edu.stanford.muse.AddressBookManager.AddressBook in project epadd by ePADD.
the class SearchResult method filterForContactId.
/**
* returns only the docs matching the given contact id. used by facets, correspondents table, etc
*/
private static SearchResult filterForContactId(SearchResult inputSet, String cid) {
AddressBook ab = inputSet.archive.addressBook;
int contactId = -1;
try {
contactId = Integer.parseInt(cid);
} catch (NumberFormatException nfe) {
Util.print_exception("Bad contactId in filterForContactId", nfe, log);
}
if (contactId >= 0) {
Contact c = ab.getContact(contactId);
// now get the set of documents from addressbook summary object because we have already calculated that.
Set<EmailDocument> docs = ab.getDocsFromSummary(c);
inputSet.matchedDocs.keySet().retainAll(docs);
// add this information to body highlight object under "contact" key
inputSet.commonHLInfo.addContact(contactId);
}
/* //highlighting info addition
try {
int ci = Integer.parseInt(cid);
//add this information to body highlight object under "contact" key
inputSet.commonHLInfo.addContact(ci);
} catch (Exception e) {
JSPHelper.log.warn(cid + " is not a contact id");
}
return filterForCorrespondents(inputSet, correspondentName, true, true, true, true); // for contact id, all the 4 fields - to/from/cc/bcc are enabled*/
return inputSet;
}
use of edu.stanford.muse.AddressBookManager.AddressBook in project epadd by ePADD.
the class SearchResult method filterForEmailDirection.
/*
Filter based on if the mails are from owner or from others..
*/
private static SearchResult filterForEmailDirection(SearchResult inputSet) {
AddressBook addressBook = inputSet.archive.addressBook;
String val = JSPHelper.getParam(inputSet.queryParams, "sender");
if ("any".equals(val) || Util.nullOrEmpty(val))
return inputSet;
if (addressBook != null) {
inputSet.matchedDocs = inputSet.matchedDocs.entrySet().stream().filter(entry -> {
EmailDocument edoc = (EmailDocument) entry.getKey();
int sent_or_received = edoc.sentOrReceived(addressBook);
/*if (direction_in)
if (((sent_or_received & EmailDocument.RECEIVED_MASK) != 0) || sent_or_received == 0) // if sent_or_received == 0 => we neither directly recd. nor sent it (e.g. it could be received on a mailing list). so count it as received.
return true;//result.add(ed);
*/
return // add only if it was sent by the owner
(sent_or_received & EmailDocument.SENT_MASK) != 0;
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
return inputSet;
}
use of edu.stanford.muse.AddressBookManager.AddressBook in project epadd by ePADD.
the class EmailDocument method buildAddressBook.
/**
* recompute own email addrs, and then all the contacts. to be done after fetching all messages
*/
public static AddressBook buildAddressBook(Collection<EmailDocument> docs, Collection<String> ownAddrs, Collection<String> ownNames) {
String[] ownAddrsArray = new String[ownAddrs.size()];
ownAddrs.toArray(ownAddrsArray);
String[] ownNamesArray = new String[ownNames.size()];
ownNames.toArray(ownNamesArray);
AddressBook addressBook = new AddressBook(ownAddrsArray, ownNamesArray);
// log.info("Own addresses: " + EmailUtils.emailAddrsToString(ownAddrs));
EmailFetcherThread.log.debug("First pass processing contacts for " + docs.size() + " messages");
Set<String> trustedAddrs = new LinkedHashSet<>();
for (String a : ownAddrsArray) trustedAddrs.add(a.toLowerCase());
fillAddressBookFromTrustedAddresses(docs, trustedAddrs, addressBook);
return addressBook;
}
use of edu.stanford.muse.AddressBookManager.AddressBook in project epadd by ePADD.
the class IndexUtils method computeDetailedFacetsForMessageBrowsing.
/**
* Compute facet list for message browsing screen.
*/
public static Map<String, Collection<DetailedFacetItem>> computeDetailedFacetsForMessageBrowsing(Collection<Document> docs, Archive archive) {
AddressBook addressBook = archive.addressBook;
Map<String, Collection<DetailedFacetItem>> facetMap = new LinkedHashMap<>();
if (addressBook != null) {
// people
Map<Contact, DetailedFacetItem> peopleMap = partitionDocsByPerson(docs, addressBook);
facetMap.put("correspondent", peopleMap.values());
// direction (sender: only one if anything with owner)
Map<String, DetailedFacetItem> directionMap = partitionDocsByDirection(docs, addressBook);
if (// this size can at max be 1 when there is at least one message sent from the owner
directionMap.size() > 0)
facetMap.put("sender", directionMap.values());
/*
--No longer need this code as restriction, reviewed etc. are handled by labels--
// flags -- provide them only if they have at least 2 types in these docs. if all docs have the same value for a particular flag, no point showing it.
Map<String, DetailedFacetItem> doNotTransferMap = partitionDocsByDoNotTransfer(docs);
if (doNotTransferMap.size() > 1)
facetMap.put("transfer", doNotTransferMap.values());
Map<String, DetailedFacetItem> transferWithRestrictionsMap = partitionDocsByTransferWithRestrictions(docs);
if (transferWithRestrictionsMap.size() > 1)
facetMap.put("restrictions", transferWithRestrictionsMap.values());
Map<String, DetailedFacetItem> reviewedMap = partitionDocsByReviewed(docs);
if (reviewedMap.size() > 1)
facetMap.put("reviewed", reviewedMap.values());
*/
// facet for restriction labels
Map<String, DetailedFacetItem> restrlabels = partitionDocsByLabelTypes(docs, archive, LabelManager.LabType.RESTRICTION);
facetMap.put("Restriction Labels", restrlabels.values());
// facet for general labels
Map<String, DetailedFacetItem> genlabels = partitionDocsByLabelTypes(docs, archive, LabelManager.LabType.GENERAL);
facetMap.put("General Labels", genlabels.values());
// facet for accession IDs- only in modes other than appraisal
if (!ModeConfig.isAppraisalMode()) {
Map<String, DetailedFacetItem> accIDs = partitionDocsByAccessionID(docs, archive);
facetMap.put("Accessions", accIDs.values());
}
Map<String, DetailedFacetItem> annotationPresenceMap = partitionDocsByAnnotationPresence(docs, archive);
facetMap.put("Annotations", annotationPresenceMap.values());
// attachments
if (!ModeConfig.isPublicMode()) {
Map<String, DetailedFacetItem> attachmentTypesMap = partitionDocsByAttachmentType(archive, docs);
facetMap.put("attachment type", attachmentTypesMap.values());
}
}
if (!ModeConfig.isPublicMode()) {
Map<String, DetailedFacetItem> folderNameMap = partitionDocsByFolder(docs);
if (folderNameMap.size() > 0)
facetMap.put("folders", folderNameMap.values());
}
// sort so that in each topic, the heaviest facets are first
for (String s : facetMap.keySet()) {
Collection<DetailedFacetItem> detailedFacets = facetMap.get(s);
List<DetailedFacetItem> list = new ArrayList<>(detailedFacets);
Collections.sort(list);
facetMap.put(s, list);
}
return facetMap;
}
Aggregations