IDEMPIERE-3770 Translation : export only centralized data

This commit is contained in:
Nicolas Micoud 2018-12-15 17:00:03 +01:00
parent 00b15802d0
commit ec6d32fdd5
5 changed files with 49 additions and 9 deletions

View File

@ -0,0 +1,10 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-3770: Translation : export only centralized data
-- Aug 2, 2018 3:36:33 PM CEST
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','Only centralized data',0,0,'Y',TO_DATE('2018-08-02 15:36:32','YYYY-MM-DD HH24:MI:SS'),0,TO_DATE('2018-08-02 15:36:32','YYYY-MM-DD HH24:MI:SS'),0,200481,'OnlyCentralizedData','D','f43c0cce-0462-4247-baf6-e7da842152ab')
;
SELECT register_migration_script('201808021530_IDEMPIERE-3770.sql') FROM dual
;

View File

@ -0,0 +1,7 @@
-- IDEMPIERE-3770: Translation : export only centralized data
-- Aug 2, 2018 3:36:33 PM CEST
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','Only centralized data',0,0,'Y',TO_TIMESTAMP('2018-08-02 15:36:32','YYYY-MM-DD HH24:MI:SS'),0,TO_TIMESTAMP('2018-08-02 15:36:32','YYYY-MM-DD HH24:MI:SS'),0,200481,'OnlyCentralizedData','D','f43c0cce-0462-4247-baf6-e7da842152ab')
;
SELECT register_migration_script('201808021530_IDEMPIERE-3770.sql') FROM dual
;

View File

@ -173,7 +173,7 @@ public class Translation implements IApplication
* @param Trl_Table translation table _Trl
* @return status message
*/
public String exportTrl (String directory, int AD_Client_ID, String AD_Language, String Trl_Table)
public String exportTrl (String directory, int AD_Client_ID, String AD_Language, String Trl_Table, boolean onlyCentralized)
{
String fileName = directory + File.separator + Trl_Table + "_" + AD_Language + ".xml";
log.info(fileName);
@ -185,6 +185,12 @@ public class Translation implements IApplication
String Base_Table = Trl_Table.substring(0, pos);
if (isBaseLanguage)
tableName = Base_Table;
if (onlyCentralized) {
if (MTable.get(m_ctx, tableName).getAD_Table_ID() > MTable.MAX_OFFICIAL_ID)
return "";
}
String keyColumn = Base_Table + "_ID";
String uuidColumn = MTable.getUUIDColumnName(Base_Table);
String[] trlColumns = getTrlColumns (Base_Table);
@ -237,6 +243,10 @@ public class Translation implements IApplication
}
if (AD_Client_ID >= 0)
sql.append(haveWhere ? " AND " : " WHERE ").append("o.AD_Client_ID=").append(AD_Client_ID);
if (onlyCentralized)
sql.append(haveWhere ? " AND " : " WHERE ").append(" o.").append(keyColumn).append("<=").append(MTable.MAX_OFFICIAL_ID).append(" AND o.IsActive = 'Y'");
sql.append(" ORDER BY t.").append(keyColumn);
//
pstmt = DB.prepareStatement(sql.toString(), null);
@ -500,7 +510,7 @@ public class Translation implements IApplication
System.out.println("Cannot create directory " + directory + " to export the language to it.");
System.exit(1);
}
exportTrl(directory, -1, AD_Language, table);
exportTrl(directory, -1, AD_Language, table, true);
} else
System.out.println("Just import and export are supported as modes.");
}

View File

@ -36,6 +36,7 @@ import org.compiere.apps.ADialog;
import org.compiere.apps.StatusBar;
import org.compiere.apps.form.FormFrame;
import org.compiere.apps.form.FormPanel;
import org.compiere.grid.ed.VCheckBox;
import org.compiere.swing.CPanel;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
@ -80,6 +81,7 @@ public class VTranslationDialog extends TranslationController
private StatusBar statusBar = new StatusBar();
private JLabel lClient = new JLabel();
private JComboBox<Object> cbClient = new JComboBox<Object>();
private VCheckBox isOnlyCentralized = new VCheckBox();
/**
@ -93,6 +95,7 @@ public class VTranslationDialog extends TranslationController
lLanguage.setText(Msg.translate(Env.getCtx(), "AD_Language"));
lLanguage.setToolTipText(Msg.translate(Env.getCtx(), "IsSystemLanguage"));
lTable.setText(Msg.translate(Env.getCtx(), "AD_Table_ID"));
isOnlyCentralized.setText(Msg.getMsg(Env.getCtx(), "OnlyCentralizedData"));
//
bExport.setText(Msg.getMsg(Env.getCtx(), "Export"));
bExport.addActionListener(this);
@ -107,9 +110,11 @@ public class VTranslationDialog extends TranslationController
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
panel.add(cbTable, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
panel.add(bExport, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
panel.add(isOnlyCentralized, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
panel.add(bExport, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
panel.add(bImport, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
panel.add(bImport, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
panel.add(lClient, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
@ -224,7 +229,7 @@ public class VTranslationDialog extends TranslationController
AD_Table = (ValueNamePair)cbTable.getItemAt(i);
msg = imp
? t.importTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue())
: t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue());
: t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue(), isOnlyCentralized.isSelected());
}
if(msg == null || msg.length() == 0)
@ -237,7 +242,7 @@ public class VTranslationDialog extends TranslationController
msg = null;
msg = imp
? t.importTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue())
: t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue());
: t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue(), isOnlyCentralized.isSelected());
if(msg == null || msg.length() == 0)
msg = (imp ? "Import" : "Export") + " Successful. [" + directory + "]";

View File

@ -29,6 +29,7 @@ import org.adempiere.exceptions.AdempiereException;
import org.adempiere.webui.AdempiereWebUI;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Checkbox;
import org.adempiere.webui.component.FolderBrowser;
import org.adempiere.webui.component.Grid;
import org.adempiere.webui.component.GridFactory;
@ -119,6 +120,7 @@ public class WTranslationDialog extends TranslationController implements IFormCo
private int m_AD_Client_ID;
private boolean m_imp;
private ValueNamePair m_AD_Language;
private Checkbox isOnlyCentralized = new Checkbox();
private void zkInit() throws Exception
{
@ -139,6 +141,8 @@ public class WTranslationDialog extends TranslationController implements IFormCo
bImportZIP.setLabel(Msg.getMsg(Env.getCtx(), "ImportZIP"));
bImportZIP.setUpload(AdempiereWebUI.getUploadSetting());
bImportZIP.addEventListener(Events.ON_UPLOAD, this);
isOnlyCentralized.setLabel(Msg.getMsg(Env.getCtx(), "OnlyCentralizedData"));
isOnlyCentralized.setChecked(true);
Rows rows = centerLayout.newRows();
Row row = rows.newRow();
@ -152,7 +156,11 @@ public class WTranslationDialog extends TranslationController implements IFormCo
row = rows.newRow();
row.appendChild(lTable.rightAlign());
row.appendChild(cbTable);
row = rows.newRow();
row.appendChild(new Label(""));
row.appendChild(isOnlyCentralized);
row = rows.newRow();
Div div = new Div();
div.setStyle("text-align: right;");
@ -298,7 +306,7 @@ public class WTranslationDialog extends TranslationController implements IFormCo
// Carlos Ruiz - globalqss - improve output message from translation import process
msg.append(m_AD_Table.getValue()).append(" ").append((m_imp
? t.importTrl (directory, m_AD_Client_ID, m_AD_Language.getValue(), m_AD_Table.getValue())
: t.exportTrl (directory, m_AD_Client_ID, m_AD_Language.getValue(), m_AD_Table.getValue()))).append(" ");
: t.exportTrl (directory, m_AD_Client_ID, m_AD_Language.getValue(), m_AD_Table.getValue(), isOnlyCentralized.isChecked()))).append(" ");
}
if(msg == null || msg.length() == 0)
@ -311,7 +319,7 @@ public class WTranslationDialog extends TranslationController implements IFormCo
msg = null;
msg = new StringBuilder(m_imp
? t.importTrl (directory, m_AD_Client_ID, m_AD_Language.getValue(), m_AD_Table.getValue())
: t.exportTrl (directory, m_AD_Client_ID, m_AD_Language.getValue(), m_AD_Table.getValue()));
: t.exportTrl (directory, m_AD_Client_ID, m_AD_Language.getValue(), m_AD_Table.getValue(), isOnlyCentralized.isChecked()));
if(msg == null || msg.length() == 0)
msg = new StringBuilder(m_imp ? "Import" : "Export").append(" Successful. [").append(directory).append("]");