From 290f8466ebc71d2ac72279ff33df9afa67d15100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Mon, 8 Apr 2019 11:10:34 +0200 Subject: [PATCH] Delete old 1.x resources --- scm-webapp/src/main/doc/enunciate.xml | 72 ------ .../resources/BrowserStreamingOutput.java | 37 --- .../resources/ChangePasswordResource.java | 173 -------------- .../rest/resources/DiffStreamingOutput.java | 109 --------- .../resources/RepositoryRootResource.java | 213 ----------------- .../api/rest/resources/SearchResource.java | 216 ----------------- .../java/sonia/scm/search/SearchHandler.java | 221 ------------------ .../java/sonia/scm/search/SearchResult.java | 117 ---------- .../java/sonia/scm/search/SearchResults.java | 110 --------- 9 files changed, 1268 deletions(-) delete mode 100644 scm-webapp/src/main/doc/enunciate.xml delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/rest/resources/ChangePasswordResource.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryRootResource.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/rest/resources/SearchResource.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/search/SearchHandler.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/search/SearchResult.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/search/SearchResults.java diff --git a/scm-webapp/src/main/doc/enunciate.xml b/scm-webapp/src/main/doc/enunciate.xml deleted file mode 100644 index 6e7fc218aa..0000000000 --- a/scm-webapp/src/main/doc/enunciate.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - SCM-Manager API - - - SCM-Manager API -

This page describes the RESTful Web Service API of SCM-Manager ${project.version}.

- ]]> -
- - - - - - - - - - - - - - - - - - -
diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java deleted file mode 100644 index 79b5dbc2ae..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/BrowserStreamingOutput.java +++ /dev/null @@ -1,37 +0,0 @@ -package sonia.scm.api.rest.resources; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import sonia.scm.repository.api.CatCommandBuilder; -import sonia.scm.repository.api.RepositoryService; -import sonia.scm.util.IOUtil; - -import javax.ws.rs.core.StreamingOutput; -import java.io.IOException; -import java.io.OutputStream; - -public class BrowserStreamingOutput implements StreamingOutput { - - private static final Logger logger = - LoggerFactory.getLogger(BrowserStreamingOutput.class); - - private final CatCommandBuilder builder; - private final String path; - private final RepositoryService repositoryService; - - public BrowserStreamingOutput(RepositoryService repositoryService, - CatCommandBuilder builder, String path) { - this.repositoryService = repositoryService; - this.builder = builder; - this.path = path; - } - - @Override - public void write(OutputStream output) throws IOException { - try { - builder.retriveContent(output, path); - } finally { - IOUtil.close(repositoryService); - } - } -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/ChangePasswordResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/ChangePasswordResource.java deleted file mode 100644 index 828cbf8164..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/ChangePasswordResource.java +++ /dev/null @@ -1,173 +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.api.rest.resources; - -//~--- non-JDK imports -------------------------------------------------------- - -import com.google.inject.Inject; -import com.webcohesion.enunciate.metadata.rs.ResponseCode; -import com.webcohesion.enunciate.metadata.rs.StatusCodes; -import com.webcohesion.enunciate.metadata.rs.TypeHint; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.authc.credential.PasswordService; -import org.apache.shiro.subject.Subject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import sonia.scm.api.rest.RestActionResult; -import sonia.scm.security.Role; -import sonia.scm.security.ScmSecurityException; -import sonia.scm.user.User; -import sonia.scm.user.UserManager; -import sonia.scm.util.AssertUtil; - -import javax.ws.rs.FormParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -//~--- JDK imports ------------------------------------------------------------ - -/** - * Resource to change the password of the authenticated user. - * - * @author Sebastian Sdorra - */ -@Path("action/change-password") -public class ChangePasswordResource -{ - - /** the logger for ChangePasswordResource */ - private static final Logger logger = - LoggerFactory.getLogger(ChangePasswordResource.class); - - //~--- constructors --------------------------------------------------------- - - /** - * Constructs ... - * - * - * @param userManager - * @param encryptionHandler - */ - @Inject - public ChangePasswordResource(UserManager userManager, - PasswordService encryptionHandler) - { - this.userManager = userManager; - this.passwordService = encryptionHandler; - } - - //~--- methods -------------------------------------------------------------- - - /** - * Changes the password of the current user. - * - * @param oldPassword old password of the current user - * @param newPassword new password for the current user - */ - @POST - @TypeHint(RestActionResult.class) - @StatusCodes({ - @ResponseCode(code = 200, condition = "success"), - @ResponseCode(code = 400, condition = "bad request, the old password is not correct"), - @ResponseCode(code = 500, condition = "internal server error") - }) - @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - public Response changePassword(@FormParam("old-password") String oldPassword, @FormParam("new-password") String newPassword) { - AssertUtil.assertIsNotEmpty(oldPassword); - AssertUtil.assertIsNotEmpty(newPassword); - - int length = newPassword.length(); - - if ((length < 6) || (length > 32)) - { - throw new WebApplicationException(Response.Status.BAD_REQUEST); - } - - Response response = null; - Subject subject = SecurityUtils.getSubject(); - - if (!subject.hasRole(Role.USER)) - { - throw new ScmSecurityException("user is not authenticated"); - } - - User currentUser = subject.getPrincipals().oneByType(User.class); - - if (logger.isInfoEnabled()) - { - logger.info("password change for user {}", currentUser.getName()); - } - - // Only account of the default type can change their password - if (currentUser.getType().equals(userManager.getDefaultType())) - { - User dbUser = userManager.get(currentUser.getName()); - - if (passwordService.passwordsMatch(oldPassword, dbUser.getPassword())) - { - dbUser.setPassword(passwordService.encryptPassword(newPassword)); - userManager.modify(dbUser); - response = Response.ok(new RestActionResult(true)).build(); - } - else - { - response = Response.status(Response.Status.BAD_REQUEST).build(); - } - } - else - { - //J- - logger.error( - "Only account of the default type ({}) can change their password", - userManager.getDefaultType() - ); - //J+ - response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } - - return response; - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private final PasswordService passwordService; - - /** Field description */ - private final UserManager userManager; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java deleted file mode 100644 index b7f994b967..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/DiffStreamingOutput.java +++ /dev/null @@ -1,109 +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.api.rest.resources; - -//~--- non-JDK imports -------------------------------------------------------- - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import sonia.scm.repository.api.DiffCommandBuilder; -import sonia.scm.repository.api.RepositoryService; -import sonia.scm.util.IOUtil; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.StreamingOutput; -import java.io.IOException; -import java.io.OutputStream; - -//~--- JDK imports ------------------------------------------------------------ - -/** - * - * @author Sebastian Sdorra - */ -public class DiffStreamingOutput implements StreamingOutput -{ - - /** the logger for DiffStreamingOutput */ - private static final Logger logger = - LoggerFactory.getLogger(DiffStreamingOutput.class); - - //~--- constructors --------------------------------------------------------- - - /** - * Constructs ... - * - * - * - * @param repositoryService - * @param builder - */ - public DiffStreamingOutput(RepositoryService repositoryService, - DiffCommandBuilder builder) - { - this.repositoryService = repositoryService; - this.builder = builder; - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * @param output - * - * @throws IOException - * @throws WebApplicationException - */ - @Override - public void write(OutputStream output) throws IOException { - try - { - builder.retrieveContent(output); - } - finally - { - IOUtil.close(repositoryService); - } - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private final DiffCommandBuilder builder; - - /** Field description */ - private final RepositoryService repositoryService; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryRootResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryRootResource.java deleted file mode 100644 index d5ea6c88de..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryRootResource.java +++ /dev/null @@ -1,213 +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.api.rest.resources; - -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.google.common.collect.Maps; -import com.google.common.collect.Ordering; -import com.google.inject.Inject; -import sonia.scm.repository.Repository; -import sonia.scm.repository.RepositoryManager; -import sonia.scm.repository.RepositoryTypePredicate; -import sonia.scm.template.Viewable; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import java.io.IOException; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Map; - -/** - * - * @author Sebastian Sdorra - */ -@Path("help/repository-root/{type}.html") -public class RepositoryRootResource -{ - - private static final String TEMPLATE = "/templates/repository-root.mustache"; - - private final RepositoryManager repositoryManager; - - /** - * Constructs ... - * - * @param repositoryManager - */ - @Inject - public RepositoryRootResource(RepositoryManager repositoryManager) - { - this.repositoryManager = repositoryManager; - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * - * @param request - * @param type - * - * @return - * - * @throws IOException - */ - @GET - @Produces(MediaType.TEXT_HTML) - public Viewable renderRepositoriesRoot(@Context HttpServletRequest request, @PathParam("type") final String type) - { - //J- - Collection unsortedRepositories = - Collections2.transform( - Collections2.filter( - repositoryManager.getAll(), new RepositoryTypePredicate(type)) - , new RepositoryTransformFunction() - ); - - List repositories = Ordering.from( - new RepositoryTemplateElementComparator() - ).sortedCopy(unsortedRepositories); - //J+ - Map environment = Maps.newHashMap(); - - environment.put("repositories", repositories); - - return new Viewable(TEMPLATE, environment); - } - - //~--- inner classes -------------------------------------------------------- - - /** - * Class description - * - * - * @version Enter version here..., 12/05/28 - * @author Enter your name here... - */ - public static class RepositoryTemplateElement - { - - public RepositoryTemplateElement(Repository repository) - { - this.repository = repository; - } - - //~--- get methods -------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - public String getName() - { - return repository.getName(); - } - - /** - * Method description - * - * - * @return - */ - public Repository getRepository() - { - return repository; - } - - //~--- fields ------------------------------------------------------------- - - /** Field description */ - private Repository repository; - - } - - - /** - * Class description - * - * - * @version Enter version here..., 12/05/29 - * @author Enter your name here... - */ - private static class RepositoryTemplateElementComparator - implements Comparator - { - - /** - * Method description - * - * - * @param left - * @param right - * - * @return - */ - @Override - public int compare(RepositoryTemplateElement left, - RepositoryTemplateElement right) - { - return left.getName().compareTo(right.getName()); - } - } - - - /** - * Class description - * - * - * @version Enter version here..., 12/05/28 - * @author Enter your name here... - */ - private static class RepositoryTransformFunction - implements Function - { - @Override - public RepositoryTemplateElement apply(Repository repository) - { - return new RepositoryTemplateElement(repository); - } - } -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/SearchResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/SearchResource.java deleted file mode 100644 index f22e6cf8c4..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/SearchResource.java +++ /dev/null @@ -1,216 +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.api.rest.resources; - -//~--- non-JDK imports -------------------------------------------------------- - -import com.github.legman.Subscribe; - -import com.google.common.base.Function; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.webcohesion.enunciate.metadata.rs.ResponseCode; -import com.webcohesion.enunciate.metadata.rs.StatusCodes; - -import sonia.scm.cache.Cache; -import sonia.scm.cache.CacheManager; -import sonia.scm.group.Group; -import sonia.scm.group.GroupEvent; -import sonia.scm.group.GroupManager; -import sonia.scm.search.SearchHandler; -import sonia.scm.search.SearchResult; -import sonia.scm.search.SearchResults; -import sonia.scm.user.User; -import sonia.scm.user.UserEvent; -import sonia.scm.user.UserManager; - -//~--- JDK imports ------------------------------------------------------------ - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - -/** - * RESTful Web Service Resource to search users and groups. This endpoint can be used to implement typeahead input - * fields for permissions. - * - * @author Sebastian Sdorra - */ -@Singleton -@Path("search") -public class SearchResource -{ - - /** Field description */ - public static final String CACHE_GROUP = "sonia.cache.search.groups"; - - /** Field description */ - public static final String CACHE_USER = "sonia.cache.search.users"; - - //~--- constructors --------------------------------------------------------- - - /** - * Constructs ... - * - * - * @param userManager - * @param groupManager - * @param cacheManager - */ - @Inject - public SearchResource(UserManager userManager, GroupManager groupManager, - CacheManager cacheManager) - { - - // create user searchhandler - Cache userCache = cacheManager.getCache(CACHE_USER); - - this.userSearchHandler = new SearchHandler(userCache, userManager); - - // create group searchhandler - Cache groupCache = - cacheManager.getCache(CACHE_GROUP); - - this.groupSearchHandler = new SearchHandler(groupCache, - groupManager); - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * @param event - */ - @Subscribe - public void onEvent(UserEvent event) - { - if (event.getEventType().isPost()) - { - userSearchHandler.clearCache(); - } - } - - /** - * Method description - * - * - * @param event - */ - @Subscribe - public void onEvent(GroupEvent event) - { - if (event.getEventType().isPost()) - { - groupSearchHandler.clearCache(); - } - } - - /** - * Returns a list of groups found by the given search string. - * - * @param queryString the search string - * - * @return - */ - @GET - @Path("groups") - @StatusCodes({ - @ResponseCode(code = 200, condition = "success"), - @ResponseCode(code = 500, condition = "internal server error") - }) - @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - public SearchResults searchGroups(@QueryParam("query") String queryString) - { - return groupSearchHandler.search(queryString, - new Function() - { - @Override - public SearchResult apply(Group group) - { - String label = group.getName(); - String description = group.getDescription(); - - if (description != null) - { - label = label.concat(" (").concat(description).concat(")"); - } - - return new SearchResult(group.getName(), label); - } - }); - } - - /** - * Returns a list of users found by the given search string. - * - * @param queryString the search string - * - * @return - */ - @GET - @Path("users") - @StatusCodes({ - @ResponseCode(code = 200, condition = "success"), - @ResponseCode(code = 500, condition = "internal server error") - }) - @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - public SearchResults searchUsers(@QueryParam("query") String queryString) - { - return userSearchHandler.search(queryString, - new Function() - { - @Override - public SearchResult apply(User user) - { - StringBuilder label = new StringBuilder(user.getName()); - - label.append(" (").append(user.getDisplayName()).append(")"); - - return new SearchResult(user.getName(), label.toString()); - } - }); - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private final SearchHandler groupSearchHandler; - - /** Field description */ - private final SearchHandler userSearchHandler; -} diff --git a/scm-webapp/src/main/java/sonia/scm/search/SearchHandler.java b/scm-webapp/src/main/java/sonia/scm/search/SearchHandler.java deleted file mode 100644 index 1f00328246..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/search/SearchHandler.java +++ /dev/null @@ -1,221 +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.search; - -//~--- non-JDK imports -------------------------------------------------------- - -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; - -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.subject.Subject; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import sonia.scm.cache.Cache; -import sonia.scm.security.ScmSecurityException; -import sonia.scm.util.Util; - -//~--- JDK imports ------------------------------------------------------------ - -import java.util.Collection; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response.Status; -import sonia.scm.security.Role; - -/** - * - * @author Sebastian Sdorra - * - * @param - */ -public class SearchHandler -{ - - /** the logger for SearchHandler */ - private static final Logger logger = - LoggerFactory.getLogger(SearchHandler.class); - - //~--- constructors --------------------------------------------------------- - - /** - * Constructs ... - * - * - * @param securityContextProvider - * @param cache - * @param searchable - */ - public SearchHandler(Cache cache, - Searchable searchable) - { - - this.cache = cache; - this.searchable = searchable; - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - */ - public void clearCache() - { - this.cache.clear(); - } - - /** - * Method description - * - * - * @param queryString - * @param function - * - * @return - */ - public SearchResults search(String queryString, - Function function) - { - Subject subject = SecurityUtils.getSubject(); - - if (!subject.hasRole(Role.USER)) - { - throw new ScmSecurityException("Authentication is required"); - } - - if (Util.isEmpty(queryString)) - { - throw new WebApplicationException(Status.BAD_REQUEST); - } - - SearchResults result = cache.get(queryString); - - if (result == null) - { - SearchRequest request = new SearchRequest(queryString, ignoreCase); - - request.setMaxResults(maxResults); - - Collection users = searchable.search(request); - - result = new SearchResults(); - - if (Util.isNotEmpty(users)) - { - Collection resultCollection = - Collections2.transform(users, function); - - result.setSuccess(true); - - // create a copy of the result collection to reduce memory - // use ArrayList instead of ImmutableList for copy, - // because the list must be mutable for decorators - result.setResults(Lists.newArrayList(resultCollection)); - cache.put(queryString, result); - } - } - else if (logger.isDebugEnabled()) - { - logger.debug("return searchresults for {} from cache", queryString); - } - - return result; - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - public int getMaxResults() - { - return maxResults; - } - - /** - * Method description - * - * - * @return - */ - public boolean isIgnoreCase() - { - return ignoreCase; - } - - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param ignoreCase - */ - public void setIgnoreCase(boolean ignoreCase) - { - this.ignoreCase = ignoreCase; - } - - /** - * Method description - * - * - * @param maxResults - */ - public void setMaxResults(int maxResults) - { - this.maxResults = maxResults; - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - protected Cache cache; - - /** Field description */ - protected Searchable searchable; - - /** Field description */ - private int maxResults = 5; - - /** Field description */ - private boolean ignoreCase = true; -} diff --git a/scm-webapp/src/main/java/sonia/scm/search/SearchResult.java b/scm-webapp/src/main/java/sonia/scm/search/SearchResult.java deleted file mode 100644 index 3862fafe8b..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/search/SearchResult.java +++ /dev/null @@ -1,117 +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.search; - -/** - * - * @author Sebastian Sdorra - */ -public class SearchResult -{ - - /** - * Constructs ... - * - */ - public SearchResult() {} - - /** - * Constructs ... - * - * - * @param value - * @param label - */ - public SearchResult(String value, String label) - { - this.value = value; - this.label = label; - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - public String getLabel() - { - return label; - } - - /** - * Method description - * - * - * @return - */ - public String getValue() - { - return value; - } - - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param label - */ - public void setLabel(String label) - { - this.label = label; - } - - /** - * Method description - * - * - * @param value - */ - public void setValue(String value) - { - this.value = value; - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private String label; - - /** Field description */ - private String value; -} diff --git a/scm-webapp/src/main/java/sonia/scm/search/SearchResults.java b/scm-webapp/src/main/java/sonia/scm/search/SearchResults.java deleted file mode 100644 index a26982052a..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/search/SearchResults.java +++ /dev/null @@ -1,110 +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.search; - -//~--- JDK imports ------------------------------------------------------------ - -import java.util.Collection; - -import javax.xml.bind.annotation.XmlRootElement; -import sonia.scm.api.rest.RestActionResult; - -/** - * - * @author Sebastian Sdorra - */ -@XmlRootElement(name = "search-results") -public class SearchResults extends RestActionResult -{ - - /** - * Constructs ... - * - */ - public SearchResults() {} - - /** - * Constructs ... - * - * - * @param success - */ - public SearchResults(boolean success) - { - super(success); - } - - /** - * Constructs ... - * - * - * @param results - */ - public SearchResults(Collection results) - { - super(true); - this.results = results; - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - public Collection getResults() - { - return results; - } - - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param results - */ - public void setResults(Collection results) - { - this.results = results; - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private Collection results; -}