use of fi.otavanopisto.pyramus.rest.model.CourseDescription in project muikku by otavanopisto.
the class PyramusWorkspaceSchoolDataBridge method copyWorkspace.
@Override
public Workspace copyWorkspace(SchoolDataIdentifier identifier, String name, String nameExtension, String description) {
if (!getSchoolDataSource().equals(identifier.getDataSource())) {
logger.severe(String.format("Invalid workspace identfier for Pyramus bridge", identifier));
return null;
}
Long pyramusCourseId = identifierMapper.getPyramusCourseId(identifier.getIdentifier());
if (pyramusCourseId == null) {
logger.severe(String.format("Workspace identifier %s is not valid", identifier));
return null;
}
Course course = pyramusClient.get(String.format("/courses/courses/%d", pyramusCourseId), Course.class);
if (course == null) {
logger.severe(String.format("Could not find Pyramus course by id %d", pyramusCourseId));
return null;
}
List<String> copiedTags = null;
if (course.getTags() != null) {
copiedTags = new ArrayList<String>();
for (String tag : course.getTags()) {
copiedTags.add(tag);
}
}
Course courseCopy = new Course(// copy has no id
null, // copy has new name
name, course.getCreated(), course.getLastModified(), // copy has new description
description, course.getArchived(), course.getCourseNumber(), course.getMaxParticipantCount(), course.getBeginDate(), course.getEndDate(), // copy has new name extension
nameExtension, course.getLocalTeachingDays(), course.getTeachingHours(), course.getDistanceTeachingHours(), course.getDistanceTeachingDays(), course.getAssessingHours(), course.getPlanningHours(), course.getEnrolmentTimeEnd(), course.getCreatorId(), course.getLastModifierId(), course.getSubjectId(), course.getCurriculumIds(), course.getLength(), course.getLengthUnitId(), course.getModuleId(), course.getStateId(), course.getTypeId(), // variables are not copied
null, // copy has its own tag list
copiedTags);
Course createdCourse = pyramusClient.post("/courses/courses/", courseCopy);
if (createdCourse == null) {
logger.severe(String.format("Failed to create new course based on course %d", pyramusCourseId));
return null;
}
// #2915: Copy additional course descriptions
CourseDescription[] courseDescriptions = pyramusClient.get(String.format("/courses/courses/%d/descriptions", pyramusCourseId), CourseDescription[].class);
if (ArrayUtils.isNotEmpty(courseDescriptions)) {
for (int i = 0; i < courseDescriptions.length; i++) {
pyramusClient.post(String.format("/courses/courses/%d/descriptions", createdCourse.getId()), new CourseDescription(null, createdCourse.getId(), courseDescriptions[i].getCourseDescriptionCategoryId(), courseDescriptions[i].getDescription()));
}
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(identifierMapper.getWorkspaceIdentifier(createdCourse.getId()), SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE);
workspaceDiscoveryWaiter.waitDiscovered(workspaceIdentifier);
return createWorkspaceEntity(createdCourse);
}
Aggregations