IDEMPIERE-4858 : Helper process "Make Table a Document" - fixes for t… (#990)
* IDEMPIERE-4858 : Helper process "Make Table a Document" - fixes for translation tables see details in tickets * IDEMPIERE-4858 : Helper process "Make Table a Document" - add TableIndex records * IDEMPIERE-4858 : Helper process "Make Table a Document" - AD_Message / tick IsTranslated on main table Co-Authored-By: Carlos Ruiz <carg67@gmail.com> * Delete pr990_PR.txt commited by error Co-authored-by: Carlos Ruiz <carg67@gmail.com>
This commit is contained in:
parent
ceb056e6d8
commit
2486ff8148
|
@ -0,0 +1,11 @@
|
|||
SET SQLBLANKLINES ON
|
||||
SET DEFINE OFF
|
||||
|
||||
-- IDEMPIERE-4858 Helper process "Make Table a Document"
|
||||
-- Nov 19, 2021, 3:18:02 PM CET
|
||||
INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','Table Index records have been added on the Translation table - do not forget to execute ''Index Validate'' process after you run ''Sync Column''',0,0,'Y',TO_DATE('2021-11-19 15:18:01','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-11-19 15:18:01','YYYY-MM-DD HH24:MI:SS'),100,200721,'TrlCreatedSyncColumnValidateIndex','D','81b87d52-17c3-46cd-bfdf-e08cdfc11851')
|
||||
;
|
||||
|
||||
SELECT register_migration_script('202111191531_IDEMPIERE-4858.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
-- IDEMPIERE-4858 Helper process "Make Table a Document"
|
||||
-- Nov 19, 2021, 3:18:02 PM CET
|
||||
INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','Table Index records have been added on the Translation table - do not forget to execute ''Index Validate'' process after you run ''Sync Column''',0,0,'Y',TO_TIMESTAMP('2021-11-19 15:18:01','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-11-19 15:18:01','YYYY-MM-DD HH24:MI:SS'),100,200721,'TrlCreatedSyncColumnValidateIndex','D','81b87d52-17c3-46cd-bfdf-e08cdfc11851')
|
||||
;
|
||||
|
||||
SELECT register_migration_script('202111191531_IDEMPIERE-4858.sql') FROM dual
|
||||
;
|
||||
|
|
@ -45,8 +45,10 @@ import java.util.logging.Level;
|
|||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.compiere.acct.Doc;
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.MIndexColumn;
|
||||
import org.compiere.model.MProcess;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.MTableIndex;
|
||||
import org.compiere.model.M_Element;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.model.X_AD_WF_Node;
|
||||
|
@ -55,6 +57,7 @@ import org.compiere.process.DocAction;
|
|||
import org.compiere.process.ProcessInfoParameter;
|
||||
import org.compiere.process.SvrProcess;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Util;
|
||||
import org.compiere.wf.MWFNode;
|
||||
import org.compiere.wf.MWFNodeNext;
|
||||
|
@ -312,8 +315,9 @@ public class CreateTable extends SvrProcess {
|
|||
if (p_isCreateTranslationTable) {
|
||||
MTable tableTrl = createTable(true);
|
||||
|
||||
int colElementID = 0;
|
||||
if (elementID != null)
|
||||
createColumn(tableTrl, elementID.getColumnName()); // <TableName>_ID (ID of parent table)
|
||||
colElementID = createColumn(tableTrl, elementID.getColumnName()); // <TableName>_ID (ID of parent table)
|
||||
|
||||
M_Element elementTrlUU = M_Element.get(getCtx(), tableTrl.getTableName() + "_UU");
|
||||
if (elementTrlUU == null) {
|
||||
|
@ -322,9 +326,14 @@ public class CreateTable extends SvrProcess {
|
|||
}
|
||||
createColumn(tableTrl, elementTrlUU.getColumnName()); // <TableName>_Trl_UU
|
||||
|
||||
createColumn(tableTrl, "AD_Language");
|
||||
int colLanguageID = createColumn(tableTrl, "AD_Language");
|
||||
createColumn(tableTrl, "IsTranslated");
|
||||
|
||||
for (MColumn column : MTable.get(getCtx(), p_tableName).getColumns(false)) {
|
||||
if (column.isTranslated())
|
||||
createColumn(tableTrl, column.getColumnName());
|
||||
}
|
||||
|
||||
if (p_isCreateColName)
|
||||
createColumn(tableTrl, "Name");
|
||||
if (p_isCreateColDescription)
|
||||
|
@ -332,6 +341,19 @@ public class CreateTable extends SvrProcess {
|
|||
if (p_isCreateColHelp)
|
||||
createColumn(tableTrl, "Help");
|
||||
|
||||
// Index
|
||||
MTableIndex ti = new MTableIndex(tableTrl, tableTrl.getTableName() + "_pkey");
|
||||
ti.setIsCreateConstraint(true);
|
||||
ti.setIsUnique(true);
|
||||
ti.setIsKey(true);
|
||||
ti.saveEx();
|
||||
|
||||
MIndexColumn ic = new MIndexColumn(ti, new MColumn(getCtx(), colLanguageID, get_TrxName()), 1);
|
||||
ic.saveEx();
|
||||
ic = new MIndexColumn(ti, new MColumn(getCtx(), colElementID, get_TrxName()), 2);
|
||||
ic.saveEx();
|
||||
|
||||
addLog(Msg.getMsg(getCtx(), "TrlCreatedSyncColumnValidateIndex"));
|
||||
}
|
||||
|
||||
return "@ProcessOK@";
|
||||
|
@ -405,9 +427,20 @@ public class CreateTable extends SvrProcess {
|
|||
* @param table
|
||||
* @param columnName
|
||||
*/
|
||||
private void createColumn(MTable table, String columnName) {
|
||||
if (getColumn(table, columnName) != null)
|
||||
return;
|
||||
private int createColumn(MTable table, String columnName) {
|
||||
MColumn columnThatExists = getColumn(table, columnName);
|
||||
if (columnThatExists != null) {
|
||||
if ( p_isCreateTranslationTable
|
||||
&& !columnThatExists.isTranslated()
|
||||
&& !table.getTableName().toUpperCase().endsWith("_TRL")
|
||||
&& ( (p_isCreateColName && columnName.equals("Name"))
|
||||
|| (p_isCreateColHelp && columnName.equals("Help"))
|
||||
|| (p_isCreateColDescription && columnName.equals("Description")))) {
|
||||
columnThatExists.setIsTranslated(true);
|
||||
columnThatExists.saveEx();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
MColumn column = new MColumn(table);
|
||||
|
||||
|
@ -571,9 +604,11 @@ public class CreateTable extends SvrProcess {
|
|||
column.setAD_Reference_ID(DisplayType.Search);
|
||||
column.setIsParent(true);
|
||||
column.setIsMandatory(true);
|
||||
column.setFKConstraintType(MColumn.FKCONSTRAINTTYPE_Cascade);
|
||||
}
|
||||
|
||||
column.saveEx();
|
||||
return column.getAD_Column_ID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -62,6 +62,7 @@ public class MIndexColumn extends X_AD_IndexColumn {
|
|||
setAD_TableIndex_ID(parent.getAD_TableIndex_ID());
|
||||
setAD_Column_ID(column.getAD_Column_ID());
|
||||
setSeqNo(seqNo);
|
||||
setEntityType(parent.getEntityType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue