details: https://code.openbravo.com/erp/devel/pi/rev/692305cb1996 changeset: 34761:692305cb1996 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Fri Sep 07 09:51:56 2018 +0200 summary: fixed issue 39229: source path is required to import reference data
Reference data is now deployed to WebContent which can be accessed from Tomcat as a resource. details: https://code.openbravo.com/erp/devel/pi/rev/038384250ba9 changeset: 34762:038384250ba9 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Fri Sep 07 11:37:29 2018 +0200 summary: fixed issue 39229: source path is required to import Chart Of Accounts Now it is deployed as resource accessible from Tomcat. details: https://code.openbravo.com/erp/devel/pi/rev/701d003b887b changeset: 34763:701d003b887b user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Fri Sep 07 11:46:19 2018 +0200 summary: fixed issue 39229: do not make publicly available reference data files Reference data and COA files should be internally accessible from Tomcat, but they shouldn't be publicly available to be downloaded. Moved them to the non public WEB-INF directory. details: https://code.openbravo.com/erp/devel/pi/rev/9a51de54cd96 changeset: 34764:9a51de54cd96 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Fri Sep 07 11:51:03 2018 +0200 summary: related to issue 39229: removed unneded source.path params details: https://code.openbravo.com/erp/devel/pi/rev/3e0f540c5540 changeset: 34765:3e0f540c5540 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Mon Sep 10 12:40:04 2018 +0200 summary: related to issue 39229: make it work in Windows Using file.separator in Windows was interpreted as regexp escape character. Using common slash works fine also in Windows. diffstat: src-db/database/sourcedata/AD_MESSAGE.xml | 12 ++ src-test/src/org/openbravo/test/db/model/functions/ADOrgTreeTest.java | 6 +- src-test/src/org/openbravo/test/generalsetup/enterprise/organization/ADOrgPersistInfoUtility.java | 6 +- src/build.xml | 15 ++ src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java | 3 +- src/org/openbravo/erpCommon/businessUtility/COAUtility.java | 30 +++++- src/org/openbravo/erpCommon/businessUtility/InitialClientSetup.java | 23 ++- src/org/openbravo/erpCommon/businessUtility/InitialOrgSetup.java | 55 ++++----- src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java | 44 +++---- 9 files changed, 118 insertions(+), 76 deletions(-) diffs (truncated from 449 to 300 lines): diff -r 686664db43e1 -r 3e0f540c5540 src-db/database/sourcedata/AD_MESSAGE.xml --- a/src-db/database/sourcedata/AD_MESSAGE.xml Thu Sep 06 10:14:53 2018 +0200 +++ b/src-db/database/sourcedata/AD_MESSAGE.xml Mon Sep 10 12:40:04 2018 +0200 @@ -21082,6 +21082,18 @@ <!--6775556A78264AB192CAD83F25E37E7B--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> <!--6775556A78264AB192CAD83F25E37E7B--></AD_MESSAGE> +<!--67CC7B2901FC47D3BBE259F2E125764C--><AD_MESSAGE> +<!--67CC7B2901FC47D3BBE259F2E125764C--> <AD_MESSAGE_ID><![CDATA[67CC7B2901FC47D3BBE259F2E125764C]]></AD_MESSAGE_ID> +<!--67CC7B2901FC47D3BBE259F2E125764C--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--67CC7B2901FC47D3BBE259F2E125764C--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--67CC7B2901FC47D3BBE259F2E125764C--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--67CC7B2901FC47D3BBE259F2E125764C--> <VALUE><![CDATA[FileDoesNotExist]]></VALUE> +<!--67CC7B2901FC47D3BBE259F2E125764C--> <MSGTEXT><![CDATA[Could not find file]]></MSGTEXT> +<!--67CC7B2901FC47D3BBE259F2E125764C--> <MSGTYPE><![CDATA[I]]></MSGTYPE> +<!--67CC7B2901FC47D3BBE259F2E125764C--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID> +<!--67CC7B2901FC47D3BBE259F2E125764C--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> +<!--67CC7B2901FC47D3BBE259F2E125764C--></AD_MESSAGE> + <!--68082E2D67E94A7E8FB1416A7FCEBC47--><AD_MESSAGE> <!--68082E2D67E94A7E8FB1416A7FCEBC47--> <AD_MESSAGE_ID><![CDATA[68082E2D67E94A7E8FB1416A7FCEBC47]]></AD_MESSAGE_ID> <!--68082E2D67E94A7E8FB1416A7FCEBC47--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r 686664db43e1 -r 3e0f540c5540 src-test/src/org/openbravo/test/db/model/functions/ADOrgTreeTest.java --- a/src-test/src/org/openbravo/test/db/model/functions/ADOrgTreeTest.java Thu Sep 06 10:14:53 2018 +0200 +++ b/src-test/src/org/openbravo/test/db/model/functions/ADOrgTreeTest.java Mon Sep 10 12:40:04 2018 +0200 @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -35,7 +34,6 @@ import org.hibernate.query.Query; import org.junit.Ignore; import org.junit.Test; -import org.openbravo.base.session.OBPropertiesProvider; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.service.OBDal; import org.openbravo.dal.service.OBQuery; @@ -413,11 +411,9 @@ } private String createOrganization(String newOrgName, String newOrgType, String strParentOrg) { - Properties properties = OBPropertiesProvider.getInstance().getOpenbravoProperties(); - String strSourcePath = properties.getProperty("source.path"); InitialOrgSetup initialOrg = new InitialOrgSetup(OBContext.getOBContext().getCurrentClient()); initialOrg.createOrganization(newOrgName, "", newOrgType, strParentOrg, "", "", "", false, - null, "", false, false, false, false, false, strSourcePath); + null, "", false, false, false, false, false); OBDal.getInstance().get(Organization.class, initialOrg.getOrgId()).setSummaryLevel(true); return initialOrg.getOrgId(); } diff -r 686664db43e1 -r 3e0f540c5540 src-test/src/org/openbravo/test/generalsetup/enterprise/organization/ADOrgPersistInfoUtility.java --- a/src-test/src/org/openbravo/test/generalsetup/enterprise/organization/ADOrgPersistInfoUtility.java Thu Sep 06 10:14:53 2018 +0200 +++ b/src-test/src/org/openbravo/test/generalsetup/enterprise/organization/ADOrgPersistInfoUtility.java Mon Sep 10 12:40:04 2018 +0200 @@ -23,12 +23,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.util.Properties; import org.apache.commons.lang.StringUtils; import org.hibernate.criterion.Restrictions; import org.openbravo.base.provider.OBProvider; -import org.openbravo.base.session.OBPropertiesProvider; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.security.OrganizationStructureProvider; import org.openbravo.dal.service.OBCriteria; @@ -65,11 +63,9 @@ static String createOrganization(String newOrgType, String strParentOrg, boolean summary, String currencyId) { long number = System.currentTimeMillis(); - Properties properties = OBPropertiesProvider.getInstance().getOpenbravoProperties(); - String strSourcePath = properties.getProperty("source.path"); InitialOrgSetup initialOrg = new InitialOrgSetup(OBContext.getOBContext().getCurrentClient()); initialOrg.createOrganization("Test_" + number, "", newOrgType, strParentOrg, "", "", "", - false, null, "", false, false, false, false, false, strSourcePath); + false, null, "", false, false, false, false, false); Organization org = OBDal.getInstance().get(Organization.class, initialOrg.getOrgId()); org.setSummaryLevel(summary); if (StringUtils.equals(newOrgType, ADOrgPersistInfoConstants.ORGTYPE_LEGALWITHACCOUNTING)) { diff -r 686664db43e1 -r 3e0f540c5540 src/build.xml --- a/src/build.xml Thu Sep 06 10:14:53 2018 +0200 +++ b/src/build.xml Mon Sep 10 12:40:04 2018 +0200 @@ -413,6 +413,21 @@ </fileset> <mapper type="regexp" from="(.*\${file.separator}lib\${file.separator}runtime)(.*)" to="\2" /> </copy> + + <copy todir="${base.context}/WEB-INF/referencedata/standard/org.openbravo"> + <fileset dir="${basedir}/../referencedata/standard"> + <include name="*.xml" /> + </fileset> + </copy> + + <copy todir="${base.context}/WEB-INF/referencedata"> + <fileset dir="${base.modules}"> + <include name="*/referencedata/standard/*.xml" /> + <include name="*/referencedata/accounts/COA.csv" /> + </fileset> + <mapper type="regexp" from="(.*\${file.separator})referencedata\${file.separator}(standard|accounts)\${file.separator}(.*)" to="\2/\1\3" /> + </copy> + <antcall target="build.web.folder" inheritAll="true" inheritrefs="true" /> </target> diff -r 686664db43e1 -r 3e0f540c5540 src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java --- a/src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java Thu Sep 06 10:14:53 2018 +0200 +++ b/src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java Mon Sep 10 12:40:04 2018 +0200 @@ -74,8 +74,7 @@ OBError obeResult = ios.createOrganization(strOrganization, strOrgUser, strOrgType, strParentOrg, strcLocationId, strPassword, strModules, isTrue(strCreateAccounting), - fileCoAFilePath, strCurrency, bBPartner, bProduct, bProject, bCampaign, bSalesRegion, - vars.getSessionValue("#SOURCEPATH")); + fileCoAFilePath, strCurrency, bBPartner, bProduct, bProject, bCampaign, bSalesRegion); if (!obeResult.getType().equals(OKTYPE)) { OBContext.getOBContext().removeWritableOrganization(ios.getOrgId()); OBContext.getOBContext().removeFromWritableOrganization(ios.getOrgId()); diff -r 686664db43e1 -r 3e0f540c5540 src/org/openbravo/erpCommon/businessUtility/COAUtility.java --- a/src/org/openbravo/erpCommon/businessUtility/COAUtility.java Thu Sep 06 10:14:53 2018 +0200 +++ b/src/org/openbravo/erpCommon/businessUtility/COAUtility.java Mon Sep 10 12:40:04 2018 +0200 @@ -18,6 +18,7 @@ */ package org.openbravo.erpCommon.businessUtility; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; @@ -31,11 +32,13 @@ import org.apache.log4j.Logger; import org.openbravo.base.VariablesBase; import org.openbravo.base.secureApp.VariablesSecureApp; +import org.openbravo.client.kernel.RequestContext; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.service.OBDal; import org.openbravo.data.FieldProvider; import org.openbravo.erpCommon.utility.OBError; import org.openbravo.erpCommon.utility.Utility; +import org.openbravo.model.ad.module.Module; import org.openbravo.model.ad.system.Client; import org.openbravo.model.ad.utility.Tree; import org.openbravo.model.ad.utility.TreeNode; @@ -176,6 +179,29 @@ return obeResult; } + /** + * Returns the COA.csv resource as an {@link InputStream}, obtained from deployed reources + * + * @param coaModule + * Module containing chart of accounts + * @return {@link InputStream} to chart of accounts file + * @throws FileNotFoundException + * In case expected COA.csv file cannot be found + */ + public static InputStream getCOAResource(Module coaModule) throws FileNotFoundException { + OBContext.setAdminMode(); + try { + String coaPath = "/WEB-INF/referencedata/accounts/" + coaModule.getJavaPackage() + "/COA.csv"; + InputStream inputStream = RequestContext.getServletContext().getResourceAsStream(coaPath); + if (inputStream == null) { + throw new FileNotFoundException(RequestContext.getServletContext().getRealPath(coaPath)); + } + return inputStream; + } finally { + OBContext.restorePreviousMode(); + } + } + private String setAccountType(COAData data) { if (data == null) return null; @@ -860,8 +886,8 @@ log4j.debug("updateOperands() - Procesing operand " + strOperand[j][0] + ", of the account " + data[i].accountValue); ElementValueOperand operandElement = InitialSetupUtility.insertOperand(operand, - elementValue, Long.valueOf((strOperand[j][1].equals("+") ? "1" : "-1")), Long.valueOf( - strSeqNo)); + elementValue, Long.valueOf((strOperand[j][1].equals("+") ? "1" : "-1")), + Long.valueOf(strSeqNo)); strSeqNo = nextSeqNo(strSeqNo); if (operandElement == null) logEvent("@OperandNotInserted@. @Account_ID@ = " + data[i].accountValue diff -r 686664db43e1 -r 3e0f540c5540 src/org/openbravo/erpCommon/businessUtility/InitialClientSetup.java --- a/src/org/openbravo/erpCommon/businessUtility/InitialClientSetup.java Thu Sep 06 10:14:53 2018 +0200 +++ b/src/org/openbravo/erpCommon/businessUtility/InitialClientSetup.java Mon Sep 10 12:40:04 2018 +0200 @@ -11,14 +11,14 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2010-2015 Openbravo SLU + * All portions are Copyright (C) 2010-2018 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ */ package org.openbravo.erpCommon.businessUtility; -import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -580,17 +580,20 @@ logEvent(NEW_LINE + "@ProcessingAccountingModule@ " + modCoA.getName()); log4j.debug("createReferenceData() - Processing Chart of Accounts module " + modCoA.getName()); - String strPath = vars.getSessionValue("#SOURCEPATH") + "/modules/" - + modCoA.getJavaPackage() + "/referencedata/accounts/COA.csv"; - COAUtility coaUtility = new COAUtility(client, treeAccount); - FileInputStream inputStream = new FileInputStream(strPath); - obeResult = coaUtility.createAccounting(vars, inputStream, bBPartner, bProduct, bProject, - bCampaign, bSalesRegion, strAccountText, "US", "A", strCalendarText, currency); - strLog.append(coaUtility.getLog()); - } else + try (InputStream coaFile = COAUtility.getCOAResource(modCoA)) { + COAUtility coaUtility = new COAUtility(client, treeAccount); + obeResult = coaUtility.createAccounting(vars, coaFile, bBPartner, bProduct, bProject, + bCampaign, bSalesRegion, strAccountText, "US", "A", strCalendarText, currency); + strLog.append(coaUtility.getLog()); + } catch (FileNotFoundException e) { + logEvent("@FileDoesNotExist@ " + e.getMessage()); + throw new OBException("Could not find resource", e); + } + } else { return logErrorAndRollback( "@CreateReferenceDataFailed@. @CreateAccountingButNoCoAProvided@", "createReferenceData() - Create accounting option was active, but no file was provided, and no accoutning module was chosen"); + } } catch (Exception e) { return logErrorAndRollback("@CreateReferenceDataFailed@", "createReferenceData() - Exception while processing accounting modules", e); diff -r 686664db43e1 -r 3e0f540c5540 src/org/openbravo/erpCommon/businessUtility/InitialOrgSetup.java --- a/src/org/openbravo/erpCommon/businessUtility/InitialOrgSetup.java Thu Sep 06 10:14:53 2018 +0200 +++ b/src/org/openbravo/erpCommon/businessUtility/InitialOrgSetup.java Mon Sep 10 12:40:04 2018 +0200 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2010-2016 Openbravo SLU + * All portions are Copyright (C) 2010-2018 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -19,7 +19,7 @@ package org.openbravo.erpCommon.businessUtility; -import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -27,6 +27,7 @@ import org.apache.commons.fileupload.FileItem; import org.apache.log4j.Logger; +import org.openbravo.base.exception.OBException; import org.openbravo.base.secureApp.VariablesSecureApp; import org.openbravo.base.structure.BaseOBObject; import org.openbravo.dal.core.OBContext; @@ -125,8 +126,7 @@ public OBError createOrganization(String strOrgName, String strOrgUser, String strOrgType, String strParentOrg, String strcLocationId, String strPassword, String strModules, boolean boCreateAccounting, FileItem fileCoAFilePath, String strCurrency, boolean bBPartner, - boolean bProduct, boolean bProject, boolean bCampaign, boolean bSalesRegion, - String strSourcePath) { + boolean bProduct, boolean bProject, boolean bCampaign, boolean bSalesRegion) { OBError obResult = new OBError(); obResult.setType(ERRORTYPE); strHeaderLog.append("@ReportSummary@").append(NEW_LINE).append(NEW_LINE); @@ -232,8 +232,8 @@ } else { logEvent(NEW_LINE + "@StartingReferenceData@"); log4j.debug("process() - Starting creation of reference data"); - obResult = createReferenceData(strSourcePath, strModules, bProduct, bBPartner, bProject, - bCampaign, bSalesRegion, (bAccountingCreated) ? false : boCreateAccounting, strCurrency); + obResult = createReferenceData(strModules, bProduct, bBPartner, bProject, bCampaign, + bSalesRegion, (bAccountingCreated) ? false : boCreateAccounting, strCurrency); if (!obResult.getType().equals(OKTYPE)) return obResult; logEvent(NEW_LINE + "@CreateReferenceDataSuccess@"); @@ -258,9 +258,9 @@ } - private OBError createReferenceData(String strSourcePath, String strModulesProvided, - boolean product, boolean partner, boolean project, boolean campaign, boolean salesRegion, - boolean boCreateAccounting, String strCurrency) { + private OBError createReferenceData(String strModulesProvided, boolean product, boolean partner, + boolean project, boolean campaign, boolean salesRegion, boolean boCreateAccounting, + String strCurrency) { log4j.debug("createReferenceData() - Starting the process to create" + " reference data for modules: " + strModulesProvided); OBError obeResult = new OBError(); @@ -273,9 +273,8 @@ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits