use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.
the class PyramusCourseMetaSchoolDataBridge method findCourseIdentifier.
@Override
public CourseIdentifier findCourseIdentifier(String identifier) {
if (StringUtils.isBlank(identifier)) {
return null;
}
if (identifier.indexOf("/") == -1)
throw new SchoolDataBridgeInternalException("Invalid CourseIdentifierId");
String[] idParts = identifier.split("/");
fi.otavanopisto.pyramus.rest.model.Subject subject = pyramusClient.get("/common/subjects/" + idParts[0], fi.otavanopisto.pyramus.rest.model.Subject.class);
return new PyramusCourseIdentifier(identifier, subject.getCode() + idParts[1], subject.getId().toString());
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.
the class PyramusUserSchoolDataBridge method getUserProperty.
@Override
public UserProperty getUserProperty(String userIdentifier, String key) {
Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
if (studentId != null) {
Student student = pyramusClient.get("/students/students/" + studentId, Student.class);
Map<String, String> variables = student.getVariables();
String value = variables.get(key);
if (value == null) {
return null;
} else {
return new PyramusUserProperty(userIdentifier, key, value);
}
}
logger.warning(String.format("PyramusUserSchoolDataBridge.getUserProperty 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.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.
the class PyramusUserSchoolDataBridge method listUserAddresses.
@Override
public List<UserAddress> listUserAddresses(SchoolDataIdentifier userIdentifier) {
if (!StringUtils.equals(userIdentifier.getDataSource(), getSchoolDataSource())) {
throw new SchoolDataBridgeInternalException(String.format("Could not list email addresses for user from school data source %s", userIdentifier.getDataSource()));
}
Address[] addresses = null;
Long pyramusStudentId = identifierMapper.getPyramusStudentId(userIdentifier.getIdentifier());
if (pyramusStudentId != null) {
addresses = pyramusClient.get(String.format("/students/students/%d/addresses", pyramusStudentId), Address[].class);
} else {
Long pyramusStaffId = identifierMapper.getPyramusStaffId(userIdentifier.getIdentifier());
if (pyramusStaffId != null) {
addresses = pyramusClient.get(String.format("/staff/members/%d/addresses", pyramusStaffId), Address[].class);
}
}
if (addresses == null) {
return Collections.emptyList();
}
List<UserAddress> result = new ArrayList<>(addresses.length);
for (Address address : addresses) {
ContactType contactType = address.getContactTypeId() != null ? pyramusClient.get(String.format("/common/contactTypes/%d", address.getContactTypeId()), ContactType.class) : null;
result.add(entityFactory.createEntity(userIdentifier, address, contactType));
}
return result;
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException 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.muikku.schooldata.SchoolDataBridgeInternalException 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));
}
Aggregations