Search in sources :

Example 6 with ASDataException

use of com.intel.mtwilson.as.controller.exceptions.ASDataException in project OpenAttestation by OpenAttestation.

the class TblPcrManifestJpaController method edit.

public void edit(TblPcrManifest tblPcrManifest) throws NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblPcrManifest persistentTblPcrManifest = em.find(TblPcrManifest.class, tblPcrManifest.getId());
        // @since 1.1 we are relying on the audit log for "created on", "created by", etc. type information
        /*
            TblDbPortalUser updatedByOld = persistentTblPcrManifest.getUpdatedBy();
            TblDbPortalUser updatedByNew = tblPcrManifest.getUpdatedBy();
            TblDbPortalUser createdByOld = persistentTblPcrManifest.getCreatedBy();
            TblDbPortalUser createdByNew = tblPcrManifest.getCreatedBy();
            */
        TblMle mleIdOld = persistentTblPcrManifest.getMleId();
        TblMle mleIdNew = tblPcrManifest.getMleId();
        /*
            if (updatedByNew != null) {
                updatedByNew = em.getReference(updatedByNew.getClass(), updatedByNew.getId());
                tblPcrManifest.setUpdatedBy(updatedByNew);
            }
            if (createdByNew != null) {
                createdByNew = em.getReference(createdByNew.getClass(), createdByNew.getId());
                tblPcrManifest.setCreatedBy(createdByNew);
            }*/
        if (mleIdNew != null) {
            mleIdNew = em.getReference(mleIdNew.getClass(), mleIdNew.getId());
            tblPcrManifest.setMleId(mleIdNew);
        }
        tblPcrManifest = em.merge(tblPcrManifest);
        /*
            if (updatedByOld != null && !updatedByOld.equals(updatedByNew)) {
                updatedByOld.getTblPcrManifestCollection().remove(tblPcrManifest);
                updatedByOld = em.merge(updatedByOld);
            }
            if (updatedByNew != null && !updatedByNew.equals(updatedByOld)) {
                updatedByNew.getTblPcrManifestCollection().add(tblPcrManifest);
                em.merge(updatedByNew);
            }
            if (createdByOld != null && !createdByOld.equals(createdByNew)) {
                createdByOld.getTblPcrManifestCollection().remove(tblPcrManifest);
                createdByOld = em.merge(createdByOld);
            }
            if (createdByNew != null && !createdByNew.equals(createdByOld)) {
                createdByNew.getTblPcrManifestCollection().add(tblPcrManifest);
                em.merge(createdByNew);
            }
            */
        if (mleIdOld != null && !mleIdOld.equals(mleIdNew)) {
            mleIdOld.getTblPcrManifestCollection().remove(tblPcrManifest);
            mleIdOld = em.merge(mleIdOld);
        }
        if (mleIdNew != null && !mleIdNew.equals(mleIdOld)) {
            mleIdNew.getTblPcrManifestCollection().add(tblPcrManifest);
            em.merge(mleIdNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblPcrManifest.getId();
            if (findTblPcrManifest(id) == null) {
                throw new NonexistentEntityException("The tblPcrManifest with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
        em.close();
    }
}
Also used : ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) EntityManager(javax.persistence.EntityManager) TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 7 with ASDataException

use of com.intel.mtwilson.as.controller.exceptions.ASDataException in project OpenAttestation by OpenAttestation.

the class TblRequestQueueJpaController method edit.

public void edit(TblRequestQueue tblRequestQueue) throws NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        em.merge(tblRequestQueue);
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblRequestQueue.getId();
            if (findTblRequestQueue(id) == null) {
                throw new NonexistentEntityException("The tblRequestQueue with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
        em.close();
    }
}
Also used : ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) EntityManager(javax.persistence.EntityManager) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 8 with ASDataException

use of com.intel.mtwilson.as.controller.exceptions.ASDataException in project OpenAttestation by OpenAttestation.

the class TblSamlAssertionJpaController method edit.

public void edit(TblSamlAssertion tblSamlAssertion) throws NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblSamlAssertion persistentTblSamlAssertion = em.find(TblSamlAssertion.class, tblSamlAssertion.getId());
        TblHosts hostIdOld = persistentTblSamlAssertion.getHostId();
        TblHosts hostIdNew = tblSamlAssertion.getHostId();
        if (hostIdNew != null) {
            hostIdNew = em.getReference(hostIdNew.getClass(), hostIdNew.getId());
            tblSamlAssertion.setHostId(hostIdNew);
        }
        tblSamlAssertion = em.merge(tblSamlAssertion);
        if (hostIdOld != null && !hostIdOld.equals(hostIdNew)) {
            hostIdOld.getTblSamlAssertionCollection().remove(tblSamlAssertion);
            hostIdOld = em.merge(hostIdOld);
        }
        if (hostIdNew != null && !hostIdNew.equals(hostIdOld)) {
            hostIdNew.getTblSamlAssertionCollection().add(tblSamlAssertion);
            em.merge(hostIdNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblSamlAssertion.getId();
            if (findTblSamlAssertion(id) == null) {
                throw new NonexistentEntityException("The tblSamlAssertion with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
        em.close();
    }
}
Also used : ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) EntityManager(javax.persistence.EntityManager) TblHosts(com.intel.mtwilson.as.data.TblHosts) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 9 with ASDataException

use of com.intel.mtwilson.as.controller.exceptions.ASDataException in project OpenAttestation by OpenAttestation.

the class TblEventTypeJpaController method edit.

public void edit(TblEventType tblEventType) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblEventType persistentTblEventType = em.find(TblEventType.class, tblEventType.getId());
        Collection<TblModuleManifest> tblModuleManifestCollectionOld = persistentTblEventType.getTblModuleManifestCollection();
        Collection<TblModuleManifest> tblModuleManifestCollectionNew = tblEventType.getTblModuleManifestCollection();
        List<String> illegalOrphanMessages = null;
        for (TblModuleManifest tblModuleManifestCollectionOldTblModuleManifest : tblModuleManifestCollectionOld) {
            if (!tblModuleManifestCollectionNew.contains(tblModuleManifestCollectionOldTblModuleManifest)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain TblModuleManifest " + tblModuleManifestCollectionOldTblModuleManifest + " since its eventID field is not nullable.");
            }
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        Collection<TblModuleManifest> attachedTblModuleManifestCollectionNew = new ArrayList<TblModuleManifest>();
        for (TblModuleManifest tblModuleManifestCollectionNewTblModuleManifestToAttach : tblModuleManifestCollectionNew) {
            tblModuleManifestCollectionNewTblModuleManifestToAttach = em.getReference(tblModuleManifestCollectionNewTblModuleManifestToAttach.getClass(), tblModuleManifestCollectionNewTblModuleManifestToAttach.getId());
            attachedTblModuleManifestCollectionNew.add(tblModuleManifestCollectionNewTblModuleManifestToAttach);
        }
        tblModuleManifestCollectionNew = attachedTblModuleManifestCollectionNew;
        tblEventType.setTblModuleManifestCollection(tblModuleManifestCollectionNew);
        tblEventType = em.merge(tblEventType);
        for (TblModuleManifest tblModuleManifestCollectionNewTblModuleManifest : tblModuleManifestCollectionNew) {
            if (!tblModuleManifestCollectionOld.contains(tblModuleManifestCollectionNewTblModuleManifest)) {
                TblEventType oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest = tblModuleManifestCollectionNewTblModuleManifest.getEventID();
                tblModuleManifestCollectionNewTblModuleManifest.setEventID(tblEventType);
                tblModuleManifestCollectionNewTblModuleManifest = em.merge(tblModuleManifestCollectionNewTblModuleManifest);
                if (oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest != null && !oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest.equals(tblEventType)) {
                    oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest.getTblModuleManifestCollection().remove(tblModuleManifestCollectionNewTblModuleManifest);
                    em.merge(oldEventIDOfTblModuleManifestCollectionNewTblModuleManifest);
                }
            }
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblEventType.getId();
            if (findTblEventType(id) == null) {
                throw new NonexistentEntityException("The tblEventType with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
        em.close();
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) ArrayList(java.util.ArrayList) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType)

Example 10 with ASDataException

use of com.intel.mtwilson.as.controller.exceptions.ASDataException in project OpenAttestation by OpenAttestation.

the class TblHostSpecificManifestJpaController method edit.

public void edit(TblHostSpecificManifest tblHostSpecificManifest) throws NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblHostSpecificManifest persistentTblHostSpecificManifest = em.find(TblHostSpecificManifest.class, tblHostSpecificManifest.getId());
        TblModuleManifest moduleManifestIDOld = persistentTblHostSpecificManifest.getModuleManifestID();
        TblModuleManifest moduleManifestIDNew = tblHostSpecificManifest.getModuleManifestID();
        if (moduleManifestIDNew != null) {
            moduleManifestIDNew = em.getReference(moduleManifestIDNew.getClass(), moduleManifestIDNew.getId());
            tblHostSpecificManifest.setModuleManifestID(moduleManifestIDNew);
        }
        tblHostSpecificManifest = em.merge(tblHostSpecificManifest);
        if (moduleManifestIDOld != null && !moduleManifestIDOld.equals(moduleManifestIDNew)) {
            moduleManifestIDOld.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifest);
            moduleManifestIDOld = em.merge(moduleManifestIDOld);
        }
        if (moduleManifestIDNew != null && !moduleManifestIDNew.equals(moduleManifestIDOld)) {
            moduleManifestIDNew.getTblHostSpecificManifestCollection().add(tblHostSpecificManifest);
            em.merge(moduleManifestIDNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblHostSpecificManifest.getId();
            if (findTblHostSpecificManifest(id) == null) {
                throw new NonexistentEntityException("The tblHostSpecificManifest with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
        em.close();
    }
}
Also used : ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) EntityManager(javax.persistence.EntityManager) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Aggregations

ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)15 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)15 EntityNotFoundException (javax.persistence.EntityNotFoundException)15 EntityManager (javax.persistence.EntityManager)14 NoResultException (javax.persistence.NoResultException)8 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)7 TblMle (com.intel.mtwilson.as.data.TblMle)5 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)5 ArrayList (java.util.ArrayList)5 TblEventType (com.intel.mtwilson.as.data.TblEventType)3 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)3 TblHosts (com.intel.mtwilson.as.data.TblHosts)3 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)3 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)2 TblModuleManifestLog (com.intel.mtwilson.as.data.TblModuleManifestLog)1 TblSamlAssertion (com.intel.mtwilson.as.data.TblSamlAssertion)1 TblTaLog (com.intel.mtwilson.as.data.TblTaLog)1 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)1