Coverage Report - org.mule.module.atom.endpoint.AtomEndpointBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
AtomEndpointBuilder
0%
0/46
0%
0/8
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.atom.endpoint;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.endpoint.EndpointException;
 11  
 import org.mule.api.endpoint.EndpointURI;
 12  
 import org.mule.api.endpoint.InboundEndpoint;
 13  
 import org.mule.api.endpoint.OutboundEndpoint;
 14  
 import org.mule.api.lifecycle.InitialisationException;
 15  
 import org.mule.api.routing.filter.Filter;
 16  
 import org.mule.endpoint.AbstractMetaEndpointBuilder;
 17  
 import org.mule.endpoint.EndpointURIEndpointBuilder;
 18  
 import org.mule.endpoint.URIBuilder;
 19  
 import org.mule.module.atom.routing.EntryLastUpdatedFilter;
 20  
 import org.mule.module.atom.routing.FeedSplitter;
 21  
 import org.mule.transport.http.HttpPollingConnector;
 22  
 import org.mule.util.StringUtils;
 23  
 
 24  
 import java.text.ParseException;
 25  
 import java.text.SimpleDateFormat;
 26  
 import java.util.Date;
 27  
 
 28  
 /**
 29  
  * An endpoint factory used for creating an ATOM endpoint
 30  
  */
 31  
 public class AtomEndpointBuilder extends AbstractMetaEndpointBuilder
 32  
 {
 33  
     public static final String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
 34  
     public static final String SHORT_DATE_FORMAT = "yyyy-MM-dd";
 35  
 
 36  0
     private boolean splitFeed = true;
 37  
 
 38  0
     private String lastUpdate = null;
 39  
 
 40  0
     private long pollingFrequency = 1000;
 41  
 
 42  0
     private final SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT);
 43  0
     private final SimpleDateFormat shortDateFormatter = new SimpleDateFormat(SHORT_DATE_FORMAT);
 44  
 
 45  
     public AtomEndpointBuilder()
 46  
     {
 47  0
         super();
 48  0
     }
 49  
 
 50  
     public AtomEndpointBuilder(EndpointURIEndpointBuilder global) throws EndpointException
 51  
     {
 52  0
         super(global);
 53  0
     }
 54  
 
 55  
     public AtomEndpointBuilder(URIBuilder uriBuilder)
 56  
     {
 57  0
         super(uriBuilder);
 58  0
     }
 59  
 
 60  
     public AtomEndpointBuilder(String address, MuleContext muleContext)
 61  
     {
 62  0
         super(address, muleContext);
 63  0
     }
 64  
 
 65  
     protected AtomEndpointBuilder(EndpointURI endpointURI)
 66  
     {
 67  0
         super(endpointURI);
 68  0
     }
 69  
 
 70  
     @Override
 71  
     public InboundEndpoint buildInboundEndpoint() throws EndpointException, InitialisationException
 72  
     {
 73  
         try
 74  
         {
 75  0
             Date date = formatDate(getLastUpdate());
 76  0
             if (isSplitFeed())
 77  
             {
 78  0
                 Filter filter = new EntryLastUpdatedFilter(date);
 79  0
                 FeedSplitter splitter = new FeedSplitter();
 80  0
                 splitter.setEntryFilter(filter);
 81  0
                 addMessageProcessor(splitter);
 82  
             }
 83  0
             AtomInboundEndpoint in = new AtomInboundEndpoint(isSplitFeed(), date, super.buildInboundEndpoint());
 84  0
             in.registerSupportedProtocol("http");
 85  0
             in.registerSupportedProtocol("https");
 86  0
             in.registerSupportedProtocol("vm");
 87  0
             if (in.getConnector() instanceof HttpPollingConnector)
 88  
             {
 89  0
                 ((HttpPollingConnector) in.getConnector()).setPollingFrequency(pollingFrequency);
 90  
             }
 91  0
             return in;
 92  
         }
 93  0
         catch (ParseException e)
 94  
         {
 95  0
             throw new EndpointException(e);
 96  
         }
 97  
     }
 98  
 
 99  
     @Override
 100  
     public OutboundEndpoint buildOutboundEndpoint() throws EndpointException, InitialisationException
 101  
     {
 102  0
         throw new UnsupportedOperationException("Outbound ATOM endpoints not supported");
 103  
     }
 104  
 
 105  
     public String getLastUpdate()
 106  
     {
 107  0
         return lastUpdate;
 108  
     }
 109  
 
 110  
     public void setLastUpdate(String lastUpdate)
 111  
     {
 112  0
         this.lastUpdate = lastUpdate;
 113  0
     }
 114  
 
 115  
     public boolean isSplitFeed()
 116  
     {
 117  0
         return splitFeed;
 118  
     }
 119  
 
 120  
     public void setSplitFeed(boolean splitFeed)
 121  
     {
 122  0
         this.splitFeed = splitFeed;
 123  0
     }
 124  
 
 125  
     public long getPollingFrequency()
 126  
     {
 127  0
         return pollingFrequency;
 128  
     }
 129  
 
 130  
     public void setPollingFrequency(long pollingFrequency)
 131  
     {
 132  0
         this.pollingFrequency = pollingFrequency;
 133  0
     }
 134  
 
 135  
     protected Date formatDate(String date) throws ParseException
 136  
     {
 137  0
         Date lastUpdateDate = null;
 138  0
         if (StringUtils.isNotBlank(date))
 139  
         {
 140  0
             if (lastUpdate.length() == 10)
 141  
             {
 142  0
                 lastUpdateDate = shortDateFormatter.parse(date);
 143  
             }
 144  
             else
 145  
             {
 146  0
                 lastUpdateDate = dateFormatter.parse(date);
 147  
             }
 148  
         }
 149  0
         return lastUpdateDate;
 150  
     }
 151  
 }