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()); }
@Override public int removeFromCreatedOrModifiedFields(String userId) { List<Category> categories = getAll(); int numRecordsChanged = 0; for (Category category : categories) { boolean changed = false; String createdUser = category.getCreatedUserId(); String lastModifiedUser = category.getLastModifiedUserId(); if (createdUser != null && userId.equals(createdUser)) { category.setCreatedUserId(null); changed = true; } if (lastModifiedUser != null && userId.equals(lastModifiedUser)) { category.setLastModifiedUserId(null); changed = true; } if (changed) { numRecordsChanged++; save(category); } } return numRecordsChanged; } }
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 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()); } }