{"action":"created","comment":{"url":"https://api.github.com/repos/strongbox/strongbox/pulls/comments/109308983","pull_request_review_id":30404161,"id":109308983,"diff_hunk":"@@ -38,94 +52,166 @@\n     @Autowired\n     private ConfigurationManager configurationManager;\n \n+    @Autowired\n+    private ArtifactEntryService artifactEntryService;\n \n     @Override\n     public SearchResults search(SearchRequest searchRequest)\n-            throws IOException, ParseException\n+        throws IOException,\n+        ParseException\n     {\n         SearchResults searchResults = new SearchResults();\n \n-        final String repositoryId = searchRequest.getRepositoryId();\n+        String storageId = searchRequest.getStorageId();\n+        String repositoryId = searchRequest.getRepositoryId();\n+        String query = searchRequest.getQuery();\n+\n+        Pattern pattern = Pattern.compile(QUERY_PATTERN_DB);\n+        Matcher matcher = pattern.matcher(query);\n+        // If query matches then we have a DataBase search request\n+        if (matcher.find())\n+        {\n+            Map<String, String> coordinates = new HashMap<>();\n+            do\n+            {\n+                coordinates.put(matcher.group(1), matcher.group(2));\n+            } while (matcher.find());\n+            searchResults.getResults()\n+                         .addAll(dbSearch(coordinates));\n+            return searchResults;\n+        }\n \n         final Collection<Storage> storages = getConfiguration().getStorages().values();\n         if (repositoryId != null && !repositoryId.isEmpty())\n         {\n             logger.debug(\"Repository: {}\", repositoryId);\n-\n-            final String storageId = searchRequest.getStorageId();\n             if (storageId == null)\n             {\n-                for (Storage storage : storages)\n-                {\n-                    if (storage.containsRepository(repositoryId))\n-                    {\n-                        final String contextId = storage.getId() + \":\" +\n-                                                 repositoryId + \":\" +\n-                                                 IndexTypeEnum.LOCAL.getType();\n-                        final Set<SearchResult> sr = repositoryIndexManager.getRepositoryIndexer(contextId)\n-                                                                           .search(searchRequest.getQuery());\n-\n-                        if (sr != null && !sr.isEmpty())\n-                        {\n-                            searchResults.getResults().addAll(sr);\n-                        }\n-                    }\n-                }\n-\n-                logger.debug(\"Results: {}\", searchResults.getResults().size());\n-\n-                return searchResults;\n+                searchResults.getResults().addAll(indexSearch(query, repositoryId, storages));\n             }\n             else\n             {\n-                String contextId = searchRequest.getStorageId() + \":\" +\n-                                   searchRequest.getRepositoryId() + \":\" +\n-                                   IndexTypeEnum.LOCAL.getType();\n+                Storage storage = getConfiguration().getStorage(storageId);\n+                searchResults.getResults().addAll(indexSearch(query, storage, repositoryId));\n+            }\n+        }\n+        else\n+        {\n+            searchResults.getResults().addAll(indexSearch(query, storages));\n+        }\n+        logger.debug(\"Results: {}\", searchResults.getResults().size());\n+        return searchResults;\n+    }\n \n-                final Set<SearchResult> sr = repositoryIndexManager.getRepositoryIndexer(contextId)\n-                                                                   .search(searchRequest.getQuery());\n+    private List<SearchResult> dbSearch(Map<String, String> coordinates)\n+    {\n+        List<SearchResult> result = new LinkedList<>();\n+        result.addAll(artifactEntryService.findByCoordinates(coordinates)\n+                                          .stream()\n+                                          .map(a -> createSearchResult(a))\n+                                          .collect(Collectors.toList()));\n+        return result;\n+    }\n \n-                if (!sr.isEmpty())\n-                {\n-                    searchResults.getResults().addAll(sr);\n-                }\n+    protected SearchResult createSearchResult(ArtifactEntry a)\n+    {\n+        String storageId = a.getStorageId();\n+        String url = getURLForArtifact(storageId, a.getRepositoryId(), a.getArtifactCoordinates().toPath());\n \n-                logger.debug(\"Results: {}\", searchResults.getResults().size());\n+        return new SearchResult(storageId, a.getRepositoryId(),\n+                a.getArtifactCoordinates(), url);\n+    }\n \n-                return searchResults;\n-            }\n-        }\n-        else\n+    // TODO: [sbespalov] extract this logic into some common utility class\n+    public String getURLForArtifact(String storageId,\n+                                    String repositoryId,\n+                                    String pathToArtifactFile)\n+    {\n+        String baseUrl = getConfiguration().getBaseUrl();\n+        baseUrl = (baseUrl.endsWith(\"/\") ? baseUrl : baseUrl + \"/\");","path":"strongbox-storage/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/services/impl/ArtifactSearchServiceImpl.java","position":152,"original_position":152,"commit_id":"351eebeb2dcf60364410529c898b48c318b519c4","original_commit_id":"5c5e3f21b627ecef6ed2795689e8be26839c1978","user":{"login":"sbespalov","id":22783811,"avatar_url":"https://avatars1.githubusercontent.com/u/22783811?v=3","gravatar_id":"","url":"https://api.github.com/users/sbespalov","html_url":"https://github.com/sbespalov","followers_url":"https://api.github.com/users/sbespalov/followers","following_url":"https://api.github.com/users/sbespalov/following{/other_user}","gists_url":"https://api.github.com/users/sbespalov/gists{/gist_id}","starred_url":"https://api.github.com/users/sbespalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbespalov/subscriptions","organizations_url":"https://api.github.com/users/sbespalov/orgs","repos_url":"https://api.github.com/users/sbespalov/repos","events_url":"https://api.github.com/users/sbespalov/events{/privacy}","received_events_url":"https://api.github.com/users/sbespalov/received_events","type":"User","site_admin":false},"body":"done","created_at":"2017-04-02T13:31:58Z","updated_at":"2017-04-02T13:31:58Z","html_url":"https://github.com/strongbox/strongbox/pull/228#discussion_r109308983","pull_request_url":"https://api.github.com/repos/strongbox/strongbox/pulls/228","_links":{"self":{"href":"https://api.github.com/repos/strongbox/strongbox/pulls/comments/109308983"},"html":{"href":"https://github.com/strongbox/strongbox/pull/228#discussion_r109308983"},"pull_request":{"href":"https://api.github.com/repos/strongbox/strongbox/pulls/228"}}},"pull_request":{"url":"https://api.github.com/repos/strongbox/strongbox/pulls/228","id":113451053,"html_url":"https://github.com/strongbox/strongbox/pull/228","diff_url":"https://github.com/strongbox/strongbox/pull/228.diff","patch_url":"https://github.com/strongbox/strongbox/pull/228.patch","issue_url":"https://api.github.com/repos/strongbox/strongbox/issues/228","number":228,"state":"open","locked":false,"title":"SB-761","user":{"login":"sbespalov","id":22783811,"avatar_url":"https://avatars1.githubusercontent.com/u/22783811?v=3","gravatar_id":"","url":"https://api.github.com/users/sbespalov","html_url":"https://github.com/sbespalov","followers_url":"https://api.github.com/users/sbespalov/followers","following_url":"https://api.github.com/users/sbespalov/following{/other_user}","gists_url":"https://api.github.com/users/sbespalov/gists{/gist_id}","starred_url":"https://api.github.com/users/sbespalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbespalov/subscriptions","organizations_url":"https://api.github.com/users/sbespalov/orgs","repos_url":"https://api.github.com/users/sbespalov/repos","events_url":"https://api.github.com/users/sbespalov/events{/privacy}","received_events_url":"https://api.github.com/users/sbespalov/received_events","type":"User","site_admin":false},"body":"SB-761 fixed","created_at":"2017-03-30T15:03:46Z","updated_at":"2017-04-02T13:31:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d1e39a14f5f7234e8a06aae38447befa2b4ca4fa","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/strongbox/strongbox/pulls/228/commits","review_comments_url":"https://api.github.com/repos/strongbox/strongbox/pulls/228/comments","review_comment_url":"https://api.github.com/repos/strongbox/strongbox/pulls/comments{/number}","comments_url":"https://api.github.com/repos/strongbox/strongbox/issues/228/comments","statuses_url":"https://api.github.com/repos/strongbox/strongbox/statuses/351eebeb2dcf60364410529c898b48c318b519c4","head":{"label":"sbespalov:SB-761,SB-762","ref":"SB-761,SB-762","sha":"351eebeb2dcf60364410529c898b48c318b519c4","user":{"login":"sbespalov","id":22783811,"avatar_url":"https://avatars1.githubusercontent.com/u/22783811?v=3","gravatar_id":"","url":"https://api.github.com/users/sbespalov","html_url":"https://github.com/sbespalov","followers_url":"https://api.github.com/users/sbespalov/followers","following_url":"https://api.github.com/users/sbespalov/following{/other_user}","gists_url":"https://api.github.com/users/sbespalov/gists{/gist_id}","starred_url":"https://api.github.com/users/sbespalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbespalov/subscriptions","organizations_url":"https://api.github.com/users/sbespalov/orgs","repos_url":"https://api.github.com/users/sbespalov/repos","events_url":"https://api.github.com/users/sbespalov/events{/privacy}","received_events_url":"https://api.github.com/users/sbespalov/received_events","type":"User","site_admin":false},"repo":{"id":72494340,"name":"strongbox","full_name":"sbespalov/strongbox","owner":{"login":"sbespalov","id":22783811,"avatar_url":"https://avatars1.githubusercontent.com/u/22783811?v=3","gravatar_id":"","url":"https://api.github.com/users/sbespalov","html_url":"https://github.com/sbespalov","followers_url":"https://api.github.com/users/sbespalov/followers","following_url":"https://api.github.com/users/sbespalov/following{/other_user}","gists_url":"https://api.github.com/users/sbespalov/gists{/gist_id}","starred_url":"https://api.github.com/users/sbespalov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbespalov/subscriptions","organizations_url":"https://api.github.com/users/sbespalov/orgs","repos_url":"https://api.github.com/users/sbespalov/repos","events_url":"https://api.github.com/users/sbespalov/events{/privacy}","received_events_url":"https://api.github.com/users/sbespalov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sbespalov/strongbox","description":null,"fork":true,"url":"https://api.github.com/repos/sbespalov/strongbox","forks_url":"https://api.github.com/repos/sbespalov/strongbox/forks","keys_url":"https://api.github.com/repos/sbespalov/strongbox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sbespalov/strongbox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sbespalov/strongbox/teams","hooks_url":"https://api.github.com/repos/sbespalov/strongbox/hooks","issue_events_url":"https://api.github.com/repos/sbespalov/strongbox/issues/events{/number}","events_url":"https://api.github.com/repos/sbespalov/strongbox/events","assignees_url":"https://api.github.com/repos/sbespalov/strongbox/assignees{/user}","branches_url":"https://api.github.com/repos/sbespalov/strongbox/branches{/branch}","tags_url":"https://api.github.com/repos/sbespalov/strongbox/tags","blobs_url":"https://api.github.com/repos/sbespalov/strongbox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sbespalov/strongbox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sbespalov/strongbox/git/refs{/sha}","trees_url":"https://api.github.com/repos/sbespalov/strongbox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sbespalov/strongbox/statuses/{sha}","languages_url":"https://api.github.com/repos/sbespalov/strongbox/languages","stargazers_url":"https://api.github.com/repos/sbespalov/strongbox/stargazers","contributors_url":"https://api.github.com/repos/sbespalov/strongbox/contributors","subscribers_url":"https://api.github.com/repos/sbespalov/strongbox/subscribers","subscription_url":"https://api.github.com/repos/sbespalov/strongbox/subscription","commits_url":"https://api.github.com/repos/sbespalov/strongbox/commits{/sha}","git_commits_url":"https://api.github.com/repos/sbespalov/strongbox/git/commits{/sha}","comments_url":"https://api.github.com/repos/sbespalov/strongbox/comments{/number}","issue_comment_url":"https://api.github.com/repos/sbespalov/strongbox/issues/comments{/number}","contents_url":"https://api.github.com/repos/sbespalov/strongbox/contents/{+path}","compare_url":"https://api.github.com/repos/sbespalov/strongbox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sbespalov/strongbox/merges","archive_url":"https://api.github.com/repos/sbespalov/strongbox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sbespalov/strongbox/downloads","issues_url":"https://api.github.com/repos/sbespalov/strongbox/issues{/number}","pulls_url":"https://api.github.com/repos/sbespalov/strongbox/pulls{/number}","milestones_url":"https://api.github.com/repos/sbespalov/strongbox/milestones{/number}","notifications_url":"https://api.github.com/repos/sbespalov/strongbox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sbespalov/strongbox/labels{/name}","releases_url":"https://api.github.com/repos/sbespalov/strongbox/releases{/id}","deployments_url":"https://api.github.com/repos/sbespalov/strongbox/deployments","created_at":"2016-11-01T01:54:58Z","updated_at":"2016-11-01T01:55:00Z","pushed_at":"2017-04-02T11:12:28Z","git_url":"git://github.com/sbespalov/strongbox.git","ssh_url":"git@github.com:sbespalov/strongbox.git","clone_url":"https://github.com/sbespalov/strongbox.git","svn_url":"https://github.com/sbespalov/strongbox","homepage":null,"size":4436,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"strongbox:master","ref":"master","sha":"f7fa05f63c4e0553d17991830b11693c528f9021","user":{"login":"strongbox","id":5637881,"avatar_url":"https://avatars3.githubusercontent.com/u/5637881?v=3","gravatar_id":"","url":"https://api.github.com/users/strongbox","html_url":"https://github.com/strongbox","followers_url":"https://api.github.com/users/strongbox/followers","following_url":"https://api.github.com/users/strongbox/following{/other_user}","gists_url":"https://api.github.com/users/strongbox/gists{/gist_id}","starred_url":"https://api.github.com/users/strongbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongbox/subscriptions","organizations_url":"https://api.github.com/users/strongbox/orgs","repos_url":"https://api.github.com/users/strongbox/repos","events_url":"https://api.github.com/users/strongbox/events{/privacy}","received_events_url":"https://api.github.com/users/strongbox/received_events","type":"Organization","site_admin":false},"repo":{"id":11830269,"name":"strongbox","full_name":"strongbox/strongbox","owner":{"login":"strongbox","id":5637881,"avatar_url":"https://avatars3.githubusercontent.com/u/5637881?v=3","gravatar_id":"","url":"https://api.github.com/users/strongbox","html_url":"https://github.com/strongbox","followers_url":"https://api.github.com/users/strongbox/followers","following_url":"https://api.github.com/users/strongbox/following{/other_user}","gists_url":"https://api.github.com/users/strongbox/gists{/gist_id}","starred_url":"https://api.github.com/users/strongbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongbox/subscriptions","organizations_url":"https://api.github.com/users/strongbox/orgs","repos_url":"https://api.github.com/users/strongbox/repos","events_url":"https://api.github.com/users/strongbox/events{/privacy}","received_events_url":"https://api.github.com/users/strongbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/strongbox/strongbox","description":null,"fork":false,"url":"https://api.github.com/repos/strongbox/strongbox","forks_url":"https://api.github.com/repos/strongbox/strongbox/forks","keys_url":"https://api.github.com/repos/strongbox/strongbox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/strongbox/strongbox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/strongbox/strongbox/teams","hooks_url":"https://api.github.com/repos/strongbox/strongbox/hooks","issue_events_url":"https://api.github.com/repos/strongbox/strongbox/issues/events{/number}","events_url":"https://api.github.com/repos/strongbox/strongbox/events","assignees_url":"https://api.github.com/repos/strongbox/strongbox/assignees{/user}","branches_url":"https://api.github.com/repos/strongbox/strongbox/branches{/branch}","tags_url":"https://api.github.com/repos/strongbox/strongbox/tags","blobs_url":"https://api.github.com/repos/strongbox/strongbox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/strongbox/strongbox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/strongbox/strongbox/git/refs{/sha}","trees_url":"https://api.github.com/repos/strongbox/strongbox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/strongbox/strongbox/statuses/{sha}","languages_url":"https://api.github.com/repos/strongbox/strongbox/languages","stargazers_url":"https://api.github.com/repos/strongbox/strongbox/stargazers","contributors_url":"https://api.github.com/repos/strongbox/strongbox/contributors","subscribers_url":"https://api.github.com/repos/strongbox/strongbox/subscribers","subscription_url":"https://api.github.com/repos/strongbox/strongbox/subscription","commits_url":"https://api.github.com/repos/strongbox/strongbox/commits{/sha}","git_commits_url":"https://api.github.com/repos/strongbox/strongbox/git/commits{/sha}","comments_url":"https://api.github.com/repos/strongbox/strongbox/comments{/number}","issue_comment_url":"https://api.github.com/repos/strongbox/strongbox/issues/comments{/number}","contents_url":"https://api.github.com/repos/strongbox/strongbox/contents/{+path}","compare_url":"https://api.github.com/repos/strongbox/strongbox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/strongbox/strongbox/merges","archive_url":"https://api.github.com/repos/strongbox/strongbox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/strongbox/strongbox/downloads","issues_url":"https://api.github.com/repos/strongbox/strongbox/issues{/number}","pulls_url":"https://api.github.com/repos/strongbox/strongbox/pulls{/number}","milestones_url":"https://api.github.com/repos/strongbox/strongbox/milestones{/number}","notifications_url":"https://api.github.com/repos/strongbox/strongbox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/strongbox/strongbox/labels{/name}","releases_url":"https://api.github.com/repos/strongbox/strongbox/releases{/id}","deployments_url":"https://api.github.com/repos/strongbox/strongbox/deployments","created_at":"2013-08-01T23:27:37Z","updated_at":"2017-02-23T07:57:51Z","pushed_at":"2017-04-02T11:29:34Z","git_url":"git://github.com/strongbox/strongbox.git","ssh_url":"git@github.com:strongbox/strongbox.git","clone_url":"https://github.com/strongbox/strongbox.git","svn_url":"https://github.com/strongbox/strongbox","homepage":null,"size":4544,"stargazers_count":8,"watchers_count":8,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":6,"forks":27,"open_issues":6,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/strongbox/strongbox/pulls/228"},"html":{"href":"https://github.com/strongbox/strongbox/pull/228"},"issue":{"href":"https://api.github.com/repos/strongbox/strongbox/issues/228"},"comments":{"href":"https://api.github.com/repos/strongbox/strongbox/issues/228/comments"},"review_comments":{"href":"https://api.github.com/repos/strongbox/strongbox/pulls/228/comments"},"review_comment":{"href":"https://api.github.com/repos/strongbox/strongbox/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/strongbox/strongbox/pulls/228/commits"},"statuses":{"href":"https://api.github.com/repos/strongbox/strongbox/statuses/351eebeb2dcf60364410529c898b48c318b519c4"}}}}
{"actor":{"display_login":"sbespalov"}}