Search in sources :

Example 21 with NonexistentEntityException

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

the class MwAssetTagCertificateJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        MwAssetTagCertificate mwAssetTagCertificate;
        try {
            mwAssetTagCertificate = em.getReference(MwAssetTagCertificate.class, id);
            mwAssetTagCertificate.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The mwAssetTagCertificate with id " + id + " no longer exists.", enfe);
        }
        em.remove(mwAssetTagCertificate);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) MwAssetTagCertificate(com.intel.mtwilson.as.data.MwAssetTagCertificate)

Example 22 with NonexistentEntityException

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

the class MwAssetTagCertificateJpaController method edit.

public void edit(MwAssetTagCertificate mwAssetTagCertificate) {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        mwAssetTagCertificate = em.merge(mwAssetTagCertificate);
        mwAssetTagCertificate.getId();
        em.getTransaction().commit();
    } catch (PersistenceException ex) {
        String msg = ex.getLocalizedMessage();
        Integer id = mwAssetTagCertificate.getId();
        if (msg == null || msg.length() == 0) {
            if (id != null && findMwAssetTagCertificate(id) == null) {
                try {
                    throw new NonexistentEntityException("The mwAssetTagCertificate with id " + id + " no longer exists.");
                } catch (NonexistentEntityException ex1) {
                    Logger.getLogger(MwAssetTagCertificateJpaController.class.getName()).log(Level.SEVERE, null, ex1);
                }
            }
        }
        throw ex;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) PersistenceException(javax.persistence.PersistenceException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)

Example 23 with NonexistentEntityException

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

the class MwCertificateX509JpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        MwCertificateX509 mwCertificateX509;
        try {
            mwCertificateX509 = em.getReference(MwCertificateX509.class, id);
            mwCertificateX509.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The mwCertificateX509 with id " + id + " no longer exists.", enfe);
        }
        em.remove(mwCertificateX509);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) MwCertificateX509(com.intel.mtwilson.as.data.MwCertificateX509) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 24 with NonexistentEntityException

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

the class TblTaLogJpaController method edit.

public void edit(TblTaLog tblTaLog) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        // commenting out unused variable for klocwork scans
        // stdalex 3/4
        //TblTaLog persistentTblTaLog = em.find(TblTaLog.class, tblTaLog.getId());
        em.merge(tblTaLog);
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblTaLog.getId();
            if (findTblTaLog(id) == null) {
                throw new NonexistentEntityException("The tblTaLog 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) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 25 with NonexistentEntityException

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

the class TblMleJpaController method destroy.

public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblMle tblMle;
        try {
            tblMle = em.getReference(TblMle.class, id);
            tblMle.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblMle with id " + id + " no longer exists.", enfe);
        }
        List<String> illegalOrphanMessages = null;
        Collection<TblHosts> tblHostsCollectionOrphanCheck = tblMle.getTblHostsCollection();
        for (TblHosts tblHostsCollectionOrphanCheckTblHosts : tblHostsCollectionOrphanCheck) {
            if (illegalOrphanMessages == null) {
                illegalOrphanMessages = new ArrayList<String>();
            }
            illegalOrphanMessages.add("This TblMle (" + tblMle + ") cannot be destroyed since the TblHosts " + tblHostsCollectionOrphanCheckTblHosts + " in its tblHostsCollection field has a non-nullable vmmMleId field.");
        }
        Collection<TblHosts> tblHostsCollection1OrphanCheck = tblMle.getTblHostsCollection1();
        for (TblHosts tblHostsCollection1OrphanCheckTblHosts : tblHostsCollection1OrphanCheck) {
            if (illegalOrphanMessages == null) {
                illegalOrphanMessages = new ArrayList<String>();
            }
            illegalOrphanMessages.add("This TblMle (" + tblMle + ") cannot be destroyed since the TblHosts " + tblHostsCollection1OrphanCheckTblHosts + " in its tblHostsCollection1 field has a non-nullable biosMleId field.");
        }
        Collection<TblPcrManifest> tblPcrManifestCollectionOrphanCheck = tblMle.getTblPcrManifestCollection();
        for (TblPcrManifest tblPcrManifestCollectionOrphanCheckTblPcrManifest : tblPcrManifestCollectionOrphanCheck) {
            if (illegalOrphanMessages == null) {
                illegalOrphanMessages = new ArrayList<String>();
            }
            illegalOrphanMessages.add("This TblMle (" + tblMle + ") cannot be destroyed since the TblPcrManifest " + tblPcrManifestCollectionOrphanCheckTblPcrManifest + " in its tblPcrManifestCollection field has a non-nullable mleId field.");
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        em.remove(tblMle);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) EntityManager(javax.persistence.EntityManager) TblMle(com.intel.mtwilson.as.data.TblMle) TblHosts(com.intel.mtwilson.as.data.TblHosts) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest)

Aggregations

NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)40 EntityNotFoundException (javax.persistence.EntityNotFoundException)36 EntityManager (javax.persistence.EntityManager)34 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)15 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)12 TblMle (com.intel.mtwilson.as.data.TblMle)12 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)10 NoResultException (javax.persistence.NoResultException)8 TblHosts (com.intel.mtwilson.as.data.TblHosts)6 TblEventType (com.intel.mtwilson.as.data.TblEventType)5 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)5 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)5 ArrayList (java.util.ArrayList)5 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)4 TblTaLog (com.intel.mtwilson.as.data.TblTaLog)4 TblSamlAssertion (com.intel.mtwilson.as.data.TblSamlAssertion)3 MwMleSource (com.intel.mtwilson.as.data.MwMleSource)2 TblModuleManifestLog (com.intel.mtwilson.as.data.TblModuleManifestLog)2 ASException (com.intel.mountwilson.as.common.ASException)1 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)1