use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class PublisherCommonUtils method addDocumentationContent.
/**
* Add documentation content of inline and markdown documents.
*
* @param documentation Documentation
* @param apiProvider API Provider
* @param apiId API/API Product UUID
* @param documentId Document ID
* @param organization Identifier of the organization
* @param inlineContent Inline content string
* @throws APIManagementException If an error occurs while adding the documentation content
*/
public static void addDocumentationContent(Documentation documentation, APIProvider apiProvider, String apiId, String documentId, String organization, String inlineContent) throws APIManagementException {
DocumentationContent content = new DocumentationContent();
content.setSourceType(DocumentationContent.ContentSourceType.valueOf(documentation.getSourceType().toString()));
content.setTextContent(inlineContent);
apiProvider.addDocumentationContent(apiId, documentId, organization, content);
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsDocumentIdGet.
@Override
public Response apisApiIdDocumentsDocumentIdGet(String apiId, String documentId, String xWSO2Tenant, String ifModifiedSince, MessageContext messageContext) {
Documentation documentation;
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
if (!RestAPIStoreUtils.isUserAccessAllowedForAPIByUUID(apiId, organization)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_API, apiId, log);
}
documentation = apiConsumer.getDocumentation(apiId, documentId, organization);
if (null != documentation) {
DocumentDTO documentDTO = DocumentationMappingUtil.fromDocumentationToDTO(documentation);
return Response.ok().entity(documentDTO).build();
} else {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_DOCUMENTATION, documentId, log);
}
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Error while getting API " + apiId, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsGet.
@Override
public Response apisApiIdDocumentsGet(String apiId, Integer limit, Integer offset, String xWSO2Tenant, String ifNoneMatch, MessageContext messageContext) {
// pre-processing
// setting default limit and offset values if they are not set
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
// this will fail if user doesn't have access to the API or the API does not exist
// APIIdentifier apiIdentifier = APIMappingUtil.getAPIIdentifierFromUUID(apiId, organization);
// List<Documentation> documentationList = apiConsumer.getAllDocumentation(apiIdentifier, username);
List<Documentation> documentationList = apiConsumer.getAllDocumentation(apiId, organization);
DocumentListDTO documentListDTO = DocumentationMappingUtil.fromDocumentationListToDTO(documentationList, offset, limit);
// todo : set total count properly
DocumentationMappingUtil.setPaginationParams(documentListDTO, apiId, offset, limit, documentationList.size());
return Response.ok().entity(documentListDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Error while getting API " + apiId, e, log);
}
}
/*catch (UnsupportedEncodingException e) {
String errorMessage = "Error while Decoding apiId" + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}*/
return null;
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class SearchApiServiceImpl method searchGet.
@Override
public Response searchGet(Integer limit, Integer offset, String xWSO2Tenant, String query, String ifNoneMatch, MessageContext messageContext) {
SearchResultListDTO resultListDTO = new SearchResultListDTO();
List<SearchResultDTO> allmatchedResults = new ArrayList<>();
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
query = query == null ? "*" : query;
String organization = RestApiUtil.getOrganization(messageContext);
try {
if (!query.contains(":")) {
query = (APIConstants.CONTENT_SEARCH_TYPE_PREFIX + ":" + query);
}
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
Map<String, Object> result = null;
// Extracting search queries for the recommendation system
apiConsumer.publishSearchQuery(query, username);
if (query.startsWith(APIConstants.CONTENT_SEARCH_TYPE_PREFIX)) {
result = apiConsumer.searchPaginatedContent(query, organization, offset, limit);
} else {
result = apiConsumer.searchPaginatedAPIs(query, organization, offset, limit, null, null);
}
ArrayList<Object> apis;
/* Above searchPaginatedAPIs method underneath calls searchPaginatedAPIsByContent method,searchPaginatedAPIs
method and searchAPIDoc method in AbstractApiManager. And those methods respectively returns ArrayList,
TreeSet and a HashMap.
Hence the below logic.
*/
Object apiSearchResults = result.get("apis");
if (apiSearchResults instanceof List<?>) {
apis = (ArrayList<Object>) apiSearchResults;
} else if (apiSearchResults instanceof HashMap) {
Collection<String> values = ((HashMap) apiSearchResults).values();
apis = new ArrayList<Object>(values);
} else {
apis = new ArrayList<Object>();
apis.addAll((Collection<?>) apiSearchResults);
}
for (Object searchResult : apis) {
if (searchResult instanceof API) {
API api = (API) searchResult;
SearchResultDTO apiResult = SearchResultMappingUtil.fromAPIToAPIResultDTO(api);
allmatchedResults.add(apiResult);
} else if (searchResult instanceof Map.Entry) {
Map.Entry pair = (Map.Entry) searchResult;
SearchResultDTO docResult = SearchResultMappingUtil.fromDocumentationToDocumentResultDTO((Documentation) pair.getKey(), (API) pair.getValue());
allmatchedResults.add(docResult);
} else if (searchResult instanceof APIProduct) {
APIProduct apiProduct = (APIProduct) searchResult;
SearchResultDTO apiResult = SearchResultMappingUtil.fromAPIToAPIResultDTO(apiProduct);
allmatchedResults.add(apiResult);
}
}
Object totalLength = result.get("length");
Integer length = 0;
if (totalLength != null) {
length = (Integer) totalLength;
}
List<Object> allmatchedObjectResults = new ArrayList<>(allmatchedResults);
resultListDTO.setList(allmatchedObjectResults);
resultListDTO.setCount(allmatchedResults.size());
SearchResultMappingUtil.setPaginationParams(resultListDTO, query, offset, limit, length);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving search results";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return Response.ok().entity(resultListDTO).build();
}
use of org.wso2.carbon.apimgt.persistence.dto.Documentation in project carbon-apimgt by wso2.
the class SearchResultMappingUtil method fromDocumentationToDocumentResultDTO.
/**
* Get Document result representation for content search
* @param document
* @return
*/
public static DocumentSearchResultDTO fromDocumentationToDocumentResultDTO(Documentation document, API api) {
DocumentSearchResultDTO docResultDTO = new DocumentSearchResultDTO();
docResultDTO.setId(document.getId());
docResultDTO.setName(document.getName());
docResultDTO.setDocType(DocumentSearchResultDTO.DocTypeEnum.valueOf(document.getType().toString()));
docResultDTO.setType(SearchResultDTO.TypeEnum.DOC);
docResultDTO.setSummary(document.getSummary());
docResultDTO.setVisibility(DocumentSearchResultDTO.VisibilityEnum.valueOf(document.getVisibility().toString()));
docResultDTO.setSourceType(DocumentSearchResultDTO.SourceTypeEnum.valueOf(document.getSourceType().toString()));
docResultDTO.setOtherTypeName(document.getOtherTypeName());
APIIdentifier apiId = api.getId();
docResultDTO.setApiName(apiId.getApiName());
docResultDTO.setApiVersion(apiId.getVersion());
docResultDTO.setApiProvider(apiId.getProviderName());
docResultDTO.setApiUUID(api.getUUID());
return docResultDTO;
}
Aggregations