use of org.compiere.model.MAssetDelivery in project adempiere by adempiere.
the class AssetDelivery method confirmDelivery.
// deliverIt
/*************************************************************************
* Confirm Asset EMail Delivery
* @param MAsset asset
* @param email email sent
* @param AD_User_ID recipient
* @return asset delivery
*/
public MAssetDelivery confirmDelivery(MAsset asset, EMail email, int AD_User_ID) {
asset.setVersionNo(asset.getProductVersionNo());
MAssetDelivery ad = new MAssetDelivery(asset, email, AD_User_ID);
return ad;
}
use of org.compiere.model.MAssetDelivery in project adempiere by adempiere.
the class AssetDelivery method deliverIt.
// sendNoGuaranteeMail
/**************************************************************************
* Deliver Asset
* @param A_Asset_ID asset
* @return message - delivery errors start with **
*/
private String deliverIt(int A_Asset_ID) {
log.fine("A_Asset_ID=" + A_Asset_ID);
long start = System.currentTimeMillis();
//
MAsset asset = new MAsset(getCtx(), A_Asset_ID, get_TrxName());
if (asset.getAD_User_ID() == 0)
return "** No Asset User";
MUser user = new MUser(getCtx(), asset.getAD_User_ID(), get_TrxName());
if (user.getEMail() == null || user.getEMail().length() == 0)
return "** No Asset User Email";
if (asset.getProductR_MailText_ID() == 0)
return "** Product Mail Text";
if (m_MailText == null || m_MailText.getR_MailText_ID() != asset.getProductR_MailText_ID())
m_MailText = new MMailText(getCtx(), asset.getProductR_MailText_ID(), get_TrxName());
if (m_MailText.getMailHeader() == null || m_MailText.getMailHeader().length() == 0)
return "** No Subject";
// Create Mail
EMail email = m_client.createEMail(user.getEMail(), null, null);
if (!email.isValid()) {
asset.setHelp(asset.getHelp() + " - Invalid EMail");
asset.setIsActive(false);
return "** Invalid EMail: " + user.getEMail();
}
if (m_client.isSmtpAuthorization())
email.createAuthenticator(m_client.getRequestUser(), m_client.getRequestUserPW());
m_MailText.setUser(user);
m_MailText.setPO(asset);
String message = m_MailText.getMailText(true);
if (m_MailText.isHtml() || m_AttachAsset)
email.setMessageHTML(m_MailText.getMailHeader(), message);
else {
email.setSubject(m_MailText.getMailHeader());
email.setMessageText(message);
}
if (m_AttachAsset) {
MProductDownload[] pdls = asset.getProductDownloads();
if (pdls != null) {
for (int i = 0; i < pdls.length; i++) {
URI url = pdls[i].getDownloadURL(m_client.getDocumentDir());
if (url != null)
email.addAttachment(url);
}
} else
log.warning("No DowloadURL for A_Asset_ID=" + A_Asset_ID);
}
String msg = email.send();
new MUserMail(m_MailText, asset.getAD_User_ID(), email).saveEx();
if (!EMail.SENT_OK.equals(msg))
return "** Not delivered: " + user.getEMail() + " - " + msg;
MAssetDelivery ad = confirmDelivery(asset, email, user.getAD_User_ID());
ad.saveEx();
asset.saveEx();
//
log.fine((System.currentTimeMillis() - start) + " ms");
// success
return user.getEMail() + " - " + asset.getProductVersionNo();
}
use of org.compiere.model.MAssetDelivery in project adempiere by adempiere.
the class AssetServlet method streamAsset.
// doPost
/**
* Stream asset
* @param request request
* @param response response
* @return "" or error message
*/
protected String streamAsset(HttpServletRequest request, HttpServletResponse response) {
// Get Asset ID
int A_Asset_ID = WebUtil.getParameterAsInt(request, "Asset_ID");
if (A_Asset_ID == 0) {
log.fine("No ID)");
return "No Asset ID";
}
byte[] assetInfo = String.valueOf(A_Asset_ID).getBytes();
// Get Asset
Properties ctx = JSPEnv.getCtx(request);
HttpSession session = request.getSession(true);
WebEnv.dump(request);
MAsset asset = new MAsset(ctx, A_Asset_ID, null);
if (asset.getA_Asset_ID() != A_Asset_ID) {
log.fine("Asset not found - ID=" + A_Asset_ID);
return "Asset not found";
}
// Get WebUser & Compare with invoice
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu.getC_BPartner_ID() != asset.getC_BPartner_ID()) {
log.warning("A_Asset_ID=" + A_Asset_ID + " - BP_Invoice=" + asset.getC_BPartner_ID() + " <> BP_User=" + wu.getC_BPartner_ID());
return "Your asset not found";
}
if (!asset.isDownloadable() || wu.isCreditStopHold() || !wu.isEMailVerified())
return "Asset not downloadable";
// Name & URL
String pd = WebUtil.getParameter(request, "PD");
String dl_name = null;
String dl_url = null;
InputStream in = null;
int M_ProductDownload_ID = 0;
if (pd != null && pd.length() > 0) {
MProductDownload[] pdls = asset.getProductDownloads();
if (pdls != null) {
for (int i = 0; i < pdls.length; i++) {
if (pdls[i].getDownloadURL().indexOf(pd) != -1) {
M_ProductDownload_ID = pdls[i].getM_ProductDownload_ID();
dl_name = pd;
dl_url = pdls[i].getDownloadURL();
in = pdls[i].getDownloadStream(ctx.getProperty(WebSessionCtx.CTX_DOCUMENT_DIR));
break;
}
}
}
}
log.fine(dl_name + " - " + dl_url);
if (dl_name == null || dl_url == null || in == null)
return "@NotFound@ @A_Asset_ID@: " + pd;
/**
Download SupportContract.pdf for Jorg Janke - jjanke@adempiere.org
Version = 120 - Lot = . - SerNo = .
Guarantee Date = 5/30/05
Thank you for using Adempiere Customer Asset Management
**/
String lot = asset.getLot();
if (lot == null || lot.length() == 0)
lot = ".";
String ser = asset.getSerNo();
if (ser == null || ser.length() == 0)
ser = ".";
Object[] args = new Object[] { dl_name, wu.getName() + " - " + wu.getEmail(), asset.getVersionNo(), lot, ser, asset.getGuaranteeDate() };
String readme = Msg.getMsg(ctx, "AssetDeliveryTemplate", args);
// Send File
MAssetDelivery ad = confirmDelivery(asset, request, wu.getAD_User_ID());
if (M_ProductDownload_ID != 0)
ad.setM_ProductDownload_ID(M_ProductDownload_ID);
ad.setDescription(dl_name);
//
float speed = 0;
try {
response.setContentType("application/zip");
response.setHeader("Content-Location", "asset.zip");
// response.setContentLength(length);
// 2k Buffer
int bufferSize = 2048;
response.setBufferSize(bufferSize);
//
log.fine(in + ", available=" + in.available());
long time = System.currentTimeMillis();
// Zip Output Stream
ServletOutputStream out = response.getOutputStream();
// Servlet out
ZipOutputStream zip = new ZipOutputStream(out);
zip.setMethod(ZipOutputStream.DEFLATED);
zip.setLevel(Deflater.BEST_COMPRESSION);
zip.setComment(readme);
// Readme File
ZipEntry entry = new ZipEntry("readme.txt");
entry.setExtra(assetInfo);
zip.putNextEntry(entry);
zip.write(readme.getBytes(), 0, readme.length());
zip.closeEntry();
// Payload
entry = new ZipEntry(dl_name);
entry.setExtra(assetInfo);
zip.putNextEntry(entry);
byte[] buffer = new byte[bufferSize];
int count = 0;
int totalSize = 0;
do {
// read delivery
count = in.read(buffer, 0, bufferSize);
if (count > 0) {
totalSize += count;
// write zip
zip.write(buffer, 0, count);
}
} while (count != -1);
zip.closeEntry();
// Fini
zip.finish();
zip.close();
in.close();
time = System.currentTimeMillis() - time;
speed = ((float) totalSize / 1024) / ((float) time / 1000);
String msg = (totalSize / 1024) + "kB - " + time + " ms - " + speed + " kB/sec";
log.fine(msg);
// Delivery Record
ad.setDeliveryConfirmation(msg);
ad.saveEx();
asset.saveEx();
} catch (IOException ex) {
String msg = ex.getMessage();
if (msg == null || msg.length() == 0)
msg = ex.toString();
log.warning(msg);
// Delivery Record
try {
if (msg.length() > 120)
msg = msg.substring(0, 119);
ad.setDeliveryConfirmation(msg);
ad.save();
// asset.saveEx(); not delivered
} catch (Exception ex1) {
log.log(Level.SEVERE, "2 - " + ex);
}
// nned to differentiate error message as response committed
return "** Streaming error; Please Retry";
}
//
return null;
}
use of org.compiere.model.MAssetDelivery in project adempiere by adempiere.
the class AssetServlet method confirmDelivery.
// streamAsset
/**
* Confirm Asset Download Delivery
* @param MAsset asset
* @param request request
* @param AD_User_ID recipient
* @return asset delivery
*/
public MAssetDelivery confirmDelivery(MAsset asset, HttpServletRequest request, int AD_User_ID) {
asset.setVersionNo(asset.getProductVersionNo());
asset.setLifeUseUnits(asset.getLifeUseUnits() + 1);
MAssetDelivery ad = new MAssetDelivery(asset, request, AD_User_ID);
return ad;
}
use of org.compiere.model.MAssetDelivery in project adempiere by adempiere.
the class MAssetTest method testQuery.
public void testQuery() throws Exception {
//test with mock A_Asset and A_Asset_Delivery record
MAsset asset = new MAsset(getCtx(), 1000000, getTrxName());
MAssetDelivery[] assets = asset.getDeliveries();
assertTrue("assets must have values", assets.length > 0);
MAsset getstmt = MAsset.getFromShipment(getCtx(), 1000000, getTrxName());
assertTrue("stmt must be active", getstmt.isActive() == true);
}
Aggregations