Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cdlftw
Created September 18, 2019 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdlftw/5718222ae0c6450602e4e50976bed08e to your computer and use it in GitHub Desktop.
Save cdlftw/5718222ae0c6450602e4e50976bed08e to your computer and use it in GitHub Desktop.
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.*;
public class SLFIMasterDataBuilder {
private static final Logger logger = Logger.getLogger(SLFIMasterDataBuilder.class);
/**
* For ***** we write two sets of data, one for each company code.
*
* @param jsonArray
*/
private void writeLinkFile(JSONArray jsonArray) {
String path = Constants.getInstance().getFinancialForceProperty(Constants.PATH_SUPPLIER_LINK);
String[] supplierFields = new String[]{
"Account_Number__c", // code
"Account_Number__c", // third party code
"!xyz", // company code
"!STANDARD", // systemcode
"!TRUE" // is default type
};
String linkCSV = Util.buildCSVDataFromJSON(supplierFields, jsonArray);
supplierFields = new String[]{
"Account_Number__c", // code
"Account_Number__c", // third party code
"!abc", // company code
"!STANDARD", // systemcode
"!TRUE" // is default type
};
linkCSV = Util.buildCSVDataFromJSON(linkCSV, supplierFields, jsonArray);
String header = "suppliercode;thirdpartycode;companycode;systemcode;isdefaulttype";
Util.writeCSVFile(path, header, linkCSV);
}
private void writeThirdPartyFile(JSONArray jsonArray) {
String path = Constants.getInstance().getFinancialForceProperty(Constants.PATH_THIRD_PARTIES);
String[] supplierFields = new String[]{
"Account_Number__c", // code
"Name", // name
"c2g__CODAVATRegistrationNumber__c", // vat
"!", // siren
"!", // siret
"c2g__CODABankIBANNumber__c", // iban
"!", // iban2
"BillingAddress.street", // address1
"!", // address2
"!", // address3
"!", // address4
"BillingAddress.postalCode", // zipcode
"BillingAddress.state", // state
"BillingAddress.city", // town
"BillingAddress.country", // country
"Phone", // phone
"!", // fax
"c2g__CODAInvoiceEmail__c", // email
"Website", // web
"c2g__CODAPaymentMethod__c", // paymentmethod
"!", // payment termcode
"Name", // alternativename
"!STANDARD" // systemcode
};
String supplierCSV = Util.buildCSVDataFromJSON(supplierFields, jsonArray);
String header = "code;name;vat;siren;siret;iban;iban2;address1;address2;address3;address4;zipcode;state;town;country;phone;fax;email;web;paymentmethod;paymenttermcode;alternativename;systemcode";
Util.writeCSVFile(path, header, supplierCSV);
}
private void writeSupplierFile(JSONArray jsonArray) {
String path = Constants.getInstance().getFinancialForceProperty(Constants.PATH_SUPPLIERS);
String[] supplierFields = new String[]{
"Account_Number__c", // code
"Name", // name
"Name", // alternative name
"c2g__CODAAccountsPayableControl__c", // general account
"PO_Required__c", // is matching mandatory
"PO_Required__c", // default document category
"!STANDARD" // system code
};
String supplierCSV = Util.buildCSVDataFromJSON(supplierFields, jsonArray);
String header = "code;name;alternativename;generalaccount;ismatchingmandatory;defaultdocumentcategory;systemcode";
Util.writeCSVFile(path, header, supplierCSV);
}
private void buildSupplierFiles() throws IOException {
logger.info("Building Supplier Files...");
JSONArray jsonArray = Util.getJSONFromQuery(Constants.QUERY_GET_SUPPLIERS);
logger.info("Writing Supplier File...");
writeSupplierFile(jsonArray);
logger.info("Writing Third Party File...");
writeThirdPartyFile(jsonArray);
logger.info("Writing Link File...");
writeLinkFile(jsonArray);
}
private void buildDIM4File() throws IOException {
logger.info("Building DIM4 File...");
String header = "code;name;systemCode";
String[] jsonFields = new String[] {
"c2g__ReportingCode__c", // code
"Name", // name
"c2g__ReportingCode__c" // systemcode
};
Util.buildFile(Constants.QUERY_GET_DIM4, Constants.PATH_DIM4, header, jsonFields);
}
private void buildDIM3File() throws IOException {
logger.info("Building DIM3 File...");
String header = "code;name;systemCode";
String[] jsonFields = new String[] {
"c2g__ReportingCode__c", // code
"Name", // name
"c2g__ReportingCode__c" // systemcode
};
Util.buildFile(Constants.QUERY_GET_DIM3, Constants.PATH_DIM3, header, jsonFields);
}
private void buildDIM2File() throws IOException {
logger.info("Building DIM2 File...");
String header = "code;name;systemCode";
String[] jsonFields = new String[] {
"c2g__ReportingCode__c", // code
"Name", // name
"c2g__ReportingCode__c" // systemcode
};
Util.buildFile(Constants.QUERY_GET_DIM2, Constants.PATH_DIM2, header, jsonFields);
}
private void buildDIM1File() throws IOException {
logger.info("Building DIM1 File...");
String header = "code;name;systemCode";
String[] jsonFields = new String[] {
"c2g__ReportingCode__c", // code
"Name", // name
"c2g__ReportingCode__c" // systemcode
};
Util.buildFile(Constants.QUERY_GET_DIM1, Constants.PATH_DIM1, header, jsonFields);
}
private void buildGLAccountFile() throws IOException {
logger.info("Building GL File...");
String header = "code;name;systemCode";
String[] jsonFields = new String[] {
"c2g__ReportingCode__c", // code
"Name", // name
"c2g__ReportingCode__c" // systemcode
};
Util.buildFile(Constants.QUERY_GET_GL_ACCOUNTS, Constants.PATH_GL_ACCOUNTS, header, jsonFields);
}
private void buildTaxFile() throws IOException {
logger.info("Building Tax File...");
String header = "code;name;rate;account;jurisdiction;ledgerCode";
String[] jsonFields = new String[] {
"c2g__TaxCode__r.Name", // code
"c2g__TaxCode__r.Name", // name
"c2g__Rate__c", // rate
"c2g__TaxCode__r.c2g__GeneralLedgerAccount__c", // account
"!", // jurisdiction
"c2g__TaxCode__r.c2g__Description__c" // ledgercode
};
Util.buildFile(Constants.QUERY_GET_TAX_CODES, Constants.PATH_TAX_CODES, header, jsonFields);
}
private void buildApprovalsMatrix1() throws IOException {
logger.info("Building DIM1 Approvals Matrix...");
String header = "code;name;systemCode";
String[] jsonFields = new String[] {
"c2g__ReportingCode__c", // code
"Name", // name
"c2g__ReportingCode__c" // systemcode
};
Util.buildFile(Constants.QUERY_GET_APPROVALS_1, Constants.PATH_APPROVALS_MATRIX_1, header, jsonFields);
}
private void buildApprovalsMatrix3() throws IOException {
logger.info("Building DIM3 Approvals Matrix...");
String header = "code;name;systemCode";
String[] jsonFields = new String[] {
"c2g__ReportingCode__c", // code
"Name", // name
"c2g__ReportingCode__c" // systemcode
};
Util.buildFile(Constants.QUERY_GET_APPROVALS_3, Constants.PATH_APPROVALS_MATRIX_3, header, jsonFields);
}
/**
* Generate all the files we require for the Master Data.
*/
private void generateFiles() {
try {
logger.info("Generating Master Data Files...");
buildSupplierFiles();
buildTaxFile();
buildGLAccountFile();
buildDIM1File();
buildDIM2File();
buildDIM3File();
buildDIM4File();
buildApprovalsMatrix1();
buildApprovalsMatrix3();
} catch(Exception e) {
logger.error(e);
}
}
/**
* Main entry point.
*
* @param args
*/
public static void main(String[] args) {
logger.info("SLFIMasterDataBuilder invoked.");
new SLFIMasterDataBuilder().generateFiles();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment