Class AbstractCrudService<E extends PersistentObject,D extends GenericHibernateDao<E,Integer>>
- java.lang.Object
-
- de.terrestris.shoguncore.service.AbstractDaoService<E,D>
-
- de.terrestris.shoguncore.service.AbstractCrudService<E,D>
-
- Direct Known Subclasses:
PermissionAwareCrudService,PermissionCollectionService
public abstract class AbstractCrudService<E extends PersistentObject,D extends GenericHibernateDao<E,Integer>> extends AbstractDaoService<E,D>
This abstract service class provides basic CRUD functionality.- Author:
- Nils Bühner
- See Also:
AbstractDaoService
-
-
Field Summary
-
Fields inherited from class de.terrestris.shoguncore.service.AbstractDaoService
dao, logger
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCrudService(Class<E> entityClass)Constructor that sets the concrete entity class for the service.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete(E e)List<E>findAll()List<E>findAllRestricted(org.springframework.util.MultiValueMap<String,String> restrictToRequest)Returns all entities, but possibly with only the passed fields set with actual values.List<E>findAllWhereFieldEquals(String fieldName, Object fieldValue)Returns a list of entity objects that have field namedfieldName, which has an objectfieldEntityas value.List<E>findAllWithCollectionContaining(String fieldName, PersistentObject subElement)Returns a list of entity objects that have a collection namedfieldName, which contains the passedsubElement.EfindById(Integer id)Return the real object from the database.List<E>findBySimpleFilter(org.springframework.util.MultiValueMap<String,String> requestedFilter)Finds all entities that match the given filter (multi value map).EloadById(int id)Return a proxy of the object (without hitting the database).voidsaveOrUpdate(E e)EupdatePartialWithJsonNode(E entity, com.fasterxml.jackson.databind.JsonNode jsonObject, com.fasterxml.jackson.databind.ObjectMapper objectMapper)-
Methods inherited from class de.terrestris.shoguncore.service.AbstractDaoService
getDao, getEntityClass, setDao
-
-
-
-
Method Detail
-
saveOrUpdate
@PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or (#e.id == null and hasPermission(#e, \'CREATE\')) or (#e.id != null and hasPermission(#e, \'UPDATE\'))") public void saveOrUpdate(E e)- Parameters:
e-
-
updatePartialWithJsonNode
@PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#entity, \'UPDATE\')") public E updatePartialWithJsonNode(E entity, com.fasterxml.jackson.databind.JsonNode jsonObject, com.fasterxml.jackson.databind.ObjectMapper objectMapper) throws IOException, com.fasterxml.jackson.core.JsonProcessingException- Parameters:
jsonObject-entity-- Returns:
- Throws:
IOExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
findById
@PostAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(returnObject, \'READ\')") @Transactional(readOnly=true) public E findById(Integer id)Return the real object from the database. Returns null if the object does not exist.- Parameters:
id-
-
loadById
@PostAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(returnObject, \'READ\')") @Transactional(readOnly=true) public E loadById(int id)Return a proxy of the object (without hitting the database). This should only be used if it is assumed that the object really exists and where non-existence would be an actual error.- Parameters:
id-
-
findAll
@PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, \'READ\')") @Transactional(readOnly=true) public List<E> findAll()
-
findAllRestricted
@PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, \'READ\')") public List<E> findAllRestricted(org.springframework.util.MultiValueMap<String,String> restrictToRequest)Returns all entities, but possibly with only the passed fields set with actual values.
-
findBySimpleFilter
@PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, \'READ\')") @Transactional(readOnly=true) public List<E> findBySimpleFilter(org.springframework.util.MultiValueMap<String,String> requestedFilter)Finds all entities that match the given filter (multi value map).Each key in the multi value map is the name of a field/property of the entity. These values may be case insensitive! Each field name is mapped to a list of values (passed as Strings).
Fields that do not exist in the entity will be ignored.
Example:
int=['1','2'] string=['foo'] bool1=['0'] bool2=['true']
would be translated to a filter like (values are casted to the target type of the field)
(int == 1 || int == 2) && (string == 'foo') && (bool1 == false) && (bool2 == true)
and return all entities that match this condition.
This will only work on simple properties of an entity.
The optional special key "output:only" can contain a comma separated list of fieldNames you want to be filled with actual values. If you e.g. pass
output:only=id,Name, the returned object will have all other fields being set to null, except foridandname(Notice how casing does not matter).- Parameters:
requestedFilter-- Returns:
-
findAllWhereFieldEquals
@PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, \'READ\')") @Transactional(readOnly=true) public List<E> findAllWhereFieldEquals(String fieldName, Object fieldValue)Returns a list of entity objects that have field namedfieldName, which has an objectfieldEntityas value.- Parameters:
fieldName- The name of the fieldfieldValue- The element that should be set as value- Returns:
- The list of objects
-
findAllWithCollectionContaining
@PostFilter("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(filterObject, \'READ\')") @Transactional(readOnly=true) public List<E> findAllWithCollectionContaining(String fieldName, PersistentObject subElement)Returns a list of entity objects that have a collection namedfieldName, which contains the passedsubElement.The can e.g. be used to return all applications that contain a certain layer.
- Parameters:
fieldName- The name of the collection fieldsubElement- The element that should be contained in the collection- Returns:
- The list of objects
-
delete
@PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#e, \'DELETE\')") public void delete(E e)- Parameters:
e-
-
-