Commit 0b386589 authored by Carlos Aristu's avatar Carlos Aristu
Browse files

related to ISSUE-47259: support on trl file import hooks

  Provide the ability of executing custom code after a translation file
is imported through the TranslationManager
parent 4e657f4c
......@@ -10,7 +10,7 @@
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): Openbravo SLU
* Contributions are Copyright (C) 2001-2020 Openbravo S.L.U.
* Contributions are Copyright (C) 2001-2021 Openbravo S.L.U.
******************************************************************************/
package org.openbravo.erpCommon.ad_forms;
......@@ -38,6 +38,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openbravo.base.exception.OBException;
import org.openbravo.base.weld.WeldUtils;
import org.openbravo.dal.xml.XMLUtil;
import org.openbravo.database.ConnectionProvider;
import org.openbravo.erpCommon.utility.BasicUtility;
......@@ -666,8 +667,9 @@ public class TranslationManager {
final SAXParser parser = factory.newSAXParser();
parser.parse(in, handler);
conn.releaseCommitConnection(con);
log4j
.info("importTrl - Updated=" + handler.getUpdateCount() + " - from file " + in.getName());
int updateCount = handler.getUpdateCount();
log4j.info("importTrl - Updated={} - from file {}", updateCount, in.getName());
onTrlFileImport(fileName, Trl_Table, updateCount);
return "";
} catch (final Exception e) {
log4j.error("importTrlFile - error parsing file: " + fileName, e);
......@@ -680,6 +682,12 @@ public class TranslationManager {
}
}
private static void onTrlFileImport(String fileName, String trlTable, int updateCount) {
WeldUtils.getInstances(TranslationManagerHook.class)
.stream()
.forEach(hook -> hook.onTrlFileImport(fileName, trlTable, updateCount));
}
private static TranslationData[] getTrlColumns(ConnectionProvider cp, String Base_Table,
boolean isReducedVersion) {
......
/*
*************************************************************************
* The contents of this file are subject to the Openbravo Public License
* Version 1.1 (the "License"), being the Mozilla Public License
* Version 1.1 with a permitted attribution clause; you may not use this
* file except in compliance with the License. You may obtain a copy of
* the License at http://www.openbravo.com/legal/license.html
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
* All portions are Copyright (C) 2021 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
*/
package org.openbravo.erpCommon.ad_forms;
/**
* Allows to extend the standard behavior of the {@link TranslationManager} when handling
* translations
*/
public interface TranslationManagerHook {
/**
* Executed after importing a translation file
*
* @param fileName
* the name of the translation file
* @param tableName
* the upper case name of the trl table where records in the translation file are
* imported
* @param updateCount
* the number of updated records
*/
public void onTrlFileImport(String fileName, String tableName, int updateCount);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment