1 package org.kuali.maven.mojo.s3; 2 3 import java.io.IOException; 4 5 import org.apache.commons.lang.StringUtils; 6 import org.kuali.common.threads.ElementHandler; 7 import org.kuali.common.threads.ListIteratorContext; 8 import org.slf4j.Logger; 9 import org.slf4j.LoggerFactory; 10 11 import com.amazonaws.AmazonServiceException; 12 13 public class UpdateDirectoryContextHandler implements ElementHandler<UpdateDirectoryContext> { 14 private final Logger logger = LoggerFactory.getLogger(ListObjectsContextHandler.class); 15 16 UpdateOriginBucketMojo mojo; 17 18 public UpdateDirectoryContextHandler() { 19 this(null); 20 } 21 22 public UpdateDirectoryContextHandler(UpdateOriginBucketMojo mojo) { 23 super(); 24 this.mojo = mojo; 25 } 26 27 @Override 28 public void handleElement(ListIteratorContext<UpdateDirectoryContext> context, int index, 29 UpdateDirectoryContext element) { 30 logger.debug("[Thread:" + lpad(context.getId()) + ", Element:" + lpad(index) + "] " + element.getCopyToKey()); 31 32 try { 33 S3PrefixContext prefixContext = element.getContext(); 34 if (prefixContext.isRoot()) { 35 mojo.updateRoot(element); 36 } else { 37 mojo.updateDirectory(element); 38 } 39 } catch (IOException e) { 40 throw new AmazonServiceException("Unexpected error:", e); 41 } 42 } 43 44 protected String lpad(int i) { 45 return StringUtils.leftPad(i + "", 3, " "); 46 } 47 48 public UpdateOriginBucketMojo getMojo() { 49 return mojo; 50 } 51 52 public void setMojo(UpdateOriginBucketMojo mojo) { 53 this.mojo = mojo; 54 } 55 }