Class Utility


  • public class Utility
    extends Object
    Author:
    Fernando Iriazabal Utility class
    • Constructor Detail

      • Utility

        public Utility()
    • Method Detail

      • getCommunityBrandingUrl

        public static String getCommunityBrandingUrl()
        Computes the community branding url on the basis of system information. Note the returned url does not contain the protocol part, it starts with //... So the caller has to prepend it with the needed protocol part (i.e. http: or https:).
      • isExcludedFromAutoSave

        public static boolean isExcludedFromAutoSave​(String canonicalName)
        Checks if a class is excluded from the autosave process
        Parameters:
        canonicalName -
        Returns:
        True is the class is excluded or false if not.
      • isNumericParameter

        @Deprecated
        public static boolean isNumericParameter​(String reference)
        Deprecated.
        Checks if a getNumericParameters is needed based on a reference. Deprecated, use UIReference.
        Parameters:
        reference -
        Returns:
        true if the passed reference represents a numeric type, false otherwise.
      • isID

        @Deprecated
        public static boolean isID​(String reference)
        Deprecated.
        Checks if the reference is an ID. Deprecated, use UIReference.
        Parameters:
        reference - String with the reference
        Returns:
        True if is a ID reference
      • isDecimalNumber

        @Deprecated
        public static boolean isDecimalNumber​(String reference)
        Deprecated.
        Checks if the references is a decimal number type. Deprecated, use UIReference.
        Parameters:
        reference - String with the reference.
        Returns:
        True if is a decimal or false if not.
      • isIntegerNumber

        @Deprecated
        public static boolean isIntegerNumber​(String reference)
        Deprecated.
        Checks if the references is an integer number type. Deprecated, use UIReference.
        Parameters:
        reference - String with the reference.
        Returns:
        True if is an integer or false if not.
      • isDateTime

        @Deprecated
        public static boolean isDateTime​(String reference)
        Deprecated.
        Checks if the references is a datetime type. Deprecated, use UIReference.
        Parameters:
        reference - String with the reference.
        Returns:
        True if is a datetime or false if not.
      • throwErrorMessage

        public static void throwErrorMessage​(String message)
        Throws an OBException with a message in the right language.
        Parameters:
        message - the key of the message
      • getPreference

        public static String getPreference​(VariablesSecureApp vars,
                                           String context,
                                           String window)
        Gets the value of the given preference.
        Parameters:
        vars - Handler for the session info.
        context - String with the preference.
        window - String with the window id.
        Returns:
        String with the value.
      • getTransactionalDate

        public static String getTransactionalDate​(ConnectionProvider conn,
                                                  VariablesSecureApp vars,
                                                  String window)
        Gets the transactional range defined.
        Parameters:
        conn - Handler for the database connection.
        vars - Handler for the session info.
        window - String with the window id.
        Returns:
        String with the value.
      • getContext

        public static String getContext​(ConnectionProvider conn,
                                        VariablesSecureApp vars,
                                        String context,
                                        String window)
        Gets a value from the context. For client 0 is always added (used for references), to check if it must be added or not use the getContext with accesslevel method.
        Parameters:
        conn - Handler for the database connection.
        vars - Handler for the session info.
        context - String with the parameter to search.
        window - String with the window id.
        Returns:
        String with the value.
      • getContext

        public static String getContext​(ConnectionProvider conn,
                                        VariablesSecureApp vars,
                                        String context,
                                        String strWindow,
                                        int accessLevel)
        Gets a value from the context. Access level values: 1 Organization 3 Client/Organization 4 System only 6 System/Client 7 All
        Parameters:
        conn - Handler for the database connection.
        vars - Handler for the session info.
        context - String with the parameter to search.
        strWindow - String with the window id.
        accessLevel -
        Returns:
        String with the value.
      • getReferenceableOrg

        public static String getReferenceableOrg​(VariablesSecureApp vars,
                                                 String currentOrg)
        Returns the list of referenceables organizations from the current one. This includes all its ancestors and descendants.
        Parameters:
        vars -
        currentOrg -
        Returns:
        comma delimited Stirng of referenceable organizations.
      • getReferenceableOrg

        public static String getReferenceableOrg​(ConnectionProvider conn,
                                                 VariablesSecureApp vars,
                                                 String currentOrg,
                                                 String window,
                                                 int accessLevel)
        Returns the list of referenceables organizations from the current one. This includes all its ancestors and descendants. This method takes into account accessLevel and user level: useful to calculate org list for child tabs
        Parameters:
        conn -
        vars -
        currentOrg -
        window -
        accessLevel -
        Returns:
        the list of referenceable organizations, comma delimited
      • getSelectorOrgs

        public static String getSelectorOrgs​(ConnectionProvider conn,
                                             VariablesSecureApp vars,
                                             String currentOrg)
        Returns the organization list for selectors, two cases are possible:
        • Organization is empty (null or ""): accessible list of organizations will be returned. This case is used in calls from filters to selectors.
        • Organization is not empty: referenceable from current organization list of organizations will be returned. This is the way it is called from wad windows.
        Parameters:
        conn - Handler for the database connection
        vars -
        currentOrg -
        Returns:
        the organization list for selectors
      • getDefault

        public static String getDefault​(ConnectionProvider conn,
                                        VariablesSecureApp vars,
                                        String columnname,
                                        String context,
                                        String window,
                                        String defaultValue,
                                        FieldProvider sessionData)
        Gets a default value.
        Parameters:
        conn - Handler for the database connection.
        vars - Handler for the session info.
        columnname - String with the column name.
        context - String with the parameter.
        window - String with the window id.
        defaultValue - with the default value.
        sessionData - FieldProvider with the data stored in session
        Returns:
        String with the value.
      • getStringVector

        public static Vector<String> getStringVector​(String s)
        Returns a Vector<String> composed by the comma separated elements in String s
        Parameters:
        s -
        Returns:
        the list of String obtained by converting the comma delimited String
      • getIntersectionVector

        public static Vector<String> getIntersectionVector​(Vector<String> v1,
                                                           Vector<String> v2)
        Returns a Vector<String> with the elements that appear in both v1 and v2 Vectors
        Parameters:
        v1 -
        v2 -
        Returns:
        the combination of v1 and v2 without duplicates
      • getVectorToString

        public static String getVectorToString​(Vector<String> v)
        Returns the elements in Vector v as an String separating with commas the elements
        Parameters:
        v -
        Returns:
        a comma delimited String
      • parseContext

        public static String parseContext​(ConnectionProvider conn,
                                          VariablesSecureApp vars,
                                          String context,
                                          String window)
        Parse the given string searching the @ elements to translate with the correct values. Parameters are directly inserted in the returned String.
        Parameters:
        conn - Handler for the database connection.
        vars - Handler for the session info.
        context - String to parse.
        window - String with the window id.
        Returns:
        String parsed.
      • parseContext

        public static String parseContext​(ConnectionProvider conn,
                                          VariablesSecureApp vars,
                                          String context,
                                          String window,
                                          Vector<String> params)
        Parse the given string searching the @ elements to translate with the correct values. If params is not null it adds a ? symbol in the context and adds the actual value to the params Vector, other case the actual value is replaced in the context.
      • getDocumentNo

        public static String getDocumentNo​(ConnectionProvider conn,
                                           VariablesSecureApp vars,
                                           String WindowNo,
                                           String TableName,
                                           String C_DocTypeTarget_ID,
                                           String C_DocType_ID,
                                           boolean onlyDocType,
                                           boolean updateNext)
        Gets the document number from the database.
        Parameters:
        conn - Handler for the database connection.
        vars - Handler for the session info.
        WindowNo - Window id.
        TableName - Table name.
        C_DocTypeTarget_ID - Id of the doctype target.
        C_DocType_ID - id of the doctype.
        onlyDocType - Search only for doctype.
        updateNext - Save the new sequence in database.
        Returns:
        String with the new document number.
      • getDocumentNo

        public static String getDocumentNo​(ConnectionProvider conn,
                                           String AD_Client_ID,
                                           String TableName,
                                           boolean updateNext)
        Gets the document number from database.
        Parameters:
        conn - Handler for the database connection.
        AD_Client_ID - String with the client id.
        TableName - Table name.
        updateNext - Save the new sequence in database.
        Returns:
        String with the new document number.
      • getDocumentNoConnection

        public static String getDocumentNoConnection​(Connection conn,
                                                     ConnectionProvider con,
                                                     String AD_Client_ID,
                                                     String TableName,
                                                     boolean updateNext)
        Gets the document number from database.
        Parameters:
        conn - Handler for the database connection.
        AD_Client_ID - String with the client id.
        TableName - Table name.
        updateNext - Save the new sequence in database.
        Returns:
        String with the new document number.
      • addSystem

        public static String addSystem​(String list)
        Adds the system element to the given list.
        Parameters:
        list - String with the list.
        Returns:
        String with the modified list.
      • canUpdate

        public static boolean canUpdate​(ConnectionProvider conn,
                                        VariablesSecureApp vars,
                                        String AD_Client_ID,
                                        String AD_Org_ID,
                                        String window)
                                 throws javax.servlet.ServletException
        Checks if the user can make modifications in the window.
        Parameters:
        conn - Handler for the database connection.
        vars - Handler for the session info.
        AD_Client_ID - Id of the client.
        AD_Org_ID - Id of the organization.
        window - Window id.
        Returns:
        True if has permission, false if not.
        Throws:
        javax.servlet.ServletException
      • isInFieldProvider

        public static boolean isInFieldProvider​(FieldProvider[] data,
                                                String fieldName,
                                                String key)
        Checks if the value exists in the given array of FieldProviders.
        Parameters:
        data - Array of FieldProviders.
        fieldName - Name of the field to search.
        key - The value to search.
        Returns:
        True if exists or false if not.
      • getWindowID

        public static String getWindowID​(ConnectionProvider conn,
                                         String strTabID)
                                  throws javax.servlet.ServletException
        Gets the window id for a tab.
        Parameters:
        conn - Handler for the database connection.
        strTabID - Id of the tab.
        Returns:
        String with the id of the window.
        Throws:
        javax.servlet.ServletException
      • generateFile

        public static boolean generateFile​(String strPath,
                                           String strFile,
                                           String data)
        Saves the content into a fisical file.
        Parameters:
        strPath - path for the file.
        strFile - name of the file.
        data - content of the file.
        Returns:
        true if everything is ok or false if not.
      • generateFileEncoding

        public static boolean generateFileEncoding​(String strPath,
                                                   String strFile,
                                                   String data,
                                                   String encoding)
      • isTreeTab

        public static boolean isTreeTab​(ConnectionProvider conn,
                                        String stradTabId)
                                 throws javax.servlet.ServletException
        Checks if the tab is declared as a tree tab.
        Parameters:
        conn - Handler for the database connection.
        stradTabId - Id of the tab.
        Returns:
        True if is a tree tab or false if isn't.
        Throws:
        javax.servlet.ServletException
      • fillSQLParameters

        public static void fillSQLParameters​(ConnectionProvider conn,
                                             VariablesSecureApp vars,
                                             FieldProvider data,
                                             ComboTableData cmb,
                                             String window,
                                             String actual_value)
                                      throws javax.servlet.ServletException
        Fill the parameters of the sql with the session values or FieldProvider values. Used in the combo fields.
        Parameters:
        conn - Handler for the database connection.
        vars - Handler for the session info.
        data - FieldProvider with the columns values.
        cmb - ComboTableData object.
        window - Window id.
        actual_value - actual value for the combo.
        Throws:
        javax.servlet.ServletException
        See Also:
        ComboTableData.fillParameters(FieldProvider, String, String)
      • getServletInfo

        public String getServletInfo()
      • isElementInList

        public static boolean isElementInList​(String strList,
                                              String strElement)
        Checks if an element is in a list. List is an string like "(e1, e2, e3,...)" where en are elements. It is inteeded to be used for checking user client and organizations.
        Parameters:
        strList - List to check in
        strElement - Element to check in the list
        Returns:
        true in case the element is in the list
      • focusFieldJS

        public static String focusFieldJS​(String id)
        Returns a JavaScript function to be used on selectors Depending on what element you want to focus, you pass the id
        Parameters:
        id - the html tag id to focus on
        Returns:
        a String JavaScript function
      • dumpFile

        public static void dumpFile​(String fileLocation,
                                    OutputStream outputstream)
        Write the output to a file. It creates a file in the file location writing the content of the outputstream.
        Parameters:
        fileLocation - the file where you are going to write
        outputstream - the data source
      • stringList

        public static String stringList​(String list)
        Returns a string list comma separated as SQL strings.
        Returns:
        comma delimited quoted string
      • getInStrList

        public static <T extends BaseOBObjectString getInStrList​(List<T> obObjectList)
        Creates a comma separated string with the Id's of the OBObjects included in the List.
        Type Parameters:
        T -
        Parameters:
        obObjectList - List of OBObjects
        Returns:
        Comma separated string of Id's
      • getInStrList

        public static <T extends BaseOBObjectString getInStrList​(List<T> obObjectList,
                                                                   boolean addParentheses)
        Creates a comma separated string with the Id's of the OBObjects included in the List.
        Type Parameters:
        T -
        Parameters:
        obObjectList - List of OBObjects
        addParentheses - String will be surrounded with parentheses
        Returns:
        Comma separated string of Id's
      • isUUIDString

        public static boolean isUUIDString​(String CharacterString)
        Determines if a string of characters is an Openbravo UUID (Universal Unique Identifier), i.e., if it is a 32 length hexadecimal string.
        Parameters:
        CharacterString - A string of characters.
        Returns:
        Returns true if this string of characters is an UUID.
      • isHexStringChar

        public static final boolean isHexStringChar​(char c)
        Returns true if the input argument character is A-F, a-f or 0-9.
        Parameters:
        c - A single character.
        Returns:
        Returns true if this character is hexadecimal.
      • deleteDir

        public static boolean deleteDir​(File[] f)
        Deletes recursively a (non-empty) array of directories
        Parameters:
        f -
        Returns:
        true in case the deletion has been successful
      • deleteDir

        public static boolean deleteDir​(File f)
        Deletes recursively a (non-empty) directory
        Parameters:
        f -
        Returns:
        true in case the deletion has been successful
      • stringBaseCurrencyId

        public static String stringBaseCurrencyId​(ConnectionProvider conn,
                                                  String strClientId)
                                           throws javax.servlet.ServletException
        Returns the ID of the base currency of the given client
        Parameters:
        strClientId - ID of client.
        Returns:
        Returns String strBaseCurrencyId with the ID of the base currency.
        Throws:
        javax.servlet.ServletException
      • getJSConfirmOnChanges

        public static String getJSConfirmOnChanges​(VariablesSecureApp vars,
                                                   String windowId)
        Build a JavaScript variable used for prompting a confirmation on changes
        Parameters:
        vars - Helper to access the user context
        windowId - Identifier of the window
        Returns:
        A string containing a JavaScript variable to be used by the checkForChanges function (utils.js)
      • stringToArrayList

        public static ArrayList<String> stringToArrayList​(String list)
        Transforms a comma separated String into an ArrayList
        Parameters:
        list -
        Returns:
        the list representation of the comma delimited String
      • stringToArrayList

        public static ArrayList<String> stringToArrayList​(String[] list)
        Transforms a String[] into an ArrayList
        Parameters:
        list -
        Returns:
        the list representation of the array
      • stringISOSymbol

        public static String stringISOSymbol​(ConnectionProvider conn,
                                             String strCurrencyID)
                                      throws javax.servlet.ServletException
        Returns the ISO code plus the symbol of the given currency in the form (ISO-SYM), e.g., (USD-$)
        Parameters:
        strCurrencyID - ID of the currency.
        Returns:
        Returns String strISOSymbol with the ISO code plus the symbol of the currency.
        Throws:
        javax.servlet.ServletException
      • getTabURL

        public static String getTabURL​(Tab tab,
                                       String type,
                                       boolean completeURL)
        Returns the URL for a tab
        Parameters:
        tab - The tab to obtain the url for
        type - "R" -> Relation, "E" -> Edition, "X" -> Excel
        completeURL - if true returns the complete ULR including server name and context, if not, it return URL relative to base context
        Returns:
        the URL for a tab.
      • getTabURL

        public static String getTabURL​(String tabId,
                                       String type,
                                       boolean completeURL)
        Returns the URL for a tab
        Parameters:
        tabId - Id for the tab to obtain the url for
        type - "R" -> Relation, "E" -> Edition, "X" -> Excel
        completeURL - if true returns the complete ULR including server name and context, if not, it return URL relative to base context
        Returns:
        the URL for a tab.
      • isBigDecimal

        public static boolean isBigDecimal​(String str)
        Determine if a String can be parsed into a BigDecimal.
        Parameters:
        str - a String
        Returns:
        true if the string can be parsed
      • mergeOpenbravoProperties

        public static boolean mergeOpenbravoProperties​(String originalFile,
                                                       String newFile)
                                                throws FileNotFoundException,
                                                       IOException
        When updating core it is necessary to update Openbravo properties maintaining already assigned properties. Thus properties in original file are preserved but the new ones in Openbravo.properties.template file are added with the default value.
        Returns:
        false in case no changes where needed, true in case the merge includes some changes and the original file is modified
        Throws:
        IOException
        FileNotFoundException
      • getListValueName

        public static String getListValueName​(String listName,
                                              String value,
                                              String lang)
        Returns the name for a value in a list reference in the selected language.
        Parameters:
        listName - Name for the reference list to look in
        value - Value to look for
        lang - Language, if null the default language will be returned
        Returns:
        Name for the value, in case the value is not found in the list the return is not the name but the passed value
      • arrayDobleEntrada

        public static String arrayDobleEntrada​(String strArrayName,
                                               FieldProvider[] data)
        Constructs and returns a two dimensional array of the data passed. Array definition is constructed according to Javascript syntax. Used to generate data storage of lists or trees within some manual windows/reports.
        Parameters:
        strArrayName - String with the name of the array to be defined.
        data - FieldProvider object with the data to be included in the array with the following three columns mandatory: padre | id | name.
        Returns:
        String containing array definition according to Javascript syntax.
      • arrayEntradaSimple

        public static String arrayEntradaSimple​(String strArrayName,
                                                FieldProvider[] data)
        Constructs and returns a two dimensional array of the data passed. Array definition is constructed according to Javascript syntax. Used to generate data storage of lists or trees within some manual windows/reports.
        Parameters:
        strArrayName - String with the name of the array to be defined.
        data - FieldProvider object with the data to be included in the array with the following two columns mandatory: id | name.
        Returns:
        String containing array definition according to Javascript syntax.
      • getReferenceValues

        public static String[] getReferenceValues​(ConnectionProvider connectionProvider,
                                                  String language,
                                                  String referenceId)
                                           throws javax.servlet.ServletException
        Gets the reference list for a particular reference id
        Parameters:
        connectionProvider -
        language -
        referenceId -
        Returns:
        refValues string array containing reference values
        Throws:
        javax.servlet.ServletException
      • getFormat

        public static DecimalFormat getFormat​(VariablesSecureApp vars,
                                              String typeName)
        Returns a DecimalFormat for the given formatting type contained in the Format.xml file
      • isNewUI

        public static boolean isNewUI()
        Checks whether the current context is using new UI
        Returns:
        true in case new UI is being used false if not
      • getImage

        public static byte[] getImage​(String id)
        Provides the image as a byte array. These images are stored in the table AD_IMAGE as a BLOB field.
        Parameters:
        id - The id of the image to display
        Returns:
        The image requested
      • getImageObject

        public static Image getImageObject​(String id)
        Provides the image as an image object. These images are stored in the table AD_IMAGE as a BLOB field.
        Parameters:
        id - The id of the image to display
        Returns:
        The image requested
        See Also:
        getImage(String)
      • getImageLogoObject

        public static Image getImageLogoObject​(String logo,
                                               String org)
        Provides the image logo as a byte array for the indicated parameters.
        Parameters:
        logo - The name of the logo to display This can be one of the following: yourcompanylogin, youritservicelogin, yourcompanymenu, yourcompanybig, yourcompanydoc, yourcompanylegal or banner-production
        org - The organization id used to get the logo In the case of requesting the yourcompanydoc logo you can indicate the organization used to request the logo.
        Returns:
        The image requested
      • getImageLogo

        public static byte[] getImageLogo​(String logo,
                                          String org)
        Provides the image logo as a byte array for the indicated parameters.
        Parameters:
        logo - The name of the logo to display This can be one of the following: yourcompanylogin, youritservicelogin, yourcompanymenu, yourcompanybig, yourcompanydoc, yourcompanylegal or banner-production
        org - The organization id used to get the logo In the case of requesting the yourcompanydoc logo you can indicate the organization used to request the logo.
        Returns:
        The image requested
      • computeImageSize

        public static Long[] computeImageSize​(byte[] bytea)
                                       throws IOException
        This method calculates the size of an image
        Parameters:
        bytea - The contents of the image
        Returns:
        An Long array with two elements (width, height)
        Throws:
        IOException
      • resizeImageByte

        public static byte[] resizeImageByte​(byte[] bytea,
                                             int maxW,
                                             int maxH,
                                             boolean maintainAspectRatio,
                                             boolean canMakeLargerImage)
                                      throws IOException
        Resize an image giving the image input as byte[]
        Parameters:
        bytea - The contents of the image as a byte array
        maxW - Maximum width that the image will be resized.
        maxH - Maximum height that the image will be resized.
        maintainAspectRatio - If true, the image will be resized exactly to the maximum parameters. If false, the imagen will be resized closest to the maximum parameters keeping aspect ratio
        canMakeLargerImage - If true and the original image is smaller than maximum parameters, the resized image could be larger than the original one. If false, not.
        Returns:
        The resized image
        Throws:
        IOException
      • showImageLogo

        public static BufferedImage showImageLogo​(String logo,
                                                  String org)
                                           throws IOException
        Provides the image logo as a BufferedImage object. Commonly used for reports.
        Parameters:
        logo - The name of the logo to display
        org - The organization id used to get the logo
        Returns:
        The image requested
        Throws:
        IOException
        See Also:
        getImageLogo(String,String)
      • isModalProcess

        public static boolean isModalProcess​(Process process)
        Returns whether the Process should be opened in modal or in poup mode.
        Parameters:
        process - Process to check
        Returns:
        true in case it should be opened in modal, false if not.
      • isModalProcess

        public static boolean isModalProcess​(String processId)
        Same as isModalProcess(Process) passing as parameter the process id.
        Parameters:
        processId - to check
        Returns:
        true in case it should be opened in modal, false if not.
        See Also:
        isModalProcess(Process)
      • getFieldName

        public static String getFieldName​(String fieldId,
                                          String language)
        Returns a field name in the specified language. If there is not translation for that language, it returns the base name of the field.
        Parameters:
        fieldId - ID of the field to look for.
        language - Language to get the name in.
        Returns:
        field name in the correct language.
      • getInStrSet

        public static String getInStrSet​(Set<String> set)
        Creates a comma separated string with the Id's of the Set of Strings.
        Parameters:
        set - Set of Strings
        Returns:
        Comma separated string of Id's
      • getCountryFromOrgId

        public static Country getCountryFromOrgId​(String orgid)
        Gets the country of the organization.
        Parameters:
        orgid - ID of the organization.
        Returns:
        the country of the organization or null if the organization address is not defined.
      • applyCountryDateFormat

        public static String applyCountryDateFormat​(Date date,
                                                    String orgid)
        Gets the date format for the organization country.
        Parameters:
        date - Date to apply the format.
        orgid - ID of the organization.
        Returns:
        date with the country format string applied. In case is not defined, a default format is applied
      • applyCountryDateFormat

        public static String applyCountryDateFormat​(Timestamp timeStamp,
                                                    String orgid)
        Gets the date format for the organization country.
        Parameters:
        timeStamp - TimeStamp to apply the format.
        orgid - ID of the organization.
        Returns:
        date with the country format string applied. In case is not defined, a default format is applied
      • getCountryNumberFormat

        public static DecimalFormat getCountryNumberFormat​(String orgid,
                                                           DecimalFormat defaultDecimalFormat)
        Gets the number format for the organization country.
        Parameters:
        orgid - ID of the organization.
        defaultDecimalFormat - Default decimal format. It will be returned in case the country of the organization is not defined.
        Returns:
        DecimalFormat for the number representation defined for the country.