1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.hr.time.docsearch;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.hr.time.assignment.Assignment;
23  import org.kuali.hr.time.service.base.TkServiceLocator;
24  import org.kuali.hr.time.timesheet.TimesheetDocument;
25  import org.kuali.rice.kew.api.document.DocumentWithContent;
26  import org.kuali.rice.kew.api.extension.ExtensionDefinition;
27  import org.kuali.rice.kew.docsearch.SearchableAttributeLongValue;
28  import org.kuali.rice.kew.docsearch.SearchableAttributeValue;
29  import org.kuali.rice.kew.docsearch.xml.StandardGenericXMLSearchableAttribute;
30  
31  public class WorkAreaSearchableAttribute extends StandardGenericXMLSearchableAttribute{
32  
33  	private static String WORK_AREA = "workArea";
34  	
35  
36  
37  	private static final long serialVersionUID = 1L;
38  
39  	@Override
40      public List extractDocumentAttributes(ExtensionDefinition extensionDefinition, DocumentWithContent documentWithContent) {
41  		List<SearchableAttributeValue> searchableAttributeValues = new ArrayList<SearchableAttributeValue>();
42  		
43  		String documentId = StringUtils.substringBetween(documentWithContent.getDocumentContent().toString(), "<string>", "</string>");
44  		TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService().getTimesheetDocument(documentId);
45  		List<Long> workAreasIncluded = new ArrayList<Long>();
46  		for(Assignment assign : timesheetDocument.getAssignments()){
47  			if(!workAreasIncluded.contains(assign.getWorkArea())){
48  				SearchableAttributeValue attValue = new SearchableAttributeLongValue();
49  				attValue.setSearchableAttributeKey(WORK_AREA);
50  				attValue.setupAttributeValue(StringUtils.upperCase(assign.getWorkArea().toString()));
51  				searchableAttributeValues.add(attValue);
52  				workAreasIncluded.add(assign.getWorkArea());
53  			}
54  		}
55  		return searchableAttributeValues;
56  	}
57  }