Search in sources :

Example 6 with SchoolDataBridgeInternalException

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());
}
Also used : PyramusCourseIdentifier(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)

Example 7 with SchoolDataBridgeInternalException

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));
}
Also used : PyramusUserProperty(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)

Example 8 with SchoolDataBridgeInternalException

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;
}
Also used : ContactType(fi.otavanopisto.pyramus.rest.model.ContactType) UserAddress(fi.otavanopisto.muikku.schooldata.entity.UserAddress) Address(fi.otavanopisto.pyramus.rest.model.Address) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList) UserAddress(fi.otavanopisto.muikku.schooldata.entity.UserAddress)

Example 9 with SchoolDataBridgeInternalException

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));
}
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 10 with SchoolDataBridgeInternalException

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

Aggregations

SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)21 Student (fi.otavanopisto.pyramus.rest.model.Student)7 StudentGroupStudent (fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)7 ArrayList (java.util.ArrayList)7 PyramusUserProperty (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty)3 StaffMember (fi.otavanopisto.pyramus.rest.model.StaffMember)3 LocalUser (fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUser)2 LocalUserEmail (fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)2 LocalUserImage (fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserImage)2 PyramusCourseIdentifier (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier)2 PyramusRestClientUnauthorizedException (fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException)2 SchoolDataBridgeUnauthorizedException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException)2 UserAddress (fi.otavanopisto.muikku.schooldata.entity.UserAddress)2 Address (fi.otavanopisto.pyramus.rest.model.Address)2 ContactType (fi.otavanopisto.pyramus.rest.model.ContactType)2 Course (fi.otavanopisto.pyramus.rest.model.Course)2 EnvironmentRoleEntity (fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity)1 RoleEntity (fi.otavanopisto.muikku.model.users.RoleEntity)1 WorkspaceRoleEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)1 CourseIdentifier (fi.otavanopisto.muikku.schooldata.entity.CourseIdentifier)1