public Category editCategory( Long categoryId, String name, String description, String overpassKeyValue, User updateUser) { if (updateUser == null || !updateUser.isCategoryWrite() || name.isEmpty()) { return null; } EntityTransaction transaction = startSaveTransaction(); Category category = getCategoryById(categoryId); if (category != null) { category.setName(name); category.setDescription(description); category.setOverpassKeyValue(overpassKeyValue); category.setUpdateUser(updateUser); category.setUpdateTimestamp(new Timestamp(new Date().getTime())); } try { entityManager.persist(category); transaction.commit(); return category; } catch (Exception e) { transaction.rollback(); } return null; }
public Category createCategory( String name, String description, String overpassKeyValue, User createUser) { if (createUser == null || !createUser.isCategoryWrite() || name.isEmpty()) { return null; } EntityTransaction transaction = startSaveTransaction(); Category category = new Category(name, description, overpassKeyValue, createUser, createUser); try { entityManager.persist(category); transaction.commit(); return category; } catch (Exception e) { transaction.rollback(); } return null; }