Skip to content

Commit

Permalink
Merge pull request #1176 from yashkohli88/yk/fix-origins-maven-error
Browse files Browse the repository at this point in the history
Fixed origins api for maven components throwing 500 error when invalid group id is provided
  • Loading branch information
elrayle authored Aug 22, 2024
2 parents c9419ab + 9316fdc commit 9a1cb7a
Show file tree
Hide file tree
Showing 7 changed files with 1,516 additions and 2 deletions.
5 changes: 3 additions & 2 deletions routes/originMaven.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ function getSuggestions(answer, group) {
return docs.map(item => {
return { id: item.id }
})
const suggestions = answer.spellcheck.suggestions[1]
const suggestions = answer.spellcheck?.suggestions?.[1]
const result = suggestions ? suggestions.suggestion : []
return group ? result.map(entry => `${group}:${entry}`) : result
}

function setup() {
function setup(testFlag = false) {
if (testFlag) router._getSuggestions = getSuggestions
return router
}

Expand Down
22 changes: 22 additions & 0 deletions test/fixtures/origins/maven/12345-1234.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"responseHeader": {
"status": 0,
"QTime": 2,
"params": {
"q": "g:\"12345\" AND a:\"1234\"",
"core": "gav",
"indent": "off",
"fl": "id,g,a,v,p,ec,timestamp,tags",
"start": "",
"sort": "score desc,timestamp desc,g asc,a asc,v desc",
"rows": "100",
"wt": "json",
"version": "2.2"
}
},
"response": {
"numFound": 0,
"start": 0,
"docs": []
}
}
26 changes: 26 additions & 0 deletions test/fixtures/origins/maven/12345.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"responseHeader": {
"status": 0,
"QTime": 1,
"params": {
"q": "12345",
"core": "",
"defType": "dismax",
"qf": "text^20 g^5 a^10",
"indent": "off",
"spellcheck": "true",
"fl": "id,g,a,latestVersion,p,ec,repositoryId,text,timestamp,versionCount",
"start": "",
"spellcheck.count": "5",
"sort": "score desc,timestamp desc,g asc,a asc",
"rows": "100",
"wt": "json",
"version": "2.2"
}
},
"response": {
"numFound": 0,
"start": 0,
"docs": []
}
}
46 changes: 46 additions & 0 deletions test/fixtures/origins/maven/org.apache.httpcom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"responseHeader": {
"status": 0,
"QTime": 2,
"params": {
"q": "org.apache.httpcomp",
"core": "",
"defType": "dismax",
"qf": "text^20 g^5 a^10",
"indent": "off",
"spellcheck": "true",
"fl": "id,g,a,latestVersion,p,ec,repositoryId,text,timestamp,versionCount",
"start": "",
"spellcheck.count": "5",
"sort": "score desc,timestamp desc,g asc,a asc",
"rows": "100",
"wt": "json",
"version": "2.2"
}
},
"response": {
"numFound": 0,
"start": 0,
"docs": []
},
"spellcheck": {
"suggestions": [
"httpcomp",
{
"numFound": 5,
"startOffset": 11,
"endOffset": 19,
"suggestion": [
"httpcore",
"httpconn",
"httpcodec",
"httpcommons",
"httprox"
]
}
]
},
"alternate": [
"fc:org.apache.httpcomp"
]
}
158 changes: 158 additions & 0 deletions test/fixtures/origins/maven/org.apache.httpcomponents-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
[
{
"id": "org.apache.httpcomponents:project"
},
{
"id": "org.apache.httpcomponents:hc-stylecheck"
},
{
"id": "org.apache.httpcomponents:httpcore-niossl"
},
{
"id": "org.apache.httpcomponents:jakarta-httpcore"
},
{
"id": "org.apache.httpcomponents:httpmime"
},
{
"id": "org.apache.httpcomponents:httpcomponents-client"
},
{
"id": "org.apache.httpcomponents:httpcore-osgi"
},
{
"id": "org.apache.httpcomponents:httpcomponents-core"
},
{
"id": "org.apache.httpcomponents:httpasyncclient-osgi"
},
{
"id": "org.apache.httpcomponents:httpasyncclient"
},
{
"id": "org.apache.httpcomponents:httpcomponents-asyncclient"
},
{
"id": "org.wso2.orbit.org.apache.httpcomponents:httpasyncclient"
},
{
"id": "org.wso2.orbit.org.apache.httpcomponents:httpmime"
},
{
"id": "org.wso2.orbit.org.apache.httpcomponents:httpclient"
},
{
"id": "org.apache.httpcomponents.core5:httpcore5-osgi"
},
{
"id": "org.kie.modules:org-apache-httpcomponents-main"
},
{
"id": "org.apache.httpcomponents:maven-site-skin"
},
{
"id": "org.apache.httpcomponents:maven-notice-plugin"
},
{
"id": "org.apache.httpcomponents:jakarta-httpcore-niossl"
},
{
"id": "org.apache.httpcomponents:jakarta-httpcore-nio"
},
{
"id": "org.apache.httpcomponents.client5:httpclient5-testing"
},
{
"id": "org.apache.httpcomponents.client5:httpclient5-cache"
},
{
"id": "org.apache.httpcomponents.client5:httpclient5-fluent"
},
{
"id": "org.apache.httpcomponents.client5:httpclient5"
},
{
"id": "org.apache.httpcomponents.client5:httpclient5-parent"
},
{
"id": "org.apache.httpcomponents.core5:httpcore5-testing"
},
{
"id": "org.apache.httpcomponents.core5:httpcore5-reactive"
},
{
"id": "org.apache.httpcomponents.core5:httpcore5-h2"
},
{
"id": "org.apache.httpcomponents.core5:httpcore5"
},
{
"id": "org.apache.httpcomponents.core5:httpcore5-parent"
},
{
"id": "org.bedework.deploy:bw-wfmodules-org-apache-httpcomponents-httpcore"
},
{
"id": "org.bedework.deploy:bw-wfmodules-org-apache-httpcomponents-httpclient"
},
{
"id": "org.apache.httpcomponents.client5:httpclient5-win"
},
{
"id": "com.basistech.org.apache.httpcomponents:httpclient-osgi"
},
{
"id": "org.apache.httpcomponents:httpclient-osgi"
},
{
"id": "org.apache.httpcomponents:httpclient-win"
},
{
"id": "org.apache.httpcomponents:httpclient-cache"
},
{
"id": "org.apache.httpcomponents:fluent-hc"
},
{
"id": "org.apache.httpcomponents:httpclient"
},
{
"id": "org.apache.httpcomponents:httpcore-ab"
},
{
"id": "org.apache.httpcomponents:httpcore-nio"
},
{
"id": "org.apache.httpcomponents:httpcore"
},
{
"id": "org.apache.httpcomponents:httpcomponents-parent"
},
{
"id": "org.apache.httpcomponents:httpasyncclient-cache"
},
{
"id": "com.liferay:org.apache.httpcomponents.httpclient"
},
{
"id": "org.apache.httpcomponents.client5:httpclient5-osgi"
},
{
"id": "org.eclipse.ecf:org.apache.httpcomponents.httpcore"
},
{
"id": "org.eclipse.ecf:org.apache.httpcomponents.httpclient"
},
{
"id": "org.apache.httpcomponents.core5:httpcore5-ab"
},
{
"id": "org.apache.httpcomponents:httpclient-android"
},
{
"id": "org.apache.directory.studio:org.apache.httpcomponents.httpclient"
},
{
"id": "org.apache.directory.studio:org.apache.httpcomponents.httpcore"
}
]
Loading

0 comments on commit 9a1cb7a

Please sign in to comment.