Search in sources :

Example 71 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class UserEntityController method findUserEntityByEmailAddress.

public UserEntity findUserEntityByEmailAddress(String emailAddress) {
    UserEntity result = null;
    Collection<String> emails = new HashSet<>();
    emails.add(emailAddress);
    List<UserEmailEntity> emailEntities = userEmailEntityDAO.listByAddresses(emails);
    for (UserEmailEntity emailEntity : emailEntities) {
        if (result == null) {
            result = emailEntity.getUserSchoolDataIdentifier().getUserEntity();
        } else if (!result.getId().equals(emailEntity.getUserSchoolDataIdentifier().getUserEntity().getId())) {
            logger.severe(String.format("Email %s resolves to multiple UserEntity instances", emailAddress));
            return null;
        }
    }
    return result;
}
Also used : UserEmailEntity(fi.otavanopisto.muikku.model.users.UserEmailEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) HashSet(java.util.HashSet)

Example 72 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class TranscriptofRecordsRESTService method createHopsRESTModelForStudent.

private HopsRESTModel createHopsRESTModelForStudent(SchoolDataIdentifier userIdentifier) {
    User user = userController.findUserByIdentifier(userIdentifier);
    UserEntity userEntity = userEntityController.findUserEntityByUser(user);
    EnvironmentUser environmentUser = environmentUserController.findEnvironmentUserByUserEntity(userEntity);
    EnvironmentRoleEntity roleEntity = environmentUser.getRole();
    if (!EnvironmentRoleArchetype.STUDENT.equals(roleEntity.getArchetype())) {
        return null;
    }
    TranscriptofRecordsUserProperties userProperties = vopsController.loadUserProperties(user);
    return new HopsRESTModel(userProperties.asString("goalSecondarySchoolDegree"), userProperties.asString("goalMatriculationExam"), userProperties.asString("vocationalYears"), userProperties.asString("goalJustMatriculationExam"), userProperties.asString("justTransferCredits"), userProperties.asString("transferCreditYears"), userProperties.asString("completionYears"), userProperties.asString("mathSyllabus"), userProperties.asString("finnish"), userProperties.asBoolean("swedish"), userProperties.asBoolean("english"), userProperties.asBoolean("german"), userProperties.asBoolean("french"), userProperties.asBoolean("italian"), userProperties.asBoolean("spanish"), userProperties.asString("science"), userProperties.asString("religion"), userProperties.asString("additionalInfo"));
}
Also used : EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity) User(fi.otavanopisto.muikku.schooldata.entity.User) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) TranscriptofRecordsUserProperties(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptofRecordsUserProperties)

Example 73 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class TranscriptofRecordsRESTService method updateHops.

@PUT
@Consumes("application/json")
@Path("/hops")
@RESTPermit(handling = Handling.INLINE)
public Response updateHops(HopsRESTModel model) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.FORBIDDEN).entity("Must be logged in").build();
    }
    SchoolDataIdentifier userIdentifier = sessionController.getLoggedUser();
    User user = userController.findUserByIdentifier(userIdentifier);
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    EnvironmentUser environmentUser = environmentUserController.findEnvironmentUserByUserEntity(userEntity);
    EnvironmentRoleEntity roleEntity = environmentUser.getRole();
    if (!EnvironmentRoleArchetype.STUDENT.equals(roleEntity.getArchetype())) {
        return Response.status(Status.FORBIDDEN).entity("Must be a student").build();
    }
    vopsController.saveStringProperty(user, "goalSecondarySchoolDegree", model.getGoalSecondarySchoolDegree());
    vopsController.saveStringProperty(user, "goalMatriculationExam", model.getGoalMatriculationExam());
    vopsController.saveStringProperty(user, "vocationalYears", model.getVocationalYears());
    vopsController.saveStringProperty(user, "goalJustMatriculationExam", model.getGoalJustMatriculationExam());
    vopsController.saveStringProperty(user, "justTransferCredits", model.getJustTransferCredits());
    vopsController.saveStringProperty(user, "transferCreditYears", model.getTransferCreditYears());
    vopsController.saveStringProperty(user, "completionYears", model.getCompletionYears());
    vopsController.saveStringProperty(user, "mathSyllabus", model.getMathSyllabus());
    vopsController.saveStringProperty(user, "finnish", model.getFinnish());
    vopsController.saveBoolProperty(user, "swedish", model.isSwedish());
    vopsController.saveBoolProperty(user, "english", model.isEnglish());
    vopsController.saveBoolProperty(user, "german", model.isGerman());
    vopsController.saveBoolProperty(user, "french", model.isFrench());
    vopsController.saveBoolProperty(user, "italian", model.isItalian());
    vopsController.saveBoolProperty(user, "spanish", model.isSpanish());
    vopsController.saveStringProperty(user, "science", model.getScience());
    vopsController.saveStringProperty(user, "religion", model.getReligion());
    vopsController.saveStringProperty(user, "additionalInfo", model.getAdditionalInfo());
    return Response.ok().entity(model).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity) User(fi.otavanopisto.muikku.schooldata.entity.User) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 74 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class UserEntityFileRESTService method getFileContent.

@GET
@Path("/user/{USERENTITYID}/identifier/{IDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getFileContent(@PathParam("USERENTITYID") Long userEntityId, @PathParam("IDENTIFIER") String identifier, @Context Request request) {
    // Check if the file exists
    UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
    if (userEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    UserEntityFile userEntityFile = userEntityFileController.findByUserEntityAndIdentifier(userEntity, identifier);
    if (userEntityFile == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (userEntityFile.getVisibility() != UserEntityFileVisibility.PUBLIC) {
        UserEntity loggedUserEntity = sessionController.getLoggedUserEntity();
        if (loggedUserEntity == null) {
            return Response.status(Status.NOT_FOUND).build();
        } else if (!userEntityFile.getUserEntity().getId().equals(loggedUserEntity.getId())) {
            if (userEntityFile.getVisibility() == UserEntityFileVisibility.STAFF) {
                EnvironmentUser environmentUser = environmentUserController.findEnvironmentUserByUserEntity(loggedUserEntity);
                if (environmentUser == null || environmentUser.getRole() == null || environmentUser.getRole().getArchetype() == EnvironmentRoleArchetype.STUDENT) {
                    return Response.status(Status.NOT_FOUND).build();
                }
            } else {
                return Response.status(Status.NOT_FOUND).build();
            }
        }
    }
    // Serve the content
    String tagIdentifier = String.format("%d-%s-%d", userEntityFile.getUserEntity().getId(), userEntityFile.getIdentifier(), userEntityFile.getLastModified().getTime());
    EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(tagIdentifier)));
    ResponseBuilder builder = request.evaluatePreconditions(tag);
    if (builder != null) {
        return builder.build();
    }
    CacheControl cacheControl = new CacheControl();
    cacheControl.setMustRevalidate(true);
    byte[] data = userEntityFile.getData();
    return Response.ok(data).cacheControl(cacheControl).tag(tag).header("Content-Length", data.length).header("Content-Disposition", String.format("attachment; filename=\"%s\"", userEntityFile.getName())).type(userEntityFile.getContentType()).build();
}
Also used : EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) EntityTag(javax.ws.rs.core.EntityTag) CacheControl(javax.ws.rs.core.CacheControl) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserEntityFile(fi.otavanopisto.muikku.model.users.UserEntityFile) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 75 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class DefaultSchoolDataWorkspaceListener method onSchoolDataWorkspaceUserRemovedEvent.

public void onSchoolDataWorkspaceUserRemovedEvent(@Observes SchoolDataWorkspaceUserRemovedEvent event) {
    UserEntity userEntity = userEntityController.findUserEntityByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
    if (userEntity != null) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(event.getWorkspaceDataSource(), event.getWorkspaceIdentifier());
        if (workspaceEntity != null) {
            SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(event.getIdentifier(), event.getDataSource());
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
            if (workspaceUserEntity != null) {
                workspaceUserEntityController.archiveWorkspaceUserEntity(workspaceUserEntity);
            }
        } else {
            logger.warning("could not remove workspace user because workspace entity #" + event.getWorkspaceIdentifier() + '/' + event.getWorkspaceDataSource() + " could not be found");
        }
    } else {
        logger.warning("could not remove workspace user because user entity #" + event.getUserIdentifier() + '/' + event.getUserDataSource() + " could not be found");
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Aggregations

UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)163 Path (javax.ws.rs.Path)101 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)88 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)65 GET (javax.ws.rs.GET)58 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)54 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)50 User (fi.otavanopisto.muikku.schooldata.entity.User)36 ArrayList (java.util.ArrayList)35 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)27 POST (javax.ws.rs.POST)26 Date (java.util.Date)24 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)22 HashMap (java.util.HashMap)20 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)18 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)14 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)14 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)13 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)12 PUT (javax.ws.rs.PUT)12