}
} catch (StorageException e) { }
}
public Resolution upload() throws Exception {
Invoice invc = null;
capturedCount = 0;
final int nItems = (getItems()==null ? 0 : getItems().size());
if (nItems>0) {
Log.out.debug("InvoiceUpload "+String.valueOf(nItems)+" items found");
try {
connect(getSessionAttribute("nickname"), getSessionAttribute("password"));
Dms oDms = getSession().getDms();
Document rcpt = oDms.getDocument(getRecipientTaxPayer());
String sTaxPayerId = rcpt.type().name().equals("TaxPayer") ? getRecipientTaxPayer() : getSessionAttribute("taxpayer_docid");
TaxPayer txpy = new TaxPayer(getSession().getDms(), sTaxPayerId);
Invoices invs = txpy.invoices(getSession());
invc = invs.create(getSession(), getSessionAttribute("user_uuid"), getServiceFlavor(),
sTaxPayerId, getBillerTaxPayer(), getRecipientTaxPayer());
capureddocid = invc.id();
for (FileBean attachment : getItems()) {
if (attachment != null) {
if (attachment.getSize() > 0) {
InvoicePage page = invc.createPage(getSession(), attachment.getInputStream(), ++capturedCount, attachment.getFileName());
if (capturedCount==1) {
capuredpage1 = page.id();
}
attachment.delete();
} else {
ValidationError error = new SimpleError(attachment.getFileName()+ " is not a valid file." );
getContext().getValidationErrors().add("items" , error);
}
}
} // next
disconnect();
Log.out.debug("Done uploading items");
if (capturedCount>0) {
ThumbnailCreator.createThumbnailFor(capureddocid, capuredpage1);
}
} catch (Exception e) {
Log.out.error("InvoiceUpload.upload() "+e.getClass().getName()+" "+e.getMessage(), e);
getContext().getMessages().add(new SimpleMessage("ERROR "+e.getMessage(), items));
} finally { close(); }
} else {
Log.out.debug("InvoiceUpload no items found");
}
if (invc==null)
return new RedirectResolution("/error.jsp");
if (invc.getServiceFlavor().equals(CaptureServiceFlavor.BASIC))
return new ForwardResolution("EditInvoice.action?id="+invc.id());
else
return new ForwardResolution(FORM);
}