|| (clientTransfer && dataTransferClass == null)) {
System.err.println(ingestProductOperation);
System.exit(1);
}
Product product = new Product();
product.setProductName(productName);
product.setProductStructure(productStructure);
product
.setProductType(client
.getProductTypeByName(productTypeName));
if (clientTransfer) {
client.setDataTransfer(GenericFileManagerObjectFactory
.getDataTransferServiceFromFactory(dataTransferClass));
}
// need to build up the ref uri list in case the Product structure
// is
// heirarchical
if (product.getProductStructure().equals(
Product.STRUCTURE_HIERARCHICAL)) {
String ref = (String) refs.get(0);
refs.addAll(VersioningUtils.getURIsFromDir(new File(
new URI(ref))));
}
// add Product References from the URI list
VersioningUtils.addRefsFromUris(product, refs);
try {
Metadata metadata = null;
URL metaUrl = new File(new URI(metadataFileName)).toURL();
metadata = new SerializableMetadata(metaUrl.openStream());
System.out.println("ingestProduct: Result: "
+ client.ingestProduct(product, metadata,
clientTransfer));
} catch (Exception e) {
e.printStackTrace();
LOG.log(Level.SEVERE, "Exception ingesting product!: Message: "
+ e.getMessage());
throw new RuntimeException(e);
}
} else if (operation.equals("--hasProduct")) {
String productName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--productName")) {
productName = args[++i];
}
}
if (productName == null) {
System.err.println(hasProductOperation);
System.exit(1);
}
try {
System.out.println("hasProduct: Result: "
+ client.hasProduct(productName));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else if (operation.equals("--getProductTypeByName")) {
String productTypeName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--productTypeName")) {
productTypeName = args[++i];
}
}
if (productTypeName == null) {
System.err.println(getProductTypeByNameOperation);
System.exit(1);
}
try {
ProductType type = client.getProductTypeByName(productTypeName);
System.out.println("getProductTypeByName: Result: [name="
+ type.getName() + ", description="
+ type.getDescription() + ", id="
+ type.getProductTypeId() + ", versionerClass="
+ type.getVersioner() + ", repositoryPath="
+ type.getProductRepositoryPath() + "]");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else if (operation.equals("--getNumProducts")) {
String typeName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--productTypeName")) {
typeName = args[++i];
}
}
if (typeName == null) {
System.err.println(getNumProductsOperation);
System.exit(1);
}
try {
System.out.println("Type: ["
+ typeName
+ "], Num Products: ["
+ client.getNumProducts(client
.getProductTypeByName(typeName)) + "]");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else if (operation.equals("--getFirstPage")) {
String typeName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--productTypeName")) {
typeName = args[++i];
}
}
if (typeName == null) {
System.err.println(getFirstPageOperation);
System.exit(1);
}
try {
ProductType type = client.getProductTypeByName(typeName);
ProductPage firstPage = client.getFirstPage(type);
System.out.println("Page: [num=" + firstPage.getPageNum()
+ ", totalPages=" + firstPage.getTotalPages()
+ ", pageSize=" + firstPage.getPageSize() + "]");
System.out.println("Products:");
if (firstPage.getPageProducts() != null
&& firstPage.getPageProducts().size() > 0) {
for (Iterator<Product> i = firstPage.getPageProducts()
.iterator(); i.hasNext();) {
Product p = i.next();
System.out.println("Product: [id=" + p.getProductId()
+ ",name=" + p.getProductName() + ",type="
+ p.getProductType().getName() + ",structure="
+ p.getProductStructure() + ", transferStatus="
+ p.getTransferStatus() + "]");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else if (operation.equals("--getNextPage")) {
String typeName = null;
int currentPageNum = -1;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--productTypeName")) {
typeName = args[++i];
} else if (args[i].equals("--currentPageNum")) {
currentPageNum = Integer.parseInt(args[++i]);
}
}
if (typeName == null || currentPageNum == -1) {
System.err.println(getNextPageOperation);
System.exit(1);
}
try {
ProductType type = client.getProductTypeByName(typeName);
ProductPage firstPage = client.getFirstPage(type);
ProductPage currentPage = new ProductPage();
currentPage.setPageNum(currentPageNum);
currentPage.setPageSize(firstPage.getPageSize());
currentPage.setTotalPages(firstPage.getTotalPages());
ProductPage nextPage = client.getNextPage(type, currentPage);
System.out.println("Page: [num=" + nextPage.getPageNum()
+ ", totalPages=" + nextPage.getTotalPages()
+ ", pageSize=" + nextPage.getPageSize() + "]");
System.out.println("Products:");
if (nextPage.getPageProducts() != null
&& nextPage.getPageProducts().size() > 0) {
for (Iterator<Product> i = nextPage.getPageProducts()
.iterator(); i.hasNext();) {
Product p = i.next();
System.out.println("Product: [id=" + p.getProductId()
+ ",name=" + p.getProductName() + ",type="
+ p.getProductType().getName() + ",structure="
+ p.getProductStructure() + ", transferStatus="
+ p.getTransferStatus() + "]");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else if (operation.equals("--getPrevPage")) {
String typeName = null;
int currentPageNum = -1;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--productTypeName")) {
typeName = args[++i];
} else if (args[i].equals("--currentPageNum")) {
currentPageNum = Integer.parseInt(args[++i]);
}
}
if (typeName == null || currentPageNum == -1) {
System.err.println(getNextPageOperation);
System.exit(1);
}
try {
ProductType type = client.getProductTypeByName(typeName);
ProductPage firstPage = client.getFirstPage(type);
ProductPage currentPage = new ProductPage();
currentPage.setPageNum(currentPageNum);
currentPage.setPageSize(firstPage.getPageSize());
currentPage.setTotalPages(firstPage.getTotalPages());
ProductPage prevPage = client.getPrevPage(type, currentPage);
System.out.println("Page: [num=" + prevPage.getPageNum()
+ ", totalPages=" + prevPage.getTotalPages()
+ ", pageSize=" + prevPage.getPageSize() + "]");
System.out.println("Products:");
if (prevPage.getPageProducts() != null
&& prevPage.getPageProducts().size() > 0) {
for (Iterator<Product> i = prevPage.getPageProducts()
.iterator(); i.hasNext();) {
Product p = i.next();
System.out.println("Product: [id=" + p.getProductId()
+ ",name=" + p.getProductName() + ",type="
+ p.getProductType().getName() + ",structure="
+ p.getProductStructure() + ", transferStatus="
+ p.getTransferStatus() + "]");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else if (operation.equals("--getLastPage")) {
String typeName = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--productTypeName")) {
typeName = args[++i];
}
}
if (typeName == null) {
System.err.println(getLastPageOperation);
System.exit(1);
}
try {
ProductType type = client.getProductTypeByName(typeName);
ProductPage lastPage = client.getLastPage(type);
System.out.println("Page: [num=" + lastPage.getPageNum()
+ ", totalPages=" + lastPage.getTotalPages()
+ ", pageSize=" + lastPage.getPageSize() + "]");
System.out.println("Products:");
if (lastPage.getPageProducts() != null
&& lastPage.getPageProducts().size() > 0) {
for (Iterator<Product> i = lastPage.getPageProducts()
.iterator(); i.hasNext();) {
Product p = i.next();
System.out.println("Product: [id=" + p.getProductId()
+ ",name=" + p.getProductName() + ",type="
+ p.getProductType().getName() + ",structure="
+ p.getProductStructure() + ", transferStatus="
+ p.getTransferStatus() + "]");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else if (operation.equals("--getCurrentTransfer")) {
FileTransferStatus status = null;
try {
status = client.getCurrentFileTransfer();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
System.out.println("File Transfer: [ref={orig="
+ status.getFileRef().getOrigReference() + ",ds="
+ status.getFileRef().getDataStoreReference()
+ "},product=" + status.getParentProduct().getProductName()
+ ",fileSize=" + status.getFileRef().getFileSize()
+ ",amtTransferred=" + status.getBytesTransferred()
+ ",pct=" + status.computePctTransferred() + "]");
} else if (operation.equals("--getCurrentTransfers")) {
List<FileTransferStatus> statuses = null;
try {
statuses = client.getCurrentFileTransfers();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
if (statuses != null && statuses.size() > 0) {
for (Iterator<FileTransferStatus> i = statuses.iterator(); i
.hasNext();) {
FileTransferStatus status = i.next();
System.out.println("File Transfer: [ref={orig="
+ status.getFileRef().getOrigReference() + ",ds="
+ status.getFileRef().getDataStoreReference()
+ "},product="
+ status.getParentProduct().getProductName()
+ ",fileSize=" + status.getFileRef().getFileSize()
+ ",amtTransferred=" + status.getBytesTransferred()
+ ",pct=" + status.computePctTransferred() + "]");
}
}
} else if (operation.equals("--getProductPctTransferred")) {
String productTypeName = null, productId = null;
for (int i = 4; i < args.length; i++) {
if (args[i].equals("--productId")) {
productId = args[++i];
} else if (args[i].equals("--productTypeName")) {
productTypeName = args[++i];
}
}
if (productTypeName == null || productId == null) {
System.err.println(getProductPctTransferredOperation);
System.exit(1);
}
Product product = new Product();
product.setProductName(" ");
product.setProductStructure(" ");
product
.setProductType(client
.getProductTypeByName(productTypeName));
product.setProductId(productId);
double pct = 0.0;
try {
pct = client.getProductPctTransferred(product);