use of org.compiere.process.DocAction in project adempiere by adempiere.
the class ImportHelper method importXMLDocument.
/**
* Import XML Document
* @param result
* @param documentToBeImported
* @param trxName
* @throws Exception
* @throws SQLException
* @throws XPathExpressionException
*/
public void importXMLDocument(StringBuffer result, Document documentToBeImported, String trxName) throws Exception, SQLException, XPathExpressionException {
Element rootElement = documentToBeImported.getDocumentElement();
// Find which Export format to Load...
String AD_Client_Value = null;
AD_Client_Value = rootElement.getAttribute("AD_Client_Value");
log.info("AD_Client_Value = " + AD_Client_Value);
if (AD_Client_Value == null || Util.isEmpty(AD_Client_Value)) {
throw new Exception(Msg.getMsg(ctx, "XMLClientValueMandatory"));
}
String version = null;
version = rootElement.getAttribute("Version");
log.info("Version = " + version);
if (version == null || Util.isEmpty(version)) {
throw new Exception(Msg.getMsg(ctx, "XMLVersionAttributeMandatory"));
}
///Getting Attributes.
int ReplicationMode = new Integer(rootElement.getAttribute("ReplicationMode"));
String ReplicationType = rootElement.getAttribute("ReplicationType");
int ReplicationEvent = new Integer(rootElement.getAttribute("ReplicationEvent"));
MClient client = null;
client = getAD_ClientByValue(ctx, AD_Client_Value, trxName);
if (client == null) {
throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound"));
}
log.info("XML ROOT AD_Client = " + client.toString());
String EXP_Format_Value = null;
EXP_Format_Value = rootElement.getNodeName();
log.info("EXP_Format_Value = " + EXP_Format_Value);
MEXPFormat expFormat = null;
expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, client.getAD_Client_ID(), version, trxName);
if (expFormat == null || expFormat.getEXP_Format_ID() == 0) {
// Fall back to SYSTEM Client.
// Try to search Export format defined for SYSTEM Client!!!
MClient systemClient = null;
systemClient = MClient.get(ctx, 0);
if (systemClient == null) {
throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound"));
}
log.info("SYSTEM Client = " + systemClient.toString());
expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, systemClient.getAD_Client_ID(), version, trxName);
}
if (expFormat == null || expFormat.getEXP_Format_ID() == 0) {
throw new Exception(Msg.getMsg(ctx, "EXPFormatNotFound"));
}
log.info("expFormat = " + expFormat.toString());
isChanged = false;
PO po = importElement(ctx, result, rootElement, expFormat, ReplicationType, trxName);
if (ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent || ModelValidator.TYPE_BEFORE_DELETE_REPLICATION == ReplicationEvent || ModelValidator.TYPE_DELETE == ReplicationEvent)
;
else if (!po.is_Changed() && !isChanged) {
log.info("Object not changed = " + po.toString());
return;
}
if (po != null) {
Env.setContext(po.getCtx(), "#AD_Client_ID", po.getAD_Client_ID());
if (MReplicationStrategy.REPLICATION_TABLE == ReplicationMode) {
// Here must invoke other method else we get cycle...
if (ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent || ModelValidator.TYPE_BEFORE_DELETE_REPLICATION == ReplicationEvent || ModelValidator.TYPE_DELETE == ReplicationEvent) {
po.deleteEx(true);
} else {
if (X_AD_ReplicationTable.REPLICATIONTYPE_Broadcast.equals(ReplicationType)) {
MReplicationStrategy rplStrategy = new MReplicationStrategy(client.getCtx(), client.getAD_ReplicationStrategy_ID(), po.get_TrxName());
ExportHelper expHelper = new ExportHelper(client, rplStrategy);
expHelper.exportRecord(po, MReplicationStrategy.REPLICATION_TABLE, X_AD_ReplicationTable.REPLICATIONTYPE_Merge, ModelValidator.TYPE_AFTER_CHANGE);
po.saveReplica(true);
} else if (X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(ReplicationType) || X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType)) {
po.saveReplica(true);
} else /*else if (X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType))
{
//Do nothing??
}*/
if (X_AD_ReplicationTable.REPLICATIONTYPE_Local.equals(ReplicationType)) {
//Do nothing??
} else {
// Replication Type is not one of the possible values...ERROR
throw new Exception(Msg.getMsg(ctx, "EXPReplicationTypeNonValidType"));
}
}
} else if (MReplicationStrategy.REPLICATION_DOCUMENT == ReplicationMode && X_AD_ReplicationDocument.REPLICATIONTYPE_Merge.equals(ReplicationType) && po instanceof DocAction) {
DocAction document = (DocAction) po;
String action = document.getDocAction();
String status = document.getDocStatus();
log.info("Document:" + document.toString() + " DocStauts:" + status + " DocAction:" + action);
if (ModelValidator.TIMING_AFTER_REVERSECORRECT == ReplicationEvent) {
if (status.equals(DocAction.STATUS_Reversed) && action.equals(DocAction.ACTION_None)) {
po.saveEx();
return;
}
}
if ((action.equals(DocAction.ACTION_Complete) && status.equals(DocAction.STATUS_InProgress)) || (action.equals(DocAction.ACTION_Close) && status.equals(DocAction.STATUS_Completed))) {
if (!document.processIt(action)) {
log.info("PO.toString() = can not " + po.get_Value("DocAction"));
}
po.saveEx();
} else {
po.saveEx();
return;
}
}
}
result.append("Save Successful ;");
}
use of org.compiere.process.DocAction in project adempiere by adempiere.
the class MWFActivity method sendEMail.
// fillParameter
/*********************************
* Send EMail
*/
private void sendEMail() {
DocAction doc = (DocAction) m_po;
MMailText text = new MMailText(getCtx(), m_node.getR_MailText_ID(), null);
text.setPO(m_po, true);
//
String subject = doc.getDocumentInfo() + ": " + text.getMailHeader();
String message = text.getMailText(true) + "\n-----\n" + doc.getDocumentInfo() + "\n" + doc.getSummary();
File pdf = doc.createPDF();
//
MClient client = MClient.get(doc.getCtx(), doc.getAD_Client_ID());
// Explicit EMail
sendEMail(client, 0, m_node.getEMail(), subject, message, pdf, text.isHtml());
// Recipient Type
String recipient = m_node.getEMailRecipient();
// email to document user
if (recipient == null || recipient.length() == 0)
sendEMail(client, doc.getDoc_User_ID(), null, subject, message, pdf, text.isHtml());
else if (recipient.equals(MWFNode.EMAILRECIPIENT_DocumentBusinessPartner)) {
int index = m_po.get_ColumnIndex("AD_User_ID");
if (index > 0) {
Object oo = m_po.get_Value(index);
if (oo instanceof Integer) {
int AD_User_ID = ((Integer) oo).intValue();
if (AD_User_ID != 0)
sendEMail(client, AD_User_ID, null, subject, message, pdf, text.isHtml());
else
log.fine("No User in Document");
} else
log.fine("Empty User in Document");
} else
log.fine("No User Field in Document");
} else if (recipient.equals(MWFNode.EMAILRECIPIENT_DocumentOwner))
sendEMail(client, doc.getDoc_User_ID(), null, subject, message, pdf, text.isHtml());
else if (recipient.equals(MWFNode.EMAILRECIPIENT_WFResponsible)) {
MWFResponsible resp = getResponsible();
if (resp.isInvoker())
sendEMail(client, doc.getDoc_User_ID(), null, subject, message, pdf, text.isHtml());
else if (resp.isHuman())
sendEMail(client, resp.getAD_User_ID(), null, subject, message, pdf, text.isHtml());
else if (resp.isRole()) {
MRole role = resp.getRole();
if (role != null) {
MUser[] users = MUser.getWithRole(role);
for (int i = 0; i < users.length; i++) sendEMail(client, users[i].getAD_User_ID(), null, subject, message, pdf, text.isHtml());
}
} else if (resp.isOrganization()) {
MOrgInfo org = MOrgInfo.get(getCtx(), m_po.getAD_Org_ID(), get_TrxName());
if (org.getSupervisor_ID() == 0)
log.fine("No Supervisor for AD_Org_ID=" + m_po.getAD_Org_ID());
else
sendEMail(client, org.getSupervisor_ID(), null, subject, message, pdf, text.isHtml());
}
}
}
use of org.compiere.process.DocAction in project adempiere by adempiere.
the class MWFActivity method setUserChoice.
// setVariable
/**
* Set User Choice
* @param AD_User_ID user
* @param value new Value
* @param displayType display type
* @param textMsg optional Message
* @return true if set
* @throws Exception if error
*/
public boolean setUserChoice(int AD_User_ID, String value, int displayType, String textMsg) throws Exception {
// Check if user approves own document when a role is reponsible
/*
* 2007-06-08, matthiasO.
* The following sequence makes sure that only users in roles which
* have the 'Approve own document flag' set can set the user choice
* of 'Y' (approve) or 'N' (reject).
* IMHO this is against the meaning of 'Approve own document': Why
* should a user who is faced with the task of approving documents
* generally be required to have the ability to approve his OWN
* documents? If the document to approve really IS his own document
* this will be respected when trying to find an approval user in
* the call to getApprovalUser(...) below.
*/
/*
if (getNode().isUserApproval() && getPO() instanceof DocAction)
{
DocAction doc = (DocAction)m_po;
MUser user = new MUser (getCtx(), AD_User_ID, null);
MRole[] roles = user.getRoles(m_po.getAD_Org_ID());
boolean canApproveOwnDoc = false;
for (int r = 0; r < roles.length; r++)
{
if (roles[r].isCanApproveOwnDoc())
{
canApproveOwnDoc = true;
break;
} // found a role which allows to approve own document
}
if (!canApproveOwnDoc)
{
String info = user.getName() + " cannot approve own document " + doc;
addTextMsg(info);
log.fine(info);
return false; // ignore
}
}*/
setWFState(StateEngine.STATE_Running);
setAD_User_ID(AD_User_ID);
Trx trx = (get_TrxName() != null) ? Trx.get(get_TrxName(), false) : null;
boolean ok = setVariable(value, displayType, textMsg, trx);
if (!ok)
return false;
String newState = StateEngine.STATE_Completed;
// Approval
if (getNode().isUserApproval() && getPO(trx) instanceof DocAction) {
DocAction doc = (DocAction) m_po;
try {
// Not approved
if (!"Y".equals(value)) {
newState = StateEngine.STATE_Aborted;
if (!(doc.processIt(DocAction.ACTION_Reject)))
setTextMsg("Cannot Reject - Document Status: " + doc.getDocStatus());
} else {
if (isInvoker()) {
int startAD_User_ID = Env.getAD_User_ID(getCtx());
if (startAD_User_ID == 0)
startAD_User_ID = doc.getDoc_User_ID();
int nextAD_User_ID = getApprovalUser(startAD_User_ID, doc.getC_Currency_ID(), doc.getApprovalAmt(), doc.getAD_Org_ID(), // own doc
startAD_User_ID == doc.getDoc_User_ID());
// No Approver
if (nextAD_User_ID <= 0) {
newState = StateEngine.STATE_Aborted;
setTextMsg("Cannot Approve - No Approver");
doc.processIt(DocAction.ACTION_Reject);
} else if (startAD_User_ID != nextAD_User_ID) {
forwardTo(nextAD_User_ID, "Next Approver");
newState = StateEngine.STATE_Suspended;
} else // Approve
{
if (!(doc.processIt(DocAction.ACTION_Approve))) {
newState = StateEngine.STATE_Aborted;
setTextMsg("Cannot Approve - Document Status: " + doc.getDocStatus());
}
}
} else // No Invoker - Approve
if (!(doc.processIt(DocAction.ACTION_Approve))) {
newState = StateEngine.STATE_Aborted;
setTextMsg("Cannot Approve - Document Status: " + doc.getDocStatus());
}
}
doc.saveEx();
} catch (Exception e) {
newState = StateEngine.STATE_Terminated;
setTextMsg("User Choice: " + e.toString());
addTextMsg(e);
log.log(Level.WARNING, "", e);
}
// Send Approval Notification
if (newState.equals(StateEngine.STATE_Aborted)) {
MUser to = new MUser(getCtx(), doc.getDoc_User_ID(), null);
// send email
if (to.isNotificationEMail()) {
MClient client = MClient.get(getCtx(), doc.getAD_Client_ID());
client.sendEMail(doc.getDoc_User_ID(), Msg.getMsg(getCtx(), "NotApproved") + ": " + doc.getDocumentNo(), (doc.getSummary() != null ? doc.getSummary() + "\n" : "") + (doc.getProcessMsg() != null ? doc.getProcessMsg() + "\n" : "") + (getTextMsg() != null ? getTextMsg() : ""), null);
}
// Send Note
if (to.isNotificationNote()) {
MNote note = new MNote(getCtx(), "NotApproved", doc.getDoc_User_ID(), null);
note.setTextMsg((doc.getSummary() != null ? doc.getSummary() + "\n" : "") + (doc.getProcessMsg() != null ? doc.getProcessMsg() + "\n" : "") + (getTextMsg() != null ? getTextMsg() : ""));
// 2007-06-08, matthiasO.
// Add record information to the note, so that the user receiving the
// note can jump to the doc easily
note.setRecord(m_po.get_Table_ID(), m_po.get_ID());
note.saveEx();
}
}
}
setWFState(newState);
return ok;
}
use of org.compiere.process.DocAction in project adempiere by adempiere.
the class MWFProcess method setUser_ID.
// setAD_WF_Responsible_ID
/**
* Set User from
* - (1) Responsible
* - (2) Document Sales Rep
* - (3) Document UpdatedBy
* - (4) Process invoker
* @param User_ID process invoker
*/
private void setUser_ID(Integer User_ID) {
// Responsible
MWFResponsible resp = MWFResponsible.get(getCtx(), getAD_WF_Responsible_ID());
// (1) User - Directly responsible
int AD_User_ID = resp.getAD_User_ID();
// Invoker - get Sales Rep or last updater of Document
if (AD_User_ID == 0 && resp.isInvoker()) {
getPO();
// (2) Doc Owner
if (m_po != null && m_po instanceof DocAction) {
DocAction da = (DocAction) m_po;
AD_User_ID = da.getDoc_User_ID();
}
// (2) Sales Rep
if (AD_User_ID == 0 && m_po != null && m_po.get_ColumnIndex("SalesRep_ID") != -1) {
Object sr = m_po.get_Value("SalesRep_ID");
if (sr != null && sr instanceof Integer)
AD_User_ID = ((Integer) sr).intValue();
}
// (3) UpdatedBy
if (AD_User_ID == 0 && m_po != null)
AD_User_ID = m_po.getUpdatedBy();
}
// (4) Process Owner
if (AD_User_ID == 0 && User_ID != null)
AD_User_ID = User_ID.intValue();
// Fallback
if (AD_User_ID == 0)
AD_User_ID = Env.getAD_User_ID(getCtx());
//
setAD_User_ID(AD_User_ID);
}
use of org.compiere.process.DocAction in project adempiere by adempiere.
the class WorkflowProcessor method sendEmail.
// sendAlerts
/**
* Send Alert EMail
* @param activity activity
* @param AD_Message message
* @param toProcess true if to process owner
* @param toSupervisor true if to Supervisor
* @return number of mails sent
*/
private int sendEmail(MWFActivity activity, String AD_Message, boolean toProcess, boolean toSupervisor) {
if (m_client == null || m_client.getAD_Client_ID() != activity.getAD_Client_ID())
m_client = MClient.get(getCtx(), activity.getAD_Client_ID());
MWFProcess process = new MWFProcess(getCtx(), activity.getAD_WF_Process_ID(), null);
String subjectVar = activity.getNode().getName();
String message = activity.getTextMsg();
if (message == null || message.length() == 0)
message = process.getTextMsg();
File pdf = null;
PO po = activity.getPO();
if (po instanceof DocAction) {
message = ((DocAction) po).getDocumentInfo() + "\n" + message;
pdf = ((DocAction) po).createPDF();
}
// Inactivity Alert: Workflow Activity {0}
String subject = Msg.getMsg(m_client.getAD_Language(), AD_Message, new Object[] { subjectVar });
// Prevent duplicates
ArrayList<Integer> list = new ArrayList<Integer>();
int counter = 0;
// To Activity Owner
if (m_client.sendEMail(activity.getAD_User_ID(), subject, message, pdf))
counter++;
list.add(new Integer(activity.getAD_User_ID()));
// To Process Owner
if (toProcess && process.getAD_User_ID() != activity.getAD_User_ID()) {
if (m_client.sendEMail(process.getAD_User_ID(), subject, message, pdf))
counter++;
list.add(new Integer(process.getAD_User_ID()));
}
// To Activity Responsible
MWFResponsible responsible = MWFResponsible.get(getCtx(), activity.getAD_WF_Responsible_ID());
counter += sendAlertToResponsible(responsible, list, process, subject, message, pdf);
// To Process Responsible
if (toProcess && process.getAD_WF_Responsible_ID() != activity.getAD_WF_Responsible_ID()) {
responsible = MWFResponsible.get(getCtx(), process.getAD_WF_Responsible_ID());
counter += sendAlertToResponsible(responsible, list, process, subject, message, pdf);
}
// Processor SuperVisor
if (toSupervisor && m_model.getSupervisor_ID() != 0 && !list.contains(new Integer(m_model.getSupervisor_ID()))) {
if (m_client.sendEMail(m_model.getSupervisor_ID(), subject, message, pdf))
counter++;
list.add(new Integer(m_model.getSupervisor_ID()));
}
return counter;
}
Aggregations