initial input MemberAssetService
This commit is contained in:
parent
3fc3920c03
commit
084c6fae35
@ -0,0 +1,96 @@
|
|||||||
|
package de.hsadmin.service.customer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.EJB;
|
||||||
|
import javax.ejb.Stateless;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
|
|
||||||
|
import de.hsadmin.bo.customer.MemberAsset;
|
||||||
|
import de.hsadmin.common.error.TechnicalException;
|
||||||
|
import de.hsadmin.common.error.UserException;
|
||||||
|
import de.hsadmin.dao.customer.CustomerDao;
|
||||||
|
import de.hsadmin.dao.customer.MemberAssetDao;
|
||||||
|
import de.hsadmin.login.RequestContext;
|
||||||
|
import de.hsadmin.login.RequiredScope;
|
||||||
|
import de.hsadmin.login.Role;
|
||||||
|
import de.hsadmin.login.ScopePolicy;
|
||||||
|
import de.hsadmin.module.impl.AbstractModule;
|
||||||
|
import de.hsadmin.module.util.QueryBuilder;
|
||||||
|
|
||||||
|
@Stateless
|
||||||
|
public class MemberAssetService extends AbstractModule<MemberAssetVO> implements MemberAssetServiceLocal {
|
||||||
|
|
||||||
|
@PersistenceContext(name="hsar")
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@EJB
|
||||||
|
private CustomerDao customerDao;
|
||||||
|
|
||||||
|
@EJB
|
||||||
|
private MemberAssetDao memberAssetDao;
|
||||||
|
|
||||||
|
public MemberAssetService() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberAssetService(final EntityManager em, final CustomerDao customerDao, final MemberAssetDao memberAssetDao) {
|
||||||
|
this.entityManager = em;
|
||||||
|
this.customerDao = customerDao;
|
||||||
|
this.memberAssetDao = memberAssetDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MemberAssetVO buildVO() throws TechnicalException {
|
||||||
|
return new MemberAssetVO();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@RequiredScope({@ScopePolicy(Role.SYSTEM)})
|
||||||
|
public MemberAssetVO create(final RequestContext requestContext, final MemberAssetVO prototype)
|
||||||
|
throws UserException, TechnicalException {
|
||||||
|
final MemberAssetVO vo = super.create(requestContext, prototype);
|
||||||
|
final MemberAsset bo = new MemberAsset();
|
||||||
|
bo.setCustomer(customerDao.findCustomerByName(prototype.getCustomer()));
|
||||||
|
vo.copyPropertiesToPersistentObject(bo);
|
||||||
|
entityManager.persist(bo);
|
||||||
|
final MemberAssetVO newVO = new MemberAssetVO();
|
||||||
|
newVO.copyPropertiesFromPersistentObject(bo);
|
||||||
|
return newVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@RequiredScope({@ScopePolicy(Role.SYSTEM), @ScopePolicy(value=Role.CUSTOMER, property="customer")})
|
||||||
|
public List<MemberAssetVO> read(final RequestContext requestContext, final MemberAssetVO criteria)
|
||||||
|
throws UserException, TechnicalException {
|
||||||
|
final List<MemberAssetVO> emptyList = super.read(requestContext, criteria);
|
||||||
|
final List<MemberAsset> list = runCriteriaQuery(criteria);
|
||||||
|
for (MemberAsset c : list) {
|
||||||
|
final MemberAssetVO vo = new MemberAssetVO();
|
||||||
|
vo.copyPropertiesFromPersistentObject(c);
|
||||||
|
emptyList.add(vo);
|
||||||
|
}
|
||||||
|
return emptyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@RequiredScope({@ScopePolicy(Role.SYSTEM)})
|
||||||
|
public List<MemberAssetVO> update(final RequestContext requestContext, final MemberAssetVO criteria, final MemberAssetVO prototype)
|
||||||
|
throws UserException, TechnicalException {
|
||||||
|
throw new TechnicalException(new NotImplementedException("MemberAsset are immutable"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@RequiredScope({@ScopePolicy(Role.SYSTEM)})
|
||||||
|
public void delete(final RequestContext requestContext, final MemberAssetVO criteria)
|
||||||
|
throws UserException, TechnicalException {
|
||||||
|
throw new TechnicalException(new NotImplementedException("MemberAsset are immutable"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// macht diese Klasse Unit-testbar
|
||||||
|
List<MemberAsset> runCriteriaQuery(final MemberAssetVO criteria) throws UserException, TechnicalException {
|
||||||
|
return QueryBuilder.newBuilder(entityManager, MemberAsset.class).getResultList(criteria);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user