View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package org.kuali.student.enrollment.class2.courseoffering.service.impl;
6   
7   import org.kuali.rice.core.api.criteria.QueryByCriteria;
8   import org.kuali.student.common.mock.MockService;
9   import org.kuali.student.common.util.UUIDHelper;
10  import org.kuali.student.r1.common.dictionary.dto.ObjectStructureDefinition;
11  import org.kuali.student.r1.core.statement.dto.StatementTreeViewInfo;
12  import org.kuali.student.r2.common.dto.ContextInfo;
13  import org.kuali.student.r2.common.dto.StatusInfo;
14  import org.kuali.student.r2.common.dto.ValidationResultInfo;
15  import org.kuali.student.r2.common.exceptions.*;
16  import org.kuali.student.r2.core.versionmanagement.dto.VersionDisplayInfo;
17  import org.kuali.student.r2.core.versionmanagement.dto.VersionInfo;
18  import org.kuali.student.r2.lum.course.dto.ActivityInfo;
19  import org.kuali.student.r2.lum.course.dto.CourseInfo;
20  import org.kuali.student.r2.lum.course.dto.FormatInfo;
21  import org.kuali.student.r2.lum.course.dto.LoDisplayInfo;
22  import org.kuali.student.r2.lum.course.service.CourseService;
23  import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
24  
25  import java.util.ArrayList;
26  import java.util.Date;
27  import java.util.LinkedHashMap;
28  import java.util.List;
29  import java.util.Map;
30  
31  /**
32   *
33   * @author nwright
34   */
35  public class CourseServiceR1MockImpl implements CourseService, MockService {
36  
37      private Map<String, CourseInfo> courses = new LinkedHashMap<String, CourseInfo>();
38  
39      @Override
40      public void clear() {
41          this.courses.clear();
42      }
43  
44      @Override
45      public CourseInfo createCourse(CourseInfo courseInfo, ContextInfo contextInfo)
46              throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
47          
48          if (courseInfo.getId() == null) {
49              courseInfo.setId(UUIDHelper.genStringUUID());
50          }
51          
52         
53          for (FormatInfo format :  courseInfo.getFormats()) {
54              
55              if (format.getId() == null) {
56                  format.setId(UUIDHelper.genStringUUID());
57              }
58              
59              format.getActivities();
60              
61              for (ActivityInfo activity : format.getActivities()) {
62                  
63                  if (activity.getId() == null) {
64                      activity.setId(UUIDHelper.genStringUUID());
65                  }
66              }
67          }
68          
69          VersionInfo version = new VersionInfo ();
70          version.setCurrentVersionStart(new Date ());
71          version.setCurrentVersionEnd(null);
72          version.setSequenceNumber(0l);
73          version.setVersionComment("initial version");
74          version.setVersionIndId(courseInfo.getId() + "ind");
75          version.setVersionedFromId(courseInfo.getId());
76          courseInfo.setVersion(version);
77          courses.put(courseInfo.getId(), courseInfo);
78          return courseInfo;
79      }
80  
81      @Override
82      public StatementTreeViewInfo createCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException {
83          throw new UnsupportedOperationException("Not supported yet.");
84      }
85  
86      @Override
87      public CourseInfo createNewCourseVersion(String courseId, String versionComment, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
88          throw new UnsupportedOperationException("Not supported yet.");
89      }
90  
91      @Override
92      public StatusInfo deleteCourse(String courseId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DataValidationErrorException, AlreadyExistsException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, UnsupportedOperationException, CircularReferenceException {
93          if (!courses.containsKey(courseId)) {
94              throw new DoesNotExistException(courseId);
95          }
96          courses.remove(courseId);
97          StatusInfo status = new StatusInfo();
98          status.setSuccess(Boolean.TRUE);
99          return status;
100     }
101 
102     @Override
103     public StatusInfo deleteCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
104         throw new UnsupportedOperationException("Not supported yet.");
105     }
106 
107     @Override
108     public CourseInfo getCourse(String courseId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
109         if (!courses.containsKey(courseId)) {
110             throw new DoesNotExistException(courseId);
111         }
112         return courses.get(courseId);
113     }
114 
115     @Override
116     public List<ActivityInfo> getCourseActivitiesByCourseFormat(String formatId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
117         List<ActivityInfo> list = new ArrayList<ActivityInfo>();
118         for (CourseInfo course : this.courses.values()) {
119             for (FormatInfo format : course.getFormats()) {
120                 if (format.getId().equals(formatId)) {
121                     for (ActivityInfo activity : format.getActivities()) {
122                         list.add(activity);
123                     }
124                 }
125             }
126         }
127         return list;
128     }
129 
130     @Override
131     public List<FormatInfo> getCourseFormatsByCourse(String courseId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
132         List<FormatInfo> list = new ArrayList<FormatInfo>();
133         CourseInfo course = this.getCourse(courseId, null);
134         for (FormatInfo format : course.getFormats()) {
135             list.add(format);
136         }
137         return list;
138     }
139 
140     @Override
141     public List<LoDisplayInfo> getCourseLearningObjectivesByCourse(String courseId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
142         throw new UnsupportedOperationException("Not supported yet.");
143     }
144 
145     @Override
146     public List<StatementTreeViewInfo> getCourseStatements(String courseId, String nlUsageTypeKey, String language, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
147         throw new UnsupportedOperationException("Not supported yet.");
148     }
149 
150     @Override
151     public StatusInfo setCurrentCourseVersion(String courseVersionId, Date currentVersionStart, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, IllegalVersionSequencingException, OperationFailedException, PermissionDeniedException {
152         throw new UnsupportedOperationException("Not supported yet.");
153     }
154 
155     @Override
156     public CourseInfo updateCourse(String courseId, CourseInfo courseInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, VersionMismatchException, OperationFailedException, PermissionDeniedException, UnsupportedActionException, DependentObjectsExistException, AlreadyExistsException, CircularRelationshipException, CircularReferenceException, ReadOnlyException {
157         if (!courses.containsKey(courseInfo.getId())) {
158             throw new DoesNotExistException(courseInfo.getId());
159         }
160         this.courses.put(courseInfo.getId(), courseInfo);
161         return courseInfo;
162     }
163 
164     @Override
165     public StatementTreeViewInfo updateCourseStatement(String courseId, String statementId, StatementTreeViewInfo statementTreeViewInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, VersionMismatchException {
166         throw new UnsupportedOperationException("Not supported yet.");
167     }
168 
169     @Override
170     public List<ValidationResultInfo> validateCourse(String validationType, CourseInfo courseInfo, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException {
171         throw new UnsupportedOperationException("Not supported yet.");
172     }
173 
174     @Override
175     public List<ValidationResultInfo> validateCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException {
176         throw new UnsupportedOperationException("Not supported yet.");
177     }
178 
179     @Override
180     public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
181         throw new UnsupportedOperationException("Not supported yet.");
182     }
183 
184     @Override
185     public List<String> getObjectTypes() {
186         throw new UnsupportedOperationException("Not supported yet.");
187     }
188 
189     @Override
190     public VersionDisplayInfo getCurrentVersion(String refObjectTypeURI, String refObjectId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
191         throw new UnsupportedOperationException("Not supported yet.");
192     }
193 
194 
195     @Override
196     public List<CourseInfo> getCoursesByIds(List<String> courseIds, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
197         throw new UnsupportedOperationException("Not supported yet.");
198     }
199 
200     @Override
201     public List<String> searchForCourseIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
202         throw new UnsupportedOperationException("Not supported yet.");
203     }
204 
205     @Override
206     public List<CourseInfo> searchForCourses(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
207         throw new UnsupportedOperationException("Not supported yet.");
208     }
209 
210     public List<VersionDisplayInfo> getVersions(String refObjectTypeURI, String refObjectId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
211 
212         // Note: the refObjectTypeURI should only be clus because that is the only object that is versioned
213         List<VersionDisplayInfo> list = new ArrayList<VersionDisplayInfo> ();
214         for (CourseInfo info : this.courses.values()) {
215             // the refObjectid is the VERSION INDEPENDENT ID See LuDaoImpl from CM
216             if (refObjectId.equals(info.getVersion().getVersionIndId())) {
217                 VersionInfo vi = info.getVersion();
218                 VersionDisplayInfo vd = new VersionDisplayInfo ();
219                 vd.setId(info.getId());
220                 vd.setRefObjectUri(CluServiceConstants.CLU_NAMESPACE_URI);
221                 vd.setVersionedFromId(vi.getVersionedFromId());
222                 vd.setCurrentVersionStart(vi.getCurrentVersionStart());
223                 vd.setCurrentVersionEnd(vi.getCurrentVersionEnd());
224                 vd.setSequenceNumber(vi.getSequenceNumber());
225                 vd.setVersionComment(vi.getVersionComment());
226                 vd.setVersionIndId(vi.getVersionIndId());
227                 list.add (vd);
228             }
229         }
230         return list;
231     }
232 }