Search in sources :

Example 1 with DropboxAPIFacade

use of org.apache.camel.component.dropbox.core.DropboxAPIFacade in project camel by apache.

the class DropboxScheduledPollSearchConsumer method poll.

/**
     * Poll from a dropbox remote path and put the result in the message exchange
     * @return number of messages polled
     * @throws Exception
     */
@Override
protected int poll() throws Exception {
    Exchange exchange = endpoint.createExchange();
    DropboxSearchResult result = new DropboxAPIFacade(configuration.getClient(), exchange).search(configuration.getRemotePath(), configuration.getQuery());
    StringBuilder fileExtracted = new StringBuilder();
    for (DbxEntry entry : result.getFound()) {
        fileExtracted.append(entry.name).append("-").append(entry.path).append("\n");
    }
    exchange.getIn().setHeader(DropboxResultHeader.FOUND_FILES.name(), fileExtracted.toString());
    exchange.getIn().setBody(result.getFound());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Downloaded: {}", result.toString());
    }
    try {
        // send message to next processor in the route
        getProcessor().process(exchange);
        // number of messages polled
        return 1;
    } finally {
        // log exception if an exception occurred and was not handled
        if (exchange.getException() != null) {
            getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) DbxEntry(com.dropbox.core.DbxEntry) DropboxSearchResult(org.apache.camel.component.dropbox.dto.DropboxSearchResult) DropboxAPIFacade(org.apache.camel.component.dropbox.core.DropboxAPIFacade)

Example 2 with DropboxAPIFacade

use of org.apache.camel.component.dropbox.core.DropboxAPIFacade in project camel by apache.

the class DropboxScheduledPollGetConsumer method poll.

/**
     * Poll from a dropbox remote path and put the result in the message exchange
     * @return number of messages polled
     * @throws Exception
     */
@Override
protected int poll() throws Exception {
    Exchange exchange = endpoint.createExchange();
    DropboxFileDownloadResult result = new DropboxAPIFacade(configuration.getClient(), exchange).get(configuration.getRemotePath());
    Map<String, Object> map = result.getEntries();
    if (map.size() == 1) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILE.name(), entry.getKey());
            exchange.getIn().setBody(entry.getValue());
        }
    } else {
        StringBuilder pathsExtracted = new StringBuilder();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            pathsExtracted.append(entry.getKey()).append("\n");
        }
        exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILES.name(), pathsExtracted.toString());
        exchange.getIn().setBody(map);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Downloaded: {}", result.toString());
    }
    try {
        // send message to next processor in the route
        getProcessor().process(exchange);
        // number of messages polled
        return 1;
    } finally {
        // log exception if an exception occurred and was not handled
        if (exchange.getException() != null) {
            getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) DropboxFileDownloadResult(org.apache.camel.component.dropbox.dto.DropboxFileDownloadResult) Map(java.util.Map) DropboxAPIFacade(org.apache.camel.component.dropbox.core.DropboxAPIFacade)

Example 3 with DropboxAPIFacade

use of org.apache.camel.component.dropbox.core.DropboxAPIFacade in project camel by apache.

the class DropboxDelProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    DropboxDelResult result = new DropboxAPIFacade(configuration.getClient(), exchange).del(configuration.getRemotePath());
    exchange.getIn().setHeader(DropboxResultHeader.DELETED_PATH.name(), result.getEntry());
    exchange.getIn().setBody(result.getEntry());
    log.debug("Deleted: {}", configuration.getRemotePath());
}
Also used : DropboxDelResult(org.apache.camel.component.dropbox.dto.DropboxDelResult) DropboxAPIFacade(org.apache.camel.component.dropbox.core.DropboxAPIFacade)

Example 4 with DropboxAPIFacade

use of org.apache.camel.component.dropbox.core.DropboxAPIFacade in project camel by apache.

the class DropboxGetProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    DropboxFileDownloadResult result = new DropboxAPIFacade(configuration.getClient(), exchange).get(configuration.getRemotePath());
    Map<String, Object> map = result.getEntries();
    if (map.size() == 1) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILE.name(), entry.getKey());
            exchange.getIn().setBody(entry.getValue());
        }
    } else {
        StringBuilder pathsExtracted = new StringBuilder();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            pathsExtracted.append(entry.getKey()).append("\n");
        }
        exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILES.name(), pathsExtracted.toString());
        exchange.getIn().setBody(map);
    }
    LOG.debug("Downloaded: {}", result.toString());
}
Also used : DropboxFileDownloadResult(org.apache.camel.component.dropbox.dto.DropboxFileDownloadResult) Map(java.util.Map) DropboxAPIFacade(org.apache.camel.component.dropbox.core.DropboxAPIFacade)

Example 5 with DropboxAPIFacade

use of org.apache.camel.component.dropbox.core.DropboxAPIFacade in project camel by apache.

the class DropboxMoveProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    DropboxMoveResult result = new DropboxAPIFacade(configuration.getClient(), exchange).move(configuration.getRemotePath(), configuration.getNewRemotePath());
    exchange.getIn().setHeader(DropboxResultHeader.MOVED_PATH.name(), result.getOldPath());
    exchange.getIn().setBody(result.getNewPath());
    log.debug("Moved from {} to {}", configuration.getRemotePath(), configuration.getNewRemotePath());
}
Also used : DropboxMoveResult(org.apache.camel.component.dropbox.dto.DropboxMoveResult) DropboxAPIFacade(org.apache.camel.component.dropbox.core.DropboxAPIFacade)

Aggregations

DropboxAPIFacade (org.apache.camel.component.dropbox.core.DropboxAPIFacade)7 Map (java.util.Map)3 DbxEntry (com.dropbox.core.DbxEntry)2 Exchange (org.apache.camel.Exchange)2 DropboxFileDownloadResult (org.apache.camel.component.dropbox.dto.DropboxFileDownloadResult)2 DropboxSearchResult (org.apache.camel.component.dropbox.dto.DropboxSearchResult)2 DropboxDelResult (org.apache.camel.component.dropbox.dto.DropboxDelResult)1 DropboxFileUploadResult (org.apache.camel.component.dropbox.dto.DropboxFileUploadResult)1 DropboxMoveResult (org.apache.camel.component.dropbox.dto.DropboxMoveResult)1 DropboxResultCode (org.apache.camel.component.dropbox.util.DropboxResultCode)1