use of com.intel.mtwilson.as.data.TblPackageNamespace 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.data.TblPackageNamespace 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();
}
}
use of com.intel.mtwilson.as.data.TblPackageNamespace in project OpenAttestation by OpenAttestation.
the class HostBO method addModuleWhiteList.
private void addModuleWhiteList(PcrManifest pcr19, TblHosts tblHosts, TxtHost host, String uuid) {
try {
TblModuleManifestJpaController tblModuleManifestJpa = getModuleJpaController();
TblMleJpaController tblMleJpa = getMleJpaController();
TblEventTypeJpaController tblEventJpa = getEventJpaController();
TblPackageNamespaceJpaController tblPackageJpa = getPackageJpaController();
TblEventType tblEvent;
TblMle tblMle = tblMleJpa.findTblMleByUUID(uuid);
TblPackageNamespace nsPackNS;
if (tblMle == null) {
try {
// First check if the entry exists in the MLE table.
tblMle = getMleDetails(host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion(), "");
} catch (NoResultException nre) {
throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, host.getVmm().getName(), host.getVmm().getVersion());
}
}
if (tblMle == null) {
log.error("MLE specified is not found in the DB");
throw new ASException(ErrorCode.WS_MLE_RETRIEVAL_ERROR, this.getClass().getSimpleName());
}
String eventName;
String componentName;
// String fullComponentName = "";
String fullComponentName;
String digest;
String packageName;
String packageVendor;
String packageVersion;
String extendedtoPCR;
boolean useHostSpecificDigest;
try {
// Before we insert the record, we need the identity for the event name
if (pcr19.containsPcrEventLog(19)) {
PcrEventLog pcrEventLog = pcr19.getPcrEventLog(19);
if (pcrEventLog != null) {
for (Measurement m : pcrEventLog.getEventLog()) {
extendedtoPCR = m.getInfo().get("ExtendedToPCR");
if (extendedtoPCR != null) {
if (extendedtoPCR.equals("19")) {
//tblEvent = tblEventJpa.findEventTypeByName(m.getInfo().get("EventName"));
eventName = m.getInfo().get("EventName");
componentName = m.getInfo().get("ComponentName");
packageName = String.valueOf(m.getInfo().get("PackageName"));
packageVendor = String.valueOf(m.getInfo().get("PackageVendor"));
packageVersion = String.valueOf(m.getInfo().get("PackageVersion"));
extendedtoPCR = String.valueOf(m.getInfo().get("ExtendedToPCR"));
digest = String.valueOf(m.getValue());
useHostSpecificDigest = Boolean.valueOf(m.getInfo().get("UseHostSpecificDigest"));
try {
// Before we insert the record, we need the identity for the event name
tblEvent = tblEventJpa.findEventTypeByName(eventName);
} catch (NoResultException nre) {
throw new ASException(nre, ErrorCode.WS_EVENT_TYPE_DOES_NOT_EXIST, eventName);
}
validateNull("EventName", eventName);
validateNull("ComponentName", componentName);
// corresponds to VMware, then we will append the event type fieldName to the component name. Otherwise we won't
if (eventName.contains("Vim25")) {
fullComponentName = tblEvent.getFieldName() + "." + componentName;
} else {
fullComponentName = componentName;
}
Integer componentID = tblModuleManifestJpa.findByMleIdEventId(tblMle.getId(), fullComponentName, tblEvent.getId());
if (componentID != null && componentID != 0) {
throw new ASException(ErrorCode.WS_MODULE_WHITELIST_ALREADY_EXISTS, componentName);
}
try {
// Since there will be only one entry for now, we will just hardcode it for now.
// TO-DO: See if we can change this.
// Nov-12,2013: Changed to use the function that accepts the ID instead of the name for better
// performance.
nsPackNS = tblPackageJpa.findByName("Standard_Global_NS");
} catch (NoResultException nre) {
throw new ASException(ErrorCode.WS_NAME_SPACE_DOES_NOT_EXIST);
}
TblModuleManifest newModuleRecord = new TblModuleManifest();
if (uuid != null && !uuid.isEmpty()) {
newModuleRecord.setUuid_hex(uuid);
} else {
newModuleRecord.setUuid_hex(new UUID().toString());
}
newModuleRecord.setMleId(tblMle);
newModuleRecord.setMle_uuid_hex(tblMle.getUuid_hex());
newModuleRecord.setEventID(tblEvent);
newModuleRecord.setNameSpaceID(nsPackNS);
newModuleRecord.setComponentName(fullComponentName);
newModuleRecord.setDigestValue(digest);
newModuleRecord.setPackageName(packageName);
newModuleRecord.setPackageVendor(packageVendor);
newModuleRecord.setPackageVersion(packageVersion);
newModuleRecord.setUseHostSpecificDigestValue(useHostSpecificDigest);
newModuleRecord.setExtendedToPCR(extendedtoPCR);
newModuleRecord.setDescription("");
tblModuleManifestJpa.create(newModuleRecord);
// break;
}
}
}
}
}
} catch (NoResultException nre) {
throw new ASException(nre, ErrorCode.WS_EVENT_TYPE_DOES_NOT_EXIST);
}
} catch (ASException ase) {
throw ase;
} catch (Exception e) {
// throw new ASException(ErrorCode.SYSTEM_ERROR, "Exception while adding Module white list data. " + e.getMessage(), e);
// throw new ASException(e);
log.error("Error during Module whitelist creation.", e);
throw new ASException(ErrorCode.WS_MODULE_WHITELIST_CREATE_ERROR, e.getClass().getSimpleName());
}
}
use of com.intel.mtwilson.as.data.TblPackageNamespace 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 {
}
}
use of com.intel.mtwilson.as.data.TblPackageNamespace in project OpenAttestation by OpenAttestation.
the class TblModuleManifestJpaController method create_v2.
public void create_v2(TblModuleManifest tblModuleManifest, EntityManager em) {
long createV2_1 = System.currentTimeMillis();
if (tblModuleManifest.getTblHostSpecificManifestCollection() == null) {
tblModuleManifest.setTblHostSpecificManifestCollection(new ArrayList<TblHostSpecificManifest>());
}
try {
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);
}
long createV2_2 = System.currentTimeMillis();
log.debug("CREATE_V2 - Time taken to setup IDs :" + (createV2_2 - createV2_1) + "milliseconds.");
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);
long createV2_3 = System.currentTimeMillis();
log.debug("CREATE_V2 - Time taken to insert and persist :" + (createV2_3 - createV2_2) + "milliseconds.");
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);
}
}
long createV2_4 = System.currentTimeMillis();
log.debug("CREATE_V2 - Time taken for merge operations :" + (createV2_4 - createV2_3) + "milliseconds.");
} finally {
}
}
Aggregations