Search in sources :

Example 1 with MaterialResourceDAO

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);
}
Also used : MaterialResource(fi.otavanopisto.pyramus.domainmodel.resources.MaterialResource) MaterialResourceDAO(fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) ResourceCategoryDAO(fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO) MaterialResourceDAO(fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO) ResourceDAO(fi.otavanopisto.pyramus.dao.resources.ResourceDAO) ResourceCategory(fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) HashSet(java.util.HashSet)

Example 2 with MaterialResourceDAO

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);
        }
    }
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) ResourceCategoryDAO(fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO) ResourceCategory(fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory) Date(java.util.Date) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) MaterialResourceDAO(fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Example 3 with MaterialResourceDAO

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");
}
Also used : MaterialResourceDAO(fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO) ResourceCategoryDAO(fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO) Resource(fi.otavanopisto.pyramus.domainmodel.resources.Resource) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) MaterialResourceDAO(fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO) ResourceDAO(fi.otavanopisto.pyramus.dao.resources.ResourceDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) ResourceCategory(fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory)

Example 4 with MaterialResourceDAO

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));
}
Also used : MaterialResource(fi.otavanopisto.pyramus.domainmodel.resources.MaterialResource) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) ResourceCategoryDAO(fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) ResourceCategory(fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory) MaterialResourceDAO(fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO) MaterialResourceDAO(fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO) ResourceDAO(fi.otavanopisto.pyramus.dao.resources.ResourceDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) HashSet(java.util.HashSet)

Aggregations

MaterialResourceDAO (fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO)4 ResourceCategoryDAO (fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO)4 ResourceCategory (fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory)4 ResourceDAO (fi.otavanopisto.pyramus.dao.resources.ResourceDAO)3 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)3 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)2 MaterialResource (fi.otavanopisto.pyramus.domainmodel.resources.MaterialResource)2 HashSet (java.util.HashSet)2 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)1 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)1 OrganizationDAO (fi.otavanopisto.pyramus.dao.base.OrganizationDAO)1 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)1 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)1 CourseStateDAO (fi.otavanopisto.pyramus.dao.courses.CourseStateDAO)1 ModuleDAO (fi.otavanopisto.pyramus.dao.modules.ModuleDAO)1 ProjectDAO (fi.otavanopisto.pyramus.dao.projects.ProjectDAO)1 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)1 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)1 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)1 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)1