DATAREST-94 - Removed dependency to Guava.
Introduced simple Function interface. Replaced usage of Multimap with Spring's MultiValueMap.
This commit is contained in:
@@ -21,7 +21,6 @@ ext {
|
||||
sdNeo4jVersion = "2.3.0.BUILD-SNAPSHOT"
|
||||
|
||||
// Libraries
|
||||
guavaVersion = "14.0.1"
|
||||
jacksonVersion = "2.1.2"
|
||||
jodaVersion = "2.1"
|
||||
hibernateVersion = "4.2.0.Final"
|
||||
@@ -128,8 +127,6 @@ project("spring-data-rest-core") {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Google Guava
|
||||
compile "com.google.guava:guava:$guavaVersion"
|
||||
|
||||
// Spring
|
||||
compile("org.springframework:spring-aop:$springVersion") { force = true }
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
/**
|
||||
* Simple function interface.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface Function<S, T> {
|
||||
|
||||
T apply(S input);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* Helper methods to work with {@link Map}s.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public abstract class MapUtils {
|
||||
|
||||
/**
|
||||
* Turns a {@link MultiValueMap} into its {@link Map} equivalent.
|
||||
*
|
||||
* @param map must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static <K, V> Map<K, Collection<V>> toMap(MultiValueMap<K, V> map) {
|
||||
|
||||
Assert.notNull(map, "Given map must not be null!");
|
||||
Map<K, Collection<V>> result = new LinkedHashMap<K, Collection<V>>(map.size());
|
||||
|
||||
for (Entry<K, List<V>> entry : map.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,8 +6,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -26,6 +24,8 @@ import org.springframework.data.rest.repository.annotation.HandleBeforeLinkSave;
|
||||
import org.springframework.data.rest.repository.annotation.HandleBeforeSave;
|
||||
import org.springframework.data.rest.repository.annotation.RepositoryEventHandler;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@@ -36,8 +36,7 @@ public class AnnotatedHandlerBeanPostProcessor implements ApplicationListener<Re
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(
|
||||
AnnotatedHandlerBeanPostProcessor.class);
|
||||
private Multimap<Class<? extends RepositoryEvent>, EventHandlerMethod> handlerMethods = ArrayListMultimap
|
||||
.create();
|
||||
private final MultiValueMap<Class<? extends RepositoryEvent>, EventHandlerMethod> handlerMethods = new LinkedMultiValueMap<Class<? extends RepositoryEvent>, AnnotatedHandlerBeanPostProcessor.EventHandlerMethod>();
|
||||
|
||||
@Override public void onApplicationEvent(RepositoryEvent event) {
|
||||
Class<? extends RepositoryEvent> eventType = event.getClass();
|
||||
@@ -140,7 +139,7 @@ public class AnnotatedHandlerBeanPostProcessor implements ApplicationListener<Re
|
||||
if(LOG.isDebugEnabled()) {
|
||||
LOG.debug("Annotated handler method found: " + m);
|
||||
}
|
||||
handlerMethods.put(eventType, m);
|
||||
handlerMethods.add(eventType, m);
|
||||
}
|
||||
} catch(NoSuchMethodException e) {
|
||||
if(LOG.isDebugEnabled()) {
|
||||
|
||||
@@ -5,18 +5,18 @@ import static org.springframework.core.annotation.AnnotationUtils.*;
|
||||
import static org.springframework.util.StringUtils.*;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.util.MapUtils;
|
||||
import org.springframework.data.rest.repository.RepositoryConstraintViolationException;
|
||||
import org.springframework.data.rest.repository.ValidationErrors;
|
||||
import org.springframework.data.rest.repository.annotation.HandleAfterDelete;
|
||||
@@ -27,6 +27,8 @@ import org.springframework.data.rest.repository.annotation.HandleBeforeDelete;
|
||||
import org.springframework.data.rest.repository.annotation.HandleBeforeLinkDelete;
|
||||
import org.springframework.data.rest.repository.annotation.HandleBeforeLinkSave;
|
||||
import org.springframework.data.rest.repository.annotation.HandleBeforeSave;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
@@ -56,7 +58,7 @@ public class ValidatingRepositoryEventListener
|
||||
);
|
||||
@Autowired
|
||||
private Repositories repositories;
|
||||
private Multimap<String, Validator> validators = ArrayListMultimap.create();
|
||||
private MultiValueMap<String, Validator> validators = new LinkedMultiValueMap<String, Validator>();
|
||||
|
||||
@Override public void afterPropertiesSet() throws Exception {
|
||||
if(validators.size() == 0) {
|
||||
@@ -81,7 +83,7 @@ public class ValidatingRepositoryEventListener
|
||||
}
|
||||
|
||||
if(null != name) {
|
||||
this.validators.put(name, v);
|
||||
this.validators.add(name, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +95,7 @@ public class ValidatingRepositoryEventListener
|
||||
* @return Validators assigned to events.
|
||||
*/
|
||||
public Map<String, Collection<Validator>> getValidators() {
|
||||
return validators.asMap();
|
||||
return MapUtils.toMap(validators);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +108,7 @@ public class ValidatingRepositoryEventListener
|
||||
*/
|
||||
public ValidatingRepositoryEventListener setValidators(Map<String, Collection<Validator>> validators) {
|
||||
for(Map.Entry<String, Collection<Validator>> entry : validators.entrySet()) {
|
||||
this.validators.replaceValues(entry.getKey(), entry.getValue());
|
||||
this.validators.put(entry.getKey(), new ArrayList<Validator>(entry.getValue()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -122,7 +124,7 @@ public class ValidatingRepositoryEventListener
|
||||
* @return @this
|
||||
*/
|
||||
public ValidatingRepositoryEventListener addValidator(String event, Validator validator) {
|
||||
validators.put(event, validator);
|
||||
validators.add(event, validator);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
@@ -20,6 +19,7 @@ import org.springframework.data.repository.support.DomainClassConverter;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.config.ResourceMapping;
|
||||
import org.springframework.data.rest.core.util.Function;
|
||||
import org.springframework.data.rest.repository.PersistentEntityResource;
|
||||
import org.springframework.data.rest.repository.context.AfterLinkDeleteEvent;
|
||||
import org.springframework.data.rest.repository.context.AfterLinkSaveEvent;
|
||||
|
||||
Reference in New Issue
Block a user