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;
}
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"));
}
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();
}
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();
}
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");
}
}
Aggregations