use of fi.otavanopisto.pyramus.domainmodel.base.Organization in project pyramus by otavanopisto.
the class EditCourseJSONRequestController method processSignupStudentGroups.
private void processSignupStudentGroups(JSONRequestContext requestContext, Course course, StaffMember loggedUser) {
CourseSignupStudentGroupDAO courseSignupStudentGroupDAO = DAOFactory.getInstance().getCourseSignupStudentGroupDAO();
StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
List<CourseSignupStudentGroup> signupStudentGroups = courseSignupStudentGroupDAO.listByCourse(course);
Integer studentGroupsRowCount = requestContext.getInteger("signupStudentGroupsTable.rowCount");
if (studentGroupsRowCount != null) {
Set<Long> studentGroupIdsPresent = new HashSet<>();
for (int i = 0; i < studentGroupsRowCount; i++) {
Long studentGroupId = requestContext.getLong(String.format("signupStudentGroupsTable.%d.studentGroupId", i));
if (studentGroupId != null) {
studentGroupIdsPresent.add(studentGroupId);
}
}
// Create missing groups
studentGroupIdsPresent.forEach(studentGroupId -> {
if (signupStudentGroups.stream().noneMatch(signupStudentGroup -> Objects.equals(signupStudentGroup.getStudentGroup().getId(), studentGroupId))) {
StudentGroup studentGroup = studentGroupDAO.findById(studentGroupId);
if ((studentGroup != null) && UserUtils.canAccessOrganization(loggedUser, studentGroup.getOrganization())) {
courseSignupStudentGroupDAO.create(course, studentGroup);
} else {
throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
}
}
});
// Remove groups that don't exist anymore
signupStudentGroups.stream().filter(signupStudentGroup -> !studentGroupIdsPresent.contains(signupStudentGroup.getStudentGroup().getId())).forEach(signupStudentGroup -> {
if (UserUtils.canAccessOrganization(loggedUser, signupStudentGroup.getStudentGroup().getOrganization())) {
courseSignupStudentGroupDAO.delete(signupStudentGroup);
} else {
throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
}
});
}
}
use of fi.otavanopisto.pyramus.domainmodel.base.Organization in project pyramus by otavanopisto.
the class UsersService method updateUser.
public void updateUser(@WebParam(name = "userId") Long userId, @WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "role") String role) {
StaffMemberDAO staffDAO = DAOFactory.getInstance().getStaffMemberDAO();
StaffMember user = staffDAO.findById(userId);
Role userRole = EnumType.valueOf(Role.class, role);
Organization organization = user.getOrganization();
staffDAO.update(user, organization, firstName, lastName, userRole);
validateEntity(user);
}
use of fi.otavanopisto.pyramus.domainmodel.base.Organization in project pyramus by otavanopisto.
the class UsersService method createUser.
public UserEntity createUser(@WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "externalId") String externalId, @WebParam(name = "authProvider") String authProvider, @WebParam(name = "role") String role) {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
// TODO: should not create if user exists
Person person = personDAO.create(null, null, null, null, Boolean.FALSE);
userIdentificationDAO.create(person, authProvider, externalId);
Role userRole = EnumType.valueOf(Role.class, role);
// TODO organization
Organization organization = null;
StaffMember staffMember = staffMemberDAO.create(organization, firstName, lastName, userRole, person, false);
personDAO.updateDefaultUser(person, staffMember);
validateEntity(staffMember);
return EntityFactoryVault.buildFromDomainObject(staffMember);
}
use of fi.otavanopisto.pyramus.domainmodel.base.Organization in project pyramus by otavanopisto.
the class StudentGroupsAutoCompleteBinaryRequestController method process.
/**
* Processes a binary request.
* The request should contain the following parameters:
* <dl>
* <dt><code>text</code></dt>
* <dd>Already typed characters.</dd>
* </dl>
*
* @param binaryRequestContext The context of the binary request.
*/
public void process(BinaryRequestContext binaryRequestContext) {
StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
String text = binaryRequestContext.getString("text");
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.append("<ul>");
if (!StringUtils.isBlank(text)) {
text = QueryParser.escape(StringUtils.trim(text)) + '*';
StaffMember loggedUser = staffMemberDAO.findById(binaryRequestContext.getLoggedUserId());
Organization organization = UserUtils.canAccessAllOrganizations(loggedUser) ? null : loggedUser.getOrganization();
List<StudentGroup> studentGroups = studentGroupDAO.searchStudentGroupsBasic(100, 0, organization, text).getResults();
for (StudentGroup studentGroup : studentGroups) {
addResult(resultBuilder, studentGroup);
}
}
resultBuilder.append("</ul>");
try {
binaryRequestContext.setResponseContent(resultBuilder.toString().getBytes("UTF-8"), "text/html;charset=UTF-8");
} catch (UnsupportedEncodingException e) {
throw new SmvcRuntimeException(e);
}
}
use of fi.otavanopisto.pyramus.domainmodel.base.Organization in project pyramus by otavanopisto.
the class DebugDataViewController method process.
public void process(PageRequestContext requestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
MaterialResourceDAO materialResourceDAO = DAOFactory.getInstance().getMaterialResourceDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
String type = requestContext.getRequest().getParameter("type");
int count = Integer.parseInt(requestContext.getRequest().getParameter("count"));
int start = 1;
String s = requestContext.getRequest().getParameter("start");
if (!StringUtils.isBlank(s)) {
start = Integer.parseInt(s);
}
User user = userDAO.findById(requestContext.getLoggedUserId());
if ("module".equals(type)) {
for (int i = start; i < (start + count); i++) {
EducationalTimeUnit etu = educationalTimeUnitDAO.findById(new Long(1));
moduleDAO.create("Moduli " + i, null, null, new Double(10), etu, "KuvaustekstiƤ modulille " + i, null, user);
}
} else if ("course".equals(type)) {
for (int i = start; i < (start + count); i++) {
EducationalTimeUnit etu = educationalTimeUnitDAO.findById(new Long(1));
CourseState courseState = courseStateDAO.findById(new Long(1));
Organization organization = organizationDAO.findById(1L);
courseDAO.create(moduleDAO.findById(new Long(1)), organization, "Kurssi " + i, "", courseState, null, null, null, null, null, new Double(10), etu, null, null, null, null, null, null, "KuvaustekstiƤ kurssille " + i, null, null, null, null, user);
}
} else if ("resource".equals(type)) {
for (int i = start; i < (start + count); i++) {
ResourceCategory resourceCategory = resourceCategoryDAO.findById(new Long(1));
materialResourceDAO.create("Materiaaliresurssi " + i, resourceCategory, new Double(500));
}
} else if ("project".equals(type)) {
for (int i = start; i < (start + count); i++) {
EducationalTimeUnit etu = educationalTimeUnitDAO.findById(new Long(1));
projectDAO.create("Projekti " + i, "KuvaustekstiƤ projektille " + i, new Double(10), etu, user);
}
} else if ("student".equals(type)) {
for (int i = start; i < (start + count); i++) {
Person person = personDAO.create(new Date(), "030310-123R", Sex.MALE, null, Boolean.FALSE);
studentDAO.create(person, "Etunimi " + i, "Sukunimi " + i, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false);
}
}
}
Aggregations