use of org.wso2.carbon.identity.configuration.mgt.core.model.Resources in project carbon-apimgt by wso2.
the class SOAPOperationBindingUtils method getSoapOperationMapping.
/**
* Gets soap operations to rest resources mapping for a wsdl byte content
*
* @param wsdlContent WSDL byte content
* @return swagger json string with the soap operation mapping
* @throws APIManagementException if an error occurs when generating swagger
*/
public static String getSoapOperationMapping(byte[] wsdlContent) throws APIManagementException {
WSDL11SOAPOperationExtractor processor = APIMWSDLReader.getWSDLSOAPOperationExtractor(wsdlContent);
WSDLInfo wsdlInfo = processor.getWsdlInfo();
return getGeneratedSwaggerFromWSDL(wsdlInfo);
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resources in project carbon-apimgt by wso2.
the class SequenceUtils method getRestToSoapConvertedSequence.
/**
* Gets soap to rest converted sequence from the registry
* <p>
* Note: this method is directly invoked from the jaggery layer
*
* @param api API
* @param seqType to identify the sequence is whether in/out sequence
* @return converted sequences string for a given operation
* @throws APIManagementException throws exceptions on unsuccessful retrieval of resources in registry
*/
public static String getRestToSoapConvertedSequence(API api, String seqType) throws APIManagementException {
JSONObject resultJson = new JSONObject();
List<SOAPToRestSequence> sequences = api.getSoapToRestSequences();
if (sequences == null) {
handleException("Cannot find any resource policies for the api " + api.getUuid());
}
for (SOAPToRestSequence sequence : sequences) {
if (sequence.getDirection().toString().equalsIgnoreCase(seqType)) {
String content = sequence.getContent();
String resourceName = sequence.getPath();
String httpMethod = sequence.getMethod();
Map<String, String> resourceMap = new HashMap<>();
resourceMap.put(SOAPToRESTConstants.RESOURCE_ID, sequence.getUuid());
resourceMap.put(SOAPToRESTConstants.METHOD, httpMethod);
resourceMap.put(SOAPToRESTConstants.CONTENT, content);
resultJson.put(resourceName + "_" + httpMethod, resourceMap);
}
}
if (log.isDebugEnabled()) {
log.debug("Saved sequence for type " + seqType + " for api:" + api.getId().getProviderName() + "-" + api.getId().getApiName() + "-" + api.getId().getVersion() + " is: " + resultJson.toJSONString());
}
return resultJson.toJSONString();
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resources in project carbon-apimgt by wso2.
the class ServiceCatalogDAO method getServiceByNameAndVersion.
/**
* Get service information by name and version
*
* @param name Service name
* @param version Service version
* @param tenantId ID of the owner's tenant
* @return ServiceEntry
* throws APIManagementException if failed to retrieve
*/
public ServiceEntry getServiceByNameAndVersion(String name, String version, int tenantId) throws APIManagementException {
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement ps = connection.prepareStatement(SQLConstants.ServiceCatalogConstants.GET_SERVICE_BY_NAME_AND_VERSION)) {
ps.setString(1, name);
ps.setString(2, version);
ps.setInt(3, tenantId);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
ServiceEntry serviceEntry = getServiceParams(rs, false);
return serviceEntry;
}
}
} catch (SQLException e) {
handleException("Error while executing SQL for getting catalog entry resources", e);
}
return null;
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resources in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetSwaggerDefinitionTimeStamps.
@Test
public void testGetSwaggerDefinitionTimeStamps() throws Exception {
APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION);
UserRegistry registry = Mockito.mock(UserRegistry.class);
Mockito.when(tenantManager.getTenantId(Mockito.anyString())).thenThrow(UserStoreException.class).thenReturn(-1234);
PowerMockito.mockStatic(OASParserUtil.class);
Mockito.when(registryService.getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt())).thenThrow(RegistryException.class).thenReturn(registry);
AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(null, registryService, registry, tenantManager);
Assert.assertNull(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier));
Assert.assertNull(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier));
abstractAPIManager.tenantDomain = SAMPLE_TENANT_DOMAIN_1;
Map<String, String> result = new HashMap<String, String>();
result.put("swagger1", "scopes:apim_create,resources:{get:/*}");
result.put("swagger2", "scopes:apim_view,resources:{get:/menu}");
// Mockito.when(apiDefinitionFromOpenAPISpec.getAPIOpenAPIDefinitionTimeStamps((APIIdentifier) Mockito.any(),
// (org.wso2.carbon.registry.api.Registry) Mockito.any())).thenReturn(result);
// Assert.assertEquals(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier).size(),2);
// abstractAPIManager.tenantDomain = SAMPLE_TENANT_DOMAIN;
// result.put("swagger3","");
// Assert.assertEquals(abstractAPIManager.getSwaggerDefinitionTimeStamps(identifier).size(),3);
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resources in project carbon-apimgt by wso2.
the class APIProviderImpl method addAPIProductWithoutPublishingToGateway.
@Override
public Map<API, List<APIProductResource>> addAPIProductWithoutPublishingToGateway(APIProduct product) throws APIManagementException {
Map<API, List<APIProductResource>> apiToProductResourceMapping = new HashMap<>();
validateApiProductInfo(product);
String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(product.getId().getProviderName()));
if (log.isDebugEnabled()) {
log.debug("API Product details successfully added to the registry. API Product Name: " + product.getId().getName() + ", API Product Version : " + product.getId().getVersion() + ", API Product context : " + // todo: log context
"change");
}
List<APIProductResource> resources = product.getProductResources();
// list to hold resources which are actually in an existing api. If user has created an API product with invalid
// API or invalid resource of a valid API, that content will be removed .validResources array will have only
// legitimate apis
List<APIProductResource> validResources = new ArrayList<APIProductResource>();
for (APIProductResource apiProductResource : resources) {
API api;
String apiUUID;
if (apiProductResource.getProductIdentifier() != null) {
APIIdentifier productAPIIdentifier = apiProductResource.getApiIdentifier();
String emailReplacedAPIProviderName = APIUtil.replaceEmailDomain(productAPIIdentifier.getProviderName());
APIIdentifier emailReplacedAPIIdentifier = new APIIdentifier(emailReplacedAPIProviderName, productAPIIdentifier.getApiName(), productAPIIdentifier.getVersion());
apiUUID = apiMgtDAO.getUUIDFromIdentifier(emailReplacedAPIIdentifier, product.getOrganization());
api = getAPIbyUUID(apiUUID, product.getOrganization());
} else {
apiUUID = apiProductResource.getApiId();
api = getAPIbyUUID(apiUUID, product.getOrganization());
// if API does not exist, getLightweightAPIByUUID() method throws exception.
}
if (api != null) {
validateApiLifeCycleForApiProducts(api);
if (api.getSwaggerDefinition() != null) {
api.setSwaggerDefinition(getOpenAPIDefinition(apiUUID, product.getOrganization()));
}
if (!apiToProductResourceMapping.containsKey(api)) {
apiToProductResourceMapping.put(api, new ArrayList<>());
}
List<APIProductResource> apiProductResources = apiToProductResourceMapping.get(api);
apiProductResources.add(apiProductResource);
apiProductResource.setApiIdentifier(api.getId());
apiProductResource.setProductIdentifier(product.getId());
if (api.isAdvertiseOnly()) {
apiProductResource.setEndpointConfig(APIUtil.generateEndpointConfigForAdvertiseOnlyApi(api));
} else {
apiProductResource.setEndpointConfig(api.getEndpointConfig());
}
apiProductResource.setEndpointSecurityMap(APIUtil.setEndpointSecurityForAPIProduct(api));
URITemplate uriTemplate = apiProductResource.getUriTemplate();
Map<String, URITemplate> templateMap = apiMgtDAO.getURITemplatesForAPI(api);
if (uriTemplate == null) {
// if no resources are define for the API, we ingore that api for the product
} else {
String key = uriTemplate.getHTTPVerb() + ":" + uriTemplate.getResourceURI();
if (templateMap.containsKey(key)) {
// Since the template ID is not set from the request, we manually set it.
uriTemplate.setId(templateMap.get(key).getId());
// request has a valid API id and a valid resource. we add it to valid resource map
validResources.add(apiProductResource);
} else {
// ignore
log.warn("API with id " + apiProductResource.getApiId() + " does not have a resource " + uriTemplate.getResourceURI() + " with http method " + uriTemplate.getHTTPVerb());
}
}
}
}
// set the valid resources only
product.setProductResources(validResources);
// now we have validated APIs and it's resources inside the API product. Add it to database
String provider = APIUtil.replaceEmailDomain(product.getId().getProviderName());
// Set version timestamp
product.setVersionTimestamp(String.valueOf(System.currentTimeMillis()));
// Create registry artifact
String apiProductUUID = createAPIProduct(product);
product.setUuid(apiProductUUID);
// Add to database
apiMgtDAO.addAPIProduct(product, product.getOrganization());
return apiToProductResourceMapping;
}
Aggregations