use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsGet.
/**
* Retrieves a list of documents of an API
*
* @param apiId UUID of API
* @param limit maximum documents to return
* @param offset starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request minor version header
* @return a list of document DTOs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdDocumentsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
DocumentListDTO documentListDTO = null;
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
List<DocumentInfo> documentInfoResults = apiStore.getAllDocumentation(apiId, offset, limit);
documentListDTO = DocumentationMappingUtil.fromDocumentationListToDTO(documentInfoResults, offset, limit);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving documentation for given apiId " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(documentListDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdDocumentsGet.
/**
* Retrieves a list of documents of an API
*
* @param apiId UUID of API
* @param limit maximum documents to return
* @param offset starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return a list of document DTOs
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdDocumentsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
List<DocumentInfo> documentInfos = apiPublisher.getAllDocumentation(apiId, offset, limit);
DocumentListDTO documentListDTO = MappingUtil.toDocumentListDTO(documentInfos);
return Response.status(Response.Status.OK).entity(documentListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while getting list of documents" + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentListDTO in project carbon-apimgt by wso2.
the class DocumentationMappingUtil method fromDocumentationListToDTO.
/**
* Converts a List object of Documents into a DTO.
*
* @param documentations List of Documentations
* @param limit maximum number of APIs returns
* @param offset starting index
* @return DocumentListDTO object containing Document DTOs
*/
public static DocumentListDTO fromDocumentationListToDTO(List<Documentation> documentations, int offset, int limit) {
DocumentListDTO documentListDTO = new DocumentListDTO();
List<DocumentDTO> documentDTOs = documentListDTO.getList();
if (documentDTOs == null) {
documentDTOs = new ArrayList<>();
documentListDTO.setList(documentDTOs);
}
// add the required range of objects to be returned
int start = offset < documentations.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= documentations.size() - 1 ? offset + limit - 1 : documentations.size() - 1;
for (int i = start; i <= end; i++) {
documentDTOs.add(fromDocumentationToDTO(documentations.get(i)));
}
documentListDTO.setCount(documentDTOs.size());
return documentListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentListDTO 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.rest.api.publisher.v1.dto.DocumentListDTO in project carbon-apimgt by wso2.
the class DocumentationMappingUtil method fromDocumentationListToDTO.
/**
* Converts a List object of ArtifactResourceMetaData into a DTO
*
* @param documentInfoList List of ArtifactResourceMetaData
* @param limit maximum number of APIs returns
* @param offset starting index
* @return DocumentListDTO object containing Document DTOs
*/
public static DocumentListDTO fromDocumentationListToDTO(List<DocumentInfo> documentInfoList, int offset, int limit) {
DocumentListDTO documentListDTO = new DocumentListDTO();
List<DocumentDTO> documentDTOs = documentListDTO.getList();
if (documentDTOs == null) {
documentDTOs = new ArrayList<>();
documentListDTO.setList(documentDTOs);
}
// add the required range of objects to be returned
int start = offset < documentInfoList.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= documentInfoList.size() - 1 ? offset + limit - 1 : documentInfoList.size() - 1;
for (int i = start; i <= end; i++) {
documentDTOs.add(fromDocumentationToDTO(documentInfoList.get(i)));
}
documentListDTO.setCount(documentDTOs.size());
return documentListDTO;
}
Aggregations