@Override public String getAsText() { Category category = (Category)getValue(); return (category == null) ? null : category.getId().toString(); } }
@Override public void delete(Category item) { manager.remove(item instanceof JpaCategory ? item : get(item.getId())); }
public Category(org.apache.rave.model.Category category) { this.id = category.getId(); this.text = category.getText(); }
private JpaCategory createEntity(Category source) { JpaCategory converted = null; if (source != null) { converted = source.getId() == null ? new JpaCategory() : manager.find(JpaCategory.class, Long.parseLong(source.getId())); if(converted == null) { converted = new JpaCategory(); } updateProperties(source, converted); } return converted; }
@Override @Transactional public void delete(Category category) { Category categoryToBeDeleted = categoryRepository.get(category.getId()); categoryRepository.delete(categoryToBeDeleted); } }
private boolean isCategoryCreatedUser(Authentication authentication, Category category, List<Category> trustedCategoryContainer, boolean trustedDomainObject) { Category trustedCategory = null; if (trustedDomainObject) { trustedCategory = category; } else { trustedCategory = getTrustedCategory(category.getId(), trustedCategoryContainer); } return isCategoryCreatedUserByUsername(authentication, trustedCategory.getCreatedUserId()); }
private boolean validateRequest(Category category, User modifier){ return (validateRequest(category.getText(),modifier) && (categoryService.get(category.getId()) != null)); }
@RequestMapping(value = {"/admin/category/update"}, method = RequestMethod.POST) public String updateCategory(@ModelAttribute(ModelKeys.CATEGORY) Category category, @ModelAttribute(ModelKeys.TOKENCHECK) String sessionToken, @RequestParam String token, @RequestParam(required = false) String referringPageId, Model model, SessionStatus status){ checkTokens(sessionToken, token, status); model.addAttribute(ModelKeys.REFERRING_PAGE_ID, referringPageId); User currentUser = userService.getAuthenticatedUser(); boolean isValidRequest = validateRequest(category, currentUser); if (isValidRequest) { categoryService.update(category.getId(), category.getText(), currentUser); } else { addNavigationMenusToModel(SELECTED_ITEM, model, referringPageId); return ViewNames.ADMIN_CATEGORY_DETAIL; } status.setComplete(); model.asMap().clear(); return "redirect:/app/admin/categories?action=update&referringPageId=" + referringPageId; }
private Map<String, Category> saveCategories(ModelWrapper wrapper, Map<String, User> usersByOriginalId) { Map<String, Category> categoryByOldId = Maps.newHashMap(); if (wrapper.getCategories() != null) { for (Category category : wrapper.getCategories()) { String id = category.getId() == null ? category.getText() : category.getId(); category.setId(null); User lastModified = usersByOriginalId.get(category.getLastModifiedUserId()); if (lastModified != null) { category.setLastModifiedUserId(lastModified.getId()); } User created = usersByOriginalId.get(category.getCreatedUserId()); if (created != null) { category.setCreatedUserId(created.getId()); } categoryByOldId.put(id, categoryRepository.save(category)); } } return categoryByOldId; }
private Map<String, Widget> saveWidgets(ModelWrapper wrapper, Map<String, User> usersById, Map<String, Category> categoryMap) { Map<String, Widget> widgetsByOldId = Maps.newHashMap(); if (wrapper.getWidgets() != null) { for (Widget widget : wrapper.getWidgets()) { String id = widget.getId() == null ? widget.getUrl() : widget.getId(); setIdViaReflection(widget, null); User user = usersById.get(widget.getOwnerId()); if (user != null) { widget.setOwnerId(user.getId()); } List<Category> categories = Lists.newArrayList(); if (widget.getCategories() != null) { for (Category c : widget.getCategories()) { categories.add(categoryMap.get(c.getId())); } widget.setCategories(categories); } widgetsByOldId.put(id, widgetRepository.save(widget)); } } return widgetsByOldId; }
private void updateProperties(Category source, JpaCategory converted) { converted.setId(source.getId()); converted.setCreatedDate(source.getCreatedDate()); converted.setCreatedUserId(source.getCreatedUserId()); converted.setLastModifiedDate(source.getLastModifiedDate()); converted.setLastModifiedUserId(source.getLastModifiedUserId()); converted.setText(source.getText()); converted.setWidgets(source.getWidgets()); } }