use of fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO in project pyramus by otavanopisto.
the class ArchiveResourceCategoryJSONRequestController method process.
/**
* Processes the request to archive a resource category.
*
* @param jsonRequestContext The JSON request context
*/
public void process(JSONRequestContext jsonRequestContext) {
ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
Long resourceCategoryId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("resourceCategoryId"));
resourceCategoryDAO.archiveResourceCategory(resourceCategoryDAO.findById(resourceCategoryId));
}
use of fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO in project pyramus by otavanopisto.
the class CreateMaterialResourceJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
ResourceDAO resourceDAO = DAOFactory.getInstance().getResourceDAO();
ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
MaterialResourceDAO materialResourceDAO = DAOFactory.getInstance().getMaterialResourceDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
String name = jsonRequestContext.getRequest().getParameter("name");
Double unitCost = NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("unitCost"));
ResourceCategory resourceCategory = resourceCategoryDAO.findById(NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("category")));
String tagsText = jsonRequestContext.getString("tags");
Set<Tag> tagEntities = new HashSet<>();
if (!StringUtils.isBlank(tagsText)) {
List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
for (String tag : tags) {
if (!StringUtils.isBlank(tag)) {
Tag tagEntity = tagDAO.findByText(tag.trim());
if (tagEntity == null)
tagEntity = tagDAO.create(tag);
tagEntities.add(tagEntity);
}
}
}
MaterialResource materialResource = materialResourceDAO.create(name, resourceCategory, unitCost);
resourceDAO.setResourceTags(materialResource, tagEntities);
String redirectURL = jsonRequestContext.getRequest().getContextPath() + "/resources/editmaterialresource.page?resource=" + materialResource.getId();
String refererAnchor = jsonRequestContext.getRefererAnchor();
if (!StringUtils.isBlank(refererAnchor))
redirectURL += "#" + refererAnchor;
jsonRequestContext.setRedirectURL(redirectURL);
}
use of fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO in project pyramus by otavanopisto.
the class CreateWorkResourceJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
ResourceDAO resourceDAO = DAOFactory.getInstance().getResourceDAO();
ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
WorkResourceDAO workResourceDAO = DAOFactory.getInstance().getWorkResourceDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
String name = jsonRequestContext.getRequest().getParameter("name");
Double hourlyCost = NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("hourlyCost"));
Double costPerUse = NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("costPerUse"));
ResourceCategory resourceCategory = resourceCategoryDAO.findById(NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("category")));
String tagsText = jsonRequestContext.getString("tags");
Set<Tag> tagEntities = new HashSet<>();
if (!StringUtils.isBlank(tagsText)) {
List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
for (String tag : tags) {
if (!StringUtils.isBlank(tag)) {
Tag tagEntity = tagDAO.findByText(tag.trim());
if (tagEntity == null)
tagEntity = tagDAO.create(tag);
tagEntities.add(tagEntity);
}
}
}
WorkResource workResource = workResourceDAO.create(name, resourceCategory, costPerUse, hourlyCost);
resourceDAO.setResourceTags(workResource, tagEntities);
String redirectURL = jsonRequestContext.getRequest().getContextPath() + "/resources/editworkresource.page?resource=" + workResource.getId();
String refererAnchor = jsonRequestContext.getRefererAnchor();
if (!StringUtils.isBlank(refererAnchor))
redirectURL += "#" + refererAnchor;
jsonRequestContext.setRedirectURL(redirectURL);
}
use of fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO in project pyramus by otavanopisto.
the class SaveResourceCategoriesJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
int rowCount = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("resourceCategoriesTable.rowCount")).intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "resourceCategoriesTable." + i;
Long resourceCategoryId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter(colPrefix + ".resourceCategoryId"));
String name = jsonRequestContext.getRequest().getParameter(colPrefix + ".name");
boolean modified = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter(colPrefix + ".modified")) == 1;
if (resourceCategoryId == -1) {
resourceCategoryDAO.createResourceCategory(name);
} else if (modified) {
ResourceCategory resourceCategory = resourceCategoryDAO.findById(resourceCategoryId);
resourceCategoryDAO.updateResourceCategory(resourceCategory, name);
}
}
jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
use of fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO 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