merge + use the old search methods in the autocomplete feature

This commit is contained in:
Mohamed Karray
2018-10-09 11:11:25 +02:00
28 changed files with 120 additions and 475 deletions

View File

@@ -115,12 +115,4 @@ public interface GenericDAO<T>
*/
public Collection<T> getAll();
/**
* Returns items containing the searched string
*
* @param searched the search character
* @param limit the max count of the result entities. if limit is <= 0 return all filtered entities
* @return searched items
*/
Collection<T> getFiltered(String searched, int limit);
}

View File

@@ -47,6 +47,9 @@ public interface Manager<T extends ModelObject>
extends HandlerBase<T>, LastModifiedAware
{
int DEFAULT_LIMIT = 5;
/**
* Reloads a object from store and overwrites all changes.
*
@@ -77,15 +80,6 @@ public interface Manager<T extends ModelObject>
*/
Collection<T> getAll();
/**
* Returns a {@link java.util.Collection} of filtered objects
*
* @param filter the searched string
* @param limit the max count of the result entities. if limit is <= 0 return all filtered entities
* @return all object in the store
*/
Collection<T> getFiltered(String filter, int limit);
/**
* Returns all object of the store sorted by the given {@link java.util.Comparator}
*

View File

@@ -91,11 +91,6 @@ public class ManagerDecorator<T extends ModelObject> implements Manager<T> {
decorated.refresh(object);
}
@Override
public Collection<T> getFiltered(String filter, int limit) {
return decorated.getFiltered(filter, limit);
}
@Override
public T get(String id)
{

View File

@@ -44,7 +44,7 @@ import java.io.Serializable;
*/
public interface ModelObject
extends TypedObject, LastModifiedAware, Cloneable, Validateable,
Serializable, ReducedModelObject
Serializable
{
/**

View File

@@ -1,125 +0,0 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.filter;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.Priority;
import sonia.scm.util.WebUtil;
import sonia.scm.web.filter.HttpFilter;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Filter for gzip encoding.
*
* @author Sebastian Sdorra
* @since 1.15
*/
@Priority(Filters.PRIORITY_PRE_BASEURL)
@WebElement(value = Filters.PATTERN_RESOURCE_REGEX, regex = true)
public class GZipFilter extends HttpFilter
{
/**
* the logger for GZipFilter
*/
private static final Logger logger =
LoggerFactory.getLogger(GZipFilter.class);
//~--- get methods ----------------------------------------------------------
/**
* Return the configuration for the gzip filter.
*
*
* @return gzip filter configuration
*/
public GZipFilterConfig getConfig()
{
return config;
}
//~--- methods --------------------------------------------------------------
/**
* Encodes the response, if the request has support for gzip encoding.
*
*
* @param request http request
* @param response http response
* @param chain filter chain
*
* @throws IOException
* @throws ServletException
*/
@Override
protected void doFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain chain)
throws IOException, ServletException
{
if (WebUtil.isGzipSupported(request))
{
if (logger.isTraceEnabled())
{
logger.trace("compress output with gzip");
}
GZipResponseWrapper wrappedResponse = new GZipResponseWrapper(response,
config);
chain.doFilter(request, wrappedResponse);
wrappedResponse.finishResponse();
}
else
{
chain.doFilter(request, response);
}
}
//~--- fields ---------------------------------------------------------------
/** gzip filter configuration */
private GZipFilterConfig config = new GZipFilterConfig();
}

View File

@@ -0,0 +1,24 @@
package sonia.scm.filter;
import lombok.extern.slf4j.Slf4j;
import sonia.scm.util.WebUtil;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
@Provider
@Slf4j
public class GZipResponseFilter implements ContainerResponseFilter {
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
if (WebUtil.isGzipSupported(requestContext::getHeaderString)) {
log.trace("compress output with gzip");
GZIPOutputStream wrappedResponse = new GZIPOutputStream(responseContext.getEntityStream());
responseContext.getHeaders().add("Content-Encoding", "gzip");
responseContext.setEntityStream(wrappedResponse);
}
}
}

View File

@@ -42,6 +42,7 @@ import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import sonia.scm.BasicPropertiesAware;
import sonia.scm.ModelObject;
import sonia.scm.ReducedModelObject;
import sonia.scm.util.Util;
import sonia.scm.util.ValidationUtil;
@@ -64,7 +65,7 @@ import java.util.List;
@XmlRootElement(name = "groups")
@XmlAccessorType(XmlAccessType.FIELD)
public class Group extends BasicPropertiesAware
implements ModelObject, PermissionObject
implements ModelObject, PermissionObject, ReducedModelObject
{
/** Field description */

View File

@@ -61,4 +61,14 @@ public interface GroupManager
* @return all groups assigned to the given member
*/
public Collection<Group> getGroupsForMember(String member);
/**
* Returns a {@link java.util.Collection} of filtered objects
*
* @param filter the searched string
* @return filtered object from the store
*/
Collection<Group> autocomplete(String filter);
}

View File

@@ -109,6 +109,11 @@ public class GroupManagerDecorator
return decorated.getGroupsForMember(member);
}
@Override
public Collection<Group> autocomplete(String filter) {
return decorated.autocomplete(filter);
}
//~--- fields ---------------------------------------------------------------
/** Field description */

View File

@@ -256,11 +256,6 @@ public class Changeset extends BasicPropertiesAware implements ModelObject {
return id;
}
@Override
public String getDisplayName() {
return id;
}
@Override
public void setLastModified(Long timestamp) {
throw new UnsupportedOperationException("changesets are immutable");

View File

@@ -60,8 +60,7 @@ import java.util.List;
*/
@StaticPermissions(
value = "repository",
permissions = {"read", "modify", "delete", "healthCheck", "pull", "push", "permissionRead", "permissionWrite"},
globalPermissions = {"create", "autocomplete"}
permissions = {"read", "modify", "delete", "healthCheck", "pull", "push", "permissionRead", "permissionWrite"}
)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "repositories")
@@ -184,11 +183,6 @@ public class Repository extends BasicPropertiesAware implements ModelObject, Per
return id;
}
@Override
public String getDisplayName() {
return getNamespace() + "/" + getName();
}
@Override
public Long getLastModified() {
return lastModified;

View File

@@ -70,6 +70,12 @@ public class SearchRequest
this.ignoreCase = ignoreCase;
}
public SearchRequest(String query, boolean ignoreCase, int maxResults) {
this.query = query;
this.ignoreCase = ignoreCase;
this.maxResults = maxResults;
}
//~--- get methods ----------------------------------------------------------
/**

View File

@@ -41,6 +41,7 @@ import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import sonia.scm.BasicPropertiesAware;
import sonia.scm.ModelObject;
import sonia.scm.ReducedModelObject;
import sonia.scm.util.Util;
import sonia.scm.util.ValidationUtil;
@@ -58,7 +59,7 @@ import java.security.Principal;
@StaticPermissions(value = "user", globalPermissions = {"create", "list", "autocomplete"})
@XmlRootElement(name = "users")
@XmlAccessorType(XmlAccessType.FIELD)
public class User extends BasicPropertiesAware implements Principal, ModelObject, PermissionObject
public class User extends BasicPropertiesAware implements Principal, ModelObject, PermissionObject, ReducedModelObject
{
/** Field description */

View File

@@ -39,6 +39,7 @@ import sonia.scm.Manager;
import sonia.scm.search.Searchable;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.function.Consumer;
import static sonia.scm.user.ChangePasswordNotAllowedException.WRONG_USER_TYPE;
@@ -90,5 +91,13 @@ public interface UserManager
return getDefaultType().equals(user.getType());
}
/**
* Returns a {@link java.util.Collection} of filtered objects
*
* @param filter the searched string
* @return filtered object from the store
*/
Collection<User> autocomplete(String filter);
}

View File

@@ -121,6 +121,11 @@ public class UserManagerDecorator extends ManagerDecorator<User>
return decorated.getDefaultType();
}
@Override
public Collection<User> autocomplete(String filter) {
return decorated.autocomplete(filter);
}
//~--- fields ---------------------------------------------------------------
/** Field description */

View File

@@ -49,6 +49,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.function.Function;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -266,7 +267,12 @@ public final class WebUtil
*/
public static boolean isGzipSupported(HttpServletRequest request)
{
String enc = request.getHeader(HEADER_ACCEPTENCODING);
return isGzipSupported(request::getHeader);
}
public static boolean isGzipSupported(Function<String, String> headerResolver)
{
String enc = headerResolver.apply(HEADER_ACCEPTENCODING);
return (enc != null) && enc.contains("gzip");
}

View File

@@ -78,11 +78,6 @@ public class ManagerTest {
return IntStream.range(0, givenItemCount).boxed().collect(toList());
}
@Override
public Collection getFiltered(String filter, int limit) {
return null;
}
@Override
public Collection getAll(Comparator comparator) { return getAll(); }