use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class PyramusUpdater method updateCourseStaffMember.
/**
* Updates course staff member from Pyramus
*
* @param courseStaffMemberId id of course staff member in Pyramus
* @param courseId id of course in Pyramus
* @param staffMemberId id of staff member in Pyramus
* @return returns whether new staff member was created or not
*/
public boolean updateCourseStaffMember(Long courseStaffMemberId, Long courseId, Long staffMemberId) {
String workspaceIdentifier = identifierMapper.getWorkspaceIdentifier(courseId);
String identifier = identifierMapper.getWorkspaceStaffIdentifier(courseStaffMemberId);
// TODO: course staff member removals can be left unnoticed if
// webhooks fails because they do not have archived flag
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
if (workspaceEntity == null) {
updateCourse(courseId);
workspaceEntity = workspaceController.findWorkspaceEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
}
if (workspaceEntity != null) {
SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(identifier, SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE);
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
CourseStaffMember staffMember = pyramusClient.get().get("/courses/courses/" + courseId + "/staffMembers/" + courseStaffMemberId, CourseStaffMember.class);
if (staffMember != null) {
if (workspaceUserEntity == null) {
fireCourseStaffMemberDiscovered(staffMember);
return true;
} else {
fireCourseStaffMemberUpdated(staffMember);
}
} else {
if (workspaceUserEntity != null) {
fireCourseStaffMemberRemoved(courseStaffMemberId, staffMemberId, courseId);
return true;
}
}
}
return false;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class PyramusUpdater method updateCourseStaffMembers.
/**
* Updates course staff members from Pyramus
*
* @param courseId id of course in Pyramus
* @return count of updated courses staff members
*/
public int updateCourseStaffMembers(Long courseId) {
// List of staff members according to Muikku
List<WorkspaceUserEntity> currentStaffMembers;
String workspaceIdentifier = identifierMapper.getWorkspaceIdentifier(courseId);
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
if (workspaceEntity != null) {
currentStaffMembers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
} else {
currentStaffMembers = Collections.emptyList();
}
// List of staff members according to Pyramus
CourseStaffMember[] staffMembers = pyramusClient.get().get("/courses/courses/" + courseId + "/staffMembers", CourseStaffMember[].class);
if (staffMembers != null) {
for (CourseStaffMember staffMember : staffMembers) {
String staffIdentifier = identifierMapper.getWorkspaceStaffIdentifier(staffMember.getId());
SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(staffIdentifier, SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE);
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
if (workspaceUserEntity == null) {
fireCourseStaffMemberDiscovered(staffMember);
} else {
for (int i = currentStaffMembers.size() - 1; i >= 0; i--) {
if (currentStaffMembers.get(i).getId().equals(workspaceUserEntity.getId())) {
currentStaffMembers.remove(i);
}
}
}
}
}
for (WorkspaceUserEntity currentStaffMember : currentStaffMembers) {
try {
String courseStaffMemberIdentifier = currentStaffMember.getIdentifier();
String staffMemberIdentifier = currentStaffMember.getUserSchoolDataIdentifier().getUserEntity().getDefaultIdentifier();
Long courseStaffMemberId = identifierMapper.getPyramusCourseStaffId(courseStaffMemberIdentifier);
Long staffMemberId = identifierMapper.getPyramusStaffId(staffMemberIdentifier);
fireCourseStaffMemberRemoved(courseStaffMemberId, staffMemberId, courseId);
} catch (Exception e) {
logger.log(Level.WARNING, String.format("Error re-syncing WorkspaceUserEntity %d", currentStaffMember.getId()), e);
}
}
return 0;
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class UserRESTService method searchStaffMembers.
@GET
@Path("/staffMembers")
@RESTPermit(handling = Handling.INLINE)
public Response searchStaffMembers(@QueryParam("searchString") String searchString, @QueryParam("properties") String properties, @QueryParam("workspaceEntityId") Long workspaceEntityId, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.FORBIDDEN).build();
}
List<fi.otavanopisto.muikku.rest.model.StaffMember> staffMembers = new ArrayList<>();
Set<Long> userGroupFilters = null;
Set<Long> workspaceFilters = workspaceEntityId == null ? null : Collections.singleton(workspaceEntityId);
List<SchoolDataIdentifier> userIdentifiers = null;
SearchProvider elasticSearchProvider = getProvider("elastic-search");
if (elasticSearchProvider != null) {
String[] fields;
if (StringUtils.isNumeric(searchString)) {
fields = new String[] { "firstName", "lastName", "userEntityId", "email" };
} else {
fields = new String[] { "firstName", "lastName", "email" };
}
List<EnvironmentRoleArchetype> nonStudentArchetypes = new ArrayList<>(Arrays.asList(EnvironmentRoleArchetype.values()));
nonStudentArchetypes.remove(EnvironmentRoleArchetype.STUDENT);
SearchResult result = elasticSearchProvider.searchUsers(searchString, fields, nonStudentArchetypes, userGroupFilters, workspaceFilters, userIdentifiers, false, false, false, firstResult, maxResults);
List<Map<String, Object>> results = result.getResults();
if (results != null && !results.isEmpty()) {
WorkspaceEntity workspaceEntity = workspaceEntityId == null ? null : workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
String[] propertyArray = StringUtils.isEmpty(properties) ? new String[0] : properties.split(",");
for (Map<String, Object> o : results) {
String studentId = (String) o.get("id");
if (StringUtils.isBlank(studentId)) {
logger.severe("Could not process user found from search index because it had a null id");
continue;
}
String[] studentIdParts = studentId.split("/", 2);
SchoolDataIdentifier studentIdentifier = studentIdParts.length == 2 ? new SchoolDataIdentifier(studentIdParts[0], studentIdParts[1]) : null;
if (studentIdentifier == null) {
logger.severe(String.format("Could not process user found from search index with id %s", studentId));
continue;
}
if (studentIdentifier.getIdentifier().startsWith("STUDENT-")) {
// the elasticsearch query returns both. We need to filter them after the fact.
continue;
}
String email = userEmailEntityController.getUserDefaultEmailAddress(studentIdentifier, false);
Long userEntityId = new Long((Integer) o.get("userEntityId"));
UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
Map<String, String> propertyMap = new HashMap<String, String>();
if (userEntity != null) {
for (int i = 0; i < propertyArray.length; i++) {
UserEntityProperty userEntityProperty = userEntityController.getUserEntityPropertyByKey(userEntity, propertyArray[i]);
propertyMap.put(propertyArray[i], userEntityProperty == null ? null : userEntityProperty.getValue());
}
}
if (workspaceEntity != null) {
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
if (workspaceUserEntity == null || workspaceUserEntity.getWorkspaceUserRole().getArchetype() != WorkspaceRoleArchetype.TEACHER) {
continue;
}
}
staffMembers.add(new fi.otavanopisto.muikku.rest.model.StaffMember(studentIdentifier.toId(), new Long((Integer) o.get("userEntityId")), (String) o.get("firstName"), (String) o.get("lastName"), email, propertyMap));
}
}
}
return Response.ok(staffMembers).build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class WorkspaceUserEntityDAO method create.
public WorkspaceUserEntity create(UserSchoolDataIdentifier userSchoolDataIdentifier, WorkspaceEntity workspaceEntity, WorkspaceRoleEntity workspaceUserRole, String identifier, Boolean active, Boolean archived) {
WorkspaceUserEntity workspaceUserEntity = new WorkspaceUserEntity();
workspaceUserEntity.setUserSchoolDataIdentifier(userSchoolDataIdentifier);
workspaceUserEntity.setWorkspaceEntity(workspaceEntity);
workspaceUserEntity.setWorkspaceUserRole(workspaceUserRole);
workspaceUserEntity.setIdentifier(identifier);
workspaceUserEntity.setActive(active);
workspaceUserEntity.setArchived(archived);
return persist(workspaceUserEntity);
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity in project muikku by otavanopisto.
the class GuiderRESTService method getWorkspaceAssessmentsStudyProgressAnalysis.
@GET
@Path("/workspaces/{WORKSPACEENTITYID}/studentactivity/{USERIDENTIFIER}")
@RESTPermit(GuiderPermissions.GUIDER_FIND_STUDENT_WORKSPACE_ACTIVITY)
public Response getWorkspaceAssessmentsStudyProgressAnalysis(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERIDENTIFIER") String userId) {
SchoolDataIdentifier userIdentifier = SchoolDataIdentifier.fromId(userId);
if (userIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid userIdentifier").build();
}
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity("WorkspaceEntity not found").build();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifier(workspaceEntity, userIdentifier);
if (workspaceUserEntity == null) {
return Response.status(Status.NOT_FOUND).entity("WorkspaceUserEntity not found").build();
}
GuiderStudentWorkspaceActivity activity = guiderController.getStudentWorkspaceActivity(workspaceEntity, userIdentifier);
if (activity == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to analyze assignments progress for student %s in workspace %d", userIdentifier, workspaceEntity.getId())).build();
}
WorkspaceAssessmentState assessmentState = assessmentRequestController.getWorkspaceAssessmentState(workspaceUserEntity);
return Response.ok(toRestModel(activity, assessmentState)).build();
}
Aggregations