1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }