Search in sources :

Example 6 with IllegalOrphanException

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

the class TblEventTypeJpaController method destroy.

public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblEventType tblEventType;
        try {
            tblEventType = em.getReference(TblEventType.class, id);
            tblEventType.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblEventType with id " + id + " no longer exists.", enfe);
        }
        List<String> illegalOrphanMessages = null;
        Collection<TblModuleManifest> tblModuleManifestCollectionOrphanCheck = tblEventType.getTblModuleManifestCollection();
        for (TblModuleManifest tblModuleManifestCollectionOrphanCheckTblModuleManifest : tblModuleManifestCollectionOrphanCheck) {
            if (illegalOrphanMessages == null) {
                illegalOrphanMessages = new ArrayList<String>();
            }
            illegalOrphanMessages.add("This TblEventType (" + tblEventType + ") cannot be destroyed since the TblModuleManifest " + tblModuleManifestCollectionOrphanCheckTblModuleManifest + " in its tblModuleManifestCollection field has a non-nullable eventID field.");
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        em.remove(tblEventType);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 7 with IllegalOrphanException

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

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

use of com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException 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)

Example 10 with IllegalOrphanException

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

the class TblModuleManifestJpaController method edit_v2.

public void edit_v2(TblModuleManifest tblModuleManifest, EntityManager em) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    try {
        TblModuleManifest persistentTblModuleManifest = em.find(TblModuleManifest.class, tblModuleManifest.getId());
        TblMle mleIdOld = persistentTblModuleManifest.getMleId();
        TblMle mleIdNew = tblModuleManifest.getMleId();
        TblEventType eventIDOld = persistentTblModuleManifest.getEventID();
        TblEventType eventIDNew = tblModuleManifest.getEventID();
        TblPackageNamespace nameSpaceIDOld = persistentTblModuleManifest.getNameSpaceID();
        TblPackageNamespace nameSpaceIDNew = tblModuleManifest.getNameSpaceID();
        Collection<TblHostSpecificManifest> tblHostSpecificManifestCollectionOld = persistentTblModuleManifest.getTblHostSpecificManifestCollection();
        Collection<TblHostSpecificManifest> tblHostSpecificManifestCollectionNew = tblModuleManifest.getTblHostSpecificManifestCollection();
        List<String> illegalOrphanMessages = null;
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionOldTblHostSpecificManifest : tblHostSpecificManifestCollectionOld) {
            if (!tblHostSpecificManifestCollectionNew.contains(tblHostSpecificManifestCollectionOldTblHostSpecificManifest)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain TblHostSpecificManifest " + tblHostSpecificManifestCollectionOldTblHostSpecificManifest + " since its moduleManifestID field is not nullable.");
            }
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        if (mleIdNew != null) {
            mleIdNew = em.getReference(mleIdNew.getClass(), mleIdNew.getId());
            tblModuleManifest.setMleId(mleIdNew);
        }
        if (eventIDNew != null) {
            eventIDNew = em.getReference(eventIDNew.getClass(), eventIDNew.getId());
            tblModuleManifest.setEventID(eventIDNew);
        }
        if (nameSpaceIDNew != null) {
            nameSpaceIDNew = em.getReference(nameSpaceIDNew.getClass(), nameSpaceIDNew.getId());
            tblModuleManifest.setNameSpaceID(nameSpaceIDNew);
        }
        Collection<TblHostSpecificManifest> attachedTblHostSpecificManifestCollectionNew = new ArrayList<TblHostSpecificManifest>();
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach : tblHostSpecificManifestCollectionNew) {
            tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach = em.getReference(tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach.getClass(), tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach.getId());
            attachedTblHostSpecificManifestCollectionNew.add(tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach);
        }
        tblHostSpecificManifestCollectionNew = attachedTblHostSpecificManifestCollectionNew;
        tblModuleManifest.setTblHostSpecificManifestCollection(tblHostSpecificManifestCollectionNew);
        tblModuleManifest = em.merge(tblModuleManifest);
        if (mleIdOld != null && !mleIdOld.equals(mleIdNew)) {
            mleIdOld.getTblModuleManifestCollection().remove(tblModuleManifest);
            mleIdOld = em.merge(mleIdOld);
        }
        if (mleIdNew != null && !mleIdNew.equals(mleIdOld)) {
            mleIdNew.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(mleIdNew);
        }
        if (eventIDOld != null && !eventIDOld.equals(eventIDNew)) {
            eventIDOld.getTblModuleManifestCollection().remove(tblModuleManifest);
            eventIDOld = em.merge(eventIDOld);
        }
        if (eventIDNew != null && !eventIDNew.equals(eventIDOld)) {
            eventIDNew.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(eventIDNew);
        }
        if (nameSpaceIDOld != null && !nameSpaceIDOld.equals(nameSpaceIDNew)) {
            nameSpaceIDOld.getTblModuleManifestCollection().remove(tblModuleManifest);
            nameSpaceIDOld = em.merge(nameSpaceIDOld);
        }
        if (nameSpaceIDNew != null && !nameSpaceIDNew.equals(nameSpaceIDOld)) {
            nameSpaceIDNew.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(nameSpaceIDNew);
        }
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionNewTblHostSpecificManifest : tblHostSpecificManifestCollectionNew) {
            if (!tblHostSpecificManifestCollectionOld.contains(tblHostSpecificManifestCollectionNewTblHostSpecificManifest)) {
                TblModuleManifest oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest = tblHostSpecificManifestCollectionNewTblHostSpecificManifest.getModuleManifestID();
                tblHostSpecificManifestCollectionNewTblHostSpecificManifest.setModuleManifestID(tblModuleManifest);
                tblHostSpecificManifestCollectionNewTblHostSpecificManifest = em.merge(tblHostSpecificManifestCollectionNewTblHostSpecificManifest);
                if (oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest != null && !oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest.equals(tblModuleManifest)) {
                    oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifestCollectionNewTblHostSpecificManifest);
                    em.merge(oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest);
                }
            }
        }
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblModuleManifest.getId();
            if (findTblModuleManifest(id) == null) {
                throw new NonexistentEntityException("The tblModuleManifest with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) TblMle(com.intel.mtwilson.as.data.TblMle) ArrayList(java.util.ArrayList) 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) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) TblEventType(com.intel.mtwilson.as.data.TblEventType) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Aggregations

IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)12 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)12 EntityNotFoundException (javax.persistence.EntityNotFoundException)11 EntityManager (javax.persistence.EntityManager)10 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)8 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)7 TblMle (com.intel.mtwilson.as.data.TblMle)7 TblEventType (com.intel.mtwilson.as.data.TblEventType)5 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)5 ArrayList (java.util.ArrayList)5 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)3 TblHosts (com.intel.mtwilson.as.data.TblHosts)3 NoResultException (javax.persistence.NoResultException)3 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)2 ASException (com.intel.mountwilson.as.common.ASException)1 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)1 TblModuleManifestJpaController (com.intel.mtwilson.as.controller.TblModuleManifestJpaController)1 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)1