use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentListDTO in project carbon-apimgt by wso2.
the class TestMappingUtilTestCase method testDocumentInfoListToDocumentDTOMapping.
@Test(description = "Document Info list to Document DTO list mapping")
void testDocumentInfoListToDocumentDTOMapping() {
DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo().id("newId1").name("newName1").fileName("newFile1").summary("newSum1").build();
DocumentInfo documentInfo2 = SampleTestObjectCreator.createDefaultDocumentationInfo().id("newId2").name("newName2").fileName("newFile2").summary("newSum2").build();
List<DocumentInfo> documentInfos = new ArrayList<>();
documentInfos.add(documentInfo1);
documentInfos.add(documentInfo2);
DocumentListDTO documentListDTO = MappingUtil.toDocumentListDTO(documentInfos);
assertEquals((Integer) documentInfos.size(), documentListDTO.getCount());
assertEquals(documentInfo1.getName(), documentListDTO.getList().get(0).getName());
assertEquals(documentInfo1.getId(), documentListDTO.getList().get(0).getDocumentId());
assertEquals(documentInfo1.getOtherType(), documentListDTO.getList().get(0).getOtherTypeName());
assertEquals(documentInfo1.getSourceType().getType(), documentListDTO.getList().get(0).getSourceType().name());
assertEquals(documentInfo1.getSourceURL(), documentListDTO.getList().get(0).getSourceUrl());
assertEquals(documentInfo1.getFileName(), documentListDTO.getList().get(0).getFileName());
assertEquals(documentInfo1.getSummary(), documentListDTO.getList().get(0).getSummary());
assertEquals(documentInfo1.getVisibility().toString(), documentListDTO.getList().get(0).getVisibility().name());
assertEquals(documentInfo1.getType().toString(), documentListDTO.getList().get(0).getType().name());
assertEquals(documentInfo2.getName(), documentListDTO.getList().get(1).getName());
assertEquals(documentInfo2.getId(), documentListDTO.getList().get(1).getDocumentId());
assertEquals(documentInfo2.getOtherType(), documentListDTO.getList().get(1).getOtherTypeName());
assertEquals(documentInfo2.getSourceType().getType(), documentListDTO.getList().get(1).getSourceType().name());
assertEquals(documentInfo2.getSourceURL(), documentListDTO.getList().get(1).getSourceUrl());
assertEquals(documentInfo2.getFileName(), documentListDTO.getList().get(1).getFileName());
assertEquals(documentInfo2.getSummary(), documentListDTO.getList().get(1).getSummary());
assertEquals(documentInfo2.getVisibility().toString(), documentListDTO.getList().get(1).getVisibility().name());
assertEquals(documentInfo2.getType().toString(), documentListDTO.getList().get(1).getType().name());
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentListDTO in project carbon-apimgt by wso2.
the class MappingUtil method toDocumentListDTO.
/**
* This method converts documentInfoResults to documentListDTO
*
* @param documentInfoResults list of document which return as results
* @return DTO cotaning document list
*/
public static DocumentListDTO toDocumentListDTO(List<DocumentInfo> documentInfoResults) {
DocumentListDTO documentListDTO = new DocumentListDTO();
for (DocumentInfo documentInfo : documentInfoResults) {
documentListDTO.addListItem(toDocumentDTO(documentInfo));
}
documentListDTO.setCount(documentInfoResults.size());
return documentListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentListDTO in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method getAPIProductDocuments.
@Override
public Response getAPIProductDocuments(String apiProductId, Integer limit, Integer offset, String accept, String ifNoneMatch, MessageContext messageContext) {
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// this will fail if user does not have access to the API Product or the API Product does not exist
APIProductIdentifier productIdentifier = APIMappingUtil.getAPIProductIdentifierFromUUID(apiProductId, organization);
List<Documentation> allDocumentation = apiProvider.getAllDocumentation(apiProductId, organization);
DocumentListDTO documentListDTO = DocumentationMappingUtil.fromDocumentationListToDTO(allDocumentation, offset, limit);
DocumentationMappingUtil.setPaginationParams(documentListDTO, apiProductId, offset, limit, allDocumentation.size());
return Response.ok().entity(documentListDTO).build();
} catch (APIManagementException e) {
// Auth failure occurs when cross tenant accessing APIs. Sends 404, since we don't need to expose the existence of the resource
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API_PRODUCT, apiProductId, e, log);
} else if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving documents of API Product : " + apiProductId, e, log);
} else {
String msg = "Error while retrieving documents of API Product " + apiProductId;
RestApiUtil.handleInternalServerError(msg, 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 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 DocumentationMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a DocumentListDTO object given pagination parameters and url parameters
*
* @param documentListDTO a DocumentListDTO object
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(DocumentListDTO documentListDTO, String apiId, int offset, int limit, int size) {
// acquiring pagination parameters and setting pagination urls
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getDocumentationPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getDocumentationPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId);
}
PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
documentListDTO.setPagination(paginationDTO);
}
Aggregations