use of org.compiere.model.MColumn in project adempiere by adempiere.
the class ASPGenerateFields method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("ASP_Status=" + p_ASP_Status + ", ASP_Tab_ID=" + p_ASP_Tab_ID);
X_ASP_Tab asptab = new X_ASP_Tab(getCtx(), p_ASP_Tab_ID, get_TrxName());
p_ASP_Level_ID = asptab.getASP_Window().getASP_Level_ID();
// tabs
MTab tab = new MTab(getCtx(), asptab.getAD_Tab_ID(), get_TrxName());
// fields
for (MField field : tab.getFields(true, get_TrxName())) {
if (DB.getSQLValue(get_TrxName(), "SELECT COUNT(*) FROM ASP_Field WHERE ASP_Tab_ID = ? AND AD_Field_ID = ?", p_ASP_Tab_ID, field.getAD_Field_ID()) < 1) {
X_ASP_Field aspField = new X_ASP_Field(getCtx(), 0, get_TrxName());
aspField.setASP_Tab_ID(p_ASP_Tab_ID);
aspField.setAD_Field_ID(field.getAD_Field_ID());
aspField.setASP_Status(p_ASP_Status);
if (aspField.save())
noFields++;
}
// verify if a field is a button and assign permission to the corresponding process
MColumn column = MColumn.get(getCtx(), field.getAD_Column_ID());
if (column.getAD_Reference_ID() == DisplayType.Button) {
if (column.getAD_Process_ID() > 0) {
generateProcess(column.getAD_Process_ID());
}
}
}
if (noFields > 0)
addLog("Field " + noFields);
if (noProcesses > 0)
addLog("Process " + noProcesses);
if (noParameters > 0)
addLog("Process Parameter " + noParameters);
if (noWorkflows > 0)
addLog("Workflow " + noWorkflows);
return "@OK@";
}
use of org.compiere.model.MColumn in project adempiere by adempiere.
the class ImportHelper method getObjectFromFormat.
/**
* This Method gets the PO record, from the exportFormat
* @param ctx
* @param expFormat
* @param rootElement
* @param rootNodeName
* @param trxName
* @throws Exception
* */
private PO getObjectFromFormat(Properties ctx, MEXPFormat expFormat, Element rootElement, String rootNodeName, String trxName) throws Exception {
List<PO> values = null;
if (expFormat == null || rootElement == null || rootNodeName == null) {
throw new IllegalArgumentException("expFormat, rootNode and RootnodeName can't be null!");
}
log.info("expFormat = " + expFormat);
log.info("rootNode.getNodeName() = " + rootElement.getNodeName());
log.info("rootNodeName = " + rootNodeName);
if (rootElement.getParentNode() != null) {
log.info("rootNode.ParentName = " + rootElement.getParentNode().getNodeName());
}
// Get list with all Unique columns!
Collection<MEXPFormatLine> uniqueFormatLines = expFormat.getUniqueColumns();
if (uniqueFormatLines == null || uniqueFormatLines.size() < 1) {
throw new AdempiereException(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns"));
}
int replication_id = 0;
Object[] cols = new Object[uniqueFormatLines.size()];
Object[] params = new Object[uniqueFormatLines.size()];
StringBuffer whereClause = new StringBuffer("");
int col = 0;
String formatLines = "";
for (MEXPFormatLine uniqueFormatLine : uniqueFormatLines) {
MColumn column = MColumn.get(ctx, uniqueFormatLine.getAD_Column_ID());
log.info("column = [" + column + "]");
String valuecol = column.getColumnName();
formatLines = formatLines + "|" + valuecol;
if (MEXPFormatLine.TYPE_XMLElement.equals(uniqueFormatLine.getType())) {
// XML Element
String xPath = null;
xPath = "" + uniqueFormatLine.getValue();
cols[col] = XMLHelper.getString(xPath, rootElement);
log.info("values[" + col + "]=" + cols[col]);
} else if (MEXPFormatLine.TYPE_XMLAttribute.equals(uniqueFormatLine.getType())) {
// XML Attribute
String xPath = null;
xPath = "@" + uniqueFormatLine.getValue();
cols[col] = XMLHelper.getString(xPath, rootElement);
log.info("values[" + col + "]=" + cols[col]);
} else if (MEXPFormatLine.TYPE_ReferencedEXPFormat.equals(uniqueFormatLine.getType())) {
// Referenced Export Format
log.info("referencedExpFormat.EXP_EmbeddedFormat_ID = " + uniqueFormatLine.getEXP_EmbeddedFormat_ID());
//get from cache
MEXPFormat referencedExpFormat = MEXPFormat.get(ctx, uniqueFormatLine.getEXP_EmbeddedFormat_ID(), trxName);
log.info("referencedExpFormat = " + referencedExpFormat);
int record_ID = 0;
// Find Record_ID by ???Value??? In fact by Columns set as Part Of Unique Index in Export Format!
Element referencedNode = ((Element) rootElement.getElementsByTagName(uniqueFormatLine.getValue()).item(0));
log.info("referencedNode = " + referencedNode);
if (referencedNode == null) {
throw new IllegalArgumentException("referencedNode can't be found!");
}
record_ID = getID(ctx, referencedExpFormat, referencedNode, uniqueFormatLine.getValue(), trxName);
log.info("record_ID = " + record_ID);
cols[col] = new Integer(record_ID);
} else {
// Export Format Line is not one of two possible values...ERROR
throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNonValidType"));
}
if (DisplayType.DateTime == column.getAD_Reference_ID() || DisplayType.Date == column.getAD_Reference_ID()) {
Timestamp value = (Timestamp) handleDateTime(cols[col], column, uniqueFormatLine);
params[col] = value;
} else if (column.getAD_Reference_ID() == DisplayType.String) {
params[col] = (String) cols[col];
} else if (DisplayType.isID(column.getAD_Reference_ID()) || DisplayType.Integer == column.getAD_Reference_ID()) {
Object value = cols[col];
if (!Util.isEmpty(value.toString())) {
//double doubleValue = Double.parseDouble(value.toString());
value = new Integer(value.toString());
if (DisplayType.ID == column.getAD_Reference_ID()) {
replication_id = (Integer) value;
}
} else {
value = null;
}
params[col] = value;
} else if (DisplayType.isNumeric(column.getAD_Reference_ID())) {
valuecol = "Round(" + valuecol + ",2)";
params[col] = new BigDecimal((String) cols[col]).setScale(2, BigDecimal.ROUND_HALF_UP);
} else {
params[col] = cols[col];
}
if (col == 0) {
whereClause.append(" ").append(valuecol).append(" = ? ");
} else {
whereClause.append(" AND ").append(valuecol).append(" = ? ");
}
col++;
}
Query query = new Query(ctx, MTable.get(ctx, expFormat.getAD_Table_ID()), whereClause.toString(), trxName).setParameters(params);
values = query.list();
if (//The Return Object must be always one
values.size() > 1) {
throw new AdempiereException(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns") + " : " + expFormat.getName() + "(" + formatLines + ")");
}
if (//Means that is a new record
values.size() <= 0) {
PO po = MTable.get(ctx, expFormat.getAD_Table_ID()).getPO(0, trxName);
if (replication_id > 0) {
po.set_CustomColumn(po.get_KeyColumns()[0], replication_id);
}
return po;
}
//Return the first (unique) record.
return values.get(0);
}
use of org.compiere.model.MColumn in project adempiere by adempiere.
the class CopyReportProcess method copyFrom.
/**
* Copy parameters to process
* @param process
* @param record
* @throws SQLException
*/
private void copyFrom(MProcess process, int key) throws SQLException {
// Get Values
int m_AD_Column_ID = getSelectionAsInt(key, "PARAMETER_AD_Column_ID");
int m_AD_ReportView_ID = getSelectionAsInt(key, "PARAMETER_AD_ReportView_ID");
int m_AD_Process_Para_ID = getSelectionAsInt(key, "PARAMETER_AD_Process_Para_ID");
boolean m_IsMandatory = getSelectionAsBoolean(key, "PARAMETER_IsMandatory");
boolean m_IsRange = getSelectionAsBoolean(key, "PARAMETER_IsRange");
String m_DefaultValue = getSelectionAsString(key, "PARAMETER_DefaultValue");
String m_DefaultValue2 = getSelectionAsString(key, "PARAMETER_DefaultValue2");
// Do it
MProcessPara newParameter = new MProcessPara(process);
if (m_AD_ReportView_ID != 0) {
// For Create from View
MColumn column = MColumn.get(getCtx(), m_AD_Column_ID);
//
if (column.getAD_Reference_ID() == DisplayType.ID) {
return;
}
// For Process
if (process.getAD_ReportView_ID() != m_AD_ReportView_ID) {
process.setAD_ReportView_ID(m_AD_ReportView_ID);
process.saveEx();
}
// Set Values
newParameter.setEntityType(process.getEntityType());
newParameter.setAD_Element_ID(column.getAD_Element_ID());
newParameter.setAD_Reference_ID(column.getAD_Reference_ID());
newParameter.setAD_Reference_Value_ID(column.getAD_Reference_Value_ID());
newParameter.setAD_Val_Rule_ID(column.getAD_Val_Rule_ID());
newParameter.setName(column.getName());
newParameter.setColumnName(column.getColumnName());
newParameter.setDescription(column.getDescription());
newParameter.setFieldLength(column.getFieldLength());
newParameter.setHelp(column.getHelp());
newParameter.setIsCentrallyMaintained(true);
} else if (m_AD_Process_Para_ID != 0) {
// For Copy from Process
MProcessPara fromParameter = new MProcessPara(getCtx(), m_AD_Process_Para_ID, get_TrxName());
PO.copyValues(fromParameter, newParameter);
} else {
return;
}
// Fill values
newParameter.setIsMandatory(m_IsMandatory);
newParameter.setIsRange(m_IsRange);
newParameter.setDefaultValue(m_DefaultValue);
newParameter.setDefaultValue2(m_DefaultValue2);
newParameter.setSeqNo(m_SeqNo);
// Save
newParameter.saveEx();
// Add new Sequence
m_SeqNo += 10;
addLog("@AD_Process_Para_ID@ @" + newParameter.getColumnName() + "@ @Added@");
}
use of org.compiere.model.MColumn in project adempiere by adempiere.
the class ColumnEncryption method doIt.
// prepare
/**
* Process
*
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("AD_Column_ID=" + p_AD_Column_ID + ", IsEncrypted=" + p_IsEncrypted + ", ChangeSetting=" + p_ChangeSetting + ", MaxLength=" + p_MaxLength);
MColumn column = new MColumn(getCtx(), p_AD_Column_ID, get_TrxName());
if (column.get_ID() == 0 || column.get_ID() != p_AD_Column_ID)
throw new AdempiereUserError("@NotFound@ @AD_Column_ID@ - " + p_AD_Column_ID);
//
String columnName = column.getColumnName();
int dt = column.getAD_Reference_ID();
// Can it be enabled?
if (column.isKey() || column.isParent() || column.isStandardColumn() || column.isVirtualColumn() || column.isIdentifier() || column.isTranslated() || DisplayType.isLookup(dt) || DisplayType.isLOB(dt) || "DocumentNo".equalsIgnoreCase(column.getColumnName()) || "Value".equalsIgnoreCase(column.getColumnName()) || "Name".equalsIgnoreCase(column.getColumnName())) {
if (column.isEncrypted()) {
column.setIsEncrypted(false);
column.saveEx();
}
return columnName + ": cannot be encrypted";
}
// Start
addLog(0, null, null, "Encryption Class = " + SecureEngine.getClassName());
boolean error = false;
// Test Value
if (p_TestValue != null && p_TestValue.length() > 0) {
String encString = SecureEngine.encrypt(p_TestValue);
addLog(0, null, null, "Encrypted Test Value=" + encString);
String clearString = SecureEngine.decrypt(encString);
if (p_TestValue.equals(clearString))
addLog(0, null, null, "Decrypted=" + clearString + " (same as test value)");
else {
addLog(0, null, null, "Decrypted=" + clearString + " (NOT the same as test value - check algorithm)");
error = true;
}
int encLength = encString.length();
addLog(0, null, null, "Test Length=" + p_TestValue.length() + " -> " + encLength);
if (encLength <= column.getFieldLength())
addLog(0, null, null, "Encrypted Length (" + encLength + ") fits into field (" + column.getFieldLength() + ")");
else {
addLog(0, null, null, "Encrypted Length (" + encLength + ") does NOT fit into field (" + column.getFieldLength() + ") - resize field");
error = true;
}
}
// Length Test
if (p_MaxLength != 0) {
String testClear = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
while (testClear.length() < p_MaxLength) testClear += testClear;
testClear = testClear.substring(0, p_MaxLength);
log.config("Test=" + testClear + " (" + p_MaxLength + ")");
//
String encString = SecureEngine.encrypt(testClear);
int encLength = encString.length();
addLog(0, null, null, "Test Max Length=" + testClear.length() + " -> " + encLength);
if (encLength <= column.getFieldLength())
addLog(0, null, null, "Encrypted Max Length (" + encLength + ") fits into field (" + column.getFieldLength() + ")");
else {
addLog(0, null, null, "Encrypted Max Length (" + encLength + ") does NOT fit into field (" + column.getFieldLength() + ") - resize field");
error = true;
}
}
// settings resize the physical column and encrypt all its contents.
if (p_IsEncrypted && p_ChangeSetting) {
// and exit.
if (column.isEncrypted()) {
log.severe("EncryptError: Column already encrypted.");
throw new Exception();
}
// Init the transaction and setup the connection.
m_trx = Trx.get(get_TrxName(), true);
if ((m_conn = m_trx.getConnection()) == null) {
log.warning("EncryptError: No connections available");
throw new Exception();
}
m_conn.setAutoCommit(false);
int columnID = column.get_ID();
MTable table = MTable.get(getCtx(), column.getAD_Table_ID());
String tableName = table.getTableName();
// Check if the encryption exceeds the current length.
int oldLength = column.getFieldLength();
int newLength = encryptedColumnLength(oldLength);
if (newLength > oldLength)
if (changeFieldLength(columnID, columnName, newLength, tableName) == -1) {
log.warning("EncryptError [ChangeFieldLength]: " + "ColumnID=" + columnID + ", NewLength=" + newLength);
throw new Exception();
}
// Encrypt column contents.
if (encryptColumnContents(columnName, column.getAD_Table_ID()) == -1) {
log.warning("EncryptError: No records encrypted.");
throw new Exception();
}
if (p_IsEncrypted != column.isEncrypted()) {
if (error || !p_ChangeSetting)
addLog(0, null, null, "Encryption NOT changed - Encryption=" + column.isEncrypted());
else {
column.setIsEncrypted(p_IsEncrypted);
if (column.save())
addLog(0, null, null, "Encryption CHANGED - Encryption=" + column.isEncrypted());
else
addLog(0, null, null, "Save Error");
}
}
}
return "Encryption=" + column.isEncrypted();
}
use of org.compiere.model.MColumn in project adempiere by adempiere.
the class ColumnSync method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("C_Column_ID=" + p_AD_Column_ID);
if (p_AD_Column_ID == 0)
throw new AdempiereUserError("@No@ @AD_Column_ID@");
MColumn column = new MColumn(getCtx(), p_AD_Column_ID, get_TrxName());
if (column.get_ID() == 0)
throw new AdempiereUserError("@NotFound@ @AD_Column_ID@ " + p_AD_Column_ID);
String sql = column.syncDatabase();
addLog(sql);
return sql;
}
Aggregations