use of fi.otavanopisto.pyramus.rest.model.Course in project muikku by otavanopisto.
the class CourseManagementTestsBase method changeWorkspaceTypeTest.
@Test
@TestEnvironments(browsers = { TestEnvironments.Browser.CHROME, TestEnvironments.Browser.FIREFOX, TestEnvironments.Browser.INTERNET_EXPLORER, TestEnvironments.Browser.EDGE, TestEnvironments.Browser.PHANTOMJS })
public void changeWorkspaceTypeTest() throws Exception {
MockStaffMember admin = new MockStaffMember(1l, 1l, "Admin", "User", UserRole.ADMINISTRATOR, "121212-1234", "admin@example.com", Sex.MALE);
Builder mockBuilder = mocker();
try {
mockBuilder.addStaffMember(admin).mockLogin(admin).build();
login();
long courseId = 1l;
Workspace workspace = createWorkspace("testcourse", "test course for testing", String.valueOf(courseId), Boolean.TRUE);
try {
navigate(String.format("/workspace/%s/workspace-management", workspace.getUrlName()), true);
waitForPresent(".additionalinfo-data .workspace-type");
scrollIntoView(".additionalinfo-data .workspace-type");
selectOption(".additionalinfo-data .workspace-type", "PYRAMUS-2");
waitAndClick(".workspace-management-footer .workspace-management-footer-actions-container button.save");
waitForNotVisible(".loading");
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).setSerializationInclusion(Include.NON_NULL);
OffsetDateTime created = OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
OffsetDateTime begin = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
OffsetDateTime end = OffsetDateTime.of(2050, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
Course course = new Course(courseId, "testcourse", created, created, "<p>test course for testing</p>\n", false, 1, (long) 25, begin, end, "test extension", (double) 15, (double) 45, (double) 45, (double) 15, (double) 45, (double) 45, end, (long) 1, (long) 1, (long) 1, null, (double) 45, (long) 1, (long) 1, (long) 1, (long) 2, null, null);
String courseJson = objectMapper.writeValueAsString(course);
stubFor(put(urlEqualTo(String.format("/1/courses/courses/%d", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
String payload = objectMapper.writeValueAsString(new WebhookCourseUpdatePayload(course.getId()));
TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
navigate(String.format("/workspace/%s", workspace.getUrlName()), true);
waitForPresent(".workspace-meta-wrapper .workspace-meta-item-wrapper:nth-child(3) .workspace-meta-desc");
assertTextIgnoreCase(".workspace-meta-wrapper .workspace-meta-item-wrapper:nth-child(3) .workspace-meta-desc", "Ryhmäkurssi");
} finally {
deleteWorkspace(workspace.getId());
}
} finally {
mockBuilder.wiremockReset();
}
}
use of fi.otavanopisto.pyramus.rest.model.Course in project muikku by otavanopisto.
the class PyramusWorkspaceSchoolDataBridge method listWorkspacesByCourseIdentifier.
@Override
public List<Workspace> listWorkspacesByCourseIdentifier(String courseIdentifierIdentifier) {
if (courseIdentifierIdentifier.indexOf("/") == -1)
throw new SchoolDataBridgeInternalException("Invalid CourseIdentifierId");
String subjectId = courseIdentifierIdentifier.substring(0, courseIdentifierIdentifier.indexOf("/"));
String courseNumber = courseIdentifierIdentifier.substring(courseIdentifierIdentifier.indexOf("/") + 1);
Course[] courses = pyramusClient.get("/common/subjects/" + subjectId + "/courses", fi.otavanopisto.pyramus.rest.model.Course[].class);
List<Workspace> result = new ArrayList<Workspace>();
for (Course course : courses) {
String courseNumber2 = course.getCourseNumber() != null ? course.getCourseNumber().toString() : "null";
if (courseNumber.equals(courseNumber2))
result.add(createWorkspaceEntity(course));
}
return result;
}
use of fi.otavanopisto.pyramus.rest.model.Course 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);
}
use of fi.otavanopisto.pyramus.rest.model.Course in project muikku by otavanopisto.
the class PyramusUpdater method updateCourses.
/**
* Updates courses from Pyramus
*
* @param offset first course to be updated
* @param maxCourses maximum batch size
* @return count of updated courses or -1 when no courses were found with given offset
*/
public int updateCourses(int offset, int maxCourses) {
Course[] courses = pyramusClient.get().get("/courses/courses?filterArchived=false&firstResult=" + offset + "&maxResults=" + maxCourses, Course[].class);
if ((courses == null) || (courses.length == 0)) {
return -1;
}
List<String> existingIdentifiers = workspaceEntityController.listWorkspaceEntityIdentifiersByDataSource(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE);
List<Course> discoveredCourses = new ArrayList<>();
List<Course> removedCourses = new ArrayList<>();
for (Course course : courses) {
String workspaceIdentifier = identifierMapper.getWorkspaceIdentifier(course.getId());
if (course.getArchived()) {
if (existingIdentifiers.contains(workspaceIdentifier)) {
removedCourses.add(course);
}
} else {
if (!existingIdentifiers.contains(workspaceIdentifier)) {
discoveredCourses.add(course);
}
}
}
for (Course discoveredCourse : discoveredCourses) {
fireWorkspaceDiscovered(discoveredCourse);
}
for (Course removedCourse : removedCourses) {
fireWorkspaceRemoved(removedCourse.getId());
}
return discoveredCourses.size();
}
use of fi.otavanopisto.pyramus.rest.model.Course in project muikku by otavanopisto.
the class PyramusUpdater method updateCourse.
/**
* Updates a course from Pyramus
*
* @param pyramusId id of course in Pyramus
* @return returns whether new course was created or not
*/
public void updateCourse(Long courseId) {
String workspaceIdentifier = identifierMapper.getWorkspaceIdentifier(courseId);
Course course = pyramusClient.get().get("/courses/courses/" + courseId, Course.class);
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
if (course != null) {
if (workspaceEntity == null) {
fireWorkspaceDiscovered(course);
} else {
fireWorkspaceUpdated(course);
}
} else {
if (workspaceEntity != null) {
fireWorkspaceRemoved(courseId);
}
}
}
Aggregations