View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.tklm.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.kpme.core.assignment.Assignment;
23  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
24  import org.kuali.kpme.tklm.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  }