|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ApplicationStateDaoImpl | Line # 36 | 22 | 0% | 8 | 6 | 79.3% |
0.79310346
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(10) | |||
Result | |||
0.6551724
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateGetApplicationState1 org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateGetApplicationState1 | 1 PASS | |
0.6551724
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testUpdateApplicationState1 org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testUpdateApplicationState1 | 1 PASS | |
0.6551724
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testUpdateApplicationState2 org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testUpdateApplicationState2 | 1 PASS | |
0.6551724
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateGetApplicationState3 org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateGetApplicationState3 | 1 PASS | |
0.6551724
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateApplicationState1_Error_DuplicateKey org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateApplicationState1_Error_DuplicateKey | 1 PASS | |
0.5862069
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateApplicationState1_Error_DuplicateKeyUserId org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateApplicationState1_Error_DuplicateKeyUserId | 1 PASS | |
0.55172414
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testGetApplicationStateByAppIdRefIdRefTypeUserId org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testGetApplicationStateByAppIdRefIdRefTypeUserId | 1 PASS | |
0.55172414
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateApplicationState_NullParameters org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testCreateApplicationState_NullParameters | 1 PASS | |
0.37931034
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testGetApplicationState_NoApplicationState org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testGetApplicationState_NoApplicationState | 1 PASS | |
0.31034482
|
org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testGetApplicationState_NoApplicationStateforUserId org.kuali.student.common.ui.server.applicationstate.dao.impl.ApplicationStateDaoImplTest.testGetApplicationState_NoApplicationStateforUserId | 1 PASS | |
1 | /** | |
2 | * Copyright 2010 The Kuali Foundation Licensed under the | |
3 | * Educational Community License, Version 2.0 (the "License"); you may | |
4 | * not use this file except in compliance with the License. You may | |
5 | * obtain a copy of the License at | |
6 | * | |
7 | * http://www.osedu.org/licenses/ECL-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, | |
10 | * software distributed under the License is distributed on an "AS IS" | |
11 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
12 | * or implied. See the License for the specific language governing | |
13 | * permissions and limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.kuali.student.common.ui.server.applicationstate.dao.impl; | |
17 | ||
18 | import java.util.ArrayList; | |
19 | import java.util.Collection; | |
20 | import java.util.List; | |
21 | ||
22 | import javax.persistence.EntityManager; | |
23 | import javax.persistence.PersistenceContext; | |
24 | import javax.persistence.Query; | |
25 | ||
26 | import org.kuali.student.common.ui.server.applicationstate.dao.ApplicationStateDao; | |
27 | import org.kuali.student.common.ui.server.applicationstate.entity.ApplicationState; | |
28 | import org.kuali.student.core.dao.impl.AbstractSearchableCrudDaoImpl; | |
29 | import org.kuali.student.core.exceptions.AlreadyExistsException; | |
30 | import org.kuali.student.core.exceptions.DoesNotExistException; | |
31 | ||
32 | /** | |
33 | * This data access class stores the GUI (page, section, widget, etc.) | |
34 | * application states as key value pairs in a database. | |
35 | */ | |
36 | public class ApplicationStateDaoImpl extends AbstractSearchableCrudDaoImpl implements ApplicationStateDao { | |
37 | ||
38 | private final static String DEFAULT_USER_ID = "APPLICATION"; | |
39 | ||
40 | 10 | @PersistenceContext(unitName = "ApplicationState") |
41 | @Override | |
42 | public void setEm(EntityManager em) { | |
43 | 10 | super.setEm(em); |
44 | } | |
45 | ||
46 | /** | |
47 | * Gets an application states by <code>applicationId</code>, | |
48 | * <code>referenceKey</code>, <code>referenceType</code> and | |
49 | * <code>userId</code>. | |
50 | * | |
51 | * @param applicationId Application id | |
52 | * @param referenceKey Reference key | |
53 | * @param referenceType Reference type | |
54 | * @param userId User id | |
55 | * @return An application state | |
56 | * @throws DoesNotExistException Thrown if application state does not exist | |
57 | */ | |
58 | 23 | public ApplicationState getApplicationState(String applicationId, String referenceKey, String referenceType, String userId) throws DoesNotExistException { |
59 | 23 | Query query = em.createNamedQuery("ApplicationState.getApplicationStateByAppRefUserId"); |
60 | 23 | query.setParameter("applicationId", applicationId); |
61 | 23 | query.setParameter("referenceKey", referenceKey); |
62 | 23 | query.setParameter("referenceType", referenceType); |
63 | 23 | query.setParameter("userId", userId); |
64 | ||
65 | 23 | try { |
66 | 23 | ApplicationState appState = (ApplicationState) query.getSingleResult(); |
67 | 11 | return appState; |
68 | } catch(javax.persistence.NoResultException e) { | |
69 | 12 | throw new DoesNotExistException("Application state does not exist"); |
70 | } | |
71 | } | |
72 | ||
73 | /** | |
74 | * Gets an application states by <code>applicationId</code>, | |
75 | * <code>referenceKey</code> and <code>referenceType</code>. | |
76 | * | |
77 | * @param applicationId Application id | |
78 | * @param referenceKey Reference key | |
79 | * @param referenceType Reference type | |
80 | * @return A list of application states | |
81 | * @throws DoesNotExistException Thrown if application state does not exist | |
82 | */ | |
83 | 8 | public ApplicationState getApplicationState(String applicationId, String referenceKey, String referenceType) throws DoesNotExistException { |
84 | 8 | return getApplicationState(applicationId, referenceKey, referenceType, DEFAULT_USER_ID); |
85 | } | |
86 | ||
87 | /** | |
88 | * Creates and returns an application state. | |
89 | * | |
90 | * @param appState Application state | |
91 | * @return A new application state | |
92 | * @throws AlreadyExistsException Thrown if application state already exists | |
93 | */ | |
94 | 12 | public ApplicationState createApplicationState(ApplicationState appState) throws AlreadyExistsException { |
95 | 12 | if(appState.getUserId() == null) { |
96 | 7 | appState.setUserId(DEFAULT_USER_ID); |
97 | } | |
98 | ||
99 | 12 | try { |
100 | 12 | getApplicationState(appState.getApplicationId(), appState.getReferenceKey(), appState.getReferenceType(), appState.getUserId()); |
101 | } catch(DoesNotExistException e) { | |
102 | 10 | return super.create(appState); |
103 | } | |
104 | 2 | throw new AlreadyExistsException("Application state already exists"); |
105 | } | |
106 | ||
107 | /** | |
108 | * Creates a collection of application states and returns their ids. | |
109 | * | |
110 | * @param appStateList collection of application states | |
111 | * @return A list of newly created application state ids | |
112 | * @throws AlreadyExistsException Thrown if application state already exists | |
113 | */ | |
114 | 0 | public List<String> createApplicationState(Collection<ApplicationState> appStates) throws AlreadyExistsException { |
115 | 0 | List<String> newAppStateList = new ArrayList<String>(); |
116 | 0 | for(ApplicationState appState : appStates) { |
117 | 0 | ApplicationState newAppState = createApplicationState(appState); |
118 | 0 | newAppStateList.add(newAppState.getId()); |
119 | } | |
120 | 0 | return newAppStateList; |
121 | } | |
122 | ||
123 | } |
|