Search in sources :

Example 11 with NonexistentEntityException

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

the class TblHostsJpaController method edit.

public void edit(TblHosts tblHosts) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblHosts persistentTblHosts = em.find(TblHosts.class, tblHosts.getId());
        TblMle vmmMleIdOld = persistentTblHosts.getVmmMleId();
        TblMle vmmMleIdNew = tblHosts.getVmmMleId();
        TblMle biosMleIdOld = persistentTblHosts.getBiosMleId();
        TblMle biosMleIdNew = tblHosts.getBiosMleId();
        if (vmmMleIdNew != null) {
            vmmMleIdNew = em.getReference(vmmMleIdNew.getClass(), vmmMleIdNew.getId());
            tblHosts.setVmmMleId(vmmMleIdNew);
        }
        if (biosMleIdNew != null) {
            biosMleIdNew = em.getReference(biosMleIdNew.getClass(), biosMleIdNew.getId());
            tblHosts.setBiosMleId(biosMleIdNew);
        }
        // encrypt addon connection string, persist, then restore the plaintext
        String addOnConnectionString = tblHosts.getAddOnConnectionInfo();
        if (addOnConnectionString != null) {
            tblHosts = em.merge(tblHosts);
        } else {
            tblHosts = em.merge(tblHosts);
        }
        if (vmmMleIdOld != null && !vmmMleIdOld.equals(vmmMleIdNew)) {
            vmmMleIdOld.getTblHostsCollection().remove(tblHosts);
            vmmMleIdOld = em.merge(vmmMleIdOld);
        }
        if (vmmMleIdNew != null && !vmmMleIdNew.equals(vmmMleIdOld)) {
            vmmMleIdNew.getTblHostsCollection().add(tblHosts);
            em.merge(vmmMleIdNew);
        }
        if (biosMleIdOld != null && !biosMleIdOld.equals(biosMleIdNew)) {
            biosMleIdOld.getTblHostsCollection().remove(tblHosts);
            biosMleIdOld = em.merge(biosMleIdOld);
        }
        if (biosMleIdNew != null && !biosMleIdNew.equals(biosMleIdOld)) {
            biosMleIdNew.getTblHostsCollection().add(tblHosts);
            em.merge(biosMleIdNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblHosts.getId();
            if (findTblHosts(id) == null) {
                throw new NonexistentEntityException("The tblHosts 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) TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) 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 12 with NonexistentEntityException

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

the class TblLocationPcrJpaController method destroy.

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

Example 13 with NonexistentEntityException

use of com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException 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 14 with NonexistentEntityException

use of com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException 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 15 with NonexistentEntityException

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

the class TblSamlAssertionJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblSamlAssertion tblSamlAssertion;
        try {
            tblSamlAssertion = em.getReference(TblSamlAssertion.class, id);
            tblSamlAssertion.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblSamlAssertion with id " + id + " no longer exists.", enfe);
        }
        TblHosts hostId = tblSamlAssertion.getHostId();
        if (hostId != null) {
            hostId.getTblSamlAssertionCollection().remove(tblSamlAssertion);
            em.merge(hostId);
        }
        em.remove(tblSamlAssertion);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : 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) EntityNotFoundException(javax.persistence.EntityNotFoundException)

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