package com.gtp.service;
import java.util.List;
import com.gtp.dao.AuthoryDao;
import com.gtp.domain.Authority;
import commons.ExistedException;
import commons.NotFoundException;
public class AuthoryServiceImp implements AuthoryService{
AuthoryDao authoryDao;
public Authority addAuthory(Authority authory) throws ExistedException{
if(authory==null)
throw new NullPointerException("authory should not be null");
Authority auth=authoryDao.findByName(authory.getName());
if(auth!=null)
throw new ExistedException();
authory=authoryDao.addAuthory(authory);
return authory;
}
public Authority updateAuthory(Authority authory) throws ExistedException, NotFoundException{
if(authory==null)
throw new NullPointerException("authory should not be null");
Authority auth=authoryDao.findByName(authory.getName());
if(auth!=null&&authory.getId()!=auth.getId())
throw new ExistedException();
authory=authoryDao.updateAuthory(authory);
return authory;
}
public Authority removeAuthory(Authority a) throws NotFoundException{
if(a==null)
throw new NullPointerException("authory should not be null");
Authority authory=authoryDao.find(a.getId());
if(authory==null)
throw new NotFoundException();
authoryDao.removeAuthroy(a);
return a;
}
public List<Authority> findAllAuthories(){
return authoryDao.findAllAuthories();
}
public AuthoryDao getAuthoryDao() {
return authoryDao;
}
public void setAuthoryDao(AuthoryDao authoryDao) {
this.authoryDao = authoryDao;
}
}