Search in sources :

Example 11 with TblTaLog

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

the class TblTaLogJpaController method findLogsByHostId.

public List<TblTaLog> findLogsByHostId(int hostId, Date lastUpdatedTs) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblTaLog.findLogsByHostId");
        query.setParameter("hostID", hostId);
        query.setParameter("updatedOn", lastUpdatedTs);
        List<TblTaLog> logs = query.getResultList();
        return logs;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblTaLog(com.intel.mtwilson.as.data.TblTaLog)

Example 12 with TblTaLog

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

the class ReportsBOTest method testGetTrustReportWithError.

@Test
public void testGetTrustReportWithError() {
    Collection<Hostname> hostNames = new ArrayList<Hostname>();
    hostNames.add(new Hostname(SERVER_NAME));
    when(tblHostsJpaController.findByName(anyString())).thenReturn(mockFindByName());
    List<TblTaLog> taLogs = new ArrayList<TblTaLog>();
    TblTaLog taLog1 = new TblTaLog(Integer.valueOf(1), 1, 1, "0", "31B97D97B4679917EC3C1D943635693FFBAB4143", false, new Date());
    TblTaLog taLog2 = new TblTaLog(Integer.valueOf(2), 1, 2, "18", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", false, new Date());
    taLog1.setError("BIOS:1,VMM:1");
    taLog2.setError("BIOS:1,VMM:1");
    taLogs.add(taLog1);
    taLogs.add(taLog2);
    when(tblTaLogJpaController.findTrustStatusByHostId(anyInt(), anyInt())).thenReturn(taLogs);
    HostsTrustReportType hostsTrustReportType = reportsBO.getTrustReport(hostNames);
    assertNotNull(hostsTrustReportType);
    assertTrue(hostsTrustReportType.getHost().size() > 0);
}
Also used : TblTaLog(com.intel.mtwilson.as.data.TblTaLog) HostsTrustReportType(com.intel.mountwilson.as.hosttrustreport.data.HostsTrustReportType) ArrayList(java.util.ArrayList) Hostname(com.intel.mtwilson.util.net.Hostname) Date(java.util.Date) Test(org.junit.Test)

Example 13 with TblTaLog

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

the class ReportsBOTest method testGetAttestationReport.

@Test
public void testGetAttestationReport() throws NumberFormatException, IOException {
    when(tblHostsJpaController.findByName(anyString())).thenReturn(mockFindByName());
    when(tblTaLogJpaController.findLastStatusTs(any(Integer.class))).thenReturn(new Date());
    List<TblTaLog> taLogs = new ArrayList<TblTaLog>();
    taLogs.add(new TblTaLog(Integer.valueOf(1), 1, 1, "18", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", true, new Date()));
    when(tblTaLogJpaController.findLogsByHostId(anyInt(), any(Date.class))).thenReturn(taLogs);
    AttestationReport attestationReport = reportsBO.getAttestationReport(new Hostname(SERVER_NAME), false);
    assertNotNull(attestationReport);
    assertTrue(attestationReport.getPcrLogs().size() > 0);
}
Also used : TblTaLog(com.intel.mtwilson.as.data.TblTaLog) AttestationReport(com.intel.mtwilson.datatypes.AttestationReport) ArrayList(java.util.ArrayList) Hostname(com.intel.mtwilson.util.net.Hostname) Date(java.util.Date) Test(org.junit.Test)

Example 14 with TblTaLog

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

the class TblModuleManifestLogJpaController method edit.

public void edit(TblModuleManifestLog tblModuleManifestLog) throws NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblModuleManifestLog persistentTblModuleManifestLog = em.find(TblModuleManifestLog.class, tblModuleManifestLog.getId());
        TblTaLog taLogIdOld = persistentTblModuleManifestLog.getTaLogId();
        TblTaLog taLogIdNew = tblModuleManifestLog.getTaLogId();
        if (taLogIdNew != null) {
            taLogIdNew = em.getReference(taLogIdNew.getClass(), taLogIdNew.getId());
            tblModuleManifestLog.setTaLogId(taLogIdNew);
        }
        tblModuleManifestLog = em.merge(tblModuleManifestLog);
        if (taLogIdOld != null && !taLogIdOld.equals(taLogIdNew)) {
            taLogIdOld.getTblModuleManifestLogCollection().remove(tblModuleManifestLog);
            taLogIdOld = em.merge(taLogIdOld);
        }
        if (taLogIdNew != null && !taLogIdNew.equals(taLogIdOld)) {
            taLogIdNew.getTblModuleManifestLogCollection().add(tblModuleManifestLog);
            em.merge(taLogIdNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblModuleManifestLog.getId();
            if (findTblModuleManifestLog(id) == null) {
                throw new NonexistentEntityException("The tblModuleManifestLog with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
        em.close();
    }
}
Also used : ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) EntityManager(javax.persistence.EntityManager) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifestLog(com.intel.mtwilson.as.data.TblModuleManifestLog) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 15 with TblTaLog

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

the class TblTaLogJpaController method findTblTaLogEntities.

private List<TblTaLog> findTblTaLogEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblTaLog.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) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Aggregations

TblTaLog (com.intel.mtwilson.as.data.TblTaLog)23 EntityManager (javax.persistence.EntityManager)11 Date (java.util.Date)9 Query (javax.persistence.Query)7 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)7 Hostname (com.intel.mtwilson.util.net.Hostname)6 TblHosts (com.intel.mtwilson.as.data.TblHosts)5 ASException (com.intel.mountwilson.as.common.ASException)4 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)4 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 HostType (com.intel.mountwilson.as.hosttrustreport.data.HostType)3 TblTaLogJpaController (com.intel.mtwilson.as.controller.TblTaLogJpaController)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 HostManifestReportType (com.intel.mountwilson.as.hostmanifestreport.data.HostManifestReportType)2 HostsTrustReportType (com.intel.mountwilson.as.hosttrustreport.data.HostsTrustReportType)2 TblModuleManifestLog (com.intel.mtwilson.as.data.TblModuleManifestLog)2 IOException (java.io.IOException)2 ManifestType (com.intel.mountwilson.as.hostmanifestreport.data.ManifestType)1