if (p.getProductStructure().equals(Product.STRUCTURE_FLAT)) {
// we just need to get its first reference
if (p.getProductReferences() == null
|| (p.getProductReferences() != null && p
.getProductReferences().size() != 1)) {
throw new DataTransferException(
"Flat products must have a single reference: cannot move");
}
// okay, it's fine to move it
// first, we need to update the data store ref
Reference r = (Reference) p.getProductReferences().get(0);
if (r.getDataStoreReference().equals(
new File(newPath).toURI().toString())) {
throw new DataTransferException("cannot move product: ["
+ p.getProductName() + "] to same location: ["
+ r.getDataStoreReference() + "]");
}
// create a copy of the current data store path: we'll need it to
// do the data transfer
Reference copyRef = new Reference(r);
// update the copyRef to have the data store ref as the orig ref
// the the newLoc as the new ref
copyRef.setOrigReference(r.getDataStoreReference());
copyRef.setDataStoreReference(new File(newPath).toURI().toString());
p.getProductReferences().clear();
p.getProductReferences().add(copyRef);
// now transfer it
try {
this.dataTransfer.transferProduct(p);
} catch (IOException e) {
throw new DataTransferException(e.getMessage());
}
// now delete the original copy
try {
if (!new File(new URI(copyRef.getOrigReference())).delete()) {
LOG.log(Level.WARNING, "Deletion of original file: ["
+ r.getDataStoreReference()
+ "] on product move returned false");
}
} catch (URISyntaxException e) {
throw new DataTransferException(
"URI Syntax exception trying to remove original product ref: Message: "
+ e.getMessage());
}
// now save the updated reference
try {
this.catalog.modifyProduct(p);
return true;
} catch (CatalogException e) {
throw new DataTransferException(e.getMessage());
}
} else
throw new UnsupportedOperationException(
"Moving of heirarhical products not supported yet");
}