use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIProviderImplTest method testDeleteAPIProductWorkflowTask.
@Test
public void testDeleteAPIProductWorkflowTask() throws APIManagementException, WorkflowException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1111);
WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
WorkflowExecutor productStateChangeWorkflowExecutor = Mockito.mock(WorkflowExecutor.class);
Mockito.when(wfe.getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(productStateChangeWorkflowExecutor);
WorkflowDTO workflowDTO = Mockito.mock(WorkflowDTO.class);
Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(1111), WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(workflowDTO);
APIProductIdentifier identifier = new APIProductIdentifier("admin", "APIProduct", "1.0.0", apiUUID);
apiProvider.deleteWorkflowTask(identifier);
Mockito.verify(apimgtDAO, Mockito.times(1)).getAPIID(apiUUID);
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class APIProviderImplTest method createMockAPIProduct.
private APIProduct createMockAPIProduct(String provider) {
APIProductIdentifier productIdentifier = new APIProductIdentifier(provider, APIConstants.API_PRODUCT, APIConstants.API_PRODUCT_VERSION);
APIProduct apiProduct = new APIProduct(productIdentifier);
apiProduct.setContext("/test");
apiProduct.setState(APIConstants.CREATED);
apiProduct.setType(APIConstants.API_PRODUCT);
apiProduct.setOrganization(APIConstants.SUPER_TENANT_DOMAIN);
return apiProduct;
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method updateAPIProduct.
public void updateAPIProduct(APIProduct product, String username) throws APIManagementException {
Connection conn = null;
PreparedStatement ps = null;
if (log.isDebugEnabled()) {
log.debug("updateAPIProduct() : product- " + product.toString());
}
try {
conn = APIMgtDBUtil.getConnection();
conn.setAutoCommit(false);
String query = SQLConstants.UPDATE_PRODUCT_SQL;
ps = conn.prepareStatement(query);
ps.setString(1, product.getProductLevelPolicy());
ps.setString(2, username);
ps.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
ps.setString(4, product.getGatewayVendor());
APIProductIdentifier identifier = product.getId();
ps.setString(5, identifier.getName());
ps.setString(6, APIUtil.replaceEmailDomainBack(identifier.getProviderName()));
ps.setString(7, identifier.getVersion());
ps.executeUpdate();
int productId = getAPIID(product.getUuid(), conn);
updateAPIProductResourceMappings(product, productId, conn);
conn.commit();
} catch (SQLException e) {
if (conn != null) {
try {
conn.rollback();
} catch (SQLException e1) {
log.error("Error while rolling back the failed operation", e1);
}
}
handleException("Error in updating API Product: " + e.getMessage(), e);
} finally {
APIMgtDBUtil.closeAllConnections(ps, conn, null);
}
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method setAssociatedAPIProductsURLMappings.
private void setAssociatedAPIProductsURLMappings(String uuid, Map<Integer, URITemplate> uriTemplates) throws SQLException {
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(SQLConstants.GET_ASSOCIATED_API_PRODUCT_URL_TEMPLATES_SQL)) {
ps.setString(1, uuid);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String productName = rs.getString("API_NAME");
String productVersion = rs.getString("API_VERSION");
String productProvider = rs.getString("API_PROVIDER");
int uriTemplateId = rs.getInt("URL_MAPPING_ID");
URITemplate uriTemplate = uriTemplates.get(uriTemplateId);
if (uriTemplate != null) {
APIProductIdentifier productIdentifier = new APIProductIdentifier(productProvider, productName, productVersion);
uriTemplate.addUsedByProduct(productIdentifier);
}
}
}
}
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method removeSubscription.
/**
* Removes the subscription entry from AM_SUBSCRIPTIONS for identifier.
*
* @param identifier Identifier
* @param applicationId ID of the application which has the subscription
* @throws APIManagementException
*/
public void removeSubscription(Identifier identifier, int applicationId) throws APIManagementException {
Connection conn = null;
ResultSet resultSet = null;
PreparedStatement ps = null;
int id = -1;
String uuid;
try {
conn = APIMgtDBUtil.getConnection();
conn.setAutoCommit(false);
String subscriptionUUIDQuery = SQLConstants.GET_SUBSCRIPTION_UUID_SQL;
if (identifier.getId() > 0) {
id = identifier.getId();
} else if (identifier instanceof APIIdentifier) {
String apiUuid;
if (identifier.getUUID() != null) {
apiUuid = identifier.getUUID();
} else {
apiUuid = getUUIDFromIdentifier((APIIdentifier) identifier);
}
id = getAPIID(apiUuid, conn);
} else if (identifier instanceof APIProductIdentifier) {
id = ((APIProductIdentifier) identifier).getProductId();
}
ps = conn.prepareStatement(subscriptionUUIDQuery);
ps.setInt(1, id);
ps.setInt(2, applicationId);
resultSet = ps.executeQuery();
if (resultSet.next()) {
uuid = resultSet.getString("UUID");
SubscribedAPI subscribedAPI = new SubscribedAPI(uuid);
removeSubscription(subscribedAPI, conn);
} else {
throw new APIManagementException("UUID does not exist for the given apiId:" + id + " and " + "application id:" + applicationId);
}
conn.commit();
} catch (SQLException e) {
if (conn != null) {
try {
conn.rollback();
} catch (SQLException ex) {
log.error("Failed to rollback the add subscription ", ex);
}
}
handleException("Failed to add subscriber data ", e);
} finally {
APIMgtDBUtil.closeAllConnections(ps, conn, resultSet);
}
}
Aggregations