Search in sources :

Example 11 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.

the class AgencyMetadataResource method updateAgencyMetadata.

@Path("/update/{agencyIndex}")
@GET
@Produces("application/json")
public Response updateAgencyMetadata(@PathParam("agencyIndex") String agencyIndex, @QueryParam("gtfs_id") String gtfs_id, @QueryParam("name") String name, @QueryParam("short_name") String short_name, @QueryParam("legacy_id") String legacy_id, @QueryParam("gtfs_feed_url") String gtfs_feed_url, @QueryParam("gtfs_rt_feed_url") String gtfs_rt_feed_url, @QueryParam("bounding_box") String bounding_box, @QueryParam("ntd_id") String ntd_id, @QueryParam("agency_message") String agency_message) throws JsonGenerationException, JsonMappingException, IOException {
    log.info("Starting updateAgencyMetadata with agencyIndex: " + agencyIndex + ", gtfs_id: " + gtfs_id + ", name: " + name + ", short_name: " + short_name + ", legacy_id: " + legacy_id + ", gtfs_feed_url: " + gtfs_feed_url + ", gtfs_rt_feed_url: " + gtfs_rt_feed_url + ", bounding_box: " + bounding_box + ", ntd_id: " + ntd_id + ", agency_message: " + agency_message);
    String message = "Agency Metadata updated: " + agencyIndex;
    try {
        long id = Long.parseLong(agencyIndex);
        _agencyMetadataService.updateAgencyMetadata(id, gtfs_id, name, short_name, legacy_id, gtfs_feed_url, gtfs_rt_feed_url, bounding_box, ntd_id, agency_message);
    } catch (Exception e) {
        log.error(e.getMessage());
        message = e.getMessage();
    }
    Response response = constructResponse(message);
    return response;
}
Also used : Response(javax.ws.rs.core.Response) 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 12 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.

the class AgencyMetadataResource method deleteAgencyMetadata.

@Path("/delete/{agencyIndex}")
@GET
@Produces("application/json")
public Response deleteAgencyMetadata(@PathParam("agencyIndex") String agencyIndex) throws JsonGenerationException, JsonMappingException, IOException {
    String message = "Agency Metadata deleted: " + agencyIndex;
    try {
        long index = Long.parseLong(agencyIndex);
        _agencyMetadataService.delete(index);
    } catch (Exception e) {
        log.error(e.getMessage());
        message = "Failed to delete key: " + e.getMessage();
    }
    Response response = constructResponse(message);
    log.info("Returning deleteAgencyMetadata result.");
    return response;
}
Also used : Response(javax.ws.rs.core.Response) 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 13 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.

the class KeysResource method listEmails.

@Path("/list-emails")
@GET
@Produces("application/json")
public Response listEmails() throws JsonGenerationException, JsonMappingException, IOException {
    log.info("Starting listEmails");
    try {
        validateSecurity();
        List<String> apiKeys = _userService.getUserIndexKeyValuesForKeyType(UserIndexTypes.API_KEY);
        List<String> emails = new ArrayList<String>();
        int count = 0;
        for (String apiKey : apiKeys) {
            UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
            UserIndex userIndex = _userService.getUserIndexForId(key);
            count++;
            if (userIndex != null) {
                if (userIndex.getUser() != null) {
                    if (userIndex.getUser().getProperties() != null) {
                        Object o = userIndex.getUser().getProperties();
                        if (o instanceof UserPropertiesV3) {
                            UserPropertiesV3 v3 = (UserPropertiesV3) o;
                            if (!StringUtils.isBlank(v3.getContactEmail())) {
                                emails.add(v3.getContactEmail());
                            }
                        }
                    }
                }
            }
            if (count % 100 == 0)
                log.info("processed " + count + " users....");
        }
        log.info("processing complete of " + count + " users!");
        Response response = constructResponse(emails);
        log.info("Returning response from listEmails");
        return response;
    } catch (Exception e) {
        log.error(e.getMessage());
        throw new WebApplicationException(e, Response.serverError().build());
    }
}
Also used : Response(javax.ws.rs.core.Response) UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) UserPropertiesV3(org.onebusaway.users.model.properties.UserPropertiesV3) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.

the class KeysResource method createKey.

@Path("/create/{keyValue}")
@GET
@Produces("application/json")
public Response createKey(@PathParam("keyValue") String keyValue, @DefaultValue("") @QueryParam("name") String name, @DefaultValue("") @QueryParam("company") String company, @DefaultValue("") @QueryParam("email") String email, @DefaultValue("") @QueryParam("details") String details, @DefaultValue("100") @QueryParam("minApiReqInt") String minApiReqInt) throws JsonGenerationException, JsonMappingException, IOException {
    log.info("Starting createKey with keyValue: " + keyValue + ", name: " + name + ", company: " + company + ", email: " + email + ", details: " + details + ", minApiReqInt: " + minApiReqInt);
    Long minApiReqIntervalLong = 0L;
    try {
        minApiReqIntervalLong = Long.parseLong(minApiReqInt);
    } catch (NumberFormatException e) {
        log.error("Could not parse minApiReqInt: " + minApiReqInt);
    }
    String message = "API Key created: " + keyValue;
    try {
        validateSecurity();
        saveOrUpdateKey(keyValue, minApiReqIntervalLong, name, company, email, details);
    } catch (Exception e) {
        log.error(e.getMessage());
        message = e.getMessage();
    }
    Response response = constructResponse(message);
    log.info("Returning createKey result.");
    return response;
}
Also used : Response(javax.ws.rs.core.Response) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with JsonGenerationException

use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.

the class KeysResource method updateKey.

@Path("/update/{keyValue}")
@GET
@Produces("application/json")
public Response updateKey(@PathParam("keyValue") String keyValue, @QueryParam("name") String name, @QueryParam("company") String company, @QueryParam("email") String email, @QueryParam("details") String details, @QueryParam("minApiReqInt") String minApiReqInt) throws JsonGenerationException, JsonMappingException, IOException {
    log.info("Starting updateKey with keyValue: " + keyValue + ", name: " + name + ", company: " + company + ", email: " + email + ", details: " + details + ", minApiReqInt: " + minApiReqInt);
    Long minApiReqIntervalLong = 0L;
    if (!minApiReqInt.isEmpty()) {
        try {
            minApiReqIntervalLong = Long.parseLong(minApiReqInt);
        } catch (NumberFormatException e) {
            log.error("Could not parse minApiReqInt: " + minApiReqInt);
        }
    }
    String message = "API Key updated: " + keyValue;
    try {
        validateSecurity();
        updateKeyContactInfo(keyValue, name, company, email, details, minApiReqIntervalLong);
    } catch (Exception e) {
        log.error(e.getMessage());
        message = e.getMessage();
    }
    Response response = constructResponse(message);
    log.info("Returning updateKey result.");
    return response;
}
Also used : Response(javax.ws.rs.core.Response) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

JsonGenerationException (org.codehaus.jackson.JsonGenerationException)34 IOException (java.io.IOException)30 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)27 Response (javax.ws.rs.core.Response)13 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 ArrayList (java.util.ArrayList)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 JsonGenerator (org.codehaus.jackson.JsonGenerator)7 StringWriter (java.io.StringWriter)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Enterprise (com.itrus.portal.db.Enterprise)4 UserCert (com.itrus.portal.db.UserCert)4 UserInfo (com.itrus.portal.db.UserInfo)4 HttpSession (javax.servlet.http.HttpSession)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 Bill (com.itrus.portal.db.Bill)3