// Path: src/main/java/org/fjorum/controller/form/CategoryCreateForm.java
// public class CategoryCreateForm {
// 
//     public final static String NAME = "categoryCreateForm";
// 
//     @NotNull
//     private Category parentCategory;
// 
//     @NotEmpty
//     private String categoryName = "";
// 
//     CategoryCreateForm(){}
// 
//     public CategoryCreateForm(Category parentCategory){
//         this.parentCategory = parentCategory;
//     }
// 
//     public Category getParentCategory() {
//         return parentCategory;
//     }
// 
//     public void setParentCategory(Category parentCategory) {
//         this.parentCategory = parentCategory;
//     }
// 
//     public String getCategoryName() {
//         return categoryName;
//     }
// 
//     public void setCategoryName(String categoryName) {
//         this.categoryName = categoryName;
//     }
// }
// 
// Path: src/main/java/org/fjorum/model/repository/CategoryRepository.java
// public interface CategoryRepository extends JpaRepository<Category, Long> {
// 
//     @Query("SELECT c FROM Category c WHERE c.parent is null")
//     Category getRoot();
// 
// }


import org.fjorum.controller.form.CategoryCreateForm;
import org.fjorum.model.entity.Category;
import org.fjorum.model.repository.CategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
package org.fjorum.model.service;



@Service
public class CategoryServiceImpl extends AbstractEntityServiceImpl<Category> implements CategoryService {

    private final CategoryRepository categoryRepository;

    @Autowired
    public CategoryServiceImpl(CategoryRepository categoryRepository) {
        this.categoryRepository = categoryRepository;
    }

    @Override
    public Category createNewCategory(String name, Category parent) {
        Category category = new Category(name, parent);
        return categoryRepository.save(category);
    }

    @Override
    public Category createNewCategory(CategoryCreateForm form) {
        return createNewCategory(form.getCategoryName(), form.getParentCategory());
    }

    @Override
    public Category getRootCategory() {
        return categoryRepository.getRoot();
    }


    @Override
    protected JpaRepository<Category, Long> getRepository() {
        return categoryRepository;
    }

    @Override
// Path: src/main/java/org/fjorum/controller/form/CategoryCreateForm.java
// public class CategoryCreateForm {
// 
//     public final static String NAME = "categoryCreateForm";
// 
//     @NotNull
//     private Category parentCategory;
// 
//     @NotEmpty
//     private String categoryName = "";
// 
//     CategoryCreateForm(){}
// 
//     public CategoryCreateForm(Category parentCategory){
//         this.parentCategory = parentCategory;
//     }
// 
//     public Category getParentCategory() {
//         return parentCategory;
//     }
// 
//     public void setParentCategory(Category parentCategory) {
//         this.parentCategory = parentCategory;
//     }
// 
//     public String getCategoryName() {
//         return categoryName;
//     }
// 
//     public void setCategoryName(String categoryName) {
//         this.categoryName = categoryName;
//     }
// }
// 
// Path: src/main/java/org/fjorum/model/repository/CategoryRepository.java
// public interface CategoryRepository extends JpaRepository<Category, Long> {
// 
//     @Query("SELECT c FROM Category c WHERE c.parent is null")
//     Category getRoot();
// 
// }


// Path: src/main/java/org/fjorum/model/service/CategoryServiceImpl.java
import org.fjorum.controller.form.CategoryCreateForm;
import org.fjorum.model.entity.Category;
import org.fjorum.model.repository.CategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

package org.fjorum.model.service;



@Service
public class CategoryServiceImpl extends AbstractEntityServiceImpl<Category> implements CategoryService {

    private final CategoryRepository categoryRepository;

    @Autowired
    public CategoryServiceImpl(CategoryRepository categoryRepository) {
        this.categoryRepository = categoryRepository;
    }

    @Override
    public Category createNewCategory(String name, Category parent) {
        Category category = new Category(name, parent);
        return categoryRepository.save(category);
    }

    @Override
    public Category createNewCategory(CategoryCreateForm form) {
        return createNewCategory(form.getCategoryName(), form.getParentCategory());
    }

    @Override
    public Category getRootCategory() {
        return categoryRepository.getRoot();
    }


    @Override
    protected JpaRepository<Category, Long> getRepository() {
        return categoryRepository;
    }

    @Override
    public void up(Category category) {