001 /** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kew.docsearch.dao.impl; 017 018 import org.kuali.rice.core.api.criteria.QueryByCriteria; 019 import org.kuali.rice.kew.docsearch.SearchableAttributeDateTimeValue; 020 import org.kuali.rice.kew.docsearch.SearchableAttributeFloatValue; 021 import org.kuali.rice.kew.docsearch.SearchableAttributeLongValue; 022 import org.kuali.rice.kew.docsearch.SearchableAttributeStringValue; 023 import org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO; 024 import org.kuali.rice.krad.data.DataObjectService; 025 import org.springframework.beans.factory.annotation.Required; 026 027 import javax.persistence.EntityManager; 028 import java.math.BigDecimal; 029 import java.sql.Timestamp; 030 import java.util.ArrayList; 031 import java.util.List; 032 033 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal; 034 035 /** 036 * JPA implementation of SearchableAttributeDAO 037 * 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 * 040 */ 041 public class SearchableAttributeDAOJpa implements SearchableAttributeDAO { 042 043 private EntityManager entityManager; 044 private DataObjectService dataObjectService; 045 046 /** 047 * This overridden method queries the SearchableAttributeDateTimeValue persistence class 048 * 049 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeDateTimeValuesByKey( 050 * java.lang.String,java.lang.String) 051 */ 052 public List<Timestamp> getSearchableAttributeDateTimeValuesByKey( 053 String documentId, String key) { 054 055 List<Timestamp> lRet = null; 056 QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); 057 builder.setPredicates(equal("documentId",documentId), 058 equal("searchableAttributeKey",key)); 059 060 061 List<SearchableAttributeDateTimeValue> results = getDataObjectService().findMatching( 062 SearchableAttributeDateTimeValue.class,builder.build()).getResults(); 063 if (!results.isEmpty()) { 064 lRet = new ArrayList<Timestamp>(); 065 for (SearchableAttributeDateTimeValue attribute: results) { 066 lRet.add(attribute.getSearchableAttributeValue()); 067 } 068 } 069 return lRet; 070 } 071 072 /** 073 * This overridden method queries the SearchableAttributeFloatValue persistence class 074 * 075 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeFloatValuesByKey( 076 * java.lang.String,java.lang.String) 077 */ 078 public List<BigDecimal> getSearchableAttributeFloatValuesByKey( 079 String documentId, String key) { 080 List<BigDecimal> lRet = null; 081 QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); 082 builder.setPredicates(equal("documentId",documentId), 083 equal("searchableAttributeKey",key)); 084 List<SearchableAttributeFloatValue> results = getDataObjectService().findMatching( 085 SearchableAttributeFloatValue.class,builder.build()).getResults(); 086 if (!results.isEmpty()) { 087 lRet = new ArrayList<BigDecimal>(); 088 for (SearchableAttributeFloatValue attribute: results) { 089 lRet.add(attribute.getSearchableAttributeValue()); 090 } 091 } 092 return lRet; 093 } 094 095 /** 096 * This overridden method queries the searchableAttributeKey persistence class 097 * 098 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeLongValuesByKey( 099 * java.lang.String,java.lang.String) 100 */ 101 public List<Long> getSearchableAttributeLongValuesByKey(String documentId, 102 String key) { 103 List<Long> lRet = null; 104 QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); 105 builder.setPredicates(equal("documentId",documentId), 106 equal("searchableAttributeKey",key)); 107 List<SearchableAttributeLongValue> results = getDataObjectService().findMatching( 108 SearchableAttributeLongValue.class,builder.build()).getResults(); 109 if (!results.isEmpty()) { 110 lRet = new ArrayList<Long>(); 111 for (SearchableAttributeLongValue attribute: results) { 112 lRet.add(attribute.getSearchableAttributeValue()); 113 } 114 } 115 return lRet; 116 } 117 118 /** 119 * This overridden method queries the SearchableAttributeStringValue persistence class 120 * 121 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeStringValuesByKey( 122 * java.lang.String,java.lang.String) 123 */ 124 public List<String> getSearchableAttributeStringValuesByKey( 125 String documentId, String key) { 126 List<String> lRet = null; 127 QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); 128 builder.setPredicates(equal("documentId",documentId), 129 equal("searchableAttributeKey",key)); 130 List<SearchableAttributeStringValue> results = getDataObjectService().findMatching( 131 SearchableAttributeStringValue.class,builder.build()).getResults(); 132 if (!results.isEmpty()) { 133 lRet = new ArrayList<String>(); 134 for (SearchableAttributeStringValue attribute: results) { 135 lRet.add(attribute.getSearchableAttributeValue()); 136 } 137 } 138 return lRet; 139 } 140 141 public EntityManager getEntityManager() { 142 return this.entityManager; 143 } 144 145 public void setEntityManager(EntityManager entityManager) { 146 this.entityManager = entityManager; 147 } 148 149 150 public DataObjectService getDataObjectService() { 151 return dataObjectService; 152 } 153 154 @Required 155 public void setDataObjectService(DataObjectService dataObjectService) { 156 this.dataObjectService = dataObjectService; 157 } 158 159 160 }