Search in sources :

Example 1 with EntryWithReferencesBean

use of org.onebusaway.api.model.transit.EntryWithReferencesBean in project onebusaway-application-modules by camsys.

the class CurrentTimeActionTest method test.

@Test
public void test() throws ParseException {
    CurrentTimeAction action = new CurrentTimeAction();
    long t = System.currentTimeMillis();
    DefaultHttpHeaders headers = action.index();
    assertEquals(200, headers.getStatus());
    ResponseBean response = action.getModel();
    assertEquals(200, response.getCode());
    assertEquals(2, response.getVersion());
    @SuppressWarnings("unchecked") EntryWithReferencesBean<TimeBean> entry = (EntryWithReferencesBean<TimeBean>) response.getData();
    TimeBean time = entry.getEntry();
    assertNotNull(time);
    long delta = Math.abs(time.getTime() - t);
    assertTrue("check that time delta is within limits: delta=" + delta, delta < 100);
    String readableTime = DateLibrary.getTimeAsIso8601String(new Date(time.getTime()));
    assertEquals(readableTime, time.getReadableTime());
}
Also used : EntryWithReferencesBean(org.onebusaway.api.model.transit.EntryWithReferencesBean) DefaultHttpHeaders(org.apache.struts2.rest.DefaultHttpHeaders) ResponseBean(org.onebusaway.api.model.ResponseBean) TimeBean(org.onebusaway.api.model.TimeBean) Date(java.util.Date) Test(org.junit.Test)

Example 2 with EntryWithReferencesBean

use of org.onebusaway.api.model.transit.EntryWithReferencesBean in project onebusaway-application-modules by camsys.

the class CustomCsvHandler method getEntityType.

/**
 **
 *
 ***
 */
private Class<?> getEntityType(Object obj) {
    if (obj instanceof ResponseBean) {
        ResponseBean response = (ResponseBean) obj;
        if (response.getData() == null)
            return response.getClass();
        return getEntityType(response.getData());
    } else if (obj instanceof EntryWithReferencesBean) {
        EntryWithReferencesBean<?> entry = (EntryWithReferencesBean<?>) obj;
        return entry.getEntry().getClass();
    } else if (obj instanceof ListWithReferencesBean) {
        ListWithReferencesBean<?> list = (ListWithReferencesBean<?>) obj;
        List<?> values = list.getList();
        if (values.isEmpty())
            return Object.class;
        return values.get(0).getClass();
    }
    return obj.getClass();
}
Also used : ListWithReferencesBean(org.onebusaway.api.model.transit.ListWithReferencesBean) EntryWithReferencesBean(org.onebusaway.api.model.transit.EntryWithReferencesBean) ResponseBean(org.onebusaway.api.model.ResponseBean)

Example 3 with EntryWithReferencesBean

use of org.onebusaway.api.model.transit.EntryWithReferencesBean in project onebusaway-application-modules by camsys.

the class CurrentTimeAction method index.

public DefaultHttpHeaders index() {
    Date date = new Date();
    date.setTime(SystemTime.currentTimeMillis());
    String readableTime = DateLibrary.getTimeAsIso8601String(date);
    TimeBean bean = new TimeBean(date, readableTime);
    if (isVersion(V1)) {
        return setOkResponse(bean);
    } else if (isVersion(V2)) {
        BeanFactoryV2 factory = getBeanFactoryV2();
        EntryWithReferencesBean<TimeBean> response = factory.entry(bean);
        return setOkResponse(response);
    } else {
        return setUnknownVersionResponse();
    }
}
Also used : EntryWithReferencesBean(org.onebusaway.api.model.transit.EntryWithReferencesBean) TimeBean(org.onebusaway.api.model.TimeBean) Date(java.util.Date) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Aggregations

EntryWithReferencesBean (org.onebusaway.api.model.transit.EntryWithReferencesBean)3 Date (java.util.Date)2 ResponseBean (org.onebusaway.api.model.ResponseBean)2 TimeBean (org.onebusaway.api.model.TimeBean)2 DefaultHttpHeaders (org.apache.struts2.rest.DefaultHttpHeaders)1 Test (org.junit.Test)1 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)1 ListWithReferencesBean (org.onebusaway.api.model.transit.ListWithReferencesBean)1