Search in sources :

Example 16 with SchoolDataBridgeInternalException

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

the class PyramusUserSchoolDataBridge method listUserPropertiesByUser.

@Override
public List<UserProperty> listUserPropertiesByUser(String userIdentifier) {
    Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
    if (studentId != null) {
        Student student = pyramusClient.get("/students/students/" + studentId, Student.class);
        Map<String, String> variables = student.getVariables();
        List<UserProperty> userProperties = new ArrayList<>();
        for (String key : variables.keySet()) {
            String value = variables.get(key);
            if (value != null) {
                userProperties.add(new PyramusUserProperty(userIdentifier, key, value));
            }
        }
        return userProperties;
    }
    logger.warning(String.format("PyramusUserSchoolDataBridge.listUserPropertiesByUser 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) UserProperty(fi.otavanopisto.muikku.schooldata.entity.UserProperty) PyramusUserProperty(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)

Example 17 with SchoolDataBridgeInternalException

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

the class PyramusUserSchoolDataBridge method updateUserCredentials.

@Override
public void updateUserCredentials(String userIdentifier, String oldPassword, String newUsername, String newPassword) {
    Long personId = getPersonId(userIdentifier);
    if (personId == null) {
        logger.warning(String.format("PyramusUserSchoolDataBridge.updateUserCredentials malformed user identifier %s", userIdentifier));
        throw new SchoolDataBridgeInternalException(String.format("Malformed user identifier %s\n%s", userIdentifier, ExceptionUtils.getStackTrace(new Throwable())));
    }
    try {
        UserCredentials change = new UserCredentials(oldPassword, newUsername, newPassword);
        pyramusClient.put("/persons/persons/" + personId + "/credentials", change);
    } catch (PyramusRestClientUnauthorizedException purr) {
        throw new SchoolDataBridgeUnauthorizedException(purr.getMessage());
    }
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException) UserCredentials(fi.otavanopisto.pyramus.rest.model.UserCredentials) PyramusRestClientUnauthorizedException(fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException)

Example 18 with SchoolDataBridgeInternalException

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

the class LocalUserSchoolDataBridge method updateUser.

/**
 * {@inheritDoc}
 */
@Override
public User updateUser(User user) {
    if (StringUtils.isNotBlank(user.getFirstName())) {
        throw new SchoolDataBridgeInternalException("firstName is required");
    }
    if (StringUtils.isNotBlank(user.getLastName())) {
        throw new SchoolDataBridgeInternalException("lastName is required");
    }
    LocalUser localUser = localUserSchoolDataController.findUser(user.getIdentifier());
    if (localUser != null) {
        localUserSchoolDataController.updateUserFirstName(localUser, user.getFirstName());
        localUserSchoolDataController.updateUserLastName(localUser, user.getLastName());
        return toLocalUserImpl(localUser);
    }
    throw new SchoolDataBridgeInternalException("Unexpected error occured while creating LocalUser");
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) LocalUser(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUser)

Example 19 with SchoolDataBridgeInternalException

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

the class LocalUserSchoolDataBridge method listUserImagesByUserIdentifier.

/**
 * {@inheritDoc}
 */
@Override
public List<UserImage> listUserImagesByUserIdentifier(String userIdentifier) {
    List<UserImage> result = new ArrayList<>();
    List<LocalUserImage> images = localUserSchoolDataController.listUserImagesByUserIdentifier(userIdentifier);
    for (LocalUserImage image : images) {
        UserImage userImage = toLocalUserImageImpl(image);
        if (userImage != null) {
            result.add(userImage);
        } else {
            throw new SchoolDataBridgeInternalException("Unexpected error occured while listing LocalUserImages");
        }
    }
    return result;
}
Also used : LocalUserImage(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserImage) UserImage(fi.otavanopisto.muikku.schooldata.entity.UserImage) LocalUserImage(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserImage) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList)

Example 20 with SchoolDataBridgeInternalException

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

the class LocalUserSchoolDataBridge method removeUserImage.

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

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