Search in sources :

Example 1 with TblEventType

use of com.intel.mtwilson.as.data.TblEventType in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method edit.

public void edit(TblModuleManifest tblModuleManifest) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblModuleManifest persistentTblModuleManifest = em.find(TblModuleManifest.class, tblModuleManifest.getId());
        // @since 1.1 we are relying on the audit log for "created on", "created by", etc. type information
        /*
            TblDbPortalUser updatedByOld = persistentTblModuleManifest.getUpdatedBy();
            TblDbPortalUser updatedByNew = tblModuleManifest.getUpdatedBy();
            TblDbPortalUser createdByOld = persistentTblModuleManifest.getCreatedBy();
            TblDbPortalUser createdByNew = tblModuleManifest.getCreatedBy();
            */
        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 (updatedByNew != null) {
                updatedByNew = em.getReference(updatedByNew.getClass(), updatedByNew.getId());
                tblModuleManifest.setUpdatedBy(updatedByNew);
            }
            if (createdByNew != null) {
                createdByNew = em.getReference(createdByNew.getClass(), createdByNew.getId());
                tblModuleManifest.setCreatedBy(createdByNew);
            }*/
        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 (updatedByOld != null && !updatedByOld.equals(updatedByNew)) {
                updatedByOld.getTblModuleManifestCollection().remove(tblModuleManifest);
                updatedByOld = em.merge(updatedByOld);
            }
            if (updatedByNew != null && !updatedByNew.equals(updatedByOld)) {
                updatedByNew.getTblModuleManifestCollection().add(tblModuleManifest);
                em.merge(updatedByNew);
            }
            if (createdByOld != null && !createdByOld.equals(createdByNew)) {
                createdByOld.getTblModuleManifestCollection().remove(tblModuleManifest);
                createdByOld = em.merge(createdByOld);
            }
            if (createdByNew != null && !createdByNew.equals(createdByOld)) {
                createdByNew.getTblModuleManifestCollection().add(tblModuleManifest);
                em.merge(createdByNew);
            }
            */
        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);
                }
            }
        }
        em.getTransaction().commit();
    } 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 {
        em.close();
    }
}
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) EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Example 2 with TblEventType

use of com.intel.mtwilson.as.data.TblEventType in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method destroy.

public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblModuleManifest tblModuleManifest;
        try {
            tblModuleManifest = em.getReference(TblModuleManifest.class, id);
            tblModuleManifest.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblModuleManifest with id " + id + " no longer exists.", enfe);
        }
        List<String> illegalOrphanMessages = null;
        Collection<TblHostSpecificManifest> tblHostSpecificManifestCollectionOrphanCheck = tblModuleManifest.getTblHostSpecificManifestCollection();
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionOrphanCheckTblHostSpecificManifest : tblHostSpecificManifestCollectionOrphanCheck) {
            if (illegalOrphanMessages == null) {
                illegalOrphanMessages = new ArrayList<String>();
            }
            illegalOrphanMessages.add("This TblModuleManifest (" + tblModuleManifest + ") cannot be destroyed since the TblHostSpecificManifest " + tblHostSpecificManifestCollectionOrphanCheckTblHostSpecificManifest + " in its tblHostSpecificManifestCollection field has a non-nullable moduleManifestID field.");
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        // @since 1.1 we are relying on the audit log for "created on", "created by", etc. type information
        /*
            TblDbPortalUser updatedBy = tblModuleManifest.getUpdatedBy();
            if (updatedBy != null) {
                updatedBy.getTblModuleManifestCollection().remove(tblModuleManifest);
                em.merge(updatedBy);
            }
            TblDbPortalUser createdBy = tblModuleManifest.getCreatedBy();
            if (createdBy != null) {
                createdBy.getTblModuleManifestCollection().remove(tblModuleManifest);
                em.merge(createdBy);
            }
            */
        TblMle mleId = tblModuleManifest.getMleId();
        if (mleId != null) {
            mleId.getTblModuleManifestCollection().remove(tblModuleManifest);
            em.merge(mleId);
        }
        TblEventType eventID = tblModuleManifest.getEventID();
        if (eventID != null) {
            eventID.getTblModuleManifestCollection().remove(tblModuleManifest);
            em.merge(eventID);
        }
        TblPackageNamespace nameSpaceID = tblModuleManifest.getNameSpaceID();
        if (nameSpaceID != null) {
            nameSpaceID.getTblModuleManifestCollection().remove(tblModuleManifest);
            em.merge(nameSpaceID);
        }
        em.remove(tblModuleManifest);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) TblMle(com.intel.mtwilson.as.data.TblMle) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) EntityNotFoundException(javax.persistence.EntityNotFoundException) EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Example 3 with TblEventType

use of com.intel.mtwilson.as.data.TblEventType in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method create.

public void create(TblModuleManifest tblModuleManifest) {
    if (tblModuleManifest.getTblHostSpecificManifestCollection() == null) {
        tblModuleManifest.setTblHostSpecificManifestCollection(new ArrayList<TblHostSpecificManifest>());
    }
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        // @since 1.1 we are relying on the audit log for "created on", "created by", etc. type information
        /*
            TblDbPortalUser updatedBy = tblModuleManifest.getUpdatedBy();
            if (updatedBy != null) {
                updatedBy = em.getReference(updatedBy.getClass(), updatedBy.getId());
                tblModuleManifest.setUpdatedBy(updatedBy);
            }
            TblDbPortalUser createdBy = tblModuleManifest.getCreatedBy();
            if (createdBy != null) {
                createdBy = em.getReference(createdBy.getClass(), createdBy.getId());
                tblModuleManifest.setCreatedBy(createdBy);
            }
            */
        TblMle mleId = tblModuleManifest.getMleId();
        if (mleId != null) {
            mleId = em.getReference(mleId.getClass(), mleId.getId());
            tblModuleManifest.setMleId(mleId);
        }
        TblEventType eventID = tblModuleManifest.getEventID();
        if (eventID != null) {
            eventID = em.getReference(eventID.getClass(), eventID.getId());
            tblModuleManifest.setEventID(eventID);
        }
        TblPackageNamespace nameSpaceID = tblModuleManifest.getNameSpaceID();
        if (nameSpaceID != null) {
            nameSpaceID = em.getReference(nameSpaceID.getClass(), nameSpaceID.getId());
            tblModuleManifest.setNameSpaceID(nameSpaceID);
        }
        Collection<TblHostSpecificManifest> attachedTblHostSpecificManifestCollection = new ArrayList<TblHostSpecificManifest>();
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach : tblModuleManifest.getTblHostSpecificManifestCollection()) {
            tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach = em.getReference(tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach.getClass(), tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach.getId());
            attachedTblHostSpecificManifestCollection.add(tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach);
        }
        tblModuleManifest.setTblHostSpecificManifestCollection(attachedTblHostSpecificManifestCollection);
        em.persist(tblModuleManifest);
        /*
            if (updatedBy != null) {
                updatedBy.getTblModuleManifestCollection().add(tblModuleManifest);
                em.merge(updatedBy);
            }
            if (createdBy != null) {
                createdBy.getTblModuleManifestCollection().add(tblModuleManifest);
                em.merge(createdBy);
            }*/
        if (mleId != null) {
            mleId.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(mleId);
        }
        if (eventID != null) {
            eventID.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(eventID);
        }
        if (nameSpaceID != null) {
            nameSpaceID.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(nameSpaceID);
        }
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionTblHostSpecificManifest : tblModuleManifest.getTblHostSpecificManifestCollection()) {
            TblModuleManifest oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest = tblHostSpecificManifestCollectionTblHostSpecificManifest.getModuleManifestID();
            tblHostSpecificManifestCollectionTblHostSpecificManifest.setModuleManifestID(tblModuleManifest);
            tblHostSpecificManifestCollectionTblHostSpecificManifest = em.merge(tblHostSpecificManifestCollectionTblHostSpecificManifest);
            if (oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest != null) {
                oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifestCollectionTblHostSpecificManifest);
                em.merge(oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest);
            }
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) TblMle(com.intel.mtwilson.as.data.TblMle) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) ArrayList(java.util.ArrayList) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Example 4 with TblEventType

use of com.intel.mtwilson.as.data.TblEventType 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 5 with TblEventType

use of com.intel.mtwilson.as.data.TblEventType in project OpenAttestation by OpenAttestation.

the class TblEventTypeJpaController method create.

public void create(TblEventType tblEventType) {
    if (tblEventType.getTblModuleManifestCollection() == null) {
        tblEventType.setTblModuleManifestCollection(new ArrayList<TblModuleManifest>());
    }
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        Collection<TblModuleManifest> attachedTblModuleManifestCollection = new ArrayList<TblModuleManifest>();
        for (TblModuleManifest tblModuleManifestCollectionTblModuleManifestToAttach : tblEventType.getTblModuleManifestCollection()) {
            tblModuleManifestCollectionTblModuleManifestToAttach = em.getReference(tblModuleManifestCollectionTblModuleManifestToAttach.getClass(), tblModuleManifestCollectionTblModuleManifestToAttach.getId());
            attachedTblModuleManifestCollection.add(tblModuleManifestCollectionTblModuleManifestToAttach);
        }
        tblEventType.setTblModuleManifestCollection(attachedTblModuleManifestCollection);
        em.persist(tblEventType);
        for (TblModuleManifest tblModuleManifestCollectionTblModuleManifest : tblEventType.getTblModuleManifestCollection()) {
            TblEventType oldEventIDOfTblModuleManifestCollectionTblModuleManifest = tblModuleManifestCollectionTblModuleManifest.getEventID();
            tblModuleManifestCollectionTblModuleManifest.setEventID(tblEventType);
            tblModuleManifestCollectionTblModuleManifest = em.merge(tblModuleManifestCollectionTblModuleManifest);
            if (oldEventIDOfTblModuleManifestCollectionTblModuleManifest != null) {
                oldEventIDOfTblModuleManifestCollectionTblModuleManifest.getTblModuleManifestCollection().remove(tblModuleManifestCollectionTblModuleManifest);
                em.merge(oldEventIDOfTblModuleManifestCollectionTblModuleManifest);
            }
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblEventType(com.intel.mtwilson.as.data.TblEventType) ArrayList(java.util.ArrayList) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest)

Aggregations

TblEventType (com.intel.mtwilson.as.data.TblEventType)12 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)9 EntityManager (javax.persistence.EntityManager)9 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)6 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)6 TblMle (com.intel.mtwilson.as.data.TblMle)6 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)6 ArrayList (java.util.ArrayList)6 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)5 EntityNotFoundException (javax.persistence.EntityNotFoundException)5 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)3 NoResultException (javax.persistence.NoResultException)3 Query (javax.persistence.Query)3 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)3 ASException (com.intel.mountwilson.as.common.ASException)1 TblEventTypeJpaController (com.intel.mtwilson.as.controller.TblEventTypeJpaController)1 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)1 TblModuleManifestJpaController (com.intel.mtwilson.as.controller.TblModuleManifestJpaController)1 TblPackageNamespaceJpaController (com.intel.mtwilson.as.controller.TblPackageNamespaceJpaController)1 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)1