return mapping.findForward("search");
}
public ActionForward search(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws Exception {
DocumentSearchBean searchBean = getRenderedObject();
List<GeneratedDocument> documents = GenericFile.getFiles(GeneratedDocument.class);
if (searchBean.hasAddressee()) {
SearchPerson.SearchParameters parameters =
new SearchParameters(searchBean.getAddressee().getName(), null, searchBean.getAddressee().getUsername(),
searchBean.getAddressee().getDocumentIdNumber(), null, null, null, null, null, null, null,
(String) null);
SearchPersonPredicate predicate = new SearchPerson.SearchPersonPredicate(parameters);
CollectionPager<Person> persons = SearchPerson.runSearchPerson(parameters, predicate);
Set<GeneratedDocument> personDocuments = new HashSet<GeneratedDocument>();
for (Person person : persons.getCollection()) {
personDocuments.addAll(person.getAddressedDocumentSet());
}
documents.retainAll(personDocuments);
}
if (searchBean.hasOperator()) {
SearchPerson.SearchParameters parameters =
new SearchParameters(searchBean.getOperator().getName(), null, searchBean.getOperator().getUsername(),
searchBean.getOperator().getDocumentIdNumber(), null, null, null, null, null, null, null,
(String) null);
SearchPersonPredicate predicate = new SearchPerson.SearchPersonPredicate(parameters);
CollectionPager<Person> operators = SearchPerson.runSearchPerson(parameters, predicate);
Set<GeneratedDocument> operatorDocuments = new HashSet<GeneratedDocument>();
for (Person person : operators.getCollection()) {
operatorDocuments.addAll(person.getProcessedDocumentSet());
}
documents.retainAll(operatorDocuments);
}
if (searchBean.getType() != null) {
Set<GeneratedDocument> typed = new HashSet<GeneratedDocument>();
for (GeneratedDocument document : documents) {
if (document.getType() == searchBean.getType()) {
typed.add(document);
}
}
documents.retainAll(typed);
}
if (searchBean.getUploadTime() != null) {
Set<GeneratedDocument> dated = new HashSet<GeneratedDocument>();
for (GeneratedDocument document : documents) {
if (!document.getUploadTime().toLocalDate().isBefore(searchBean.getUploadTime())) {
dated.add(document);
}
}
documents.retainAll(dated);
}