Class EntityUtil

java.lang.Object
com.ssgllc.fish.service.util.published.EntityUtil

@Component public final class EntityUtil extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.ssgllc.fish.service.dto.CasetivityEntityDTO
    createEntity(String entityType, Map<String,Object> fields)
    Creates an entity of a particular type based on values provided and returns the created entity.

    Example:
    def fields = [:];
    fields.name = 'NewTemplate';
    fields.text = 'hello world';
    fields.templateTypeCode = 'PAGE';
    return entityUtil.createEntity('TextTemplate', fields);

    Returns:
    {
    "@id": "1",
    "id": "c0a83801-876b-191c-8187-6d75a77a0000",
    "entityVersion": 1,
    "entityType": "TextTemplate",
    ...
    }
    static void
    deleteEntity(String entityType, Object entityId)
    Delete an instance of an entity object based on its id.

    Example:
    entityUtil.deleteEntity('TextTemplate', 'c0a83801-876b-191c-8187-6d8d1b9d0003');

    static com.ssgllc.fish.service.dto.CasetivityEntityDTO
    findEntity(String entityType, String fieldName, String fieldValue, String expansion)
    Find a single instance of an entity object based on an exact match of a particular field or null if not found or more than one matches found.

    Example:
    return entityUtil.findEntity('TextTemplate', 'name', 'EnvConfig', null);

    Returns:
    {
    "@id": "1",
    "id": "c0a83801-8757-1958-8187-57c26eb42923",
    "entityVersion": 1,
    "entityType": "TextTemplate",
    ...
    }
    static com.ssgllc.fish.domain.CasetivityEntity
    getDomainEntity(String entityType, Object entityId)
    Get an instance of a domain entity object based on its id or null if not found.
    static com.ssgllc.fish.service.dto.CasetivityEntityDTO
    getEntity(String entityType, Object entityId, String expansion)
    Get an instance of an entity DTO object based on its id or null if not found.

    Example:
    return entityUtil.getEntity('TextTemplate', 'c0a83801-8757-1958-8187-57c296c2292b', 'roles');

    Returns:
    {
    "@id": "1",
    "id": "c0a83801-8757-1958-8187-57c296c2292b",
    "entityVersion": 1,
    "entityType": "TextTemplate",
    ...
    "roles": [...],
    "rolesIds": [...],
    ...
    }
    static List<com.ssgllc.fish.service.dto.CasetivityEntityDTO>
    searchEntity(String entityType, Map<String,Object> searchFields, int searchResultLimit, int page, String sortBy, boolean sortAscending, String expansion)
    Search for entities of a particular type matching a series of filter criterias.

    Example:
    def searchFields = [:];
    searchFields['templateType.code.equals'] = 'SCRIPT';
    return entityUtil.searchEntity('TextTemplate', searchFields, -1, 0, 'name', true, null);

    Returns:
    [{
    "@id": "1",
    "id": "c0a83801-8757-1958-8187-57c1033428db",
    "entityVersion": 1,
    "entityType": "TextTemplate",
    ...
    },{
    "@id": "1",
    "id": "c0a83801-8757-1958-8187-57c1093428dc",
    "entityVersion": 1,
    "entityType": "TextTemplate",
    ...
    }...
    }]
    static com.ssgllc.fish.service.dto.CasetivityEntityDTO
    updateEntity(String entityType, Object entityId, Map<String,Object> fields)
    Creates an entity of a particular type based on values provided and returns the created entity.

    Example:
    def fields = [:];
    fields.text = "entityUtil.getEntity('TextTemplate', 'c0a83801-876b-191c-8187-6d75a77a0000', null);";
    fields.templateTypeCode = 'SCRIPT';
    return entityUtil.updateEntity('TextTemplate', 'c0a83801-876b-191c-8187-6d7b77fd0002', fields);

    Returns:
    {
    "@id": "1",
    "id": "c0a83801-876b-191c-8187-6d7b77fd0002",
    "entityVersion": 1,
    "entityType": "TextTemplate",
    ...
    }

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EntityUtil

      public EntityUtil()
  • Method Details

    • getEntity

      public static com.ssgllc.fish.service.dto.CasetivityEntityDTO getEntity(String entityType, Object entityId, String expansion)
      Get an instance of an entity DTO object based on its id or null if not found.

      Example:
      return entityUtil.getEntity('TextTemplate', 'c0a83801-8757-1958-8187-57c296c2292b', 'roles');

      Returns:
      {
      "@id": "1",
      "id": "c0a83801-8757-1958-8187-57c296c2292b",
      "entityVersion": 1,
      "entityType": "TextTemplate",
      ...
      "roles": [...],
      "rolesIds": [...],
      ...
      }
      Parameters:
      entityType - the type of entity to get
      entityId - the id of the entity to get as a String or UUID
      expansion - expression specifying the path(s) to expand in the resulting object, pass null or empty string for no expansion
      Returns:
      the entity object DTO with the corresponding id including the expanded path(s) if requested or null if not found
    • getDomainEntity

      public static com.ssgllc.fish.domain.CasetivityEntity getDomainEntity(String entityType, Object entityId)
      Get an instance of a domain entity object based on its id or null if not found. NOTE: this is generally only used in a save script or for very specific purposes, use getEntity(String, Object, String) instead if you are not sure you need this.

      Example:
      return entityUtil.getDomainEntity('TextTemplate', 'c0a83801-8757-1958-8187-57c296c2292b');

      Returns: A domain object with the matching id
      Parameters:
      entityType - the type of entity to get
      entityId - the id of the entity to get as a String or UUID
      Returns:
      the domain entity object with the corresponding id or null if not found
    • findEntity

      public static com.ssgllc.fish.service.dto.CasetivityEntityDTO findEntity(String entityType, String fieldName, String fieldValue, String expansion)
      Find a single instance of an entity object based on an exact match of a particular field or null if not found or more than one matches found.

      Example:
      return entityUtil.findEntity('TextTemplate', 'name', 'EnvConfig', null);

      Returns:
      {
      "@id": "1",
      "id": "c0a83801-8757-1958-8187-57c26eb42923",
      "entityVersion": 1,
      "entityType": "TextTemplate",
      ...
      }
      Parameters:
      entityType - the type of entity to find
      fieldName - the name of the field to match against
      fieldValue - the value of the field to match with
      expansion - expression specifying the path(s) to expand in the resulting object, pass null or empty string for no expansion
      Returns:
      the entity object that has the value of fieldValue for the fieldName field or null if none or more than one match found
    • searchEntity

      public static List<com.ssgllc.fish.service.dto.CasetivityEntityDTO> searchEntity(String entityType, Map<String,Object> searchFields, int searchResultLimit, int page, String sortBy, boolean sortAscending, String expansion)
      Search for entities of a particular type matching a series of filter criterias.

      Example:
      def searchFields = [:];
      searchFields['templateType.code.equals'] = 'SCRIPT';
      return entityUtil.searchEntity('TextTemplate', searchFields, -1, 0, 'name', true, null);

      Returns:
      [{
      "@id": "1",
      "id": "c0a83801-8757-1958-8187-57c1033428db",
      "entityVersion": 1,
      "entityType": "TextTemplate",
      ...
      },{
      "@id": "1",
      "id": "c0a83801-8757-1958-8187-57c1093428dc",
      "entityVersion": 1,
      "entityType": "TextTemplate",
      ...
      }...
      }]
      Parameters:
      entityType - the type of entity to search
      searchFields - map of search criteria to values to filter the target entity by
      searchResultLimit - maximum number of results to return, can be used in conjunction with page, any value less than zero has no limit
      page - 0-indexed page you are requesting results for
      sortBy - comma separated list of which field(s) to sort the output by, defaults to id if null and appends id to the end if not already in sort list
      sortAscending - whether to sort ascending (true) or descending (false)
      expansion - expression specifying the path(s) to expand in the resulting object, pass null or empty string for no expansion
      Returns:
      a list of matching entities up to the searchResultLimit starting at the page index ordered by the specified sort or an empty list if no matches
    • createEntity

      public static com.ssgllc.fish.service.dto.CasetivityEntityDTO createEntity(String entityType, Map<String,Object> fields)
      Creates an entity of a particular type based on values provided and returns the created entity.

      Example:
      def fields = [:];
      fields.name = 'NewTemplate';
      fields.text = 'hello world';
      fields.templateTypeCode = 'PAGE';
      return entityUtil.createEntity('TextTemplate', fields);

      Returns:
      {
      "@id": "1",
      "id": "c0a83801-876b-191c-8187-6d75a77a0000",
      "entityVersion": 1,
      "entityType": "TextTemplate",
      ...
      }
      Parameters:
      entityType - the type of entity to create
      fields - map of field names to values to use when creating the target entity
      Returns:
      the created entity object
    • updateEntity

      public static com.ssgllc.fish.service.dto.CasetivityEntityDTO updateEntity(String entityType, Object entityId, Map<String,Object> fields)
      Creates an entity of a particular type based on values provided and returns the created entity.

      Example:
      def fields = [:];
      fields.text = "entityUtil.getEntity('TextTemplate', 'c0a83801-876b-191c-8187-6d75a77a0000', null);";
      fields.templateTypeCode = 'SCRIPT';
      return entityUtil.updateEntity('TextTemplate', 'c0a83801-876b-191c-8187-6d7b77fd0002', fields);

      Returns:
      {
      "@id": "1",
      "id": "c0a83801-876b-191c-8187-6d7b77fd0002",
      "entityVersion": 1,
      "entityType": "TextTemplate",
      ...
      }
      Parameters:
      entityType - the type of entity to update
      entityId - the id of the entity to update as a String or UUID
      fields - map of field names to values to use when updating the target entity
      Returns:
      the updated entity object
    • deleteEntity

      public static void deleteEntity(String entityType, Object entityId)
      Delete an instance of an entity object based on its id.

      Example:
      entityUtil.deleteEntity('TextTemplate', 'c0a83801-876b-191c-8187-6d8d1b9d0003');

      Parameters:
      entityType - the type of entity to delete
      entityId - the id of the entity to delete as a String or UUID