Search in sources :

Example 1 with AgencyMetadata

use of org.onebusaway.agency_metadata.model.AgencyMetadata in project onebusaway-application-modules by camsys.

the class StatusProviderImpl method getAgencyMetadataStatus.

@Override
public StatusGroup getAgencyMetadataStatus() {
    StatusGroup group = new StatusGroup();
    group.setTitle("General Notices");
    group.setScope("Informational updates about holiday and schedule changes");
    group.setSource("Agency Providers -- manual entry");
    AgencyMetadata[] response = new AgencyMetadata[0];
    String api = _config.getConfigurationValueAsString("status.obaApi", "http://localhost:8080/onebusaway-api-webapp/");
    String endpoint = _config.getConfigurationValueAsString("status.obaApiAgencyMetadata", "api/where/agency-metadata/list.json");
    String apikey = _config.getConfigurationValueAsString("display.obaApiKey", "OBAKEY");
    String url = api + endpoint + "?key=" + apikey;
    try {
        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod(url);
        client.executeMethod(method);
        InputStream result = method.getResponseBodyAsStream();
        ObjectMapper mapper = new ObjectMapper();
        JsonNode tree = mapper.readTree(result);
        JsonNode value = tree.findValue("data");
        response = mapper.readValue(value, AgencyMetadata[].class);
    } catch (IOException e) {
        _log.error("Exception getting AgencyMetadata" + e);
        group.addItem(exceptionStatus(e));
        return group;
    }
    if (response == null) {
        group.addItem(exceptionStatus());
        return group;
    }
    for (AgencyMetadata bean : response) {
        if (!StringUtils.isEmpty(bean.getAgencyMessage())) {
            StatusItem item = new StatusItem();
            item.setTitle(bean.getName() + ": " + bean.getAgencyMessage());
            item.setStatus(StatusItem.Status.INFO);
            group.addItem(item);
        }
    }
    return group;
}
Also used : StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) AgencyMetadata(org.onebusaway.agency_metadata.model.AgencyMetadata) HttpMethod(org.apache.commons.httpclient.HttpMethod) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with AgencyMetadata

use of org.onebusaway.agency_metadata.model.AgencyMetadata in project onebusaway-application-modules by camsys.

the class AgencyMetadataDaoImpl method getAgencyMetadataForId.

@Override
public List<AgencyMetadata> getAgencyMetadataForId(String id) {
    AgencyMetadata model = (AgencyMetadata) _template.get(AgencyMetadata.class, Long.valueOf(id));
    List<AgencyMetadata> metadata = new ArrayList<AgencyMetadata>();
    metadata.add(model);
    return metadata;
}
Also used : ArrayList(java.util.ArrayList) AgencyMetadata(org.onebusaway.agency_metadata.model.AgencyMetadata)

Example 3 with AgencyMetadata

use of org.onebusaway.agency_metadata.model.AgencyMetadata in project onebusaway-application-modules by camsys.

the class AgencyMetadataServiceImpl method updateAgencyMetadata.

@Override
public void updateAgencyMetadata(long id, String gtfsId, String name, String shortName, String legacyId, String gtfsFeedUrl, String gtfsRtFeedUrl, String boundingBox, String ntdId, String agencyMessage) {
    AgencyMetadata model = getAgencyMetadataForId(String.valueOf(id)).get(0);
    if (gtfsId != null) {
        model.setGtfsId(gtfsId);
    }
    if (name != null) {
        model.setName(name);
    }
    if (shortName != null) {
        model.setShortName(shortName);
    }
    if (legacyId != null) {
        model.setLegacyId(legacyId);
    }
    if (gtfsFeedUrl != null) {
        model.setGtfsFeedUrl(gtfsFeedUrl);
    }
    if (gtfsRtFeedUrl != null) {
        model.setGtfsRtFeedUrl(gtfsRtFeedUrl);
    }
    // Verify that boundingBox is a valid Well Known Text Polygon format for an agency bounding box.
    if (!isValidBoundingBox(boundingBox)) {
        boundingBox = null;
    }
    if (boundingBox != null) {
        model.setBoundingBox(boundingBox);
    }
    if (ntdId != null) {
        model.setNtdId(ntdId);
    }
    if (agencyMessage != null) {
        model.setAgencyMessage(agencyMessage);
    }
    _agencyMetadataDao.saveOrUpdate(model);
}
Also used : AgencyMetadata(org.onebusaway.agency_metadata.model.AgencyMetadata)

Example 4 with AgencyMetadata

use of org.onebusaway.agency_metadata.model.AgencyMetadata in project onebusaway-application-modules by camsys.

the class AgencyMetadataResource method listAgencyMetadata.

@Path("/list")
@GET
@Produces("application/json")
public Response listAgencyMetadata() throws JsonGenerationException, JsonMappingException, IOException {
    try {
        List<AgencyMetadata> agencyMetadata = _agencyMetadataService.getAllAgencyMetadata();
        Response response = constructResponse(agencyMetadata);
        return response;
    } catch (Exception e) {
        log.error(e.getMessage());
        throw new WebApplicationException(e, Response.serverError().build());
    }
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) AgencyMetadata(org.onebusaway.agency_metadata.model.AgencyMetadata) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with AgencyMetadata

use of org.onebusaway.agency_metadata.model.AgencyMetadata in project onebusaway-application-modules by camsys.

the class AgencyMetadataServiceImpl method createAgencyMetadata.

@Override
public void createAgencyMetadata(String gtfsId, String name, String shortName, String legacyId, String gtfsFeedUrl, String gtfsRtFeedUrl, String boundingBox, String ntdId, String agencyMessage) {
    // Verify that boundingBox is a valid Well Known Text Polygon format for an agency bounding box.
    if (!isValidBoundingBox(boundingBox)) {
        boundingBox = null;
    }
    AgencyMetadata model = new AgencyMetadata();
    // Create a new record with generated id.
    model.setId(0L);
    model.setGtfsId(gtfsId);
    model.setName(name);
    model.setShortName(shortName);
    model.setLegacyId(legacyId);
    model.setGtfsFeedUrl(gtfsFeedUrl);
    model.setGtfsRtFeedUrl(gtfsRtFeedUrl);
    model.setBoundingBox(boundingBox);
    model.setNtdId(ntdId);
    model.setAgencyMessage(agencyMessage);
    _agencyMetadataDao.saveOrUpdate(model);
}
Also used : AgencyMetadata(org.onebusaway.agency_metadata.model.AgencyMetadata)

Aggregations

AgencyMetadata (org.onebusaway.agency_metadata.model.AgencyMetadata)5 IOException (java.io.IOException)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 HttpMethod (org.apache.commons.httpclient.HttpMethod)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)1 JsonNode (org.codehaus.jackson.JsonNode)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)1 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)1