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 org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19 import org.kuali.rice.core.api.util.RiceConstants;
20 import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform;
21 import org.kuali.rice.kew.api.KewApiConstants;
22 import org.kuali.rice.kew.useroptions.UserOptions;
23 import org.kuali.rice.kew.useroptions.dao.UserOptionsDAO;
24
25 import com.google.common.collect.Iterables;
26 import com.google.common.collect.Lists;
27
28 import javax.persistence.EntityManager;
29 import javax.persistence.PersistenceContext;
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.List;
33
34
35 public class UserOptionsDaoJpaImpl implements UserOptionsDAO {
36
37 @PersistenceContext
38 private EntityManager entityManager;
39
40 public Long getNewOptionIdForActionList() {
41 return getPlatform().getNextValSQL("KREW_ACTN_LIST_OPTN_S", entityManager);
42 }
43
44 protected DatabasePlatform getPlatform() {
45 return (DatabasePlatform) GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM);
46 }
47
48 public List findByUserQualified(String principalId, String likeString) {
49 return new ArrayList(entityManager.createNamedQuery("UserOptions.FindByUserQualified").setParameter("workflowId", principalId).setParameter("optionId", likeString).getResultList());
50 }
51
52 public void deleteByUserQualified(String principalId, String likeString) {
53 List<UserOptions> userOptions = (List<UserOptions>) entityManager.createNamedQuery("UserOptions.FindByUserQualified").setParameter("workflowId", principalId).setParameter("optionId", likeString).getResultList();
54 for (UserOptions uo : userOptions) {
55 entityManager.remove(uo);
56 }
57 }
58
59 public Collection findByWorkflowUser(String principalId) {
60 return entityManager.createNamedQuery("UserOptions.FindByWorkflowId").setParameter("workflowId", principalId).getResultList();
61 }
62
63 public void save(UserOptions userOptions) {
64 if (userOptions.getOptionId() == null) {
65 entityManager.persist(userOptions);
66 } else {
67 entityManager.merge(userOptions);
68 }
69 }
70
71 public void save(Collection<UserOptions> userOptions) {
72 if (userOptions != null) for (UserOptions option : userOptions) {
73 save(option);
74 }
75 }
76
77 public void deleteUserOptions(UserOptions userOptions) {
78 UserOptions reattatched = entityManager.merge(userOptions);
79 entityManager.remove(reattatched);
80 }
81
82 public UserOptions findByOptionId(String optionId, String principalId) {
83 return (UserOptions) entityManager.createNamedQuery("UserOptions.FindByOptionId").setParameter("optionId", optionId).setParameter("workflowId", principalId).getSingleResult();
84 }
85
86 public Collection findByOptionValue(String optionId, String optionValue) {
87 return entityManager.createNamedQuery("UserOptions.FindByOptionValue").setParameter("optionId", optionId).setParameter("optionValue", optionValue).getResultList();
88 }
89
90 @Override
91 public List<UserOptions> findEmailUserOptionsByType(String emailSetting) {
92 return Lists.newArrayList(Iterables.filter(entityManager.createNamedQuery("UserOptions.FindByOptionValue")
93 .setParameter("optionId", KewApiConstants.EMAIL_RMNDR_KEY)
94 .setParameter("optionIdLike", "%" + KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_SUFFIX)
95 .setParameter("optionValue", emailSetting)
96 .getResultList(),
97 UserOptions.class));
98 }
99
100 public EntityManager getEntityManager() {
101 return this.entityManager;
102 }
103
104 public void setEntityManager(EntityManager entityManager) {
105 this.entityManager = entityManager;
106 }
107 }