use of fi.otavanopisto.pyramus.rest.model.Course in project muikku by otavanopisto.
the class PyramusCourseMetaSchoolDataBridge method listCourseIdentifiers.
@Override
public List<CourseIdentifier> listCourseIdentifiers() {
List<CourseIdentifier> result = new ArrayList<>();
fi.otavanopisto.pyramus.rest.model.Subject[] subjects = pyramusClient.get("/common/subjects/", fi.otavanopisto.pyramus.rest.model.Subject[].class);
if (subjects != null) {
for (fi.otavanopisto.pyramus.rest.model.Subject subject : subjects) {
List<String> courseNumbers = new ArrayList<String>();
String identifier = subject.getId().toString();
Course[] courses = pyramusClient.get("/common/subjects/" + identifier + "/courses", fi.otavanopisto.pyramus.rest.model.Course[].class);
if (courses != null) {
for (Course course : courses) {
String courseNumber = course.getCourseNumber() != null ? course.getCourseNumber().toString() : "null";
if (!courseNumbers.contains(courseNumber))
courseNumbers.add(courseNumber);
}
for (String cn : courseNumbers) {
result.add(new PyramusCourseIdentifier(subject.getId().toString() + "/" + cn, subject.getCode(), subject.getId().toString()));
}
}
}
}
return result;
}
use of fi.otavanopisto.pyramus.rest.model.Course in project muikku by otavanopisto.
the class PyramusCourseMetaSchoolDataBridge method listCourseIdentifiersBySubject.
@Override
public List<CourseIdentifier> listCourseIdentifiersBySubject(String subjectIdentifier) {
if (!StringUtils.isNumeric(subjectIdentifier)) {
throw new SchoolDataBridgeInternalException("Identifier has to be numeric");
}
// TODO Fix workaround
fi.otavanopisto.pyramus.rest.model.Subject subject = pyramusClient.get("/common/subjects/" + subjectIdentifier, fi.otavanopisto.pyramus.rest.model.Subject.class);
List<CourseIdentifier> result = new ArrayList<>();
List<String> courseNumbers = new ArrayList<String>();
String identifier = subject.getId().toString();
Course[] courses = pyramusClient.get("/common/subjects/" + identifier + "/courses", fi.otavanopisto.pyramus.rest.model.Course[].class);
for (Course course : courses) {
String courseNumber = course.getCourseNumber() != null ? course.getCourseNumber().toString() : "null";
if (!courseNumbers.contains(courseNumber))
courseNumbers.add(courseNumber);
}
for (String cn : courseNumbers) {
result.add(new PyramusCourseIdentifier(subject.getId().toString() + "/" + cn, subject.getCode(), subject.getId().toString()));
}
return result;
}
use of fi.otavanopisto.pyramus.rest.model.Course in project muikku by otavanopisto.
the class PyramusWorkspaceSchoolDataBridge method listWorkspaces.
@Override
public List<Workspace> listWorkspaces() {
List<Workspace> result = new ArrayList<Workspace>();
Course[] courses = pyramusClient.get("/courses/courses/", Course[].class);
if (courses != null) {
for (Course course : courses) {
result.add(createWorkspaceEntity(course));
}
}
return result;
}
use of fi.otavanopisto.pyramus.rest.model.Course in project muikku by otavanopisto.
the class PyramusWorkspaceSchoolDataBridge method updateWorkspace.
@Override
public Workspace updateWorkspace(Workspace workspace) {
Long pyramusCourseId = identifierMapper.getPyramusCourseId(workspace.getIdentifier());
if (pyramusCourseId == null) {
logger.severe(String.format("Workspace identifier %s is not valid", workspace.getIdentifier()));
return null;
}
Long typeId = identifierMapper.getPyramusCourseTypeId(workspace.getWorkspaceTypeId());
Long lengthUnitId = identifierMapper.getPyramusEducationalTimeUnitId(workspace.getLengthUnitIdentifier());
Long subjectId = identifierMapper.getPyramusSubjectId(workspace.getSubjectIdentifier());
Course course = pyramusClient.get(String.format("/courses/courses/%d", pyramusCourseId), Course.class);
course.setName(workspace.getName());
course.setNameExtension(workspace.getNameExtension());
course.setDescription(workspace.getDescription());
course.setBeginDate(workspace.getBeginDate());
course.setEndDate(workspace.getEndDate());
course.setLength(workspace.getLength());
course.setLengthUnitId(lengthUnitId);
course.setTypeId(typeId);
course.setSubjectId(subjectId);
Course updatedCourse = pyramusClient.put(String.format("/courses/courses/%d", pyramusCourseId), course);
if (updatedCourse == null) {
logger.severe(String.format("Workspace %s updating failed", workspace.getIdentifier()));
return null;
}
return createWorkspaceEntity(updatedCourse);
}
use of fi.otavanopisto.pyramus.rest.model.Course in project muikku by otavanopisto.
the class PyramusMocks method workspacePyramusMock.
public static void workspacePyramusMock(Long id, String name, String description) throws Exception {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
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(id, name, created, created, description, 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) 1, null, null);
String courseJson = objectMapper.writeValueAsString(course);
stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d", id))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
Course[] courseArray = { course };
String courseArrayJson = objectMapper.writeValueAsString(courseArray);
stubFor(get(urlEqualTo("/1/courses/courses")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseArrayJson).withStatus(200)));
stubFor(get(urlMatching("/1/courses/courses?filterArchived=false&firstResult=.*&maxResults=.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseArrayJson).withStatus(200)));
stubFor(put(urlEqualTo(String.format("/1/courses/courses/%d", id))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
mockStudyProgrammes();
mockCommons();
mockCourseTypes();
String payload = objectMapper.writeValueAsString(new WebhookCourseCreatePayload(course.getId()));
TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
}
Aggregations