use of org.compiere.model.PO in project adempiere by adempiere.
the class ImportHelper method getValueFromFormat.
/**
* Get the value from format
* @param line
* @param po
* @param rootElement
* @param result
* @param replicationType
* @return
* @throws Exception
*/
private Object getValueFromFormat(MEXPFormatLine line, PO po, Element rootElement, StringBuffer result, String replicationType) throws Exception {
Object value = null;
if (MEXPFormatLine.TYPE_XMLElement.equals(line.getType())) {
// XML Element
value = XMLHelper.getString(line.getValue(), rootElement);
log.info("value=[" + value + "]");
} else if (MEXPFormatLine.TYPE_ReferencedEXPFormat.equals(line.getType())) {
// Referenced Export Format
//get from cache
MEXPFormat referencedExpFormat = MEXPFormat.get(ctx, line.getEXP_EmbeddedFormat_ID(), po.get_TrxName());
log.info("referencedExpFormat = " + referencedExpFormat);
int refRecord_ID = 0;
// Find Record_ID by ???Value??? In fact by Columns set as Part Of Unique Index in Export Format!
String xPath = null;
xPath = "" + line.getValue() + "";
log.info("Seach for XML Element = " + xPath);
Element referencedNode = XMLHelper.getElement(xPath, rootElement);
log.info("referencedNode = " + referencedNode);
if (referencedNode != null) {
refRecord_ID = getID(ctx, referencedExpFormat, referencedNode, line.getValue(), po.get_TrxName());
log.info("refRecord_ID = " + refRecord_ID);
value = new Integer(refRecord_ID);
} else {
log.info("NULL VALUE FOR " + xPath.toString());
value = null;
}
log.info("value=[" + value + "]");
} else if (MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(line.getType())) {
if (po.is_Changed()) {
isChanged = true;
po.saveReplica(true);
} else {
return value;
}
// Embedded Export Format It is used for Parent-Son records like Order&OrderLine
//get from cache
MEXPFormat referencedExpFormat = MEXPFormat.get(ctx, line.getEXP_EmbeddedFormat_ID(), po.get_TrxName());
log.info("embeddedExpFormat = " + referencedExpFormat);
NodeList nodeList = XMLHelper.getNodeList("/" + rootElement.getNodeName() + "/" + line.getValue(), rootElement);
for (int j = 0; j < nodeList.getLength(); j++) {
Element referencedElement = (Element) nodeList.item(j);
log.info("EmbeddedEXPFormat - referencedElement.getNodeName = " + referencedElement.getNodeName());
PO embeddedPo = null;
// Import embedded PO
log.info("=== BEGIN RECURSION CALL ===");
embeddedPo = importElement(ctx, result, referencedElement, referencedExpFormat, replicationType, po.get_TrxName());
log.info("embeddedPo = " + embeddedPo);
if (!embeddedPo.is_Changed()) {
log.info("Object not changed = " + po.toString());
continue;
} else {
embeddedPo.saveReplica(true);
isChanged = true;
}
result.append(" Embedded Save Successful; ");
}
} else if (MEXPFormatLine.TYPE_XMLAttribute.equals(line.getType())) {
// XML Attribute
value = XMLHelper.getString("@" + line.getValue(), rootElement);
log.info("value=[" + value + "]");
} else {
// Export Format Line is not one of the possible values...ERROR
throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNonValidType"));
}
return value;
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class ImportHelper method importElement.
/**
*
* @param ctx
* @param result
* @param rootElement
* @param expFormat
* @param replicationType
* @param trxName
* @return
* @throws Exception
* @throws XPathExpressionException
*/
private PO importElement(Properties ctx, StringBuffer result, Element rootElement, MEXPFormat expFormat, String replicationType, String trxName) throws Exception, XPathExpressionException {
//Getting the Object for the replicate
PO po = getObjectFromFormat(ctx, expFormat, rootElement, rootElement.getNodeName(), trxName);
if (po == null) {
throw new Exception(Msg.getMsg(ctx, "Can't Load PO Object"));
}
if (//If this is just for push and exists we do nothing
X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(replicationType)) {
if (po.get_ID() == 0) {
return null;
}
}
log.info("PO.toString() = " + po.toString());
if (po.get_KeyColumns().length < 1) {
throw new Exception(Msg.getMsg(ctx, "EDIMultiColumnNotSupported"));
}
Collection<MEXPFormatLine> formatLines = expFormat.getFormatLinesOrderedBy(MEXPFormatLine.COLUMNNAME_IsMandatory + " , " + MEXPFormatLine.COLUMNNAME_Position);
if (formatLines == null || formatLines.size() < 1) {
throw new Exception(Msg.getMsg(ctx, "EXPFormatNoLines"));
}
// and set value of column!
for (MEXPFormatLine formatLine : formatLines) {
log.info("=================== Beginnig of Format Line ===============================");
log.info("formatLine: [" + formatLine.toString() + "]");
//Get the value
Object value = getValueFromFormat(formatLine, po, rootElement, result, replicationType);
if (value == null || value.toString().equals(""))
continue;
//Set the value
setReplicaValues(value, formatLine, po, result);
}
return po;
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class MWFNodeNext method isValidFor.
// isUnconditional
/**
* Is this a Valid Transition For ..
* @param activity activity
* @return true if valid
*/
public boolean isValidFor(MWFActivity activity) {
if (isStdUserWorkflow()) {
PO po = activity.getPO();
if (po instanceof DocAction) {
DocAction da = (DocAction) po;
String docStatus = da.getDocStatus();
String docAction = da.getDocAction();
if (!DocAction.ACTION_Complete.equals(docAction) || DocAction.STATUS_Completed.equals(docStatus) || DocAction.STATUS_WaitingConfirmation.equals(docStatus) || DocAction.STATUS_WaitingPayment.equals(docStatus) || DocAction.STATUS_Voided.equals(docStatus) || DocAction.STATUS_Closed.equals(docStatus) || DocAction.STATUS_Reversed.equals(docStatus)) /*
|| DocAction.ACTION_Complete.equals(docAction)
|| DocAction.ACTION_ReActivate.equals(docAction)
|| DocAction.ACTION_None.equals(docAction)
|| DocAction.ACTION_Post.equals(docAction)
|| DocAction.ACTION_Unlock.equals(docAction)
|| DocAction.ACTION_Invalidate.equals(docAction) ) */
{
log.fine("isValidFor =NO= StdUserWF - Status=" + docStatus + " - Action=" + docAction);
return false;
}
}
}
// No Conditions
if (getConditions(false).length == 0) {
log.fine("#0 " + toString());
return true;
}
// First condition always AND
boolean ok = m_conditions[0].evaluate(activity);
for (int i = 1; i < m_conditions.length; i++) {
if (m_conditions[i].isOr())
ok = ok || m_conditions[i].evaluate(activity);
else
ok = ok && m_conditions[i].evaluate(activity);
}
// for all conditions
log.fine("isValidFor (" + ok + ") " + toString());
return ok;
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class InventoryUtil method processDocument.
public static void processDocument(MMDocument doc, String docAction, String targetDocStatus) {
PO po = (PO) doc.document;
// po.saveEx();
po.load(po.get_TrxName());
po.set_ValueOfColumn("DocAction", docAction);
//
try {
if (!doc.document.processIt(docAction))
throw new AdempiereException(doc.document.getProcessMsg());
} catch (Exception e) {
throw (e instanceof AdempiereException ? (AdempiereException) e : new AdempiereException(e));
}
po.saveEx();
// Check DocSatus
if (targetDocStatus != null && !targetDocStatus.equals(doc.document.getDocStatus())) {
throw new AdempiereException("Doc process error " + doc + " (TargetDocStatus=" + targetDocStatus + ", DocStatus=" + doc.document.getDocStatus() + ")");
}
// Is Completed ?
if (DocAction.STATUS_Completed.equals(doc.document.getDocStatus())) {
// Track ASI:
if (!Util.isEmpty(doc.ASI)) {
}
}
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class MAssetChange method create.
public static MAssetChange create(Properties ctx, String changeType, PO[] pos, boolean save, String trxName) {
if (s_log.isLoggable(Level.FINE))
s_log.fine("Entering: changeType=" + changeType);
if (pos == null || pos.length == 0) {
s_log.fine("Entering/Leaving: POs is empty");
return null;
}
MAssetChange change = new MAssetChange(ctx, 0, trxName);
change.setChangeType(changeType);
for (PO po : pos) {
change.addChanges(po);
}
if (save) {
change.saveEx();
}
//
if (s_log.isLoggable(Level.FINE))
s_log.fine("Leaving: change=" + change);
return change;
}
Aggregations