-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12480 from Avishka-Shamendra/swagger-content-search
Search Enhancements Add API Definition Content Search
- Loading branch information
Showing
27 changed files
with
2,149 additions
and
52 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
....api/src/main/java/org/wso2/carbon/apimgt/api/model/APIDefinitionContentSearchResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.apimgt.api.model; | ||
|
||
/** | ||
* This model is used to represent the API defintion content search results. | ||
*/ | ||
public class APIDefinitionContentSearchResult { | ||
|
||
private String id; | ||
private String name; | ||
private String apiUuid; | ||
private String apiName; | ||
private String apiContext; | ||
private String apiVersion; | ||
private String apiProvider; | ||
private String apiType; | ||
private String associatedType; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getApiUuid() { | ||
return apiUuid; | ||
} | ||
|
||
public void setApiUuid(String apiUuid) { | ||
this.apiUuid = apiUuid; | ||
} | ||
|
||
public String getApiName() { | ||
return apiName; | ||
} | ||
|
||
public void setApiName(String apiName) { | ||
this.apiName = apiName; | ||
} | ||
|
||
public String getApiVersion() { | ||
return apiVersion; | ||
} | ||
|
||
public void setApiVersion(String apiVersion) { | ||
this.apiVersion = apiVersion; | ||
} | ||
|
||
public String getApiProvider() { | ||
return apiProvider; | ||
} | ||
|
||
public void setApiProvider(String apiProvider) { | ||
this.apiProvider = apiProvider; | ||
} | ||
|
||
public String getApiType() { | ||
return apiType; | ||
} | ||
|
||
public void setApiType(String apiType) { | ||
this.apiType = apiType; | ||
} | ||
|
||
public String getAssociatedType() { | ||
return associatedType; | ||
} | ||
|
||
public void setAssociatedType(String associatedType) { | ||
this.associatedType = associatedType; | ||
} | ||
|
||
public String getApiContext() { | ||
return apiContext; | ||
} | ||
|
||
public void setApiContext(String apiContext) { | ||
this.apiContext = apiContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...c/main/java/org/wso2/carbon/apimgt/impl/indexing/indexer/GraphQLAPIDefinitionIndexer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.apimgt.impl.indexing.indexer; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.solr.common.SolrException; | ||
import org.wso2.carbon.apimgt.api.APIManagementException; | ||
import org.wso2.carbon.apimgt.impl.APIConstants; | ||
import org.wso2.carbon.apimgt.impl.utils.IndexerUtil; | ||
import org.wso2.carbon.governance.api.util.GovernanceUtils; | ||
import org.wso2.carbon.registry.core.Registry; | ||
import org.wso2.carbon.registry.core.RegistryConstants; | ||
import org.wso2.carbon.registry.core.Resource; | ||
import org.wso2.carbon.registry.core.exceptions.RegistryException; | ||
import org.wso2.carbon.registry.core.utils.RegistryUtils; | ||
import org.wso2.carbon.registry.indexing.AsyncIndexer; | ||
import org.wso2.carbon.registry.indexing.IndexingManager; | ||
import org.wso2.carbon.registry.indexing.solr.IndexDocument; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* This is the graphql definition indexer introduced to .graphgl definition artifacts for unified content search. | ||
*/ | ||
public class GraphQLAPIDefinitionIndexer extends PlainTextIndexer { | ||
public static final Log log = LogFactory.getLog(GraphQLAPIDefinitionIndexer.class); | ||
|
||
@Override | ||
public IndexDocument getIndexedDocument(AsyncIndexer.File2Index fileData) throws SolrException, RegistryException { | ||
Registry registry = GovernanceUtils | ||
.getGovernanceSystemRegistry(IndexingManager.getInstance().getRegistry(fileData.tenantId)); | ||
String definitionResourcePath = | ||
fileData.path.substring(RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH.length()); | ||
|
||
// If the file is not a graphql definition file in provider path do not index | ||
if (!definitionResourcePath.contains(APIConstants.APPLICATION_DATA_RESOURCE_URL_PREFIX) | ||
|| !definitionResourcePath.contains(APIConstants.GRAPHQL_SCHEMA_FILE_EXTENSION)) { | ||
return null; | ||
} | ||
|
||
// Extract only required info (types) from graphql definition to index | ||
String schemaString = RegistryUtils.decodeBytes(fileData.data); | ||
String definitionString = IndexerUtil.getTypesFromGraphQLSchemaString(schemaString); | ||
fileData.data = definitionString.getBytes(); | ||
|
||
IndexDocument indexDocument = super.getIndexedDocument(fileData); | ||
IndexDocument newIndexDocument = indexDocument; | ||
|
||
if (log.isDebugEnabled()) { | ||
log.debug("Executing GraphQL file indexer for resource at " + definitionResourcePath); | ||
} | ||
|
||
Resource definitionResource = null; | ||
Map<String, List<String>> fields = indexDocument.getFields(); | ||
|
||
if (registry.resourceExists(definitionResourcePath)) { | ||
definitionResource = registry.get(definitionResourcePath); | ||
} | ||
|
||
if (definitionResource != null) { | ||
try { | ||
IndexerUtil.fetchRequiredDetailsFromAssociatedAPI(registry, definitionResource, fields); | ||
newIndexDocument = | ||
new IndexDocument(fileData.path, null, | ||
indexDocument.getRawContent(), indexDocument.getTenantId()); | ||
fields.put(APIConstants.DOCUMENT_INDEXER_INDICATOR, Arrays.asList("true")); | ||
newIndexDocument.setFields(fields); | ||
} catch (APIManagementException e) { | ||
//error occurred while fetching details from API, but continuing indexing | ||
log.error("Error while updating indexed document.", e); | ||
} | ||
} | ||
|
||
return newIndexDocument; | ||
} | ||
} |
Oops, something went wrong.