Class InitialSetupUtility


  • public class InitialSetupUtility
    extends Object
    Author:
    David Alsasua Initial Client Setup Utility class
    • Constructor Detail

      • InitialSetupUtility

        public InitialSetupUtility()
    • Method Detail

      • existsClientName

        public static boolean existsClientName​(String strClient)
                                        throws Exception
        Parameters:
        strClient - name of the client
        Returns:
        true if exists client in database with provided name
        Throws:
        Exception
      • existsUserName

        public static boolean existsUserName​(String strUser)
                                      throws Exception
        Parameters:
        strUser - user name
        Returns:
        true if exists a user with the name provided in database
        Throws:
        Exception
      • insertClient

        public static Client insertClient​(String strClientName,
                                          String strCurrency)
                                   throws Exception
        Parameters:
        strClientName - client name
        strCurrency - currency id
        Returns:
        Client object for the created client
        Throws:
        Exception
      • getCurrency

        public static Currency getCurrency​(String strCurrencyID)
                                    throws Exception
        Parameters:
        strCurrencyID - c_currency_id
        Returns:
        Currency object that belongs to provided id
        Throws:
        Exception
      • getLanguage

        public static Language getLanguage​(String strLanguage)
                                    throws Exception
        Parameters:
        strLanguage - language key (for example en_US)
        Returns:
        Language object corresponding to provided key
        Throws:
        Exception
      • treeRelation

        @Deprecated
        public static List<List> treeRelation()
                                       throws Exception
        Deprecated.
        use tableTreeRelation, because it retrieves all tableTrees, instead of only the trees defined in the DA_TreeType type list reference Returns the relation of trees defined in the reference list of the application dictionary called AD_TreeType Type
        Returns:
        java.util.List<org.openbravo.model.ad.domain.List>: the relation of AD list elements
        Throws:
        Exception
      • tableTreeRelation

        public static List<TableTree> tableTreeRelation()
                                                 throws Exception
        Returns the relation of trees that use the ADTree tree structure, AD_TABLE_TREE table
        Returns:
        java.util.List<TableTree>: the relation of all the trees that use the ADTree tree structure
        Throws:
        Exception
      • getSystemMenuTree

        public static Tree getSystemMenuTree​(String strTreeTypeMenu)
                                      throws Exception
        Returns the tree of the provided type
        Parameters:
        strTreeTypeMenu - two letters corresponding to the tree type for the menu
        Returns:
        Tree menu element (defined at system level)
        Throws:
        Exception
      • insertTree

        @Deprecated
        public static Tree insertTree​(Client client,
                                      String name,
                                      String treeType,
                                      Boolean boIsAllNodes)
                               throws Exception
        Deprecated.
        use new insertTree method where new parameter "table" is added
        Parameters:
        client -
        name -
        treeType -
        boIsAllNodes -
        Returns:
        object Tree for the new tree
        Throws:
        Exception
      • insertClientinfo

        @Deprecated
        public static ClientInformation insertClientinfo​(Client client,
                                                         Tree menuTree,
                                                         Tree orgTree,
                                                         Tree bpartnerTree,
                                                         Tree projectTree,
                                                         Tree salesRegionTree,
                                                         Tree productTree,
                                                         Boolean boDiscountCalculatedFromLineAmounts)
                                                  throws Exception
        Deprecated.
        use new insertClientinfo method where new parameter "campaignTree" is added
        Parameters:
        client -
        menuTree -
        orgTree -
        bpartnerTree -
        projectTree -
        salesRegionTree -
        productTree -
        boDiscountCalculatedFromLineAmounts -
        Returns:
        ClientInformation object for the new element
        Throws:
        Exception
      • insertClientinfo

        public static ClientInformation insertClientinfo​(Client client,
                                                         Tree menuTree,
                                                         Tree orgTree,
                                                         Tree bpartnerTree,
                                                         Tree projectTree,
                                                         Tree salesRegionTree,
                                                         Tree productTree,
                                                         Tree campaignTree,
                                                         Boolean boDiscountCalculatedFromLineAmounts)
                                                  throws Exception
        Parameters:
        client -
        menuTree -
        orgTree -
        bpartnerTree -
        projectTree -
        salesRegionTree -
        productTree -
        campaignTree -
        boDiscountCalculatedFromLineAmounts -
        Returns:
        ClientInformation object for the new element
        Throws:
        Exception
      • setClientInformation

        public static boolean setClientInformation​(Client client,
                                                   ClientInformation clientInfo)
                                            throws Exception
        Associates a client info record to a client
        Parameters:
        client -
        clientInfo -
        Returns:
        true if update was correct
        Throws:
        Exception
      • setClientImages

        public static void setClientImages​(Client client)
                                    throws Exception
        Parameters:
        client -
        Throws:
        Exception
      • setCompanyLogo

        public static void setCompanyLogo​(SystemInformation sys,
                                          Client client)
        Parameters:
        sys -
        client -
      • setCompanyLogoDark

        public static void setCompanyLogoDark​(SystemInformation sys,
                                              Client client)
        Parameters:
        sys -
        client -
      • setCompanyLogoSubmark

        public static void setCompanyLogoSubmark​(SystemInformation sys,
                                                 Client client)
        Parameters:
        sys -
        client -
      • setCompanyLogoSubmarkDark

        public static void setCompanyLogoSubmarkDark​(SystemInformation sys,
                                                     Client client)
        Parameters:
        sys -
        client -
      • setCompanyLogoForDocs

        public static void setCompanyLogoForDocs​(SystemInformation sys,
                                                 Client client)
        Parameters:
        sys -
        client -
      • setCompanyLogoForReceipts

        public static void setCompanyLogoForReceipts​(SystemInformation sys,
                                                     Client client)
        Parameters:
        sys -
        client -
      • setYourCompanyDocumentImage

        @Deprecated
        public static void setYourCompanyDocumentImage​(SystemInformation sys,
                                                       Client client)
        Deprecated.
        Parameters:
        sys -
        client -
      • insertRole

        public static Role insertRole​(Client client,
                                      Organization orgProvided,
                                      String name,
                                      String strUserLevelProvided)
                               throws Exception
        Parameters:
        client - client for which the role will be created
        orgProvided - if null, role inserted for organization with id=0
        name - name of the role
        strUserLevelProvided - if null, user level " CO" will be set to the new role
        Returns:
        Role object for new element
        Throws:
        Exception
      • insertRole

        public static Role insertRole​(Client client,
                                      Organization orgProvided,
                                      String name,
                                      String strUserLevelProvided,
                                      boolean isClientAdmin)
                               throws Exception
        Parameters:
        client - client for which the role will be created
        orgProvided - if null, role inserted for organization with id=0
        name - name of the role
        strUserLevelProvided - if null, user level " CO" will be set to the new role
        Returns:
        Role object for new element
        Throws:
        Exception
      • insertRoleOrganization

        public static RoleOrganization insertRoleOrganization​(Role role,
                                                              Organization orgProvided)
                                                       throws Exception
        Parameters:
        role - role for which the organization access information will be created
        orgProvided - if null, organization with id "0" will be used
        Returns:
        RoleOrganization object for new element
        Throws:
        Exception
      • insertRoleOrganization

        public static RoleOrganization insertRoleOrganization​(Role role,
                                                              Organization orgProvided,
                                                              boolean isOrgAdmin)
                                                       throws Exception
        Parameters:
        role - role for which the organization access information will be created
        orgProvided - if null, organization with id "0" will be used
        Returns:
        RoleOrganization object for new element
        Throws:
        Exception
      • insertUserRole

        public static UserRoles insertUserRole​(Client client,
                                               User user,
                                               Organization orgProvided,
                                               Role role,
                                               boolean isRoleAdmin)
                                        throws Exception
        Parameters:
        client -
        user -
        orgProvided -
        role -
        Returns:
        UserRoles object for new element
        Throws:
        Exception
      • insertUserRoles

        public static void insertUserRoles​(Client client,
                                           User user,
                                           Organization organization,
                                           Role role)
                                    throws Exception
        Inserts a new role for the created client and user. Also user Openbravo will have rights to access new client
        Parameters:
        client -
        user -
        organization -
        role -
        Throws:
        Exception
      • insertElement

        public static Element insertElement​(Client client,
                                            Organization orgProvided,
                                            String name,
                                            Tree accountTree,
                                            Boolean bNaturalAccount)
                                     throws Exception
        Parameters:
        client -
        orgProvided -
        name -
        accountTree -
        bNaturalAccount -
        Returns:
        Element object for new element
        Throws:
        Exception
      • insertElementValue

        public static ElementValue insertElementValue​(Element element,
                                                      Organization orgProvided,
                                                      String name,
                                                      String value,
                                                      String description,
                                                      String accountType,
                                                      String accountSign,
                                                      boolean isDocControlled,
                                                      boolean isSummary,
                                                      String elementLevel,
                                                      boolean doFlush)
                                               throws Exception
        Parameters:
        element -
        orgProvided -
        name -
        value -
        description -
        accountType -
        accountSign -
        isDocControlled -
        isSummary -
        elementLevel -
        doFlush -
        Returns:
        ElementValue object for new element
        Throws:
        Exception
      • getTreeNode

        public static List<TreeNode> getTreeNode​(Tree accountTree,
                                                 Client client,
                                                 Organization orgProvided)
                                          throws Exception
        Returns the nodes of a given tree
        Parameters:
        accountTree -
        client -
        orgProvided -
        Returns:
        List<TreeNode> with relation of tree node elements of the provided tree
        Throws:
        Exception
      • getTreeNode

        public static List<TreeNode> getTreeNode​(Tree accountTree,
                                                 Client client)
                                          throws Exception
        Returns the nodes of a given tree
        Parameters:
        accountTree -
        client -
        Returns:
        List<TreeNode> with relation of tree node elements of the provided tree
        Throws:
        Exception
      • updateAccountTree

        public static void updateAccountTree​(List<TreeNode> treeNodes,
                                             HashMap<String,​Long> mapSequence,
                                             HashMap<String,​String> mapElementValueValue,
                                             HashMap<String,​String> mapElementValueId,
                                             HashMap<String,​String> mapParent,
                                             boolean doFlush)
                                      throws Exception
        Sorts the account tree (stored in ADTreeNode) according to the order provided
        Parameters:
        treeNodes - relation of nodes in ADTreeNode belonging to the accounting tree to sort out
        mapSequence - HashMap<String,Long> where the String belongs to the value of a c_elementvalue, and Long to the sequence that must be assigned to the node that represents that element value in ADTreeNode
        mapElementValueValue - each tree node in treeNodes has one entry in mapElementValueId to link it's value with the c_elementvalue_id of that element in c_elementvalue table
        mapElementValueId - stores the link value <-> c_elementvalue_id
        mapParent - stores the link value <-> value of the parent
        doFlush - if true, each new update performs a flush in DAL
        Throws:
        Exception
      • getElementValue

        public static ElementValue getElementValue​(Element element,
                                                   String value)
                                            throws Exception
        Parameters:
        element -
        value -
        Returns:
        ElementValue object for the given value in the provided element
        Throws:
        Exception
      • insertAcctSchema

        public static AcctSchema insertAcctSchema​(Client client,
                                                  Organization orgProvided,
                                                  Currency currency,
                                                  String name,
                                                  String gAAP,
                                                  String costingMethod,
                                                  boolean hasAlias)
                                           throws Exception
        Parameters:
        client -
        orgProvided -
        currency -
        name -
        gAAP -
        costingMethod -
        hasAlias -
        Returns:
        AcctSchema element that matches provided data
        Throws:
        Exception
      • insertAcctSchemaElement

        public static AcctSchemaElement insertAcctSchemaElement​(AcctSchema acctSchema,
                                                                Organization orgProvided,
                                                                List listElement,
                                                                Long sequence,
                                                                boolean isMandatory,
                                                                boolean isBalanced,
                                                                ElementValue defaultAccount,
                                                                Element accountingElement)
                                                         throws Exception
        Parameters:
        acctSchema -
        orgProvided - optional parameter. If null, organization 0 will be used
        listElement - element of the reference list which is going to be inserted. From it's name, the name of the acct.schema element will be taken, and from it's value (search key) the type
        sequence -
        isMandatory -
        isBalanced -
        defaultAccount -
        accountingElement -
        Returns:
        AcctSchemaElement object for the inserted element
        Throws:
        Exception
      • insertAcctSchemaDefault

        public static AcctSchemaDefault insertAcctSchemaDefault​(HashMap<String,​ElementValue> defaultElementValues,
                                                                AcctSchema acctSchema)
                                                         throws Exception
        Parameters:
        defaultElementValues - map with DefaultAccount and ElementValue object that will be set
        acctSchema -
        Returns:
        AcctSchemaDefault object for the created element
        Throws:
        Exception
      • insertAcctSchemaGL

        public static AcctSchemaGL insertAcctSchemaGL​(HashMap<String,​ElementValue> defaultElementValues,
                                                      AcctSchema acctSchema)
                                               throws Exception
        Parameters:
        defaultElementValues - map with DefaultAccount and ElementValue object that will be set
        acctSchema -
        Returns:
        AcctSchemaGL object for the created element
        Throws:
        Exception
      • insertOrgAcctSchema

        public static OrganizationAcctSchema insertOrgAcctSchema​(Client client,
                                                                 AcctSchema acctSchema,
                                                                 Organization orgProvided)
        Parameters:
        client -
        acctSchema -
        orgProvided -
        Returns:
        OrganizationAcctSchema object for the new element
      • insertCategory

        public static GLCategory insertCategory​(Client client,
                                                Organization organization,
                                                String name,
                                                String categoryType,
                                                boolean isDefault)
        Parameters:
        client -
        organization -
        name -
        categoryType -
        isDefault -
        Returns:
        GLCategory object for the new element
      • insertSequence

        public static Sequence insertSequence​(Client client,
                                              Organization organization,
                                              String name,
                                              Long startNo)
        Parameters:
        client -
        organization -
        name -
        startNo -
        Returns:
        Sequence object for the new created element
      • insertDocType

        public static DocumentType insertDocType​(Client client,
                                                 Organization organization,
                                                 String name,
                                                 String printName,
                                                 String docBaseType,
                                                 String docSubTypeSO,
                                                 DocumentType shipment,
                                                 DocumentType invoice,
                                                 boolean isDocNoControlled,
                                                 Sequence sequence,
                                                 GLCategory category,
                                                 boolean isSOTrx,
                                                 Table table)
        Parameters:
        client -
        organization -
        name -
        printName -
        docBaseType -
        docSubTypeSO -
        shipment -
        invoice -
        isDocNoControlled -
        sequence -
        category -
        isSOTrx -
        table -
        Returns:
        DocumentType object for the new element
      • insertReferenceData

        public static ImportResult insertReferenceData​(DataSet dataset,
                                                       Client client,
                                                       Organization orgProvided)
                                                throws Exception
        Given a dataset, inserts the elements in the xml file into database.
        Parameters:
        dataset -
        client -
        orgProvided -
        Returns:
        ImportResult object for the created element. Errors, warnings and log is provided in this object.
        Throws:
        Exception
      • insertDoctypeTemplate

        public static DocumentTemplate insertDoctypeTemplate​(DocumentType document,
                                                             String name,
                                                             String templateLocation,
                                                             String templateFileName,
                                                             String reportFileName)
        Parameters:
        document -
        name -
        templateLocation -
        templateFileName -
        reportFileName -
        Returns:
        DocumentTemplate object with the new element
      • insertEmailTemplate

        public static EmailTemplate insertEmailTemplate​(DocumentTemplate documentTemplate)
        Parameters:
        documentTemplate -
        Returns:
        EmailTemplate object for the new element
      • getCOAModules

        public static List<Module> getCOAModules​(String strModules)
                                          throws Exception
        Returns the set of Module objects for the given ids
        Parameters:
        strModules - relation of ids (in a format so that can be included in a "in" statement of a "where" clause
        Returns:
        List<Module> with the relation of modules
        Throws:
        Exception
      • getRDModules

        public static List<Module> getRDModules​(String strModules)
                                         throws Exception
        Returns the set of Module objects for the given ids
        Parameters:
        strModules - relation of ids (in a format so that can be included in a "in" statement of a "where" clause
        Throws:
        Exception
      • getDataSets

        public static List<DataSet> getDataSets​(Module module,
                                                List<String> accessLevel)
                                         throws Exception
        Given a module, and an access level, returns all the datasets contained in that module
        Parameters:
        module -
        accessLevel - 3-> client/org; 6-> System/client
        Returns:
        List<DataSet> with the relation of DataSet objects
        Throws:
        Exception
      • getAcctSchemaElements

        public static List<List> getAcctSchemaElements()
                                                throws Exception
        Returns the relation of ad_ref_list elements for the reference with AD_Reference_id='181' (Acct.schema elements)
        Returns:
        List<org.openbravo.model.ad.domain.List> with the relation of ad_ref_list elements
        Throws:
        Exception
      • insertOrgModule

        public static ADOrgModule insertOrgModule​(Client client,
                                                  Organization orgProvided,
                                                  Module module)
                                           throws Exception
        Parameters:
        client -
        orgProvided - optional parameter. If not provided, "*" organization used
        module -
        Returns:
        ADClientModule object with the created element
        Throws:
        Exception
      • insertClientModule

        public static ADClientModule insertClientModule​(Client client,
                                                        Module module)
                                                 throws Exception
        Parameters:
        client -
        module -
        Returns:
        ADClientModule object with the created element
        Throws:
        Exception
      • getTranslatedMessage

        public static String getTranslatedMessage​(Language language,
                                                  String msgId)
      • getTranslatedColumnName

        public static String getTranslatedColumnName​(Language language,
                                                     String columnName)
      • getTranslatedElement

        public static String getTranslatedElement​(Language language,
                                                  String columnName,
                                                  String elementName)
      • getTree

        public static Tree getTree​(String strTreeTypeMenu,
                                   Client client,
                                   Organization orgProvided)
                            throws Exception
        Returns the tree of the provided type
        Parameters:
        strTreeTypeMenu - two letters corresponding to the tree type for the menu
        Returns:
        Tree menu element (defined at system level)
        Throws:
        Exception
      • getTree

        public static Tree getTree​(Table table,
                                   Client client,
                                   Organization orgProvided)
                            throws Exception
        Returns the ADTree associated with the given table
        Returns:
        Tree menu element (defined at system level)
        Throws:
        Exception