Search in sources :

Example 1 with TblOs

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

the class TblOsJpaController method findTblOsEntities.

private List<TblOs> findTblOsEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblOs.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TblOs(com.intel.mtwilson.as.data.TblOs)

Example 2 with TblOs

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

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

the class TblOsJpaControllerTest method testEdit.

@Test
public void testEdit() throws NonexistentEntityException, ASDataException {
    TblOs tblOs = new TblOs(OS_ID, "Fedora", "21");
    doReturn(tblOs).when(tblOsJpaController).findTblOs(OS_ID);
    tblOsJpaController.edit(tblOs);
    verify(em).merge(tblOs);
    verify(em).close();
    verify(transaction).begin();
    verify(transaction).commit();
}
Also used : TblOs(com.intel.mtwilson.as.data.TblOs) Test(org.junit.Test)

Example 4 with TblOs

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

the class MleBO method addMLe.

/**
	 * For VMM, the OS Name and OS Version in the new MLE must ALREADY be in the
	 * database, or this method will throw an error.
	 * 
	 * @param mleData
	 * @return
	 */
public String addMLe(MleData mleData, String mleUuid) {
    String osOemUuid = null;
    try {
        TblMle tblMle = getMleDetails(mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion(), mleData.getOemName());
        if (tblMle != null) {
            throw new ASException(ErrorCode.WS_MLE_ALREADY_EXISTS, mleData.getName());
        }
        if (mleData.getName().toUpperCase().contains("ESX")) {
            String version = getUpperCase(mleData.getVersion()).substring(0, 2);
            if (!version.equals("51") && !version.equals("50")) {
                throw new ASException(ErrorCode.WS_ESX_MLE_NOT_SUPPORTED);
            }
        }
        if (mleData.getMleType().equals("VMM")) {
            TblOs osObj = new TblOsJpaController(getEntityManagerFactory()).findTblOsByNameVersion(mleData.getOsName(), mleData.getOsVersion());
            //TblOs osObj = My.jpa().mwOs().findTblOsByNameVersion(mleData.getOsName(), mleData.getOsVersion());
            osOemUuid = osObj.getUuid_hex();
        } else if (mleData.getMleType().equals("BIOS")) {
            TblOem oemObj = new TblOemJpaController(getEntityManagerFactory()).findTblOemByName(mleData.getOemName());
            //TblOem oemObj = My.jpa().mwOem().findTblOemByName(mleData.getOemName());
            osOemUuid = oemObj.getUuid_hex();
        }
        /*
             if (mleData.getMleType().equalsIgnoreCase("BIOS")){
                 if (mleData.getManifestList() != null){
                     for (ManifestData manifestData : mleData.getManifestList()) {
                         if (Integer.valueOf(manifestData.getName()).intValue() > 5 || Integer.valueOf(manifestData.getName()).intValue() < 0) {
                             throw new ASException(ErrorCode.WS_MLE_PCR_NOT_VALID, manifestData.getName());
                         }
                     }
                 }
             }
             
             if (mleData.getMleType().equalsIgnoreCase("VMM")){
                 if (mleData.getManifestList() != null){
                     for (ManifestData manifestData : mleData.getManifestList()) {
                         if (Integer.valueOf(manifestData.getName()).intValue() > 20 || Integer.valueOf(manifestData.getName()).intValue() < 17) {
                             throw new ASException(ErrorCode.WS_MLE_PCR_NOT_VALID, manifestData.getName());
                         }
                     }
                 }
             }*/
        tblMle = getTblMle(mleData, mleUuid, osOemUuid);
        mleJpaController.create(tblMle);
        addPcrManifest(tblMle, mleData.getManifestList());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblOsJpaController(com.intel.mtwilson.as.controller.TblOsJpaController) TblOemJpaController(com.intel.mtwilson.as.controller.TblOemJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) TblOem(com.intel.mtwilson.as.data.TblOem) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) TblOs(com.intel.mtwilson.as.data.TblOs)

Example 5 with TblOs

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

the class OsBO method createOs.

/**
     * 
     * @param osData
     * @return 
     */
public String createOs(OsData osData, String uuid) {
    try {
        TblOs tblOs = tblOsJpaController.findTblOsByNameVersion(osData.getName(), osData.getVersion());
        if (tblOs != null) {
            throw new ASException(ErrorCode.WS_OS_ALREADY_EXISTS, osData.getName(), osData.getVersion());
        }
        tblOs = new TblOs();
        tblOs.setName(osData.getName());
        tblOs.setVersion(osData.getVersion());
        tblOs.setDescription(osData.getDescription());
        if (uuid != null && !uuid.isEmpty()) {
            tblOs.setUuid_hex(uuid);
        } else {
            tblOs.setUuid_hex(new UUID().toString());
        }
        tblOsJpaController.create(tblOs);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : UUID(com.intel.mtwilson.util.io.UUID) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) TblOs(com.intel.mtwilson.as.data.TblOs)

Aggregations

TblOs (com.intel.mtwilson.as.data.TblOs)23 Matchers.anyString (org.mockito.Matchers.anyString)10 TblMle (com.intel.mtwilson.as.data.TblMle)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 TblOem (com.intel.mtwilson.as.data.TblOem)7 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)6 ASException (com.intel.mountwilson.as.common.ASException)5 OsData (com.intel.mtwilson.datatypes.OsData)4 EntityManager (javax.persistence.EntityManager)4 TblHosts (com.intel.mtwilson.as.data.TblHosts)3 Query (javax.persistence.Query)3 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)3 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)2 NoResultException (javax.persistence.NoResultException)2 TblOemJpaController (com.intel.mtwilson.as.controller.TblOemJpaController)1 TblOsJpaController (com.intel.mtwilson.as.controller.TblOsJpaController)1 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)1 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)1 ManifestData (com.intel.mtwilson.datatypes.ManifestData)1