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.useroptions.dao.impl;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.List;
21  
22  import org.apache.commons.collections.CollectionUtils;
23  import org.apache.ojb.broker.PersistenceBroker;
24  import org.apache.ojb.broker.query.Criteria;
25  import org.apache.ojb.broker.query.QueryByCriteria;
26  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
27  import org.kuali.rice.core.api.util.RiceConstants;
28  import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform;
29  import org.kuali.rice.kew.api.KewApiConstants;
30  import org.kuali.rice.kew.useroptions.UserOptions;
31  import org.kuali.rice.kew.useroptions.dao.UserOptionsDAO;
32  import org.springmodules.orm.ojb.PersistenceBrokerCallback;
33  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
34  
35  import com.google.common.collect.Iterables;
36  import com.google.common.collect.Lists;
37  
38  
39  public class UserOptionsDAOOjbImpl extends PersistenceBrokerDaoSupport implements UserOptionsDAO {
40  
41  	public Long getNewOptionIdForActionList() {
42          return (Long)this.getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() {
43              public Object doInPersistenceBroker(PersistenceBroker broker) {
44              	return getPlatform().getNextValSQL("KREW_ACTN_LIST_OPTN_S", broker);
45              }
46          });
47      }
48  
49  	protected DatabasePlatform getPlatform() {
50      	return (DatabasePlatform)GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM);
51      }
52  
53      public List<UserOptions> findByUserQualified(String principalId, String likeString) {
54          Criteria criteria = new Criteria();
55          criteria.addEqualTo("workflowId", principalId);
56          criteria.addLike("optionId", likeString);
57          return new ArrayList<UserOptions>(this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(UserOptions.class, criteria)));
58      }
59  
60      public void deleteByUserQualified(String principalId, String likeString) {
61          Criteria criteria = new Criteria();
62          criteria.addEqualTo("workflowId", principalId);
63          criteria.addLike("optionId", likeString);
64          this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(UserOptions.class, criteria));
65      }
66  
67      public Collection<UserOptions> findByWorkflowUser(String principalId) {
68          UserOptions userOptions = new UserOptions();
69          userOptions.setWorkflowId(principalId);
70          return this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(userOptions));
71      }
72  
73      public void save(UserOptions userOptions) {
74      	this.getPersistenceBrokerTemplate().store(userOptions);
75      }
76      
77      public void save(Collection<UserOptions> userOptions) {
78      	if (userOptions != null) for (UserOptions option : userOptions) {
79      		this.getPersistenceBrokerTemplate().store(option);
80      	}
81      }
82      
83      public void deleteUserOptions(UserOptions userOptions) {
84      	this.getPersistenceBrokerTemplate().delete(userOptions);
85      }
86  
87      public UserOptions findByOptionId(String optionId, String principalId) {
88          UserOptions userOptions = new UserOptions();
89          userOptions.setOptionId(optionId);
90          userOptions.setWorkflowId(principalId);
91          return (UserOptions) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(userOptions));
92      }
93  
94      public Collection<UserOptions> findByOptionValue(String optionId, String optionValue) {
95          UserOptions userOptions = new UserOptions();
96          userOptions.setOptionId(optionId);
97          userOptions.setOptionVal(optionValue);
98          return this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(userOptions));
99      }
100 
101     @Override
102     public List<UserOptions> findEmailUserOptionsByType(String emailSetting) {
103         Criteria optionIDCriteria = new Criteria();
104         optionIDCriteria.addEqualTo("optionId", KewApiConstants.EMAIL_RMNDR_KEY);
105 
106         Criteria documentTypeNotificationCriteria = new Criteria();
107         documentTypeNotificationCriteria.addLike("optionId", "%" + KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_SUFFIX);
108         optionIDCriteria.addOrCriteria(documentTypeNotificationCriteria);
109 
110         Criteria criteria = new Criteria();
111         criteria.addEqualTo("optionVal", emailSetting);
112         criteria.addAndCriteria(optionIDCriteria);
113         return Lists.newArrayList(Iterables.filter(this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(UserOptions.class, criteria)), UserOptions.class));
114     }
115 }