use of fi.otavanopisto.pyramus.dao.resources.WorkResourceDAO 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.WorkResourceDAO in project pyramus by otavanopisto.
the class EditWorkResourceViewController method process.
public void process(PageRequestContext pageRequestContext) {
ResourceDAO resourceDAO = DAOFactory.getInstance().getResourceDAO();
WorkResourceDAO workResourceDAO = DAOFactory.getInstance().getWorkResourceDAO();
ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
Long resourceId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("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", workResourceDAO.findById(resource.getId()));
pageRequestContext.setIncludeJSP("/templates/resources/editworkresource.jsp");
}
use of fi.otavanopisto.pyramus.dao.resources.WorkResourceDAO in project pyramus by otavanopisto.
the class EditWorkResourceJSONRequestController 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");
Long resourceId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("resource"));
Double hourlyCost = NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("hourlyCost"));
Double costPerUse = NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("costPerUse"));
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);
}
}
}
WorkResource workResource = workResourceDAO.findById(resourceId);
if (!version.equals(workResource.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")));
workResourceDAO.update(workResource, name, resourceCategory, costPerUse, hourlyCost);
resourceDAO.setResourceTags(workResource, tagEntities);
jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
Aggregations