Search in sources :

Example 1 with PyramusUserProperty

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty 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 PyramusUserProperty

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty 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 3 with PyramusUserProperty

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty 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)

Aggregations

PyramusUserProperty (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty)3 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)3 Student (fi.otavanopisto.pyramus.rest.model.Student)3 StudentGroupStudent (fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)3 UserProperty (fi.otavanopisto.muikku.schooldata.entity.UserProperty)1 ArrayList (java.util.ArrayList)1