add type designations to NameService.delete (open issue: incorrect mapping for typeDe...
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / IService.java
index 86cfb283822c54da82b6855a60c5789430989cc2..2555a0d101d0e9b0a377fb8110591a12fe4b47fd 100644 (file)
@@ -17,14 +17,13 @@ import java.util.Map;
 import java.util.Set;\r
 import java.util.UUID;\r
 \r
+import org.hibernate.LockMode;\r
 import org.hibernate.Session;\r
-import org.springframework.transaction.annotation.Propagation;\r
-import org.springframework.transaction.annotation.Transactional;\r
+import org.springframework.security.core.Authentication;\r
 \r
 import eu.etaxonomy.cdm.api.service.pager.Pager;\r
-import eu.etaxonomy.cdm.model.common.CdmBase;\r
-import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
+import eu.etaxonomy.cdm.model.common.ICdmBase;\r
+import eu.etaxonomy.cdm.permission.CdmPermission;\r
 import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;\r
 import eu.etaxonomy.cdm.persistence.query.Grouping;\r
 import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
@@ -40,13 +39,32 @@ import eu.etaxonomy.cdm.persistence.query.OrderHint;
  *\r
  * @param <T>\r
  */\r
-@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)\r
-public interface IService<T extends CdmBase>{\r
+public interface IService<T extends ICdmBase>{\r
 \r
        // FIXME what does this method do?\r
-//     @Transactional(readOnly=false)\r
        public void clear();\r
-\r
+       \r
+       /**\r
+        * Obtain the specified lock mode on the given object t\r
+        */\r
+       public void lock(T t, LockMode lockMode);\r
+       \r
+       /**\r
+        * Refreshes a given object t using the specified lockmode\r
+        * \r
+     * All bean properties given in the <code>propertyPaths</code> parameter are recursively initialized.\r
+        * <p>\r
+        * For detailed description and examples <b>please refer to:</b> \r
+        * {@link BeanInitializer#initialize(Object, List)}\r
+        * \r
+        * NOTE: in the case of lockmodes that hit the database (e.g. LockMode.READ), you will need to re-initialize\r
+        * child propertiesto avoid a HibernateLazyInitializationException (even if the properties of the child \r
+        * were initialized prior to the refresh).\r
+        * \r
+        * @param t\r
+        * @param lockMode\r
+        */\r
+       public void refresh(T t, LockMode lockMode, List<String> propertyPaths);\r
        \r
        /**\r
         * Returns a count of all entities of type <T>  optionally restricted\r
@@ -63,7 +81,6 @@ public interface IService<T extends CdmBase>{
         * @param persistentObject the object to be deleted\r
         * @return the unique identifier of the deleted entity\r
         */\r
-       @Transactional(readOnly=false)\r
        public UUID delete(T persistentObject);\r
        \r
        /**\r
@@ -156,7 +173,6 @@ public interface IService<T extends CdmBase>{
         * @param transientObject the entity to be merged\r
         * @return The unique identifier of the persisted entity\r
         */\r
-       @Transactional(readOnly=false)\r
        public UUID merge(T transientObject);\r
        \r
        /**\r
@@ -188,7 +204,6 @@ public interface IService<T extends CdmBase>{
         * @param persistentObject the object to be refreshed\r
         * @return the unique identifier\r
         */\r
-       @Transactional(readOnly=false)\r
        public UUID refresh(T persistentObject);\r
        \r
        public List<T> rows(String tableName, int limit, int start);\r
@@ -199,7 +214,6 @@ public interface IService<T extends CdmBase>{
         * @return A Map containing the new entities, keyed using the generated UUID's\r
         *         of those entities\r
         */\r
-       @Transactional(readOnly=false)\r
        public Map<UUID,T> save(Collection<T> newInstances);    \r
        \r
        /**\r
@@ -207,7 +221,6 @@ public interface IService<T extends CdmBase>{
         * @param newInstance the new entity to be persisted\r
         * @return A generated UUID for the new persistent entity\r
         */\r
-       @Transactional(readOnly=false)\r
        public UUID save(T newInstance);\r
        \r
        /**\r
@@ -217,9 +230,17 @@ public interface IService<T extends CdmBase>{
         * @param transientObject the entity to be persisted\r
         * @return The unique identifier of the persisted entity\r
         */\r
-       @Transactional(readOnly=false)\r
        public UUID saveOrUpdate(T transientObject);\r
        \r
+       /**\r
+        * Save new entities or update the persistent state of existing \r
+        * transient entities that have been persisted previously\r
+        * \r
+        * @param transientObjects the entities to be persisted\r
+        * @return The unique identifier of the persisted entity\r
+        */\r
+       public Map<UUID,T> saveOrUpdate(Collection<T> transientObjects);\r
+       \r
     /**\r
         * Update the persistent state of an existing transient entity \r
         * that has been persisted previously\r
@@ -227,7 +248,6 @@ public interface IService<T extends CdmBase>{
         * @param transientObject the entity to be persisted\r
         * @return The unique identifier of the persisted entity\r
         */\r
-       @Transactional(readOnly=false)\r
        public UUID update(T transientObject);\r
        \r
        /**\r
@@ -254,4 +274,14 @@ public interface IService<T extends CdmBase>{
         * @return a list of matching objects\r
         */\r
        public List<T> list(T example, Set<String> includeProperties, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);\r
+       \r
+       /**\r
+     * Evaluates whether the authenticated user has the rights to perform an specific action on the target object\r
+     * @param authentication\r
+     * @param target\r
+     * @param permission\r
+     * @return\r
+     */\r
+       public boolean hasPermission(Authentication authentication, T target, CdmPermission permission);\r
+\r
 }
\ No newline at end of file