use of fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity in project muikku by otavanopisto.
the class UserRESTService method findStudent.
@GET
@Path("/students/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response findStudent(@Context Request request, @PathParam("ID") String id) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.FORBIDDEN).build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(id);
if (studentIdentifier == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid studentIdentifier %s", id)).build();
}
UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(studentIdentifier);
if (userEntity == null) {
return Response.status(Status.NOT_FOUND).entity("UserEntity not found").build();
}
// Bug fix #2966: REST endpoint should only return students
EnvironmentUser environmentUser = environmentUserController.findEnvironmentUserByUserEntity(userEntity);
if (environmentUser != null) {
EnvironmentRoleEntity userRole = environmentUser.getRole();
if (userRole == null || userRole.getArchetype() != EnvironmentRoleArchetype.STUDENT) {
return Response.status(Status.NOT_FOUND).build();
}
}
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(userEntity.getVersion())));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
// TODO: There's no permission handling, this is relying on schooldatacontroller to check for permission
User user = userController.findUserByIdentifier(studentIdentifier);
if (user == null) {
return Response.status(Status.NOT_FOUND).entity("User not found").build();
}
String emailAddress = userEmailEntityController.getUserDefaultEmailAddress(userEntity, true);
Date studyStartDate = user.getStudyStartDate() != null ? Date.from(user.getStudyStartDate().toInstant()) : null;
Date studyEndDate = user.getStudyEndDate() != null ? Date.from(user.getStudyEndDate().toInstant()) : null;
Date studyTimeEnd = user.getStudyTimeEnd() != null ? Date.from(user.getStudyTimeEnd().toInstant()) : null;
Student student = new Student(studentIdentifier.toId(), user.getFirstName(), user.getLastName(), user.getNickName(), user.getStudyProgrammeName(), false, user.getNationality(), user.getLanguage(), user.getMunicipality(), user.getSchool(), emailAddress, studyStartDate, studyEndDate, studyTimeEnd, user.getCurriculumIdentifier(), userEntity.getUpdatedByStudent());
return Response.ok(student).cacheControl(cacheControl).tag(tag).build();
}
use of fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity in project muikku by otavanopisto.
the class EnvironmentRoleEntityDAO method create.
public EnvironmentRoleEntity create(EnvironmentRoleArchetype archetype, String name) {
EnvironmentRoleEntity environmentRoleEntity = new EnvironmentRoleEntity();
environmentRoleEntity.setArchetype(archetype);
environmentRoleEntity.setName(name);
return persist(environmentRoleEntity);
}
use of fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity in project muikku by otavanopisto.
the class WorkspacePermissionsRoleManagementBackingBean method init.
@RequestAction
public String init() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return NavigationRules.NOT_FOUND;
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.WORKSPACE_MANAGEWORKSPACESETTINGS, workspaceEntity)) {
return NavigationRules.ACCESS_DENIED;
}
workspaceEntityId = workspaceEntity.getId();
workspaceBackingBean.setWorkspaceUrlName(urlName);
workspaceName = workspaceBackingBean.getWorkspaceName();
/**
* View data
*/
permissions = permissionController.listPermissionsByScope(PermissionScope.WORKSPACE);
Collections.sort(permissions, new Comparator<Permission>() {
@Override
public int compare(Permission o1, Permission o2) {
return o1.getName().compareTo(o2.getName());
}
});
roleEntities = new ArrayList<RoleEntity>();
List<SystemRoleEntity> systemRoleEntities = roleController.listSystemRoleEntities();
List<EnvironmentRoleEntity> environmentRoleEnties = roleController.listEnvironmentRoleEntities();
List<WorkspaceRoleEntity> workspaceRoleEntities = roleController.listWorkspaceRoleEntities();
Collections.sort(environmentRoleEnties, new Comparator<EnvironmentRoleEntity>() {
@Override
public int compare(EnvironmentRoleEntity o1, EnvironmentRoleEntity o2) {
return o1.getArchetype().compareTo(o2.getArchetype());
}
});
Collections.sort(workspaceRoleEntities, new Comparator<WorkspaceRoleEntity>() {
@Override
public int compare(WorkspaceRoleEntity o1, WorkspaceRoleEntity o2) {
return o1.getArchetype().compareTo(o2.getArchetype());
}
});
for (SystemRoleEntity systemRoleEntity : systemRoleEntities) {
roleEntities.add(systemRoleEntity);
}
for (EnvironmentRoleEntity environmentRoleEntity : environmentRoleEnties) {
roleEntities.add(environmentRoleEntity);
}
for (WorkspaceRoleEntity workspaceRoleEntity : workspaceRoleEntities) {
roleEntities.add(workspaceRoleEntity);
}
return null;
}
use of fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity in project muikku by otavanopisto.
the class EnvironmentRoleEntityController method findEnvironmentRoleEntity.
public EnvironmentRoleEntity findEnvironmentRoleEntity(String dataSource, String identifier) {
SchoolDataSource schoolDataSource = schoolDataSourceDAO.findByIdentifier(dataSource);
if (schoolDataSource == null) {
logger.severe("Could not find datasource " + dataSource);
return null;
}
RoleSchoolDataIdentifier roleIdentifier = roleSchoolDataIdentifierDAO.findByDataSourceAndIdentifier(schoolDataSource, identifier);
if (roleIdentifier != null) {
RoleEntity roleEntity = roleIdentifier.getRoleEntity();
if (roleEntity != null && roleEntity.getType() == UserRoleType.ENVIRONMENT) {
return (EnvironmentRoleEntity) roleEntity;
}
}
return null;
}
use of fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity 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"));
}
Aggregations