Package com.socrata.model.requests

Examples of com.socrata.model.requests.SodaRequest



    protected <T> T scanFile(final String method, final MediaType mediaType, final File file, Class<T> retType) throws SodaError, InterruptedException
    {

        SodaRequest requester = new SodaRequest<File>(null, file)
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            {
                final URI scanUri = UriBuilder.fromUri(importUri)
                                              .queryParam("method", method)
                                              .build();

                return httpLowLevel.postFileRaw(scanUri, mediaType, payload);
            }
        };

        try {
            final ClientResponse response = requester.issueRequest();
            return response.getEntity(retType);
        } catch (LongRunningQueryException e) {
            return getHttpLowLevel().getAsyncResults(e.location, e.timeToRetry, getHttpLowLevel().getMaxRetries(), retType, requester);
        }
    }
View Full Code Here


        postbodyBuilder.append("&fileId=").append(fileId)
                       .append("&translation=").append(URLEncoder.encode(translationString, "UTF-8"))
                       .append("&name=").append(URLEncoder.encode(file.getName(), "UTF-8"));

        SodaRequest requester = new SodaRequest<String>(null, postbodyBuilder.toString())
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            {
                return httpLowLevel.postRaw(importUri, MediaType.APPLICATION_FORM_URLENCODED_TYPE, ContentEncoding.IDENTITY, payload);
            }
        };

        try {
            final ClientResponse response = requester.issueRequest();
            return response.getEntity(DatasetInfo.class);
        } catch (LongRunningQueryException e) {
            LongRunningQueryException lrqe = e.location != null ? e :
                new LongRunningQueryException(UriBuilder.fromUri(importUri).queryParam("ticket", e.ticket).build(), e.timeToRetry, e.ticket);
            LongRunningRequest<String, DatasetInfo> longRunningRequest = new LongRunningRequest(lrqe, DatasetInfo.class, requester);
View Full Code Here

        if (StringUtils.isNotEmpty(viewId)) {
            postbodyBuilder.append("&viewUid=").append(viewId);
        }

        SodaRequest requester = new SodaRequest<String>(null, postbodyBuilder.toString())
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            {
                return httpLowLevel.postRaw(shapeImportUri, MediaType.APPLICATION_FORM_URLENCODED_TYPE, ContentEncoding.IDENTITY, payload);
            }
        };


        try {

            final ClientResponse response = requester.issueRequest();
            return response.getEntity(DatasetInfo.class);
        } catch (LongRunningQueryException e) {

            if (e.location != null) {
                return getHttpLowLevel().getAsyncResults(e.location, e.timeToRetry, Integer.MAX_VALUE, DatasetInfo.class, requester);
View Full Code Here

     * @return The NonDataFileDataset object that was saved to Socrata
     */
    public NonDataFileDataset importNonDataFile(final String name, final String description, final File file) throws SodaError, InterruptedException
    {

        SodaRequest requester = new SodaRequest<File>(null, file)
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            {
                final URI scanUri = UriBuilder.fromUri(importUri)
                                              .queryParam("method", "blob")
                                              .queryParam("fileUploaderfile", file.getName())
                                              .build();

                try {
                    final InputStream   is = new FileInputStream(file);
                    try {
                        ClientResponse clientResponse = httpLowLevel.postFileRaw(scanUri, MediaType.APPLICATION_OCTET_STREAM_TYPE, MediaType.TEXT_PLAIN_TYPE, file);

                        //Funny issue with service, currently only returns MediaType.TEXT_PLAIN_TYPE, but the
                        //response needs to be processed as JSON.  So, wrap the return in a ClientResponse that acts
                        //as if the content type is JSON. There is a bug on the core server side to fix this.
                        InBoundHeaders  headers = new InBoundHeaders();
                        headers.putSingle("Content-Type", MediaType.APPLICATION_JSON);
                        return new ClientResponse(clientResponse.getStatus(), headers, clientResponse.getEntityInputStream(), clientResponse.getClient().getMessageBodyWorkers());

                    } finally {
                        is.close();
                    }
                } catch (IOException ioe) {
                    throw new SodaError("Unable to load file: " + file.getAbsolutePath());
                }
            }
        };

        NonDataFileDataset nonDataFileDataset;
        try {
            final ClientResponse response = requester.issueRequest();
            nonDataFileDataset = response.getEntity(NonDataFileDataset.class);
        } catch (LongRunningQueryException e) {
            nonDataFileDataset = getHttpLowLevel().getAsyncResults(e.location, e.timeToRetry, getHttpLowLevel().getMaxRetries(), NonDataFileDataset.class, requester);
        }

View Full Code Here

     * @return The NonDataFileDataset object that was saved to Socrata
     */
    public NonDataFileDataset replaceNonDataFile(final String id, final File file) throws SodaError, InterruptedException
    {

        SodaRequest requester = new SodaRequest<File>(null, file)
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            {
                final URI scanUri = UriBuilder.fromUri(viewUri)
                                              .path(id + ".txt")
                                              .queryParam("method", "replaceBlob")
                                              .queryParam("fileUploaderfile", file.getName())
                                              .build();

                try {
                    final InputStream   is = new FileInputStream(file);
                    try {
                        ClientResponse clientResponse = httpLowLevel.postFileRaw(scanUri, MediaType.APPLICATION_OCTET_STREAM_TYPE, MediaType.TEXT_PLAIN_TYPE, file);

                        //Funny issue with service, currently only returns MediaType.TEXT_PLAIN_TYPE, but the
                        //response needs to be processed as JSON.  So, wrap the return in a ClientResponse that acts
                        //as if the content type is JSON. There is a bug on the core server side to fix this.
                        InBoundHeaders  headers = new InBoundHeaders();
                        headers.putSingle("Content-Type", MediaType.APPLICATION_JSON);
                        return new ClientResponse(clientResponse.getStatus(), headers, clientResponse.getEntityInputStream(), clientResponse.getClient().getMessageBodyWorkers());

                    } finally {
                        is.close();
                    }
                } catch (IOException ioe) {
                    throw new SodaError("Unable to load file: " + file.getAbsolutePath());
                }
            }
        };

        NonDataFileDataset nonDataFileDataset;
        try {
            final ClientResponse response = requester.issueRequest();
            nonDataFileDataset = response.getEntity(NonDataFileDataset.class);
        } catch (LongRunningQueryException e) {
            nonDataFileDataset = getHttpLowLevel().getAsyncResults(e.location, e.timeToRetry, getHttpLowLevel().getMaxRetries(), NonDataFileDataset.class, requester);
        }

View Full Code Here

     * @throws InterruptedException throws is the thread is interrupted.
     */
    public <T> T getById(String resourceId, String id, Class<T> cls) throws SodaError, InterruptedException
    {

        SodaRequest requester = new SodaRequest<String>(resourceId, id)
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            { return getById(resourceId, HttpLowLevel.JSON_TYPE, payload); }
        };

        try {
            final ClientResponse    response = requester.issueRequest();
            return response.getEntity(new GenericType<T>(cls));
        } catch (LongRunningQueryException e) {
            return getHttpLowLevel().getAsyncResults(e.location, HttpLowLevel.JSON_TYPE, e.timeToRetry, getHttpLowLevel().getMaxRetries(), new GenericType<T>(cls), requester);
        }
    }
View Full Code Here

     * @throws InterruptedException throws is the thread is interrupted.
     */
    public <T> List<T> query(String resourceId, SoqlQuery query, GenericType<List<T>> genericType) throws SodaError, InterruptedException
    {

        SodaRequest requester = new SodaRequest<SoqlQuery>(resourceId, query)
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            { return query(resourceId, HttpLowLevel.JSON_TYPE, payload); }
        };

View Full Code Here

     * @throws InterruptedException throws is the thread is interrupted.
     */
    public <T> List<T>  query(String resourceId, String query, GenericType<List<T>> genericType) throws SodaError, InterruptedException
    {

        SodaRequest requester = new SodaRequest<String>(resourceId, query)
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            { return query(resourceId, HttpLowLevel.JSON_TYPE, payload); }
        };

        try {
            final ClientResponse    response = requester.issueRequest();
            return response.getEntity(genericType);
        } catch (LongRunningQueryException e) {
            return getHttpLowLevel().getAsyncResults(e.location, HttpLowLevel.JSON_TYPE, e.timeToRetry, getHttpLowLevel().getMaxRetries(), genericType, requester);
        }
    }
View Full Code Here

    {


        waitForPendingGeocoding(datasetId);

        SodaRequest requester = new SodaRequest<String>(datasetId,null)
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            {
                final URI publicationUri = UriBuilder.fromUri(viewUri)
                                                     .path(resourceId)
                                                     .path("publication")
                                                     .build();


                return httpLowLevel.postRaw(publicationUri, HttpLowLevel.JSON_TYPE, ContentEncoding.IDENTITY, "viewId=" + resourceId);
            }
        };

        try {
            ClientResponse response = requester.issueRequest();
            return response.getEntity(DatasetInfo.class);
        } catch (LongRunningQueryException e) {
            LongRunningRequest<String, DatasetInfo> longRunningRequest = new LongRunningRequest(e, DatasetInfo.class, requester);
            HttpLowLevel http = getHttpLowLevel();
            return longRunningRequest.checkStatus(http, http.getStatusCheckErrorRetries(), http.getStatusCheckErrorTime());
View Full Code Here

     * @throws SodaError
     * @throws InterruptedException
     */
    public DatasetInfo createWorkingCopy(final String datasetId) throws SodaError, InterruptedException{

        SodaRequest requester = new SodaRequest<String>(datasetId,null)
        {
            public ClientResponse issueRequest() throws LongRunningQueryException, SodaError
            {
                final URI publicationUri = UriBuilder.fromUri(viewUri)
                                                     .path(resourceId)
                                                     .path("publication.json")
                                                     .queryParam("method", "copy")
                                                     .build();

                return httpLowLevel.postRaw(publicationUri, HttpLowLevel.JSON_TYPE, ContentEncoding.IDENTITY, "method=copy");
            }
        };

        try {
            ClientResponse response = requester.issueRequest();
            return response.getEntity(Dataset.class);
        } catch (LongRunningQueryException e) {
            LongRunningRequest<String, DatasetInfo> longRunningRequest = new LongRunningRequest(e, DatasetInfo.class, requester);
            HttpLowLevel http = getHttpLowLevel();
            return longRunningRequest.checkStatus(http, http.getStatusCheckErrorRetries(), http.getStatusCheckErrorTime());
View Full Code Here

TOP

Related Classes of com.socrata.model.requests.SodaRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.