// Path: src/main/java/yourwebproject2/framework/data/BaseJPAServiceImpl.java
// public abstract class BaseJPAServiceImpl<T extends Entity, ID extends Serializable> implements BaseService<T, ID> {
//     protected BaseJPARepository<T, ID> baseJpaRepository;
//     protected Class<T> entityClass;
// 
//     public T insert(T object) throws Exception {
//         return baseJpaRepository.insert(object);
//     }
// 
//     public T update(T object) throws Exception {
//         return baseJpaRepository.update(object);
//     }
// 
//     public void delete(T object) throws Exception {
//         baseJpaRepository.delete(object);
//     }
// 
//     public T findById(ID id) throws Exception {
//         T result = baseJpaRepository.findById(id);
// 
//         if (result != null)
//             return result;
//         else
//             throw new Exception("Not Found");
//     }
// 
//     public Collection<T> findAllByPage(int pageNum, int countPerPage, Order order) throws Exception {
//         return null;  //To change body of implemented methods use File | Settings | File Templates.
//     }
// }
// 
// Path: src/main/java/yourwebproject2/framework/exception/NotFoundException.java
// public class NotFoundException extends Exception {
//     public NotFoundException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/yourwebproject2/model/entity/Category.java
// @Entity
// @Table(indexes = {  @Index(name="name_idx", columnList = "name", unique = true),
//         @Index(name="priority_idx", columnList = "priority"),
//         @Index(name="parentCategory_idx", columnList = "parent_category")})
// public class Category extends JPAEntity<Long> {
//     private String name;
//     private Integer priority;
//     private Category parentCategory;
// 
//     @NotNull @NotBlank
//     @Column
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     @NotNull
//     @Column
//     public Integer getPriority() {
//         return priority;
//     }
// 
//     public void setPriority(Integer priority) {
//         this.priority = priority;
//     }
// 
//     @ManyToOne(fetch = FetchType.EAGER)
//     public Category getParentCategory() {
//         return parentCategory;
//     }
// 
//     public void setParentCategory(Category parentCategory) {
//         this.parentCategory = parentCategory;
//     }
// 
//     @Override
//     public String toString() {
//         return "Category{" +
//                 "name='" + name + '\'' +
//                 ", priority=" + priority +
//                 ", parentCategory=" + parentCategory +
//                 '}';
//     }
// }
// 
// Path: src/main/java/yourwebproject2/model/repository/CategoryRepository.java
// public interface CategoryRepository extends BaseJPARepository<Category, Long> {
//     /**
//      * Finds a category with the given categoryName
//      *
//      * @param categoryName
//      * @return
//      */
//     public Category findByCategoryName(String categoryName);
// 
//     /**
//      * Finds a category with the given categoryPriority
//      *
//      * @param categoryPriority
//      * @return
//      */
//     public Category findByCategoryPriority(Integer categoryPriority);
// 
//     /**
//      * Finds sub categories with the given parentCategory
//      *
//      * @param parentCategory
//      * @return
//      */
//     public List<Category> findSubCategories(Category parentCategory);
// }
// 
// Path: src/main/java/yourwebproject2/service/CategoryService.java
// public interface CategoryService extends BaseService<Category, Long> {
//     /**
//      * Validates whether the given category already
//      * exists in the system.
//      *
//      * @param categoryName
//      *
//      * @return
//      */
//     public boolean isCategoryPresent(String categoryName);
// 
//     /**
//      * Validates whether the given category priority already
//      * exists in the system.
//      *
//      * @param priorityId
//      *
//      * @return
//      */
//     public boolean isPriorityPresent(Integer priorityId);
// 
//     /**
//      * Find category by name
//      *
//      * @param categoryName
//      * @return
//      */
//     public Category findByCategoryName(String categoryName) throws NotFoundException;
// 
//     /**
//      * Find sub categories by parent category
//      *
//      * @param parentCategory
//      * @return
//      */
//     public List<Category> findSubCategories(Category parentCategory) throws NotFoundException;
// }


import yourwebproject2.framework.data.BaseJPAServiceImpl;
import yourwebproject2.framework.exception.NotFoundException;
import yourwebproject2.model.entity.Category;
import yourwebproject2.model.repository.CategoryRepository;
import yourwebproject2.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.util.List;
package yourwebproject2.service.impl;



/**
 * Created by Y.Kamesh on 8/2/2015.
 */
@Service
@Transactional
public class CategoryServiceImpl extends BaseJPAServiceImpl<Category, Long> implements CategoryService {
    private static Logger LOG = LoggerFactory.getLogger(CategoryServiceImpl.class);

    private @Autowired
    CategoryRepository categoryRepository;

    @PostConstruct
    public void setupService() {
        LOG.info("setting up categoryService...");
        this.baseJpaRepository = categoryRepository;
        this.entityClass = Category.class;
        this.baseJpaRepository.setupEntityClass(Category.class);
        LOG.info("categoryService created...");
    }


    @Override
// Path: src/main/java/yourwebproject2/framework/data/BaseJPAServiceImpl.java
// public abstract class BaseJPAServiceImpl<T extends Entity, ID extends Serializable> implements BaseService<T, ID> {
//     protected BaseJPARepository<T, ID> baseJpaRepository;
//     protected Class<T> entityClass;
// 
//     public T insert(T object) throws Exception {
//         return baseJpaRepository.insert(object);
//     }
// 
//     public T update(T object) throws Exception {
//         return baseJpaRepository.update(object);
//     }
// 
//     public void delete(T object) throws Exception {
//         baseJpaRepository.delete(object);
//     }
// 
//     public T findById(ID id) throws Exception {
//         T result = baseJpaRepository.findById(id);
// 
//         if (result != null)
//             return result;
//         else
//             throw new Exception("Not Found");
//     }
// 
//     public Collection<T> findAllByPage(int pageNum, int countPerPage, Order order) throws Exception {
//         return null;  //To change body of implemented methods use File | Settings | File Templates.
//     }
// }
// 
// Path: src/main/java/yourwebproject2/framework/exception/NotFoundException.java
// public class NotFoundException extends Exception {
//     public NotFoundException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/yourwebproject2/model/entity/Category.java
// @Entity
// @Table(indexes = {  @Index(name="name_idx", columnList = "name", unique = true),
//         @Index(name="priority_idx", columnList = "priority"),
//         @Index(name="parentCategory_idx", columnList = "parent_category")})
// public class Category extends JPAEntity<Long> {
//     private String name;
//     private Integer priority;
//     private Category parentCategory;
// 
//     @NotNull @NotBlank
//     @Column
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     @NotNull
//     @Column
//     public Integer getPriority() {
//         return priority;
//     }
// 
//     public void setPriority(Integer priority) {
//         this.priority = priority;
//     }
// 
//     @ManyToOne(fetch = FetchType.EAGER)
//     public Category getParentCategory() {
//         return parentCategory;
//     }
// 
//     public void setParentCategory(Category parentCategory) {
//         this.parentCategory = parentCategory;
//     }
// 
//     @Override
//     public String toString() {
//         return "Category{" +
//                 "name='" + name + '\'' +
//                 ", priority=" + priority +
//                 ", parentCategory=" + parentCategory +
//                 '}';
//     }
// }
// 
// Path: src/main/java/yourwebproject2/model/repository/CategoryRepository.java
// public interface CategoryRepository extends BaseJPARepository<Category, Long> {
//     /**
//      * Finds a category with the given categoryName
//      *
//      * @param categoryName
//      * @return
//      */
//     public Category findByCategoryName(String categoryName);
// 
//     /**
//      * Finds a category with the given categoryPriority
//      *
//      * @param categoryPriority
//      * @return
//      */
//     public Category findByCategoryPriority(Integer categoryPriority);
// 
//     /**
//      * Finds sub categories with the given parentCategory
//      *
//      * @param parentCategory
//      * @return
//      */
//     public List<Category> findSubCategories(Category parentCategory);
// }
// 
// Path: src/main/java/yourwebproject2/service/CategoryService.java
// public interface CategoryService extends BaseService<Category, Long> {
//     /**
//      * Validates whether the given category already
//      * exists in the system.
//      *
//      * @param categoryName
//      *
//      * @return
//      */
//     public boolean isCategoryPresent(String categoryName);
// 
//     /**
//      * Validates whether the given category priority already
//      * exists in the system.
//      *
//      * @param priorityId
//      *
//      * @return
//      */
//     public boolean isPriorityPresent(Integer priorityId);
// 
//     /**
//      * Find category by name
//      *
//      * @param categoryName
//      * @return
//      */
//     public Category findByCategoryName(String categoryName) throws NotFoundException;
// 
//     /**
//      * Find sub categories by parent category
//      *
//      * @param parentCategory
//      * @return
//      */
//     public List<Category> findSubCategories(Category parentCategory) throws NotFoundException;
// }


// Path: src/main/java/yourwebproject2/service/impl/CategoryServiceImpl.java
import yourwebproject2.framework.data.BaseJPAServiceImpl;
import yourwebproject2.framework.exception.NotFoundException;
import yourwebproject2.model.entity.Category;
import yourwebproject2.model.repository.CategoryRepository;
import yourwebproject2.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.util.List;

package yourwebproject2.service.impl;



/**
 * Created by Y.Kamesh on 8/2/2015.
 */
@Service
@Transactional
public class CategoryServiceImpl extends BaseJPAServiceImpl<Category, Long> implements CategoryService {
    private static Logger LOG = LoggerFactory.getLogger(CategoryServiceImpl.class);

    private @Autowired
    CategoryRepository categoryRepository;

    @PostConstruct
    public void setupService() {
        LOG.info("setting up categoryService...");
        this.baseJpaRepository = categoryRepository;
        this.entityClass = Category.class;
        this.baseJpaRepository.setupEntityClass(Category.class);
        LOG.info("categoryService created...");
    }


    @Override
    public boolean isCategoryPresent(String categoryName) {