package ikube.action.index.handler.internet;

import ikube.action.index.handler.IResourceProvider;
import ikube.model.IndexableExchange;
import ikube.model.Url;

import java.util.List;

/**
 * @author David Turley
 * @version 01.00
 * @since 11-07-2014
 */
@SuppressWarnings("FieldCanBeLocal")
public class ExchangeResourceProvider implements IResourceProvider<IndexableExchange> {

    private final IndexableExchange indexableExchange;

    public ExchangeResourceProvider(final IndexableExchange indexableExchange) {
        this.indexableExchange = indexableExchange;
        indexableExchange.getUrl();
        indexableExchange.getUserid();
        // TODO: Start 'crawling' Exchange server here, starting at the point left off the last time
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public IndexableExchange getResource() {
        // TODO: Return a crawled resource to the caller
        return null;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setResources(final List<IndexableExchange> resources) {
        // TODO: Add the resource crawled to the collection available in this object
    }

}

@@ -147,19 +147,155 @@
 ube.
-model.Url;%0A
+action.index.handler.internet.exchange.ExchangeClient;%0Aimport ikube.action.index.handler.internet.exchange.IndexableMessage;%0Aimport java.util.Date;
 %0Aimp
@@ -315,16 +315,17 @@
 .List;%0A%0A
+%0A
 /**%0A * @
@@ -495,85 +495,1173 @@
 der%3C
-IndexableExchange%3E %7B%0A%0A    private final IndexableExchange indexableExchange;%0A
+String%3E %7B%0A%0A    private final IndexableExchange indexableExchange;%0A%0A    private ExchangeClient exchange;%0A    private ExchangeClient.UsersMessages messages;%0A%0A    /**%0A     * TODO: store Exchange connection information in a configuration file%0A     *   EWS_URL  = %22https://outlook.office365.com/ews/exchange.asmx%22;%0A     *   EWS_USERNAME = %22administrator@iKube.onmicrosoft.com%22;%0A     *   EWS_PASSWORD = %22iKube101%22;%0A     */%0A    private ExchangeClient getExchangeClientInstance()%7B%0A        if(exchange == null)%7B%0A            try %7B%0A                exchange = new ExchangeClient(%0A                        indexableExchange.getUrl(), null,%0A                        indexableExchange.getUserid(),%0A                        indexableExchange.getPassword());%0A                // optional: exchange.setRequestVersion(RequestServerVersion.EXCHANGE_2013);%0A            %7Dcatch(Exception e)%7B%0A                throw new IllegalArgumentException(%0A                    %22Unable to establish a connection with Exchange server URL %5B%22 +%0A                    indexableExchange.getUrl() +%22%5D. Root cause is %22 + e.getMessage(), e);%0A            %7D%0A        %7D%0A        return exchange;%0A    %7D%0A%0A    /* provider */
 %0A   
@@ -1769,16 +1769,17 @@
 xchange 
+ 
 = indexa
@@ -1791,24 +1791,77 @@
 change;%0A
+%0A        messages = exchange.getUsersMessages(%0A      
         
 indexabl
@@ -1844,32 +1844,34 @@
 (%0A              
+  
 indexableExchang
@@ -1879,14 +1879,24 @@
 .get
-Url();
+IndexFromDate(),
 %0A   
@@ -1904,139 +1904,501 @@
     
-indexableExchange.getUserid();%0A        // TODO: Start 'crawling' Exchange server here, starting at the point left off the last time
+        new Date(),%0A                indexableExchange.getResumeIndexFrom(),%0A                indexableExchange.getResumeIndexFromMessage());%0A%0A        // TODO: Start 'crawling' Exchange server here, starting at the point left off the last time%0A        // Get the first email content%0A        // Clone the indexable exchange and put the raw content in it%0A%0A        IndexableMessage message = messages.next();%0A        if(message != null)%0A            indexableExchange.setIndexableMessage( message );
 %0A   
@@ -2422,32 +2422,48 @@
 * %7B@inheritDoc%7D%0A
+     * consumer%0A
      */%0A    @Ove
@@ -2479,33 +2479,22 @@
  public 
-IndexableExcha
+Stri
 ng
-e
  getReso
@@ -2678,33 +2678,22 @@
 al List%3C
-IndexableExcha
+Stri
 ng
-e
 %3E resour
@@ -2792,9 +2792,8 @@
     %7D%0A%0A%7D
-%0A

update ExchangeResourceProvider