DATAREST-446 - Removed RepositoriesUtils in favor of RepositoryMetadata.
To be sure to pick up domain type lookup customizations we now consistently use RepositoryMetadata instead of trying to be clever and re-detecting it via RepositoriesUtils.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -186,7 +186,7 @@ class RepositoryAwareResourceInformation implements ResourceMetadata {
|
||||
*/
|
||||
@Override
|
||||
public SearchResourceMappings getSearchResourceMappings() {
|
||||
return provider.getSearchResourceMappings(repositoryInterface.getRepositoryInterface());
|
||||
return provider.getSearchResourceMappings(repositoryInterface.getDomainType());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,6 @@ import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.data.rest.core.support.RepositoriesUtils;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -63,13 +62,11 @@ class RepositoryCollectionResourceMapping implements CollectionResourceMapping {
|
||||
public RepositoryCollectionResourceMapping(RepositoryMetadata metadata, RelProvider relProvider) {
|
||||
|
||||
Assert.notNull(metadata, "Repository metadata must not be null!");
|
||||
this.metadata = metadata;
|
||||
Assert.notNull(relProvider, "RelProvider must not be null!");
|
||||
|
||||
Class<?> repositoryType = metadata.getRepositoryInterface();
|
||||
|
||||
Assert.isTrue(RepositoriesUtils.isRepositoryInterface(repositoryType), "Given type is not a repository!");
|
||||
Assert.notNull(relProvider, "RelProvider must not be null!");
|
||||
|
||||
this.metadata = metadata;
|
||||
this.annotation = AnnotationUtils.findAnnotation(repositoryType, RestResource.class);
|
||||
this.repositoryAnnotation = AnnotationUtils.findAnnotation(repositoryType, RepositoryRestResource.class);
|
||||
this.repositoryIsExportCandidate = Modifier.isPublic(repositoryType.getModifiers());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,6 @@ import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.Description;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.core.support.RepositoriesUtils;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -118,15 +117,9 @@ public class RepositoryResourceMappings implements ResourceMappings {
|
||||
* @see org.springframework.data.rest.core.mapping.ResourceMappings#getSearchResourceMappings(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public SearchResourceMappings getSearchResourceMappings(Class<?> type) {
|
||||
public SearchResourceMappings getSearchResourceMappings(Class<?> domainType) {
|
||||
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
|
||||
if (searchCache.containsKey(type)) {
|
||||
return searchCache.get(type);
|
||||
}
|
||||
|
||||
Class<?> domainType = RepositoriesUtils.getDomainType(type);
|
||||
Assert.notNull(domainType, "Type must not be null!");
|
||||
|
||||
if (searchCache.containsKey(domainType)) {
|
||||
return searchCache.get(domainType);
|
||||
@@ -147,7 +140,6 @@ public class RepositoryResourceMappings implements ResourceMappings {
|
||||
}
|
||||
|
||||
SearchResourceMappings searchResourceMappings = new SearchResourceMappings(mappings);
|
||||
searchCache.put(type, searchResourceMappings);
|
||||
searchCache.put(domainType, searchResourceMappings);
|
||||
return searchResourceMappings;
|
||||
}
|
||||
@@ -200,10 +192,6 @@ public class RepositoryResourceMappings implements ResourceMappings {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (RepositoriesUtils.isRepositoryInterface(type) && hasMappingFor(RepositoriesUtils.getDomainType(type))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.rest.core.support;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.RepositoryDefinition;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.AnnotationRepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class RepositoriesUtils {
|
||||
|
||||
/**
|
||||
* Resolves the domain type from the given type. Will resolve the repository domain type if the given type is a
|
||||
* repository or return the type as is if not.
|
||||
*
|
||||
* @param type must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static Class<?> getDomainType(Class<?> type) {
|
||||
|
||||
if (!isRepositoryInterface(type)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
return getMetadataFor(type).getDomainType();
|
||||
}
|
||||
|
||||
public static boolean isRepositoryInterface(Class<?> type) {
|
||||
return Repository.class.isAssignableFrom(type)
|
||||
|| AnnotationUtils.findAnnotation(type, RepositoryDefinition.class) != null;
|
||||
}
|
||||
|
||||
private static RepositoryMetadata getMetadataFor(Class<?> type) {
|
||||
return Repository.class.isAssignableFrom(type) ? new DefaultRepositoryMetadata(type)
|
||||
: new AnnotationRepositoryMetadata(type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user