Search in sources :

Example 1 with SystemMeta

use of gov.ca.cwds.data.persistence.cms.SystemMeta in project API by ca-cwds.

the class SystemCodeService method listOfSystemMetas.

/**
   * 
   * @return the response containing List of Values from System Meta Table
   */
private Response listOfSystemMetas() {
    SystemMeta[] sysMeta = systemMetaDao.findAll();
    ImmutableSet.Builder<gov.ca.cwds.rest.api.domain.cms.SystemMeta> builder = ImmutableSet.builder();
    for (SystemMeta s : sysMeta) {
        if (s != null) {
            builder.add(new gov.ca.cwds.rest.api.domain.cms.SystemMeta(s));
        }
    }
    return new SystemMetaListResponse(builder.build());
}
Also used : SystemMetaListResponse(gov.ca.cwds.rest.api.domain.cms.SystemMetaListResponse) SystemMeta(gov.ca.cwds.data.persistence.cms.SystemMeta) ImmutableSet(com.google.common.collect.ImmutableSet)

Example 2 with SystemMeta

use of gov.ca.cwds.data.persistence.cms.SystemMeta in project api-core by ca-cwds.

the class SystemMetaDao method findAll.

/**
 * @return all meta data records
 */
@SuppressWarnings("unchecked")
public SystemMeta[] findAll() {
    final String namedQueryName = SystemMeta.class.getName() + ".findAll";
    Session session = getSessionFactory().getCurrentSession();
    Transaction txn = session.getTransaction();
    boolean transactionExists = txn != null && txn.isActive();
    try {
        txn = transactionExists ? txn : session.beginTransaction();
        Query query = session.getNamedQuery(namedQueryName);
        SystemMeta[] systemMetas = (SystemMeta[]) query.list().toArray(new SystemMeta[0]);
        if (!transactionExists)
            txn.commit();
        return systemMetas;
    } catch (HibernateException h) {
        if (txn != null) {
            txn.rollback();
        }
        throw new DaoException(h);
    }
}
Also used : SystemMeta(gov.ca.cwds.data.persistence.cms.SystemMeta) Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) DaoException(gov.ca.cwds.data.DaoException) Session(org.hibernate.Session)

Example 3 with SystemMeta

use of gov.ca.cwds.data.persistence.cms.SystemMeta in project api-core by ca-cwds.

the class SystemCodeService method loadSystemMetas.

/**
 * @return the response containing List of Values from System Meta Table
 */
protected Response loadSystemMetas() {
    Response response = null;
    SystemMeta[] sysMeta = systemMetaDao.findAll();
    if (sysMeta != null) {
        ImmutableSet.Builder<gov.ca.cwds.rest.api.domain.cms.SystemMeta> builder = ImmutableSet.builder();
        for (SystemMeta s : sysMeta) {
            if (s != null) {
                builder.add(new gov.ca.cwds.rest.api.domain.cms.SystemMeta(s));
            }
        }
        Set<gov.ca.cwds.rest.api.domain.cms.SystemMeta> systemMetas = builder.build();
        if (systemMetas != null) {
            response = new SystemMetaListResponse(builder.build());
        }
    }
    return response;
}
Also used : SystemCodeListResponse(gov.ca.cwds.rest.api.domain.cms.SystemCodeListResponse) Response(gov.ca.cwds.rest.api.Response) SystemMetaListResponse(gov.ca.cwds.rest.api.domain.cms.SystemMetaListResponse) SystemMetaListResponse(gov.ca.cwds.rest.api.domain.cms.SystemMetaListResponse) SystemMeta(gov.ca.cwds.data.persistence.cms.SystemMeta) ImmutableSet(com.google.common.collect.ImmutableSet)

Example 4 with SystemMeta

use of gov.ca.cwds.data.persistence.cms.SystemMeta in project api-core by ca-cwds.

the class SystemMetaDaoTest method findAll_Args__.

@Test
public void findAll_Args__() throws Exception {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    Session session = mock(Session.class);
    Transaction tx = mock(Transaction.class);
    Query query = mock(Query.class);
    when(sessionFactory.getCurrentSession()).thenReturn(session);
    when(session.getNamedQuery(any(String.class))).thenReturn(query);
    when(session.beginTransaction()).thenReturn(tx);
    SystemMetaDao target = new SystemMetaDao(sessionFactory);
    SystemMeta[] actual = target.findAll();
    SystemMeta[] expected = new SystemMeta[0];
    assertThat(actual, is(equalTo(expected)));
}
Also used : SessionFactory(org.hibernate.SessionFactory) Transaction(org.hibernate.Transaction) Query(org.hibernate.query.Query) SystemMeta(gov.ca.cwds.data.persistence.cms.SystemMeta) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

SystemMeta (gov.ca.cwds.data.persistence.cms.SystemMeta)4 ImmutableSet (com.google.common.collect.ImmutableSet)2 SystemMetaListResponse (gov.ca.cwds.rest.api.domain.cms.SystemMetaListResponse)2 Session (org.hibernate.Session)2 Transaction (org.hibernate.Transaction)2 DaoException (gov.ca.cwds.data.DaoException)1 Response (gov.ca.cwds.rest.api.Response)1 SystemCodeListResponse (gov.ca.cwds.rest.api.domain.cms.SystemCodeListResponse)1 HibernateException (org.hibernate.HibernateException)1 Query (org.hibernate.Query)1 SessionFactory (org.hibernate.SessionFactory)1 Query (org.hibernate.query.Query)1 Test (org.junit.Test)1