Search in sources :

Example 1 with ResourceCategory

use of fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory 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 ResourceCategory

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

Example 3 with ResourceCategory

use of fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory 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));
}
Also used : ResourceCategoryDAO(fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO) ResourceCategory(fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory)

Example 4 with ResourceCategory

use of fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory 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 5 with ResourceCategory

use of fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory in project pyramus by otavanopisto.

the class ResourceCategoryDAO method createResourceCategory.

public ResourceCategory createResourceCategory(String name) {
    EntityManager entityManager = getEntityManager();
    ResourceCategory resourceCategory = new ResourceCategory();
    resourceCategory.setName(name);
    entityManager.persist(resourceCategory);
    return resourceCategory;
}
Also used : EntityManager(javax.persistence.EntityManager) ResourceCategory(fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory)

Aggregations

ResourceCategory (fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory)16 ResourceCategoryDAO (fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO)15 ResourceDAO (fi.otavanopisto.pyramus.dao.resources.ResourceDAO)8 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)8 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)6 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)4 MaterialResourceDAO (fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO)4 Resource (fi.otavanopisto.pyramus.domainmodel.resources.Resource)4 HashSet (java.util.HashSet)4 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)3 WorkResourceDAO (fi.otavanopisto.pyramus.dao.resources.WorkResourceDAO)3 MaterialResource (fi.otavanopisto.pyramus.domainmodel.resources.MaterialResource)3 WorkResource (fi.otavanopisto.pyramus.domainmodel.resources.WorkResource)3 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