Search in sources :

Example 1 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException 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 2 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException in project OpenAttestation by OpenAttestation.

the class TblOsJpaController method destroy.

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

Example 3 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException in project OpenAttestation by OpenAttestation.

the class TblPackageNamespaceJpaController method destroy.

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

Example 4 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException 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 5 with EntityNotFoundException

use of javax.persistence.EntityNotFoundException 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)

Aggregations

EntityNotFoundException (javax.persistence.EntityNotFoundException)73 EntityManager (javax.persistence.EntityManager)20 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)18 ServiceException (gov.ca.cwds.rest.services.ServiceException)15 Transactional (org.springframework.transaction.annotation.Transactional)14 BusinessServiceException (sic.service.BusinessServiceException)11 Test (org.junit.Test)10 Calendar (java.util.Calendar)9 GregorianCalendar (java.util.GregorianCalendar)9 BooleanBuilder (com.querydsl.core.BooleanBuilder)6 TblMle (com.intel.mtwilson.as.data.TblMle)5 ArrayList (java.util.ArrayList)5 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)4 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)4 PersistenceException (javax.persistence.PersistenceException)4 Sort (org.springframework.data.domain.Sort)4 TblHosts (com.intel.mtwilson.as.data.TblHosts)3 OptimisticLockException (javax.persistence.OptimisticLockException)3 TblEventType (com.intel.mtwilson.as.data.TblEventType)2 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)2