use of fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO 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.MaterialResourceDAO 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);
}
}
}
use of fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO in project pyramus by otavanopisto.
the class EditMaterialResourceViewController method process.
public void process(PageRequestContext pageRequestContext) {
ResourceDAO resourceDAO = DAOFactory.getInstance().getResourceDAO();
MaterialResourceDAO materialResourceDAO = DAOFactory.getInstance().getMaterialResourceDAO();
ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
Long resourceId = pageRequestContext.getLong("resource");
Resource resource = resourceDAO.findById(resourceId);
StringBuilder tagsBuilder = new StringBuilder();
Iterator<Tag> tagIterator = resource.getTags().iterator();
while (tagIterator.hasNext()) {
Tag tag = tagIterator.next();
tagsBuilder.append(tag.getText());
if (tagIterator.hasNext())
tagsBuilder.append(' ');
}
List<ResourceCategory> resourceCategories = resourceCategoryDAO.listUnarchived();
Collections.sort(resourceCategories, new StringAttributeComparator("getName"));
pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
pageRequestContext.getRequest().setAttribute("categories", resourceCategories);
pageRequestContext.getRequest().setAttribute("resource", materialResourceDAO.findById(resource.getId()));
pageRequestContext.setIncludeJSP("/templates/resources/editmaterialresource.jsp");
}
use of fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO in project pyramus by otavanopisto.
the class EditMaterialResourceJSONRequestController 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");
Long resourceId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("resource"));
Double unitCost = NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("unitCost"));
Long version = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("version"));
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.findById(resourceId);
if (!version.equals(materialResource.getVersion()))
throw new SmvcRuntimeException(PyramusStatusCode.CONCURRENT_MODIFICATION, Messages.getInstance().getText(jsonRequestContext.getRequest().getLocale(), "generic.errors.concurrentModification"));
ResourceCategory resourceCategory = resourceCategoryDAO.findById(NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("category")));
materialResourceDAO.update(materialResource, name, resourceCategory, unitCost);
resourceDAO.setResourceTags(materialResource, tagEntities);
jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
Aggregations