1 17 package org.alfresco.repo.action.evaluator.compare; 18 19 import java.io.Serializable ; 20 import java.util.Date ; 21 22 import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator; 23 import org.alfresco.service.cmr.action.ActionServiceException; 24 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 25 26 31 public class DatePropertyValueComparator implements PropertyValueComparator 32 { 33 36 private static final String MSGID_INVALID_OPERATION = "date_property_value_comparator.invalid_operation"; 37 38 41 public boolean compare(Serializable propertyValue, 42 Serializable compareValue, ComparePropertyValueOperation operation) 43 { 44 boolean result = false; 45 46 if (operation == null) 47 { 48 operation = ComparePropertyValueOperation.EQUALS; 49 } 50 51 Date propertyDate = (Date )propertyValue; 52 Date compareDate = (Date )compareValue; 53 54 switch (operation) 55 { 56 case EQUALS: 57 { 58 result = propertyDate.equals(compareDate); 59 break; 60 } 61 case LESS_THAN: 62 { 63 result = propertyDate.before(compareDate); 64 break; 65 } 66 case LESS_THAN_EQUAL: 67 { 68 result = (propertyDate.equals(compareDate) || propertyDate.before(compareDate)); 69 break; 70 } 71 case GREATER_THAN: 72 { 73 result = propertyDate.after(compareDate); 74 break; 75 } 76 case GREATER_THAN_EQUAL: 77 { 78 result = (propertyDate.equals(compareDate) || propertyDate.after(compareDate)); 79 break; 80 } 81 default: 82 { 83 throw new ActionServiceException( 85 MSGID_INVALID_OPERATION, 86 new Object []{operation.toString()}); 87 } 88 } 89 90 return result; 91 } 92 93 96 public void registerComparator(ComparePropertyValueEvaluator evaluator) 97 { 98 evaluator.registerComparator(DataTypeDefinition.DATE, this); 99 evaluator.registerComparator(DataTypeDefinition.DATETIME, this); 100 } 101 102 } 103 | Popular Tags |