mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
remove direct dependencies to apache beanutils and commons collections
This commit is contained in:
@@ -37,7 +37,6 @@ package sonia.scm.api.rest.resources;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.net.UrlEscapers;
|
||||
import org.apache.commons.beanutils.BeanComparator;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -47,6 +46,7 @@ import sonia.scm.ModelObject;
|
||||
import sonia.scm.PageResult;
|
||||
import sonia.scm.api.rest.RestExceptionResult;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.Comparables;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
@@ -56,15 +56,10 @@ import javax.ws.rs.core.Request;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.Arrays;
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.net.URI;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -510,21 +505,11 @@ public abstract class AbstractManagerResource<T extends ModelObject> {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Comparator<T> createComparator(String sortBy, boolean desc)
|
||||
{
|
||||
checkSortByField(sortBy);
|
||||
Comparator comparator;
|
||||
|
||||
if (desc)
|
||||
{
|
||||
comparator = new BeanReverseComparator(sortBy);
|
||||
private Comparator<T> createComparator(String sortBy, boolean desc) {
|
||||
Comparator<T> comparator = Comparables.comparator(type, sortBy);
|
||||
if (desc) {
|
||||
comparator = comparator.reversed();
|
||||
}
|
||||
else
|
||||
{
|
||||
comparator = new BeanComparator(sortBy);
|
||||
}
|
||||
|
||||
return comparator;
|
||||
}
|
||||
|
||||
@@ -558,21 +543,6 @@ public abstract class AbstractManagerResource<T extends ModelObject> {
|
||||
return items;
|
||||
}
|
||||
|
||||
// We have to handle IntrospectionException here, because it's a checked exception
|
||||
// It shouldn't occur really - so creating a new unchecked exception would be over-engineered here
|
||||
@SuppressWarnings("squid:S00112")
|
||||
private void checkSortByField(String sortBy) {
|
||||
try {
|
||||
BeanInfo info = Introspector.getBeanInfo(type);
|
||||
PropertyDescriptor[] pds = info.getPropertyDescriptors();
|
||||
if (Arrays.stream(pds).noneMatch(p -> p.getName().equals(sortBy))) {
|
||||
throw new IllegalArgumentException("sortBy");
|
||||
}
|
||||
} catch (IntrospectionException e) {
|
||||
throw new RuntimeException("error introspecting model type " + type.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
protected PageResult<T> fetchPage(String sortBy, boolean desc, int pageNumber,
|
||||
int pageSize) {
|
||||
AssertUtil.assertPositive(pageNumber);
|
||||
@@ -608,51 +578,4 @@ public abstract class AbstractManagerResource<T extends ModelObject> {
|
||||
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class description
|
||||
*
|
||||
*
|
||||
* @version Enter version here..., 11/06/09
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
private static class BeanReverseComparator extends BeanComparator
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final long serialVersionUID = -8535047820348790009L;
|
||||
|
||||
//~--- constructors -------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param sortby
|
||||
*/
|
||||
private BeanReverseComparator(String sortby)
|
||||
{
|
||||
super(sortby);
|
||||
}
|
||||
|
||||
//~--- methods ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param o1
|
||||
* @param o2
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int compare(Object o1, Object o2)
|
||||
{
|
||||
return super.compare(o1, o2) * -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package sonia.scm.security;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
@@ -33,8 +31,9 @@ public class RepositoryRole {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof RepositoryRole)) return false;
|
||||
RepositoryRole that = (RepositoryRole) o;
|
||||
return name.equals(that.name) &&
|
||||
CollectionUtils.isEqualCollection(this.verbs, that.verbs);
|
||||
return name.equals(that.name)
|
||||
&& this.verbs.containsAll(that.verbs)
|
||||
&& this.verbs.size() == that.verbs.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user