0

For some logging purpose, i'm using AspectJ to log CRUD operations, for the delete operation i'm supporting only repository.delete(object) so repository.delete(id) is not supported, but while using http DELETE call in Spring Data repository, i intercept repository.findOne() then repository.delete(id) calls.

My Question

How i could customize Http DELETE method in Spring Data repository to call repository.delete(object) not repository.delete(id).

here's repository interface:

package com.geopro.repositories; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import com.geopro.entities.Product; @RepositoryRestResource(collectionResourceRel = "product", path = "product") public interface ProductRepository extends PagingAndSortingRepository<Product, Long> { } 

AspectJ code :

@Pointcut("execution(public * org.springframework.data.repository.Repository+.*(..))") public void publicNonVoidRepositoryMethod() { } @Around("publicNonVoidRepositoryMethod()") public Object publicNonVoidRepositoryMethod(ProceedingJoinPoint pjp) throws Throwable { if (pjp.getArgs()[0].getClass().getName() == "java.util.Arrays$ArrayList" || pjp.getArgs()[0].getClass().getName() == "java.util.LinkedList") { Iterable arr = (Iterable) pjp.getArgs()[0]; return saveHistoriqueOperation2(pjp, arr); } else { Object objs = pjp.getArgs()[0]; if (objs.getClass().getName() == "com.geopro.entities.HistOperation") { Object o = pjp.proceed(); return o; } return saveHistoriqueOperation(pjp, objs); } } 

i'm managing cases where objs is an entity object, so all my delete operations are using delete(entity_object), not delete(id), i'm looking for a manner to modify function calls where http DELETE 'ressource_url/id' gets called.

Thanks in advance

2
  • Can you kindly share some piece of code. It is not exactly clear what you're trying to do. Commented Mar 9, 2015 at 15:12
  • Just repository declaration wouldn't help. We need to know what expression you used. The methods which you wanted to intercept, and how the other method is getting intercepted.. Try to give some relevant information.. Commented Mar 9, 2015 at 15:19

1 Answer 1

1

Have you tried with @RestResource(exported = false) on the delete(id) method?

I just created a simple project and it seems to work.

Here is the code of the repository class in my project

public interface ProductRepository extends PagingAndSortingRepository<Product, Long> { @RestResource(exported = false) @Override void delete(Long var1); @Override void delete(Product var1); } 
Sign up to request clarification or add additional context in comments.

1 Comment

what would be URI for delete request in Postman or curl and my scanario is here <br> stackoverflow.com/questions/43399225/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.