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));
}
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;
}
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));
}
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)));
}
}
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)));
}
Aggregations