use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class ExternalStoreMappingUtil method fromExternalStoreCollectionToDTO.
/**
* Converts a list of APIStore objects into a ExternalStoreListDTO.
*
* @param externalStoreCollection a collection of APIStore objects
* @return ExternalStoreListDTO object containing ExternalStoreDTOs
*/
public static ExternalStoreListDTO fromExternalStoreCollectionToDTO(Collection<APIStore> externalStoreCollection) {
ExternalStoreListDTO externalStoreListDTO = new ExternalStoreListDTO();
List<ExternalStoreDTO> externalStoreDTOS = externalStoreListDTO.getList();
if (externalStoreCollection == null) {
externalStoreCollection = new HashSet<>();
}
for (APIStore externalStore : externalStoreCollection) {
externalStoreDTOS.add(fromExternalStoreToDTO(externalStore));
}
externalStoreListDTO.setList(externalStoreDTOS);
externalStoreListDTO.setCount(externalStoreDTOS.size());
return externalStoreListDTO;
}
use of org.wso2.carbon.registry.core.Collection 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.registry.core.Collection in project carbon-apimgt by wso2.
the class ApiDAOImpl method addUrlMappings.
private void addUrlMappings(Connection connection, Collection<UriTemplate> uriTemplates, String apiID) throws SQLException {
final String query = "INSERT INTO AM_API_OPERATION_MAPPING (OPERATION_ID,API_ID, HTTP_METHOD, URL_PATTERN, " + "AUTH_SCHEME, API_POLICY_ID) VALUES (?,?,?,?,?,?)";
try (PreparedStatement statement = connection.prepareStatement(query)) {
for (UriTemplate uriTemplate : uriTemplates) {
statement.setString(1, uriTemplate.getTemplateId());
statement.setString(2, apiID);
statement.setString(3, uriTemplate.getHttpVerb());
statement.setString(4, uriTemplate.getUriTemplate());
statement.setString(5, uriTemplate.getAuthType());
statement.setString(6, uriTemplate.getPolicy().getUuid());
statement.addBatch();
}
statement.executeBatch();
for (UriTemplate uriTemplate : uriTemplates) {
addEndPointsForOperation(connection, apiID, uriTemplate.getTemplateId(), uriTemplate.getEndpoint());
}
}
}
use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class WSDL20ProcessorImpl method initPath.
/**
* {@inheritDoc}
* Will return true if all the provided WSDL files in the initialized path is of 2.0 and can be successfully
* parsed by woden.
*/
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
pathToDescriptionMap = new HashMap<>();
wsdlArchiveExtractedPath = path;
try {
WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
File folderToImport = new File(path);
Collection<File> foundWSDLFiles = APIFileUtils.searchFilesWithMatchingExtension(folderToImport, "wsdl");
if (log.isDebugEnabled()) {
log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
}
for (File file : foundWSDLFiles) {
if (log.isDebugEnabled()) {
log.debug("Processing WSDL file: " + file.getAbsolutePath());
}
Description description = reader.readWSDL(file.getAbsolutePath());
pathToDescriptionMap.put(file.getAbsolutePath(), description);
}
if (foundWSDLFiles.size() > 0) {
canProcess = true;
}
if (log.isDebugEnabled()) {
log.debug("Successfully processed all WSDL files in path " + path);
}
} catch (WSDLException e) {
// This implementation class cannot process the WSDL.
log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
canProcess = false;
}
return canProcess;
}
use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method initPath.
/**
* {@inheritDoc}
* Will return true if all the provided WSDL files in the initialized path is of 1.1 and can be successfully
* parsed by WSDL4J.
*/
@Override
public boolean initPath(String path) throws APIMgtWSDLException {
pathToDefinitionMap = new HashMap<>();
wsdlArchiveExtractedPath = path;
WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
// switch off the verbose mode
wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
try {
File folderToImport = new File(path);
Collection<File> foundWSDLFiles = APIFileUtils.searchFilesWithMatchingExtension(folderToImport, "wsdl");
if (log.isDebugEnabled()) {
log.debug("Found " + foundWSDLFiles.size() + " WSDL file(s) in path " + path);
}
for (File file : foundWSDLFiles) {
String absWSDLPath = file.getAbsolutePath();
if (log.isDebugEnabled()) {
log.debug("Processing WSDL file: " + absWSDLPath);
}
Definition definition = wsdlReader.readWSDL(null, absWSDLPath);
pathToDefinitionMap.put(absWSDLPath, definition);
}
if (foundWSDLFiles.size() > 0) {
canProcess = true;
}
if (log.isDebugEnabled()) {
log.debug("Successfully processed all WSDL files in path " + path);
}
} catch (WSDLException e) {
// This implementation class cannot process the WSDL.
log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
canProcess = false;
}
return canProcess;
}
Aggregations