Search in sources :

Example 21 with SchoolDataIdentifier

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

the class UserIndexer method indexUser.

public void indexUser(UserEntity userEntity) {
    schoolDataBridgeSessionController.startSystemSession();
    try {
        List<UserSchoolDataIdentifier> identifiers = userSchoolDataIdentifierController.listUserSchoolDataIdentifiersByUserEntity(userEntity);
        for (UserSchoolDataIdentifier schoolDataIdentifier : identifiers) {
            SchoolDataIdentifier identifier = new SchoolDataIdentifier(schoolDataIdentifier.getIdentifier(), schoolDataIdentifier.getDataSource().getIdentifier());
            indexUser(identifier);
        }
    } finally {
        schoolDataBridgeSessionController.endSystemSession();
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)

Example 22 with SchoolDataIdentifier

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

the class ForgotPasswordController method getUsername.

public String getUsername(String confirmationHash) {
    UserPendingPasswordChange userPendingPasswordChange = userPendingPasswordChangeDAO.findByConfirmationHash(confirmationHash);
    if (userPendingPasswordChange != null) {
        Long userEntityId = userPendingPasswordChange.getUserEntity();
        if (userEntityId == null) {
            logger.severe(String.format("UserPendingPasswordChange with hash %s did not contain userEnityId", confirmationHash));
            return null;
        }
        UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
        if (userEntity == null) {
            logger.severe(String.format("UserPendingPasswordChange with hash %s contained invalid userEnityId", confirmationHash));
            return null;
        }
        schoolDataBridgeSessionController.startSystemSession();
        try {
            User user = userSchoolDataController.findUser(userEntity.getDefaultSchoolDataSource(), userEntity.getDefaultIdentifier());
            if (user == null) {
                logger.severe(String.format("Failed to retrieve user for UserEntity %d", userEntity.getId()));
                return null;
            }
            SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(user.getIdentifier(), user.getSchoolDataSource());
            try {
                return userSchoolDataController.findUsername(user);
            } catch (Exception e) {
                logger.log(Level.SEVERE, String.format("Failed to fetch username for user %s", userIdentifier.toId()));
                return null;
            }
        } finally {
            schoolDataBridgeSessionController.endSystemSession();
        }
    }
    return null;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) UserPendingPasswordChange(fi.otavanopisto.muikku.plugins.user.UserPendingPasswordChange) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException)

Example 23 with SchoolDataIdentifier

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

the class NotifierEmailMethod method sendNotification.

@Override
public void sendNotification(NotifierAction action, NotifierContext context) {
    NotifierEmailMessageComposer message = emailMessageComposer.select(new NotifierEmailContentAnnotationLiteral(action.getName())).get();
    if (message != null) {
        // List email addresses of user entity (only default identifier)
        UserEntity userEntity = context.getRecipient();
        SchoolDataIdentifier identifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
        List<String> addresses = userEmailEntityController.getUserEmailAddresses(identifier);
        if (CollectionUtils.isNotEmpty(addresses))
            mailer.sendMail(message.getEmailMimeType(context), systemSettingsController.getSystemEmailSenderAddress(), addresses, message.getEmailSubject(context), message.getEmailContent(context));
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 24 with SchoolDataIdentifier

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

the class SchoolDataIndexListeners method onSchoolDataUserUpdatedEvent.

public void onSchoolDataUserUpdatedEvent(@Observes SchoolDataUserUpdatedEvent event) {
    List<SchoolDataIdentifier> removeIdentifiers = new ArrayList<>(event.getRemovedIdentifiers());
    List<SchoolDataIdentifier> updatedIdentifiers = new ArrayList<>(event.getDiscoveredIdentifiers());
    updatedIdentifiers.addAll(event.getUpdatedIdentifiers());
    for (SchoolDataIdentifier identifier : updatedIdentifiers) {
        userIndexer.indexUser(identifier.getDataSource(), identifier.getIdentifier());
    }
    for (SchoolDataIdentifier identifier : removeIdentifiers) {
        userIndexer.removeUser(identifier.getDataSource(), identifier.getIdentifier());
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) ArrayList(java.util.ArrayList)

Example 25 with SchoolDataIdentifier

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

the class Evaluation2RESTService method listAssessmentRequests.

@GET
@Path("/compositeAssessmentRequests")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listAssessmentRequests(@QueryParam("workspaceEntityId") Long workspaceEntityId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<RestAssessmentRequest> restAssessmentRequests = new ArrayList<RestAssessmentRequest>();
    if (workspaceEntityId == null) {
        // List assessment requests by staff member
        SchoolDataIdentifier loggedUser = sessionController.getLoggedUser();
        List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByStaffMember(loggedUser);
        for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
            restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
        }
    } else {
        // List assessment requests by workspace
        List<String> workspaceStudentIdentifiers = new ArrayList<String>();
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
        SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
        List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
        for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
            workspaceStudentIdentifiers.add(workspaceUserEntity.getIdentifier());
        }
        List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByWorkspace(workspaceIdentifier, workspaceStudentIdentifiers);
        for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
            restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
        }
    }
    return Response.ok(restAssessmentRequests).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ArrayList(java.util.ArrayList) RestAssessmentRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessmentRequest) CompositeAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.CompositeAssessmentRequest) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)130 Path (javax.ws.rs.Path)63 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)59 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)58 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)53 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)50 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)48 ArrayList (java.util.ArrayList)38 GET (javax.ws.rs.GET)36 User (fi.otavanopisto.muikku.schooldata.entity.User)30 HashMap (java.util.HashMap)19 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)13 SearchResult (fi.otavanopisto.muikku.search.SearchResult)13 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)12 Date (java.util.Date)11 POST (javax.ws.rs.POST)11 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)10 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)10 HashSet (java.util.HashSet)9 PUT (javax.ws.rs.PUT)9