String fileName = met.getMetadata(FILENAME);
if (!check(productType, PRODUCT_TYPE)
|| !check(fileLocation, FILE_LOCATION)
|| !check(fileName, FILENAME)) {
throw new IngestException("Must specify: " + PRODUCT_TYPE + " and "
+ FILENAME + "and " + FILE_LOCATION
+ " within metadata file. Cannot ingest product: ["
+ prodFile.getAbsolutePath() + "]");
}
// allow user to override default product name (Filename)
String productName = met.getMetadata(PRODUCT_NAME) != null ? met
.getMetadata(PRODUCT_NAME) : fileName;
// check to see if product structure was specified
String productStructure = met.getMetadata(PRODUCT_STRUCTURE);
if (productStructure == null) {
// try and guess the structure
if (prodFile.isDirectory()) {
productStructure = Product.STRUCTURE_HIERARCHICAL;
} else
productStructure = Product.STRUCTURE_FLAT;
}
// create the product
Product product = new Product();
product.setProductName(productName);
product.setProductStructure(productStructure);
product.setProductType(getProductType(productType));
List<String> references = new Vector<String>();
if (!fileLocation.endsWith("/")) {
fileLocation += "/";
}
String fullFilePath = fileLocation + fileName;
references.add(new File(fullFilePath).toURI().toString());
if (productStructure.equals(Product.STRUCTURE_HIERARCHICAL)) {
references.addAll(VersioningUtils.getURIsFromDir(new File(
fullFilePath)));
}
// build refs and attach to product
VersioningUtils.addRefsFromUris(product, references);
LOG.log(Level.INFO, "StdIngester: ingesting product: " + PRODUCT_NAME
+ ": [" + productName + "]: " + PRODUCT_TYPE + ": ["
+ productType + "]: " + FILE_LOCATION + ": [" + fileLocation
+ "]");
String productID = null;
try {
productID = fmClient.ingestProduct(product, met, true);
} catch (Exception e) {
e.printStackTrace();
LOG.log(Level.WARNING, "exception ingesting product: ["
+ productName + "]: Message: " + e.getMessage());
throw new IngestException("exception ingesting product: ["
+ productName + "]: Message: " + e.getMessage());
}
return productID;