use of org.wso2.carbon.apimgt.persistence.dto.DocumentSearchResult in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAllDocumentation.
public List<Documentation> getAllDocumentation(String uuid, String organization) throws APIManagementException {
String username = CarbonContext.getThreadLocalCarbonContext().getUsername();
Organization org = new Organization(organization);
UserContext ctx = new UserContext(username, org, null, null);
List<Documentation> convertedList = null;
try {
DocumentSearchResult list = apiPersistenceInstance.searchDocumentation(org, uuid, 0, 0, null, ctx);
if (list != null) {
convertedList = new ArrayList<Documentation>();
List<org.wso2.carbon.apimgt.persistence.dto.Documentation> docList = list.getDocumentationList();
if (docList != null) {
for (int i = 0; i < docList.size(); i++) {
convertedList.add(DocumentMapper.INSTANCE.toDocumentation(docList.get(i)));
}
}
} else {
convertedList = new ArrayList<Documentation>();
}
} catch (DocumentationPersistenceException e) {
String msg = "Failed to get documentations for api/product " + uuid;
throw new APIManagementException(msg, e);
}
return convertedList;
}
use of org.wso2.carbon.apimgt.persistence.dto.DocumentSearchResult in project carbon-apimgt by wso2.
the class RegistryPersistenceImpl method searchDocumentation.
@Override
public DocumentSearchResult searchDocumentation(Organization org, String apiId, int start, int offset, String searchQuery, UserContext ctx) throws DocumentationPersistenceException {
DocumentSearchResult result = null;
Registry registryType;
String requestedTenantDomain = org.getName();
boolean isTenantFlowStarted = false;
try {
RegistryHolder holder = getRegistry(requestedTenantDomain);
registryType = holder.getRegistry();
isTenantFlowStarted = holder.isTenantFlowStarted();
GenericArtifactManager apiArtifactManager = RegistryPersistenceUtil.getArtifactManager(registryType, APIConstants.API_KEY);
GenericArtifact apiArtifact = apiArtifactManager.getGenericArtifact(apiId);
String apiProviderName = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER);
String apiName = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME);
String apiVersion = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION);
String apiPath = GovernanceUtils.getArtifactPath(registryType, apiId);
int prependIndex = apiPath.lastIndexOf("/api");
String apiSourcePath = apiPath.substring(0, prependIndex);
String apiOrAPIProductDocPath = apiSourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.DOC_DIR + RegistryConstants.PATH_SEPARATOR;
String pathToContent = apiOrAPIProductDocPath + APIConstants.INLINE_DOCUMENT_CONTENT_DIR;
String pathToDocFile = apiOrAPIProductDocPath + APIConstants.DOCUMENT_FILE_DIR;
if (registryType.resourceExists(apiOrAPIProductDocPath)) {
List<Documentation> documentationList = new ArrayList<Documentation>();
Resource resource = registryType.get(apiOrAPIProductDocPath);
if (resource instanceof org.wso2.carbon.registry.core.Collection) {
String[] docsPaths = ((org.wso2.carbon.registry.core.Collection) resource).getChildren();
for (String docPath : docsPaths) {
if (!(docPath.equalsIgnoreCase(pathToContent) || docPath.equalsIgnoreCase(pathToDocFile))) {
Resource docResource = registryType.get(docPath);
GenericArtifactManager artifactManager = RegistryPersistenceDocUtil.getDocumentArtifactManager(registryType);
GenericArtifact docArtifact = artifactManager.getGenericArtifact(docResource.getUUID());
Documentation doc = RegistryPersistenceDocUtil.getDocumentation(docArtifact);
if (searchQuery != null) {
if (searchQuery.toLowerCase().startsWith("name:")) {
String requestedDocName = searchQuery.split(":")[1];
if (doc.getName().equalsIgnoreCase(requestedDocName)) {
documentationList.add(doc);
}
} else {
log.warn("Document search not implemented for the query " + searchQuery);
}
} else {
documentationList.add(doc);
}
}
}
}
result = new DocumentSearchResult();
result.setDocumentationList(documentationList);
}
} catch (RegistryException | APIPersistenceException e) {
String msg = "Failed to get documentations for api/product " + apiId;
throw new DocumentationPersistenceException(msg, e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return result;
}
use of org.wso2.carbon.apimgt.persistence.dto.DocumentSearchResult in project carbon-apimgt by wso2.
the class APIProviderImpl method isDocumentationExist.
@Override
public boolean isDocumentationExist(String uuid, String docName, String organization) throws APIManagementException {
boolean exist = false;
UserContext ctx = null;
try {
DocumentSearchResult result = apiPersistenceInstance.searchDocumentation(new Organization(organization), uuid, 0, 0, "name:" + docName, ctx);
if (result != null && result.getDocumentationList() != null && !result.getDocumentationList().isEmpty()) {
String returnDocName = result.getDocumentationList().get(0).getName();
if (returnDocName != null && returnDocName.equals(docName)) {
exist = true;
}
}
} catch (DocumentationPersistenceException e) {
handleException("Failed to search documentation for name " + docName, e);
}
return exist;
}
Aggregations