package com.megatim.fdxconsultation.core.impl.documents;
|
|
import com.bekosoftware.genericdaolayer.dao.ifaces.GenericDAO;
|
import com.bekosoftware.genericmanagerlayer.core.impl.AbstractGenericManager;
|
import com.megatim.commons.tools.exceptions.ApplicationServerException;
|
import com.megatim.fdxconsultation.core.ifaces.documents.CategoryManager;
|
import com.megatim.fdxconsultation.dao.ifaces.documents.CategoryDAO;
|
import com.megatim.fdxconsultation.dao.impl.utils.BaseEntityUtil;
|
import com.megatim.fdxconsultation.model.administration.User;
|
import com.megatim.fdxconsultation.model.documents.Category;
|
import java.util.ArrayList;
|
import java.util.List;
|
import javax.enterprise.context.Dependent;
|
import javax.inject.Inject;
|
import javax.transaction.Transactional;
|
|
/**
|
*
|
* @author Gabuntu
|
*/
|
@Dependent
|
public class CategoryManagerImpl extends AbstractGenericManager<Category, Long> implements CategoryManager {
|
|
@Inject
|
private CategoryDAO dao;
|
|
@Override
|
public GenericDAO<Category, Long> getDao() {
|
return dao;
|
}
|
|
@Override
|
public String getEntityIdName() {
|
return "id";
|
}
|
|
@Transactional
|
@Override
|
public Category add(Category category, User connectedUser) {
|
BaseEntityUtil.setBaseEntityFieldsForAdd(category, connectedUser);
|
return dao.save(category);
|
}
|
|
@Transactional
|
@Override
|
public Category update(Long id, Category category, User connectedUser) {
|
Category refreshCategory = getById(id);
|
refreshCategory.setName(category.getName());
|
refreshCategory.setPosition(category.getPosition());
|
|
BaseEntityUtil.setBaseEntityFieldsForUpdate(refreshCategory, connectedUser);
|
return dao.save(refreshCategory);
|
}
|
|
@Transactional
|
@Override
|
public Category delete(Long id, User connectedUser) {
|
Category category = getById(id);
|
BaseEntityUtil.setBaseEntityFieldsForDelete(category, connectedUser);
|
return dao.save(category);
|
}
|
|
private Category getById(Long id) {
|
Category category = dao.getById(id);
|
if (category == null) {
|
throw new ApplicationServerException("Categorie introuvable");
|
}
|
return category;
|
}
|
|
@Override
|
public List<Category> loadAll() {
|
return dao.loadAll();
|
}
|
|
}
|