This commit is contained in:
Raf Ponsaerts
2020-03-13 13:43:54 +01:00
parent 32d48ecff7
commit b19c4022ac
2 changed files with 19 additions and 0 deletions

View File

@@ -16,6 +16,13 @@ public interface LinkRestRepository {
default boolean isEmbeddableRelation(Object data, String name) {
return true;
}
/**
* Defines whether a relation can create a link to it on the resource or not
* @param data The data for the link
* @param name The name of the link
* @return A boolean indicating whether it's allowed or not
*/
default boolean isLinkableRelation(Object data, String name) {
return true;
}

View File

@@ -537,11 +537,23 @@ public class Utils {
});
}
/**
* Calls on the LinkRepository to ask whether it's allowed to embed said relation
* @param resource The current HalResource
* @param rel The relation to be asked if it can be embedded
* @return A boolean indicating the result
*/
private boolean allowEmbeddingFromLinkRepository(HALResource<? extends RestAddressableModel> resource, String rel) {
return getLinkResourceRepository(resource.getContent().getCategory(),
resource.getContent().getType(), rel).isEmbeddableRelation(resource.getContent(), rel);
}
/**
* Calls on the LinkRepository to ask whether it's allowed to link to said relation
* @param resource The current HalResource
* @param rel The relation to be asked if it can be linked to
* @return A boolean indicating the result
*/
private boolean allowLinkingFromLinkRepository(HALResource<? extends RestAddressableModel> resource, String rel) {
return getLinkResourceRepository(resource.getContent().getCategory(),