Search in sources :

Example 1 with StaffMember

use of fi.otavanopisto.pyramus.rest.model.StaffMember in project muikku by otavanopisto.

the class PyramusUserSchoolDataBridge method findUser.

@Override
public User findUser(String identifier) {
    Long studentId = identifierMapper.getPyramusStudentId(identifier);
    if (studentId != null) {
        Student student = findPyramusStudent(studentId);
        return createStudentEntity(student);
    }
    Long staffId = identifierMapper.getPyramusStaffId(identifier);
    if (staffId != null) {
        StaffMember staffMember = findPyramusStaffMember(staffId);
        return staffMember == null ? null : entityFactory.createEntity(staffMember);
    }
    logger.warning(String.format("PyramusUserSchoolDataBridge.findUser malformed user identifier %s\n%s", identifier, ExceptionUtils.getStackTrace(new Throwable())));
    throw new SchoolDataBridgeInternalException(String.format("Malformed user identifier %s", identifier));
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember)

Example 2 with StaffMember

use of fi.otavanopisto.pyramus.rest.model.StaffMember in project muikku by otavanopisto.

the class PyramusUserSchoolDataBridge method getPersonId.

private Long getPersonId(String userIdentifier) {
    Long personId = null;
    Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
    if (studentId != null) {
        Student student = findPyramusStudent(studentId);
        personId = student.getPersonId();
    }
    Long staffId = identifierMapper.getPyramusStaffId(userIdentifier);
    if (staffId != null) {
        StaffMember staffMember = findPyramusStaffMember(staffId);
        personId = staffMember.getPersonId();
    }
    return personId;
}
Also used : Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember)

Example 3 with StaffMember

use of fi.otavanopisto.pyramus.rest.model.StaffMember in project muikku by otavanopisto.

the class PyramusUserSchoolDataBridge method findUserEnvironmentRole.

@Override
public Role findUserEnvironmentRole(String userIdentifier) {
    Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
    if (studentId != null) {
        Student student = pyramusClient.get("/students/students/" + studentId, Student.class);
        return student != null ? entityFactory.createStudentEnvironmentRoleEntity() : null;
    }
    Long staffId = identifierMapper.getPyramusStaffId(userIdentifier);
    if (staffId != null) {
        StaffMember staffMember = pyramusClient.get("/staff/members/" + staffId, StaffMember.class);
        return staffMember != null ? entityFactory.createEntity(staffMember.getRole()) : null;
    }
    logger.warning(String.format("PyramusUserSchoolDataBridge.findUserEnvironmentRole malformed user identifier %s\n%s", userIdentifier, ExceptionUtils.getStackTrace(new Throwable())));
    throw new SchoolDataBridgeInternalException(String.format("Malformed user identifier %s", userIdentifier));
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember)

Example 4 with StaffMember

use of fi.otavanopisto.pyramus.rest.model.StaffMember in project muikku by otavanopisto.

the class AbstractPyramusMocks method mockPersonStaffMembers.

protected static void mockPersonStaffMembers(StaffMember[] staffMembers) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    Map<Long, List<StaffMember>> personStaffMembers = new HashMap<>();
    for (StaffMember staffMember : staffMembers) {
        if (!personStaffMembers.containsKey(staffMember.getPersonId())) {
            personStaffMembers.put(staffMember.getPersonId(), new ArrayList<StaffMember>());
        }
        personStaffMembers.get(staffMember.getPersonId()).add(staffMember);
    }
    for (Long personId : personStaffMembers.keySet()) {
        stubFor(get(urlMatching(String.format("/1/persons/persons/%d/staffMembers", personId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(personStaffMembers.get(personId))).withStatus(200)));
    }
}
Also used : HashMap(java.util.HashMap) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ArrayList(java.util.ArrayList) List(java.util.List) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with StaffMember

use of fi.otavanopisto.pyramus.rest.model.StaffMember in project muikku by otavanopisto.

the class PyramusMocksRest method mockUsers.

public static void mockUsers(List<String> payloads) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    OffsetDateTime birthday = OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
    Person person = mockPerson(1l, birthday, "345345-3453", Sex.MALE, 1l);
    Person staff1 = mockPerson(2l, birthday, "345345-3453", Sex.MALE, 2l);
    Person staff2 = mockPerson(3l, birthday, "345345-3453", Sex.MALE, 3l);
    Person staff3 = mockPerson(4l, birthday, "345345-3453", Sex.MALE, 4l);
    Person staff4 = mockPerson(5l, birthday, "345345-3453", Sex.MALE, 5l);
    Person studentPerson2 = mockPerson(6l, birthday, "345345-3453", Sex.MALE, 6l);
    Person[] personArray = { person, staff1, staff2, staff3, staff4, studentPerson2 };
    String personArrayJson = objectMapper.writeValueAsString(personArray);
    for (Person p : personArray) addPayload(payloads, objectMapper.writeValueAsString(new WebhookPersonCreatePayload(p.getId())));
    stubFor(get(urlMatching("/1/persons/persons?filterArchived=.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(personArrayJson).withStatus(200)));
    stubFor(get(urlEqualTo("/1/persons/persons")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(personArrayJson).withStatus(200)));
    Map<String, String> variables = null;
    List<String> tags = null;
    Student student1 = mockStudent(1l, 1l, "Test", "User", "testuser@example.com", tags, variables, payloads, toDate(2010, 1, 1), getNextYear());
    Student student2 = mockStudent(6l, 6l, "Hidden", "Dragon", "crouchingtiger@example.com", tags, variables, payloads, toDate(2010, 1, 1), toDate(2011, 1, 1));
    StaffMember staffMember1 = mockStaffMember(2l, 2l, "Test", "Staff1member", "teacher@example.com", UserRole.USER, tags, variables, payloads);
    StaffMember staffMember2 = mockStaffMember(3l, 3l, "Test", "Staff2member", "mana@example.com", UserRole.MANAGER, tags, variables, payloads);
    StaffMember staffMember3 = mockStaffMember(4l, 4l, "Test", "Administrator", "admin@example.com", UserRole.ADMINISTRATOR, tags, variables, payloads);
    StaffMember staffMember4 = mockStaffMember(5l, 5l, "Trusted", "System", "trusted@example.com", UserRole.TRUSTED_SYSTEM, tags, variables, payloads);
    Student[] studentArray = { student1, student2 };
    StaffMember[] staffArray = { staffMember1, staffMember2, staffMember3, staffMember4 };
    String studentArrayJson = objectMapper.writeValueAsString(studentArray);
    String staffArrayJson = objectMapper.writeValueAsString(staffArray);
    stubFor(get(urlMatching("/1/students/students?filterArchived=false&firstResult=.*&maxResults=.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentArrayJson).withStatus(200)));
    stubFor(get(urlEqualTo("/1/staff/members")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffArrayJson).withStatus(200)));
    mockPersonStudens(studentArray);
    mockPersonStaffMembers(staffArray);
    ContactType contactType = new ContactType((long) 1, "Koti", false, false);
    ContactType[] contactTypes = { contactType };
    String contactTypeJson = objectMapper.writeValueAsString(contactType);
    stubFor(get(urlMatching("/1/common/contactTypes/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(contactTypeJson).withStatus(200)));
    String contactTypesJson = objectMapper.writeValueAsString(contactTypes);
    stubFor(get(urlEqualTo("/1/common/contactTypes")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(contactTypesJson).withStatus(200)));
}
Also used : WebhookPersonCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookPersonCreatePayload) ContactType(fi.otavanopisto.pyramus.rest.model.ContactType) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember) OffsetDateTime(java.time.OffsetDateTime) Person(fi.otavanopisto.pyramus.rest.model.Person) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

StaffMember (fi.otavanopisto.pyramus.rest.model.StaffMember)13 Student (fi.otavanopisto.pyramus.rest.model.Student)9 StudentGroupStudent (fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)6 CourseStaffMember (fi.otavanopisto.pyramus.rest.model.CourseStaffMember)6 Email (fi.otavanopisto.pyramus.rest.model.Email)5 Person (fi.otavanopisto.pyramus.rest.model.Person)5 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)3 CourseStudent (fi.otavanopisto.pyramus.rest.model.CourseStudent)3 WebhookPersonCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookPersonCreatePayload)3 WebhookStaffMemberCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookStaffMemberCreatePayload)3 OffsetDateTime (java.time.OffsetDateTime)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ContactType (fi.otavanopisto.pyramus.rest.model.ContactType)2 CourseStaffMemberRole (fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole)2 List (java.util.List)2 MockCourseStudent (fi.otavanopisto.muikku.mock.model.MockCourseStudent)1 RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)1