use of fi.otavanopisto.pyramus.rest.model.StudentGroupStudent in project muikku by otavanopisto.
the class PyramusUpdater method updateStudentGroupUsers.
public int updateStudentGroupUsers(Long studentGroupId) {
String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, userGroupIdentifier, true);
if (userGroupEntity != null) {
if (userGroupEntity.getArchived()) {
// Just skip archived user groups
return 0;
}
List<UserGroupUserEntity> existingUsers = userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(userGroupEntity);
List<String> existingGroupUserIds = new ArrayList<String>();
for (UserGroupUserEntity existingUser : existingUsers) {
existingGroupUserIds.add(existingUser.getIdentifier());
}
List<String> foundGroupUserIds = new ArrayList<String>();
int count = 0;
StudentGroupUser[] userGroupStaffMembers = pyramusClient.get().get(String.format("/students/studentGroups/%d/staffmembers", studentGroupId), StudentGroupUser[].class);
if (userGroupStaffMembers != null) {
for (StudentGroupUser sgStaffMember : userGroupStaffMembers) {
String identifier = identifierMapper.getStudentGroupStaffMemberIdentifier(sgStaffMember.getId());
foundGroupUserIds.add(identifier);
// If not existing, then it's a new one
if (!existingGroupUserIds.contains(identifier)) {
String staffMemberIdentifier = identifierMapper.getStaffIdentifier(sgStaffMember.getStaffMemberId());
fireUserGroupUserDiscovered(identifier, userGroupIdentifier, staffMemberIdentifier);
}
}
count += userGroupStaffMembers.length;
}
StudentGroupStudent[] userGroupStudents = pyramusClient.get().get(String.format("/students/studentGroups/%d/students", studentGroupId), StudentGroupStudent[].class);
if (userGroupStudents != null) {
for (StudentGroupStudent sgs : userGroupStudents) {
String identifier = identifierMapper.getStudentGroupStudentIdentifier(sgs.getId());
foundGroupUserIds.add(identifier);
// If not existing, then it's a new one
if (!existingGroupUserIds.contains(identifier)) {
String studentIdentifier = identifierMapper.getStudentIdentifier(sgs.getStudentId());
fireUserGroupUserDiscovered(identifier, userGroupIdentifier, studentIdentifier);
}
}
count += userGroupStudents.length;
}
// Remove found ids from existing and we'll get the ones to remove
existingGroupUserIds.removeAll(foundGroupUserIds);
for (String identifier : existingGroupUserIds) {
UserGroupUserEntity ugu = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
if (ugu != null)
fireUserGroupUserRemoved(identifier, userGroupIdentifier, ugu.getUserSchoolDataIdentifier().getIdentifier());
}
return count;
} else {
logger.log(Level.WARNING, String.format("UserGroup is null for id %d - update of users is skipped", studentGroupId));
}
return 0;
}
use of fi.otavanopisto.pyramus.rest.model.StudentGroupStudent in project muikku by otavanopisto.
the class PyramusUpdater method updateStudentGroupStudent.
public void updateStudentGroupStudent(Long studentGroupId, Long studentGroupStudentId) {
StudentGroupStudent studentGroupStudent = pyramusClient.get().get(String.format("/students/studentGroups/%d/students/%d", studentGroupId, studentGroupStudentId), StudentGroupStudent.class);
String identifier = identifierMapper.getStudentGroupStudentIdentifier(studentGroupStudentId);
UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
if (studentGroupStudent == null) {
if (userGroupUserEntity != null)
fireUserGroupUserRemoved(identifier, userGroupIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
} else {
String studentIdentifier = identifierMapper.getStudentIdentifier(studentGroupStudent.getStudentId());
if (userGroupUserEntity == null) {
fireUserGroupUserDiscovered(identifier, userGroupIdentifier, studentIdentifier);
} else {
fireUserGroupUserUpdated(identifier, userGroupIdentifier, studentIdentifier);
}
}
}
use of fi.otavanopisto.pyramus.rest.model.StudentGroupStudent in project muikku by otavanopisto.
the class PyramusMocksRest method mockUserGroups.
public static void mockUserGroups(List<String> payloads) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
OffsetDateTime begin = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
Long creatorId = 1l;
Long groupId = 2l;
StudentGroup studentGroup = new StudentGroup(groupId, "Group1", "", begin, creatorId, begin, creatorId, begin, null, false, false);
StudentGroup[] studentGroups = new StudentGroup[] { studentGroup };
stubFor(get(urlEqualTo("/1/students/studentGroups")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroups)).withStatus(200)));
stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d", groupId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroup)).withStatus(200)));
addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentGroupCreatePayload(groupId)));
StudentGroupUser studentGroupStaffMember = new StudentGroupUser(1l, 4l);
StudentGroupUser[] studentGroupStaffMembers = { studentGroupStaffMember };
stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/staffmembers", groupId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStaffMembers)).withStatus(200)));
stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/staffmembers/%d", groupId, studentGroupStaffMember.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStaffMember)).withStatus(200)));
addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentGroupStaffMemberCreatePayload(studentGroupStaffMember.getId(), groupId, studentGroupStaffMember.getStaffMemberId())));
StudentGroupStudent studentGroupStudent = new StudentGroupStudent(2l, 1l);
StudentGroupStudent[] studentGroupStudents = { studentGroupStudent };
stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/students", groupId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStudents)).withStatus(200)));
stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/students/%d", groupId, studentGroupStudent.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStudent)).withStatus(200)));
addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentGroupStudentCreatePayload(studentGroupStudent.getId(), groupId, studentGroupStudent.getStudentId())));
}
Aggregations