View Javadoc

1   /*
2    * Copyright 2012 The Kuali Foundation 
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the
6    * License. You may obtain a copy of the License at
7    *
8    * http://www.osedu.org/licenses/ECL-2.0
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
13   * implied. See the License for the specific language governing
14   * permissions and limitations under the License.
15   */
16  package org.kuali.student.enrollment.class1.lrr.service.impl.mock;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.kuali.student.common.mock.MockService;
24  import org.kuali.student.enrollment.lrr.dto.LearningResultRecordInfo;
25  import org.kuali.student.enrollment.lrr.dto.ResultSourceInfo;
26  import org.kuali.student.enrollment.lrr.service.LearningResultRecordService;
27  import org.kuali.student.r2.common.dto.ContextInfo;
28  import org.kuali.student.r2.common.dto.StatusInfo;
29  import org.kuali.student.r2.common.dto.ValidationResultInfo;
30  import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
31  import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
32  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
33  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
34  import org.kuali.student.r2.common.exceptions.MissingParameterException;
35  import org.kuali.student.r2.common.exceptions.OperationFailedException;
36  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
37  import org.kuali.student.r2.common.exceptions.VersionMismatchException;
38  
39  /**
40   * A java.util.Map based implementation of the {@link LearningResultRecordService}.
41   * 
42   * @author Kuali Student Team
43   *
44   */
45  public class LRRServiceMockImpl implements LearningResultRecordService, MockService {
46  
47  	private Map<String, LearningResultRecordInfo> learningResultCache = new HashMap<String, LearningResultRecordInfo>();
48  	private Map<String, ResultSourceInfo> resultSourcesCache = new HashMap<String, ResultSourceInfo>();
49  
50      @Override
51      public void clear() {
52          learningResultCache.clear();
53          resultSourcesCache.clear();
54      }
55  
56      @Override
57  	public LearningResultRecordInfo getLearningResultRecord(
58  			String learningResultRecordId, ContextInfo context)
59  			throws DoesNotExistException, InvalidParameterException,
60  			MissingParameterException, OperationFailedException,
61  			PermissionDeniedException {
62  		return learningResultCache.get(learningResultRecordId);
63  	}
64  
65  	@Override
66  	public List<LearningResultRecordInfo> getLearningResultRecordsForLpr(
67  			String lprId) throws DoesNotExistException,
68  			InvalidParameterException, MissingParameterException,
69  			OperationFailedException {
70  		List<LearningResultRecordInfo> matchingLrrs = new ArrayList<LearningResultRecordInfo>();
71  		for (LearningResultRecordInfo lrrInfo : learningResultCache.values()) {
72  			if (lrrInfo.getLprId().equals(lprId)) {
73  				matchingLrrs.add(lrrInfo);
74  			}
75  		}
76  
77  		return matchingLrrs;
78  	}
79  
80  	@Override
81  	public List<LearningResultRecordInfo> getLearningResultRecordsForLprIds(
82  			List<String> lprIds, ContextInfo context)
83  			throws DoesNotExistException, InvalidParameterException,
84  			MissingParameterException, OperationFailedException {
85  		List<LearningResultRecordInfo> allLRRsForLPR = new ArrayList<LearningResultRecordInfo>();
86  		for (String lprId : lprIds) {
87  			allLRRsForLPR.addAll(getLearningResultRecordsForLpr(lprId));
88  		}
89  		return allLRRsForLPR;
90  	}
91  
92  	@Override
93  	public List<LearningResultRecordInfo> getLearningResultRecordsBySourceId(
94  			List<String> sourceIds, ContextInfo context)
95  			throws DoesNotExistException, InvalidParameterException,
96  			MissingParameterException, OperationFailedException {
97  		List<LearningResultRecordInfo> lrrsMatchingSource = new ArrayList<LearningResultRecordInfo>();
98  		for (LearningResultRecordInfo lrr : learningResultCache.values()) {
99  			if (lrr.getResultSourceIds().retainAll(sourceIds)  ) {
100 				lrrsMatchingSource.add(lrr);
101 			}
102 		}
103 
104 		return lrrsMatchingSource;
105 	}
106 
107 	@Override
108 	public LearningResultRecordInfo createLearningResultRecord(
109 			LearningResultRecordInfo learningResultRecord, ContextInfo context)
110 			throws AlreadyExistsException, DataValidationErrorException,
111 			InvalidParameterException, MissingParameterException,
112 			OperationFailedException, PermissionDeniedException {
113 		learningResultRecord.setId(String.valueOf(Math.random()));
114 		learningResultCache.put(learningResultRecord.getId(),
115 				learningResultRecord);
116 		return learningResultRecord;
117 
118 	}
119 
120 	@Override
121 	public LearningResultRecordInfo updateLearningResultRecord(
122 			String learningResultRecordId,
123 			LearningResultRecordInfo learningResultRecordInfo,
124 			ContextInfo context) throws DataValidationErrorException,
125 			DoesNotExistException, InvalidParameterException,
126 			MissingParameterException, OperationFailedException,
127 			PermissionDeniedException, VersionMismatchException {
128 
129 		learningResultCache.put(learningResultRecordId,
130 				learningResultRecordInfo);
131 		return learningResultRecordInfo;
132 	}
133 
134 	@Override
135 	public StatusInfo deleteLearningResultRecord(String learningResultRecordId,
136 			ContextInfo context) throws DoesNotExistException,
137 			InvalidParameterException, MissingParameterException,
138 			OperationFailedException, PermissionDeniedException {
139 		learningResultCache.remove(learningResultRecordId);
140 		return new StatusInfo();
141 	}
142 
143 	@Override
144 	public List<ValidationResultInfo> validateLearningResultRecord(
145 			String validationType,
146 			LearningResultRecordInfo learningResultRecordInfo,
147 			ContextInfo context) throws DoesNotExistException,
148 			InvalidParameterException, MissingParameterException,
149 			OperationFailedException {
150     	return new ArrayList<ValidationResultInfo>();
151 	}
152 
153 	@Override
154 	public ResultSourceInfo getResultSource(String resultSourceId,
155 			ContextInfo context) throws DoesNotExistException,
156 			InvalidParameterException, MissingParameterException,
157 			OperationFailedException, PermissionDeniedException {
158 		return resultSourcesCache.get(resultSourceId);
159 	}
160 
161 	@Override
162 	public List<ResultSourceInfo> getResultSourcesByIds(
163 			List<String> resultSourceIds, ContextInfo context)
164 			throws DoesNotExistException, InvalidParameterException,
165 			MissingParameterException, OperationFailedException,
166 			PermissionDeniedException {
167 
168 		List<ResultSourceInfo> resultSources = new ArrayList<ResultSourceInfo>();
169 		for (String sourceId : resultSourceIds) {
170 			resultSources.add(getResultSource(sourceId, context));
171 
172 		}
173 		return resultSources;
174 
175 	}
176 
177 	@Override
178 	public List<ResultSourceInfo> getResultSourcesByType(
179 			String resultSourceTypeKey, ContextInfo context)
180 			throws DoesNotExistException, InvalidParameterException,
181 			MissingParameterException, OperationFailedException,
182 			PermissionDeniedException {
183 		List <ResultSourceInfo> resultSources = new ArrayList<ResultSourceInfo>();
184 			for(ResultSourceInfo resultSource: resultSourcesCache.values() ){
185 				if(resultSource.getTypeKey().equals(resultSourceTypeKey)){
186 					resultSources.add(resultSource);
187 				}
188 			}
189 		return resultSources;
190 	}
191 
192 	@Override
193 	public ResultSourceInfo createResultSource(ResultSourceInfo sourceInfo,
194 			ContextInfo context) throws AlreadyExistsException,
195 			DataValidationErrorException, InvalidParameterException,
196 			MissingParameterException, OperationFailedException,
197 			PermissionDeniedException {
198 		sourceInfo.setId(String.valueOf(Math.random()));
199 		resultSourcesCache.put(sourceInfo.getId(),sourceInfo);
200 		return sourceInfo;
201 	}
202 
203 	@Override
204 	public ResultSourceInfo updateResultSource(String resultSourceId,
205 			ResultSourceInfo resultSourceInfo, ContextInfo context)
206 			throws DataValidationErrorException, DoesNotExistException,
207 			InvalidParameterException, MissingParameterException,
208 			OperationFailedException, PermissionDeniedException,
209 			VersionMismatchException {
210 		resultSourcesCache.put(resultSourceId, resultSourceInfo);
211 		return resultSourceInfo;
212 	}
213 
214 	@Override
215 	public StatusInfo deleteResultSource(String resultSourceId,
216 			ContextInfo context) throws DoesNotExistException,
217 			InvalidParameterException, MissingParameterException,
218 			OperationFailedException, PermissionDeniedException {
219 		resultSourcesCache.remove(resultSourceId);
220 		return new StatusInfo();
221 	}
222 
223 	@Override
224 	public List<ValidationResultInfo> validateResultSource(
225 			String validationType, ResultSourceInfo resultSourceInfo,
226 			ContextInfo context) throws DoesNotExistException,
227 			InvalidParameterException, MissingParameterException,
228 			OperationFailedException {
229     	return new ArrayList<ValidationResultInfo>();
230 	}
231 
232     @Override
233     public List<LearningResultRecordInfo> getLearningResultRecordsForLprAndType(String lprId, String lrrType) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
234             OperationFailedException {
235         return new ArrayList<LearningResultRecordInfo>();
236     }
237 
238     @Override
239 	public StatusInfo changeLearningResultRecordState(
240 			String learningResultRecordId, String nextStateKey,
241 			ContextInfo contextInfo) throws DoesNotExistException,
242 			InvalidParameterException, MissingParameterException,
243 			OperationFailedException, PermissionDeniedException {
244 		// TODO KSENROLL-8713
245 		throw new UnsupportedOperationException("not implemented");
246 	}
247 
248 	@Override
249 	public StatusInfo changeResultSourceState(String resultSourceId,
250 			String nextStateKey, ContextInfo contextInfo)
251 			throws DoesNotExistException, InvalidParameterException,
252 			MissingParameterException, OperationFailedException,
253 			PermissionDeniedException {
254 		// TODO KSENROLL-8713
255 		throw new UnsupportedOperationException("not implemented");
256 	}
257     
258 }