Search in sources :

Example 1 with SchoolDataBridgeInternalException

use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.

the class PyramusUserSchoolDataBridge method setUserProperty.

@Override
public UserProperty setUserProperty(String userIdentifier, String key, String value) {
    Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
    if (studentId != null) {
        Student student = pyramusClient.get("/students/students/" + studentId, Student.class);
        Map<String, String> variables = student.getVariables();
        variables.put(key, value);
        student.setVariables(variables);
        pyramusClient.put(String.format("/students/students/%d", studentId), student);
        return new PyramusUserProperty(userIdentifier, key, value);
    }
    logger.warning(String.format("PyramusUserSchoolDataBridge.setUserProperty 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 2 with SchoolDataBridgeInternalException

use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.

the class PyramusUserSchoolDataBridge method findRole.

@Override
public Role findRole(String identifier) {
    UserRole pyramusUserRole = identifierMapper.getPyramusUserRole(identifier);
    if (pyramusUserRole != null) {
        return entityFactory.createEntity(pyramusUserRole);
    }
    String id = identifierMapper.getPyramusCourseRoleId(identifier);
    if (StringUtils.isBlank(id)) {
        throw new SchoolDataBridgeInternalException("Malformed role identifier");
    }
    if ("STUDENT".equals(id)) {
        return entityFactory.createCourseStudentRoleEntity();
    }
    return entityFactory.createEntity(pyramusClient.get("/courses/staffMemberRoles/" + id, CourseStaffMemberRole.class));
}
Also used : CourseStaffMemberRole(fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole) UserRole(fi.otavanopisto.pyramus.rest.model.UserRole) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)

Example 3 with SchoolDataBridgeInternalException

use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.

the class PyramusWorkspaceSchoolDataBridge method listWorkspacesByCourseIdentifier.

@Override
public List<Workspace> listWorkspacesByCourseIdentifier(String courseIdentifierIdentifier) {
    if (courseIdentifierIdentifier.indexOf("/") == -1)
        throw new SchoolDataBridgeInternalException("Invalid CourseIdentifierId");
    String subjectId = courseIdentifierIdentifier.substring(0, courseIdentifierIdentifier.indexOf("/"));
    String courseNumber = courseIdentifierIdentifier.substring(courseIdentifierIdentifier.indexOf("/") + 1);
    Course[] courses = pyramusClient.get("/common/subjects/" + subjectId + "/courses", fi.otavanopisto.pyramus.rest.model.Course[].class);
    List<Workspace> result = new ArrayList<Workspace>();
    for (Course course : courses) {
        String courseNumber2 = course.getCourseNumber() != null ? course.getCourseNumber().toString() : "null";
        if (courseNumber.equals(courseNumber2))
            result.add(createWorkspaceEntity(course));
    }
    return result;
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList) Course(fi.otavanopisto.pyramus.rest.model.Course) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace)

Example 4 with SchoolDataBridgeInternalException

use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.

the class LocalUserSchoolDataBridge method findUserEnvironmentRole.

/**
 * {@inheritDoc}
 */
public Role findUserEnvironmentRole(String userIdentifier) {
    LocalUser user = localUserSchoolDataController.findUser(userIdentifier);
    if (user == null) {
        throw new SchoolDataBridgeInternalException("User not found");
    }
    Long roleId = user.getRoleId();
    if (roleId != null) {
        RoleEntity roleEntity = localUserSchoolDataController.findCoreRoleEntityById(roleId);
        if (roleEntity == null) {
            throw new SchoolDataBridgeInternalException("User role could not be found");
        }
        return toLocalRoleEntity(roleEntity);
    }
    return null;
}
Also used : WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) RoleEntity(fi.otavanopisto.muikku.model.users.RoleEntity) EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) LocalUser(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUser)

Example 5 with SchoolDataBridgeInternalException

use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.

the class LocalUserSchoolDataBridge method removeUserEmail.

/**
 * {@inheritDoc}
 */
@Override
public void removeUserEmail(String identifier) {
    LocalUserEmail localUserEmail = localUserSchoolDataController.findUserEmail(identifier);
    if (localUserEmail == null) {
        throw new SchoolDataBridgeInternalException("UserEmail can not be removed because it does not exist");
    }
    localUserSchoolDataController.removeUserEmail(localUserEmail);
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) LocalUserEmail(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)

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