use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.
the class CreateNotificationJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
ApplicationNotificationDAO applicationNotificationDAO = DAOFactory.getInstance().getApplicationNotificationDAO();
UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
String line = requestContext.getString("line");
ApplicationState state = ApplicationState.valueOf(requestContext.getString("state"));
Set<User> users = new HashSet<>();
int rowCount = requestContext.getInteger("usersTable.rowCount");
for (int i = 0; i < rowCount; i++) {
String colPrefix = "usersTable." + i;
Long userId = requestContext.getLong(colPrefix + ".userId");
User user = userDAO.findById(userId);
users.add(user);
}
ApplicationNotification applicationNotification = applicationNotificationDAO.create(line, state);
applicationNotificationDAO.setUsers(applicationNotification, users);
requestContext.setRedirectURL(requestContext.getRequest().getContextPath() + "/applications/editnotification.page?notification=" + applicationNotification.getId());
}
use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.
the class CoursesService method createCourse.
public CourseEntity createCourse(@WebParam(name = "moduleId") Long moduleId, @WebParam(name = "name") String name, @WebParam(name = "nameExtension") String nameExtension, @WebParam(name = "subjectId") Long subjectId, @WebParam(name = "courseNumber") Integer courseNumber, @WebParam(name = "beginDate") Date beginDate, @WebParam(name = "endDate") Date endDate, @WebParam(name = "courseLength") Double courseLength, @WebParam(name = "courseLengthTimeUnitId") Long courseLengthTimeUnitId, @WebParam(name = "description") String description, @WebParam(name = "creatingUserId") Long creatingUserId) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
CourseEducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
CourseEducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
Module module = moduleId == null ? null : moduleDAO.findById(moduleId);
Subject subject = subjectId == null ? null : subjectDAO.findById(subjectId);
EducationalTimeUnit courseLengthTimeUnit = courseLengthTimeUnitId == null ? null : educationalTimeUnitDAO.findById(courseLengthTimeUnitId);
User creatingUser = userDAO.findById(creatingUserId);
if (module != null) {
name = name == null ? module.getName() : name;
subject = subject == null ? module.getSubject() : subject;
courseNumber = courseNumber == null ? module.getCourseNumber() : courseNumber;
if (courseLength == null && module.getCourseLength() != null) {
courseLength = module.getCourseLength().getUnits();
courseLengthTimeUnit = module.getCourseLength().getUnit();
}
description = description == null ? module.getDescription() : description;
}
CourseState state = defaultsDAO.getDefaults().getInitialCourseState();
CourseType type = null;
// Course creation
Course course = courseDAO.create(module, name, nameExtension, state, type, subject, courseNumber, beginDate, endDate, courseLength, courseLengthTimeUnit, null, null, null, null, null, null, description, null, null, null, null, creatingUser);
validateEntity(course);
if (module != null) {
// Course Description copying from module to course
descriptionDAO.copy(module, course);
// Curriculums
courseDAO.updateCurriculums(course, new HashSet<Curriculum>(module.getCurriculums()));
// Components
List<ModuleComponent> moduleComponents = module.getModuleComponents();
if (moduleComponents != null) {
for (ModuleComponent moduleComponent : moduleComponents) {
EducationalLength educationalLength = moduleComponent.getLength();
CourseComponent courseComponent = componentDAO.create(course, educationalLength == null ? null : educationalLength.getUnits(), educationalLength == null ? null : educationalLength.getUnit(), moduleComponent.getName(), moduleComponent.getDescription());
validateEntity(courseComponent);
}
}
// Education types
List<CourseEducationType> typesInModule = module.getCourseEducationTypes();
if (typesInModule != null) {
for (CourseEducationType typeInModule : typesInModule) {
CourseEducationType typeInCourse = educationTypeDAO.create(course, typeInModule.getEducationType());
validateEntity(typeInCourse);
// Education subtypes
List<CourseEducationSubtype> subTypesInModule = typeInModule.getCourseEducationSubtypes();
if (subTypesInModule != null) {
for (CourseEducationSubtype subtypeInModule : subTypesInModule) {
CourseEducationSubtype courseEducationSubtype = educationSubtypeDAO.create(typeInCourse, subtypeInModule.getEducationSubtype());
validateEntity(courseEducationSubtype);
}
}
}
}
}
return EntityFactoryVault.buildFromDomainObject(course);
}
use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.
the class FileService method uploadStudentFile.
@WebMethod
public void uploadStudentFile(@WebParam(name = "studentId") Long studentId, @WebParam(name = "name") String name, @WebParam(name = "fileName") String fileName, @WebParam(name = "fileTypeId") Long fileTypeId, @WebParam(name = "contentType") String contentType, @WebParam(name = "creatorId") Long creatorId, @WebParam(name = "content") DataHandler content) {
StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
Student student = studentDAO.findById(studentId);
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
FileTypeDAO fileTypeDAO = DAOFactory.getInstance().getFileTypeDAO();
User creator = creatorId != null ? userDAO.findById(creatorId) : null;
FileType fileType = fileTypeId != null ? fileTypeDAO.findById(fileTypeId) : null;
byte[] data = null;
try {
InputStream inputStream = content.getInputStream();
data = IOUtils.toByteArray(inputStream);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
studentFileDAO.create(student, name, fileName, null, fileType, contentType, data, creator);
}
use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.
the class ModulesService method createModule.
public ModuleEntity createModule(@WebParam(name = "name") String name, @WebParam(name = "subjectId") Long subjectId, @WebParam(name = "courseNumber") Integer courseNumber, @WebParam(name = "moduleLength") Double moduleLength, @WebParam(name = "moduleLengthTimeUnitId") Long moduleLengthTimeUnitId, @WebParam(name = "description") String description, @WebParam(name = "creatingUserId") Long creatingUserId) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
Subject subject = subjectDAO.findById(subjectId);
User creatingUser = userDAO.findById(creatingUserId);
EducationalTimeUnit moduleLengthTimeUnit = moduleLengthTimeUnitId == null ? null : educationalTimeUnitDAO.findById(moduleLengthTimeUnitId);
Module module = moduleDAO.create(name, subject, courseNumber, moduleLength, moduleLengthTimeUnit, description, null, creatingUser);
validateEntity(module);
return EntityFactoryVault.buildFromDomainObject(module);
}
use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.
the class OpenIDAuthorizationStrategy method processResponse.
@SuppressWarnings("unchecked")
public User processResponse(RequestContext requestContext) throws AuthenticationException {
UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
try {
HttpSession session = requestContext.getRequest().getSession();
// extract the parameters from the authentication response
// (which comes in as a HTTP request from the OpenID provider)
ParameterList openidResp = new ParameterList(requestContext.getRequest().getParameterMap());
// retrieve the previously stored discovery information
DiscoveryInformation discovered = (DiscoveryInformation) session.getAttribute("discovered");
// extract the receiving URL from the HTTP request
StringBuffer receivingURL = requestContext.getRequest().getRequestURL();
String queryString = requestContext.getRequest().getQueryString();
if (queryString != null && queryString.length() > 0) {
receivingURL.append("?").append(requestContext.getRequest().getQueryString());
}
// verify the response
VerificationResult verification = consumerManager.verify(receivingURL.toString(), openidResp, discovered);
// examine the verification result and extract the verified identifier
Identifier verified = verification.getVerifiedId();
if (verified != null) {
AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
List<String> emails = null;
if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
emails = fetchResp.getAttributeValues("email");
}
UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
User user = userDAO.findByExternalIdAndAuthProvider(verified.getIdentifier(), getName());
if (user == null) {
user = userDAO.findByEmail(emails.get(0));
if (user != null) {
String expectedLoginServer = userVariableDAO.findByUserAndKey(user, "openid.expectedlogin");
String loginServer = verification.getAuthResponse().getParameterValue("openid.op_endpoint");
if (!StringUtils.isBlank(expectedLoginServer) && expectedLoginServer.equals(loginServer)) {
userVariableDAO.setUserVariable(user, "openid.expectedlogin", null);
userDAO.updateExternalId(user, verified.getIdentifier());
} else {
throw new AuthenticationException(AuthenticationException.LOCAL_USER_MISSING);
}
} else {
throw new AuthenticationException(AuthenticationException.LOCAL_USER_MISSING);
}
}
return user;
} else {
return null;
}
} catch (MessageException e) {
throw new SmvcRuntimeException(e);
} catch (DiscoveryException e) {
throw new SmvcRuntimeException(e);
} catch (AssociationException e) {
throw new SmvcRuntimeException(e);
}
}
Aggregations