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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations