Class EntityUtil
java.lang.Object
com.ssgllc.fish.service.util.published.EntityUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.ssgllc.fish.service.dto.CasetivityEntityDTOcreateEntity(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 voiddeleteEntity(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.CasetivityEntityDTOfindEntity(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.CasetivityEntitygetDomainEntity(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.CasetivityEntityDTOGet 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 com.ssgllc.fish.service.dto.CasetivityEntityDTOgetEntityAsCurrentUser(String entityType, Object entityId, String expansion) Get an instance of an entity DTO object based on its id, enforcing the current user's security permissions, or null if not found or not accessible.
UnlikegetEntity(String, Object, String), this method does not bypass row-level security.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.CasetivityEntityDTOCreates 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",
...
}
-
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 getentityId- the id of the entity to get as a String or UUIDexpansion- 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
-
getEntityAsCurrentUser
public static com.ssgllc.fish.service.dto.CasetivityEntityDTO getEntityAsCurrentUser(String entityType, Object entityId, String expansion) Get an instance of an entity DTO object based on its id, enforcing the current user's security permissions, or null if not found or not accessible.
UnlikegetEntity(String, Object, String), this method does not bypass row-level security. Use it when the fetch should be subject to the same visibility rules as a normal user-initiated request (e.g. inside a script that runs on behalf of the authenticated caller).
Example:
return entityUtil.getEntityAsCurrentUser('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 getentityId- the id of the entity to get as a String or UUIDexpansion- 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 or not accessible to the current user
-
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, usegetEntity(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 getentityId- 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 findfieldName- the name of the field to match againstfieldValue- the value of the field to match withexpansion- 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 searchsearchFields- map of search criteria to values to filter the target entity bysearchResultLimit- maximum number of results to return, can be used in conjunction with page, any value less than zero has no limitpage- 0-indexed page you are requesting results forsortBy- 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 listsortAscending- 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 createfields- 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 updateentityId- the id of the entity to update as a String or UUIDfields- map of field names to values to use when updating the target entity- Returns:
- the updated entity object
-
deleteEntity
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 deleteentityId- the id of the entity to delete as a String or UUID
-