com.ibm.openpages.api.resource.util

## Class ResourceUtil

- java.lang.Object
- - com.ibm.openpages.api.resource.util.ResourceUtil

-     public final class ResourceUtil
      extends java.lang.Object

  Resource utility class. It provides utility methods to manage object paths and fields.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `addObjectNameToPath(java.lang.String relativePath)` Adds an object name to the path, for example: input: /Company ABC/AsiaPac output: /Company ABC/AsiaPac/AsiaPac See unit test for more details.
    `static java.lang.String` | `getBundleName(java.lang.String bundleFieldPath)` Gets the name of the Bundle from the bundleFieldPath.
    `static java.lang.String` | `getFieldName(java.lang.String bundleFieldPath)` Gets the name of the Field from the bundleFieldPath.
    `static java.lang.String` | `getFullPath(ContentType contentType, java.lang.String rawPath)`
    `static java.lang.String` | `getFullPath(java.lang.String relativePath, boolean isFolder, ITypeDefinition typeDefinition)` Returns full resource path provided relative path, boolean isFolder and the ITypeDefinition for the GRCObject.
    `static java.lang.String` | `getFullPath(java.lang.String path, boolean isFolder, java.util.List<ITypeDefinition> typeDefinitions)` Returns full resource path provided relative path, boolean isFolder, and list of all ITypeDefinitions.
    `static java.util.List<IField>` | `getModifiedFields(IGRCObject grcObject)` Gets a list of Fields that have been modified on the GRCObject before it is saved (committed).
    `static java.lang.Object` | `getOriginalValueForField(java.lang.String bundleFieldPath, IGRCObject object)` Gets the original value of an IField object by using bundleFieldPath.
    `static java.lang.String` | `getRelativePath(java.lang.String fullPath, ITypeDefinition typeDefinition)` Returns relative path of the IResource provided full path and ITypedefinition.
    `static java.lang.String` | `getRelativePath(java.lang.String fullPath, java.util.List<ITypeDefinition> typeDefinitions)` Returns relative path of the IResource provided full path and List of all ITypeDefinitions.
    `static java.lang.String` | `getRelativePath(java.lang.String fullPath, java.lang.String rootFolderPath)` Returns relative path of the IResource provided full path, and root folder path.
    `static java.lang.String` | `getRelativePath(java.lang.String fullPath, java.lang.String rootFolderPath, boolean excludeFolderName)` Returns relative path of the IResource provided full path, and root folder path.
    `static int` | `getResourceLevel(ContentType contentType, Resource resource)` Global Financial Services / Corporate / HR --> 3 Global Financial Services / Corporate --> 2 -> 0 Note: this seems like a hack to calculate the level based on the path rather than doing a proper lookup.
    `static void` | `setFieldValue(IField field, java.lang.Object value)` Sets the value of the Field with the object specified.
    `static java.lang.String` | `trimPathWhitespace(java.lang.String path)` Trims whitespace around path delimiters, i.e.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### setFieldValue

          public static void setFieldValue(IField field,
                                           java.lang.Object value)

           Sets the value of the Field with the object specified.
           The Field should be of Type ICurrencyField, IBooleanField, IReferenceField,
           IIntegerField, IDateField, IEnumField, IFloatField, IMultiEnumField, or
           IStringField.

           CurrencyField
           The value object should be a String array.
           object[0] should have com.ibm.openpages.api.configuration.ICurrency Metadata.
           object[1] should have local amount.
           object[2] should have exchange rate (optional).

           BooleanField
           Value object should be of type Boolean.

           IntegerField
           Value object should be of type Integer.

           StringField
           Value object should be of type String.

           DateField
           Value object should of of type Date.

           FloatField
           Value object should be of type Float.

           EnumField
           Value object should be of type String.

           MultiEnumField
           Value object should be String array.

           IReferenceField
           Value object should be of type String, representing an Id.

      Parameters:
        `field` - (required) field whose value needs to be changed
        `value` - the value of the field

    - #### getRelativePath

          public static java.lang.String getRelativePath(java.lang.String fullPath,
                                                         java.util.List<ITypeDefinition> typeDefinitions)

      Returns relative path of the IResource provided full path and List of all ITypeDefinitions. If IGRCObject or IFolder, relative path will be returned; otherwise, full path is returned.

      Parameters:
        `fullPath` - the full path
        `typeDefinitions` - the List of ITypeDefinition
      Returns:
        path the relative path

    - #### getRelativePath

          public static java.lang.String getRelativePath(java.lang.String fullPath,
                                                         ITypeDefinition typeDefinition)

      Returns relative path of the IResource provided full path and ITypedefinition. If IGRCObject or IFolder, relative path will be returned; otherwise, full path is returned.

      Parameters:
        `fullPath` - the full path
        `typeDefinition` - the ITypeDefinition
      Returns:
        path the relative path

    - #### getRelativePath

          public static java.lang.String getRelativePath(java.lang.String fullPath,
                                                         java.lang.String rootFolderPath)

      Returns relative path of the IResource provided full path, and root folder path. If IGRCObject or IFolder, relative path will be returned; otherwise, full path is returned.

      Parameters:
        `fullPath` - the full path
        `rootFolderPath` - the root folder path
      Returns:
        path the relative path

    - #### getRelativePath

          public static java.lang.String getRelativePath(java.lang.String fullPath,
                                                         java.lang.String rootFolderPath,
                                                         boolean excludeFolderName)

      Returns relative path of the IResource provided full path, and root folder path. If IGRCObject or IFolder, relative path will be returned; otherwise, full path is returned.

      Parameters:
        `fullPath` - the full path
        `rootFolderPath` - the root folder path
        `excludeFolderName` - if 'true' will exclude the root Object Type folder name from the relative path.
      Returns:
        path the relative path

    - #### getFullPath

          public static java.lang.String getFullPath(java.lang.String path,
                                                     boolean isFolder,
                                                     java.util.List<ITypeDefinition> typeDefinitions)

      Returns full resource path provided relative path, boolean isFolder, and list of all ITypeDefinitions. Parameters are used to match the relative path against a particular type, which is used to construct the actual Full path for the resource. If the relative path belongs to a folder, then the isFolder value is true.

      Parameters:
        `path` - the relative path including the type's root folder without a leading folder separator '/'. e.g. "BusinessEntity/Company ABC/AsiaPac/AsiaPac"
        `isFolder` -
        `typeDefinitions` - the List of possible ITypeDefinition to try to match the relative path against
      Returns:
        path the full path
      See Also:
        `IMetaDataService#getTypes()}`

    - #### addObjectNameToPath

          public static java.lang.String addObjectNameToPath(java.lang.String relativePath)

      Adds an object name to the path, for example: input: /Company ABC/AsiaPac output: /Company ABC/AsiaPac/AsiaPac See unit test for more details. Also trims internal whitespace surrounding path delimiters.
      Parameters:
        `relativePath` - (required)
      Returns:

    - #### trimPathWhitespace

          public static java.lang.String trimPathWhitespace(java.lang.String path)

      Trims whitespace around path delimiters, i.e. 'level1 / level2' becomes 'level1/level2'
      Parameters:
        `path` - A path delimited by StringUtil.PATH_DELIMITER
      Returns:
        Same path with whitespace around delimiters trimmed

    - #### getFullPath

          public static java.lang.String getFullPath(ContentType contentType,
                                                     java.lang.String rawPath)

      Parameters:
        `contentType` - Usually the Business Entity content type
        `rawPath` - Example: "Global Financial Services / Corporate / HR"
      Returns:
        Example: "/_op_sox/Project/Default/BusinessEntity/Global Financial Services/Corporate/HR/HR.txt"

    - #### getResourceLevel

          public static int getResourceLevel(ContentType contentType,
                                             Resource resource)

      Global Financial Services / Corporate / HR --> 3 Global Financial Services / Corporate --> 2 -> 0 Note: this seems like a hack to calculate the level based on the path rather than doing a proper lookup. I could not find any way to do a lookup unfortunately.
      Parameters:
        `contentTypeFullPath` -
        `resource` - A resource with a path like: "Global Financial Services / Corporate / HR"
      Returns:
        It would be 3 in the example above

    - #### getFullPath

          public static java.lang.String getFullPath(java.lang.String relativePath,
                                                     boolean isFolder,
                                                     ITypeDefinition typeDefinition)

      Returns full resource path provided relative path, boolean isFolder and the ITypeDefinition for the GRCObject. Parameters are used to construct the actual Full path for the resource. If the relative path belongs to a folder, then the isFolder value is true.

      This method does not validate whether the path is for an actual GRCObject.

      Parameters:
        `relativePath` - (required) the relative path including a leading folder separator '/'. e.g. "/Company ABC/AsiaPac/AsiaPac", Note, it does not include extensions for GRCObjects
        `isFolder` - (required) true if the path is for a folder and false if the path is for a GRCObject
        `typeDefinition` - (required) the TypeDefinition for the object being retrieved
      Returns:
        the full path for the object including the type's root folder path

    - #### getModifiedFields

          public static java.util.List<IField> getModifiedFields(IGRCObject grcObject)
                                                          throws java.lang.Exception

      Gets a list of Fields that have been modified on the GRCObject before it is saved (committed).
      Parameters:
        `grcObject` - the GRC Object
      Returns:
        get a list of modified fields from the GRC Object
      Throws:
        `java.lang.Exception`

    - #### getOriginalValueForField

          public static java.lang.Object getOriginalValueForField(java.lang.String bundleFieldPath,
                                                                  IGRCObject object)
                                                           throws java.lang.Exception

      Gets the original value of an IField object by using bundleFieldPath.
      Parameters:
        `bundleFieldPath` - (required) colon-separated path of bundle and field
        `object` - IGRCObject which has the bundle and field identified in bundleFieldPath
      Returns:
        Object value
      Throws:
        `java.lang.Exception`

    - #### getBundleName

          public static java.lang.String getBundleName(java.lang.String bundleFieldPath)

      Gets the name of the Bundle from the bundleFieldPath.
      Parameters:
        `bundleFieldPath` - (required) colon-separated bundle field path. i.e. Bundle:Field
      Returns:
        the Bundle name

    - #### getFieldName

          public static java.lang.String getFieldName(java.lang.String bundleFieldPath)

      Gets the name of the Field from the bundleFieldPath.
      Parameters:
        `bundleFieldPath` - (required) colon-separated bundle field path. i.e. Bundle:Field
      Returns:
        the Field name

Licensed Materials - Property of IBM
OpenPages with Watson (PID: 5725-D51)
© Copyright IBM Corporation 2013, 2022. All Rights Reserved.
US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.