use of com.intel.mtwilson.as.controller.exceptions.ASDataException 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();
}
}
use of com.intel.mtwilson.as.controller.exceptions.ASDataException in project OpenAttestation by OpenAttestation.
the class TblOsJpaController method edit.
public void edit(TblOs tblOs) throws NonexistentEntityException, ASDataException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
em.merge(tblOs);
em.getTransaction().commit();
} catch (Exception ex) {
String msg = ex.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
Integer id = tblOs.getId();
if (findTblOs(id) == null) {
throw new NonexistentEntityException("The tblOs with id " + id + " no longer exists.");
}
}
throw new ASDataException(ex);
} finally {
em.close();
}
}
use of com.intel.mtwilson.as.controller.exceptions.ASDataException 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.ASDataException 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.ASDataException in project OpenAttestation by OpenAttestation.
the class TblHostsJpaController method edit.
public void edit(TblHosts tblHosts) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
TblHosts persistentTblHosts = em.find(TblHosts.class, tblHosts.getId());
TblMle vmmMleIdOld = persistentTblHosts.getVmmMleId();
TblMle vmmMleIdNew = tblHosts.getVmmMleId();
TblMle biosMleIdOld = persistentTblHosts.getBiosMleId();
TblMle biosMleIdNew = tblHosts.getBiosMleId();
if (vmmMleIdNew != null) {
vmmMleIdNew = em.getReference(vmmMleIdNew.getClass(), vmmMleIdNew.getId());
tblHosts.setVmmMleId(vmmMleIdNew);
}
if (biosMleIdNew != null) {
biosMleIdNew = em.getReference(biosMleIdNew.getClass(), biosMleIdNew.getId());
tblHosts.setBiosMleId(biosMleIdNew);
}
// encrypt addon connection string, persist, then restore the plaintext
String addOnConnectionString = tblHosts.getAddOnConnectionInfo();
if (addOnConnectionString != null) {
tblHosts = em.merge(tblHosts);
} else {
tblHosts = em.merge(tblHosts);
}
if (vmmMleIdOld != null && !vmmMleIdOld.equals(vmmMleIdNew)) {
vmmMleIdOld.getTblHostsCollection().remove(tblHosts);
vmmMleIdOld = em.merge(vmmMleIdOld);
}
if (vmmMleIdNew != null && !vmmMleIdNew.equals(vmmMleIdOld)) {
vmmMleIdNew.getTblHostsCollection().add(tblHosts);
em.merge(vmmMleIdNew);
}
if (biosMleIdOld != null && !biosMleIdOld.equals(biosMleIdNew)) {
biosMleIdOld.getTblHostsCollection().remove(tblHosts);
biosMleIdOld = em.merge(biosMleIdOld);
}
if (biosMleIdNew != null && !biosMleIdNew.equals(biosMleIdOld)) {
biosMleIdNew.getTblHostsCollection().add(tblHosts);
em.merge(biosMleIdNew);
}
em.getTransaction().commit();
} catch (Exception ex) {
String msg = ex.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
Integer id = tblHosts.getId();
if (findTblHosts(id) == null) {
throw new NonexistentEntityException("The tblHosts with id " + id + " no longer exists.");
}
}
throw new ASDataException(ex);
} finally {
em.close();
}
}
Aggregations