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