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.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.service.dto.CasetivityEntityDTO
Get an instance of an entity 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
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",
...
}
-
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 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 with the corresponding id including the expanded path(s) if requested 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
- which field to sort the output by, defaults to id if nullsortAscending
- 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
-