View Javadoc

1   /**
2    * Copyright 2005-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.rice.kew.docsearch;
17  
18  import org.joda.time.DateTime;
19  import org.kuali.rice.core.api.uif.AttributeLookupSettings;
20  import org.kuali.rice.core.api.uif.DataType;
21  import org.kuali.rice.core.api.uif.RemotableAttributeError;
22  import org.kuali.rice.core.api.uif.RemotableAttributeField;
23  import org.kuali.rice.core.api.uif.RemotableAttributeLookupSettings;
24  import org.kuali.rice.kew.api.document.DocumentWithContent;
25  import org.kuali.rice.kew.api.document.attribute.DocumentAttribute;
26  import org.kuali.rice.kew.api.document.attribute.DocumentAttributeFactory;
27  import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
28  import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
29  import org.kuali.rice.kew.api.extension.ExtensionDefinition;
30  import org.kuali.rice.kew.framework.document.attribute.SearchableAttribute;
31  
32  import java.util.ArrayList;
33  import java.util.Collections;
34  import java.util.List;
35  
36  public class TestXMLSearchableAttributeDateTime implements SearchableAttribute {
37  
38      private static final long serialVersionUID = 1479059967548234181L;
39  
40      public static final String SEARCH_STORAGE_KEY = "testDateTimeKey";
41      public static final Long SEARCH_STORAGE_VALUE_IN_MILLS = (new Long("1173995646535"));
42      public static final DateTime SEARCH_STORAGE_VALUE = new DateTime(SEARCH_STORAGE_VALUE_IN_MILLS.longValue());
43  
44      @Override
45      public String generateSearchContent(ExtensionDefinition extensionDefinition,
46              String documentTypeName,
47              WorkflowAttributeDefinition attributeDefinition) {
48          return "TestXMLSearchableAttributeDateTime";
49      }
50  
51      @Override
52      public List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition,
53              DocumentWithContent documentWithContent) {
54          List<DocumentAttribute> savs = new ArrayList<DocumentAttribute>();
55          savs.add(DocumentAttributeFactory.createDateTimeAttribute(SEARCH_STORAGE_KEY, SEARCH_STORAGE_VALUE));
56          return savs;
57      }
58  
59      @Override
60      public List<RemotableAttributeField> getSearchFields(ExtensionDefinition extensionDefinition,
61              String documentTypeName) {
62          List<RemotableAttributeField> fields = new ArrayList<RemotableAttributeField>();
63          RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(SEARCH_STORAGE_KEY);
64          builder.setLongLabel("title");
65          builder.setDataType(DataType.DATE);
66  
67          RemotableAttributeLookupSettings.Builder settings = RemotableAttributeLookupSettings.Builder.create();
68          settings.setRanged(true);
69          settings.setUpperBoundInclusive(false);
70  
71          // test result table column visibility
72          // see: DocumentSearchResultAttributeVisibilityTest
73          settings.setInResults(false);
74  
75          builder.setAttributeLookupSettings(settings);
76  		fields.add(builder.build());
77          return fields;
78      }
79  
80      @Override
81      public List<RemotableAttributeError> validateDocumentAttributeCriteria(ExtensionDefinition extensionDefinition,
82              DocumentSearchCriteria documentSearchCriteria) {
83          return Collections.emptyList();
84      }
85  
86  }