use of fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceStaffMember in project muikku by otavanopisto.
the class WorkspaceRESTService method listWorkspaceStaffMembers.
@GET
@Path("/workspaces/{ID}/staffMembers")
@RESTPermitUnimplemented
public Response listWorkspaceStaffMembers(@PathParam("ID") Long workspaceEntityId, @QueryParam("orderBy") String orderBy) {
// Workspace
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
// Access check
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.LIST_WORKSPACE_MEMBERS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
// Staff via WorkspaceSchoolDataBridge
List<fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser> schoolDataUsers = workspaceController.listWorkspaceStaffMembers(workspaceEntity);
List<WorkspaceStaffMember> workspaceStaffMembers = new ArrayList<>();
for (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser workspaceUser : schoolDataUsers) {
SchoolDataIdentifier userIdentifier = workspaceUser.getUserIdentifier();
User user = userController.findUserByIdentifier(userIdentifier);
if (user != null) {
UserEntity userEntity = userEntityController.findUserEntityByUser(user);
// #3111: Workspace staff members should be limited to teachers only. A better implementation would support specified workspace roles
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
if (workspaceUserEntity == null || workspaceUserEntity.getWorkspaceUserRole().getArchetype() != WorkspaceRoleArchetype.TEACHER) {
continue;
}
workspaceStaffMembers.add(new WorkspaceStaffMember(workspaceUser.getIdentifier().toId(), workspaceUser.getUserIdentifier().toId(), userEntity != null ? userEntity.getId() : null, user.getFirstName(), user.getLastName()));
} else {
logger.log(Level.SEVERE, String.format("Could not find user %s", userIdentifier));
}
}
// Sorting
if (StringUtils.equals(orderBy, "name")) {
Collections.sort(workspaceStaffMembers, new Comparator<WorkspaceStaffMember>() {
@Override
public int compare(WorkspaceStaffMember o1, WorkspaceStaffMember o2) {
String s1 = String.format("%s, %s", StringUtils.defaultString(o1.getLastName(), ""), StringUtils.defaultString(o1.getFirstName(), ""));
String s2 = String.format("%s, %s", StringUtils.defaultString(o2.getLastName(), ""), StringUtils.defaultString(o2.getFirstName(), ""));
return s1.compareTo(s2);
}
});
}
// Response
return Response.ok(workspaceStaffMembers).build();
}
Aggregations