internal.org.springframework.content.rest.mappingcontext.ContentPropertyToRequestMappingContext Maven / Gradle / Ivy
package internal.org.springframework.content.rest.mappingcontext;
import org.springframework.content.commons.mappingcontext.ClassWalker;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class ContentPropertyToRequestMappingContext {
private Map, Map> mappings = new HashMap, Map>();
public ContentPropertyToRequestMappingContext() {}
public Map getMappings(Class> domainClass) {
Map mappings = this.mappings.get(domainClass);
if (mappings == null) {
mappings = resolveMappings(domainClass);
}
return mappings;
}
public boolean hasInverseMapping(Class> domainClass, String requestSubPath) {
Map mappings = this.mappings.get(domainClass);
if (mappings == null) {
mappings = resolveMappings(domainClass);
}
return mappings.containsValue(requestSubPath);
}
public Map getInverseMappings(Class> domainClass) {
Map mappings = this.mappings.get(domainClass);
if (mappings == null) {
mappings = resolveMappings(domainClass);
}
return mappings.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
}
private Map resolveMappings(Class> domainClass) {
RestResourceMappingBuilder visitor = new RestResourceMappingBuilder((restResource -> restResource.path()));
ClassWalker walker = new ClassWalker(visitor);
walker.accept(domainClass);
Map mappings = visitor.getMappings();
this.mappings.put(domainClass, mappings);
return mappings;
}
public String resolveContentPropertyPath(Class> domainClass, String contentPropertyPath) {
if (hasInverseMapping(domainClass, contentPropertyPath)) {
return getInverseMappings(domainClass).get(contentPropertyPath);
}
return contentPropertyPath;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy