Search in sources :

Example 6 with NonexistentEntityException

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

the class TblPackageNamespaceJpaController method edit.

public void edit(TblPackageNamespace tblPackageNamespace) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblPackageNamespace persistentTblPackageNamespace = em.find(TblPackageNamespace.class, tblPackageNamespace.getId());
        Collection<TblModuleManifest> tblModuleManifestCollectionOld = persistentTblPackageNamespace.getTblModuleManifestCollection();
        Collection<TblModuleManifest> tblModuleManifestCollectionNew = tblPackageNamespace.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 nameSpaceID 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;
        tblPackageNamespace.setTblModuleManifestCollection(tblModuleManifestCollectionNew);
        tblPackageNamespace = em.merge(tblPackageNamespace);
        for (TblModuleManifest tblModuleManifestCollectionNewTblModuleManifest : tblModuleManifestCollectionNew) {
            if (!tblModuleManifestCollectionOld.contains(tblModuleManifestCollectionNewTblModuleManifest)) {
                TblPackageNamespace oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest = tblModuleManifestCollectionNewTblModuleManifest.getNameSpaceID();
                tblModuleManifestCollectionNewTblModuleManifest.setNameSpaceID(tblPackageNamespace);
                tblModuleManifestCollectionNewTblModuleManifest = em.merge(tblModuleManifestCollectionNewTblModuleManifest);
                if (oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest != null && !oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest.equals(tblPackageNamespace)) {
                    oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest.getTblModuleManifestCollection().remove(tblModuleManifestCollectionNewTblModuleManifest);
                    em.merge(oldNameSpaceIDOfTblModuleManifestCollectionNewTblModuleManifest);
                }
            }
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblPackageNamespace.getId();
            if (findTblPackageNamespace(id) == null) {
                throw new NonexistentEntityException("The tblPackageNamespace 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) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Example 7 with NonexistentEntityException

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

the class TblPcrManifestJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblPcrManifest tblPcrManifest;
        try {
            tblPcrManifest = em.getReference(TblPcrManifest.class, id);
            tblPcrManifest.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblPcrManifest with id " + id + " no longer exists.", enfe);
        }
        // @since 1.1 we are relying on the audit log for "created on", "created by", etc. type information
        /*
            TblDbPortalUser updatedBy = tblPcrManifest.getUpdatedBy();
            if (updatedBy != null) {
                updatedBy.getTblPcrManifestCollection().remove(tblPcrManifest);
                em.merge(updatedBy);
            }
            TblDbPortalUser createdBy = tblPcrManifest.getCreatedBy();
            if (createdBy != null) {
                createdBy.getTblPcrManifestCollection().remove(tblPcrManifest);
                em.merge(createdBy);
            }
            */
        TblMle mleId = tblPcrManifest.getMleId();
        if (mleId != null) {
            mleId.getTblPcrManifestCollection().remove(tblPcrManifest);
            em.merge(mleId);
        }
        em.remove(tblPcrManifest);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest)

Example 8 with NonexistentEntityException

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

the class TblModuleManifestLogJpaController method destroy.

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

Example 9 with NonexistentEntityException

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

the class TblOemJpaController method edit.

public void edit(TblOem tblOem) throws NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        em.merge(tblOem);
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblOem.getId();
            if (findTblOem(id) == null) {
                throw new NonexistentEntityException("The tblOem 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) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 10 with NonexistentEntityException

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

the class TblHostsJpaController method destroy.

public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblHosts tblHosts;
        try {
            tblHosts = em.getReference(TblHosts.class, id);
            tblHosts.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblHosts with id " + id + " no longer exists.", enfe);
        }
        TblMle vmmMleId = tblHosts.getVmmMleId();
        if (vmmMleId != null) {
            vmmMleId.getTblHostsCollection().remove(tblHosts);
            em.merge(vmmMleId);
        }
        TblMle biosMleId = tblHosts.getBiosMleId();
        if (biosMleId != null) {
            biosMleId.getTblHostsCollection().remove(tblHosts);
            em.merge(biosMleId);
        }
        em.remove(tblHosts);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : 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) 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