I'd like to create a Spring Data Repository which should get exposed via Spring Data Rest.
The problem is my "entities" don't come from a database. I have several classes which have a custom annotation and get scanned, this provides some information which I like to expose to the client.
So basically I need something like:
@RestRepository(path="myClasses")
interface MyRepo extends Repository<MyClass, String> {
List<MyClass> findAll();
}
class MyRepoImpl implements MyRepo {
List<MyClass> classes;
MyRepoImpl() {
// fetch stuff via classpath scanning
// and save it to "classes"
}
@Override
List<MyClass> findAll() {
return classes;
}
}
I now copy & pasted about 10 files from Spring Data MongoDB in order to get a custom @EnableCustomRepositories
annotation with a custom FactoryBean, etc. pp. Lot's of stuff. And it still doesn't work...
Is there a simple way of doing this? Of course I could use a custom @Controller
, but then I can't use nice rel
in my other entities.
I really just need something that extends Repository<T, ID>
and create a few custom methods. Or do I have to use CrudRepository
so Spring Data Rest can find the findOne
and findAll
methods?
EDIT:
To be more precise:
My application has a lot of hardcoded Permissions
which get used by Spring Security. Each set of permissions has its own class. For example:
@Permission
class UserPermission {
public final static String RESET_PASSWORD = "USER_RESET_PASSWORD";
public final static String UPDATE_PROFILE = "USER_UPDATE_PROFILE";
}
Now there's also a persisted class called PermissionGroup
which gets persisted to DB. This is basically just:
class PermissionGroup {
ID id;
List<String> permissions;
}
What I want is, that I get those typical URLs from Spring Data Rest, which expose my Permissions. So I can use those URL references to add/remove a permission to/from a PermissionGroup. i.e.:
POST http://localhost:8080/app/permissionGroups
{
"permissions": [
{ "href" : "http://.../permissions/USER_RESET_PASSWORD" },
{ "href" : "http://.../permissions/USER_UPDATE_PROFILE" }
]
}