public static RequestClaim entity2domain(ApplicationClaimEntity entity) { Claim claim = ClaimDAOJPAImpl.entity2domain(entity.getClaim()); RequestClaim reqClaim = new RequestClaim(claim); reqClaim.setId(entity.getId()); reqClaim.setOptional(entity.isOptional()); return reqClaim; }
@Override public void removeClaimFromApplication(Application application, RequestClaim claim) { ApplicationEntity applicationEntity = null; if (application.getId() != 0) { applicationEntity = em.find(ApplicationEntity.class, application.getId()); } else { Query query = null; query = em.createQuery("select a from Application a where a.realm=:realm"); query.setParameter("realm", application.getRealm()); applicationEntity = (ApplicationEntity) query.getSingleResult(); } ApplicationClaimEntity foundEntity = null; for (ApplicationClaimEntity acm : applicationEntity.getRequestedClaims()) { if (claim.getClaimType().toString().equals(acm.getClaim().getClaimType())) { foundEntity = acm; break; } } if (foundEntity == null) { throw new EntityNotFoundException("ApplicationClaimEntity not found"); } applicationEntity.getRequestedClaims().remove(foundEntity); }
public static void domain2entity( ApplicationEntity application, RequestClaim reqClaim, ApplicationClaimEntity entity) { // The ID must not be updated if the entity has got an id already (update case) ClaimEntity claim = new ClaimEntity(); ClaimDAOJPAImpl.domain2entity(reqClaim, claim); entity.setApplication(application); entity.setClaim(claim); entity.setOptional(reqClaim.isOptional()); }
@Override public void addClaimToApplication(Application application, RequestClaim claim) { ApplicationEntity applicationEntity = null; if (application.getId() != 0) { applicationEntity = em.find(ApplicationEntity.class, application.getId()); } else { Query query = null; query = em.createQuery("select a from Application a where a.realm=:realm"); query.setParameter("realm", application.getRealm()); applicationEntity = (ApplicationEntity) query.getSingleResult(); } Claim c = claimDAO.getClaim(claim.getClaimType().toString()); ClaimEntity claimEntity = em.find(ClaimEntity.class, c.getId()); ApplicationClaimEntity appClaimEntity = new ApplicationClaimEntity(); appClaimEntity.setClaim(claimEntity); appClaimEntity.setApplication(applicationEntity); appClaimEntity.setOptional(claim.isOptional()); applicationEntity.getRequestedClaims().add(appClaimEntity); }