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;
}
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;
}
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);
}
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());
}
}
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);
}
Aggregations