use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method addOperationPolicyContent.
/**
* This method is used to populate AM_OPERATION_POLICY table. This will return the policy ID.
*
* @param connection DB connection
* @param policyData Unique Identifier of API
* @return UUID of the newly created policy
* @throws SQLException
*/
private String addOperationPolicyContent(Connection connection, OperationPolicyData policyData) throws SQLException {
OperationPolicySpecification policySpecification = policyData.getSpecification();
String dbQuery = SQLConstants.OperationPolicyConstants.ADD_OPERATION_POLICY;
String policyUUID = UUID.randomUUID().toString();
PreparedStatement statement = connection.prepareStatement(dbQuery);
statement.setString(1, policyUUID);
statement.setString(2, policySpecification.getName());
statement.setString(3, policySpecification.getDisplayName());
statement.setString(4, policySpecification.getDescription());
statement.setString(5, policySpecification.getApplicableFlows().toString());
statement.setString(6, policySpecification.getSupportedGateways().toString());
statement.setString(7, policySpecification.getSupportedApiTypes().toString());
statement.setBinaryStream(8, new ByteArrayInputStream(APIUtil.getPolicyAttributesAsString(policySpecification).getBytes()));
statement.setString(9, policyData.getOrganization());
statement.setString(10, policySpecification.getCategory().toString());
statement.setBoolean(11, policySpecification.isMultipleAllowed());
statement.setString(12, policyData.getMd5Hash());
statement.executeUpdate();
statement.close();
if (policyData.getSynapsePolicyDefinition() != null) {
addOperationPolicyDefinition(connection, policyUUID, policyData.getSynapsePolicyDefinition());
}
if (policyData.getCcPolicyDefinition() != null) {
addOperationPolicyDefinition(connection, policyUUID, policyData.getCcPolicyDefinition());
}
return policyUUID;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method setAPIProductFromDB.
/**
* Get product Id from the product name and the provider.
*
* @param product product identifier
* @throws APIManagementException exception
*/
public void setAPIProductFromDB(APIProduct product) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = product.getId();
String currentApiUuid;
APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(product.getUuid());
if (apiRevision != null && apiRevision.getApiUUID() != null) {
currentApiUuid = apiRevision.getApiUUID();
} else {
currentApiUuid = product.getUuid();
}
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.GET_API_PRODUCT_SQL)) {
prepStmt.setString(1, currentApiUuid);
try (ResultSet rs = prepStmt.executeQuery()) {
if (rs.next()) {
product.setProductId(rs.getInt("API_ID"));
product.setProductLevelPolicy(rs.getString("API_TIER"));
} else {
String msg = "Unable to find the API Product : " + apiProductIdentifier.getName() + "-" + APIUtil.replaceEmailDomainBack(apiProductIdentifier.getProviderName()) + "-" + apiProductIdentifier.getVersion() + " in the database";
throw new APIMgtResourceNotFoundException(msg);
}
}
} catch (SQLException e) {
handleException("Error while locating API Product: " + apiProductIdentifier.getName() + "-" + APIUtil.replaceEmailDomainBack(apiProductIdentifier.getProviderName()) + "-" + apiProductIdentifier.getVersion() + " from the database", e);
}
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method getComment.
/**
************************
* Returns a specific comment of an API
*
* @param commentId Comment ID
* @param apiTypeWrapper Api Type Wrapper
* @return Comment Array
* @throws APIManagementException
*/
public Comment getComment(ApiTypeWrapper apiTypeWrapper, String commentId, Integer replyLimit, Integer replyOffset) throws APIManagementException {
String uuid;
Identifier identifier;
if (apiTypeWrapper.isAPIProduct()) {
identifier = apiTypeWrapper.getApiProduct().getId();
uuid = apiTypeWrapper.getApiProduct().getUuid();
} else {
identifier = apiTypeWrapper.getApi().getId();
uuid = apiTypeWrapper.getApi().getUuid();
}
try (Connection connection = APIMgtDBUtil.getConnection()) {
Comment comment = new Comment();
int id = -1;
String getCommentQuery = SQLConstants.GET_COMMENT_SQL;
id = getAPIID(uuid, connection);
if (id == -1) {
String msg = "Could not load API record for: " + identifier.getName();
throw new APIManagementException(msg);
}
try (PreparedStatement prepStmt = connection.prepareStatement(getCommentQuery)) {
prepStmt.setString(1, uuid);
prepStmt.setString(2, commentId);
try (ResultSet resultSet = prepStmt.executeQuery()) {
if (resultSet.next()) {
comment.setId(resultSet.getString("COMMENT_ID"));
comment.setText(resultSet.getString("COMMENT_TEXT"));
comment.setUser(resultSet.getString("CREATED_BY"));
comment.setCreatedTime(resultSet.getTimestamp("CREATED_TIME"));
comment.setUpdatedTime(resultSet.getTimestamp("UPDATED_TIME"));
comment.setApiId(resultSet.getString("API_ID"));
comment.setParentCommentID(resultSet.getString("PARENT_COMMENT_ID"));
comment.setEntryPoint(resultSet.getString("ENTRY_POINT"));
comment.setCategory(resultSet.getString("CATEGORY"));
comment.setReplies(getComments(uuid, commentId, replyLimit, replyOffset, connection));
return comment;
}
}
}
} catch (SQLException e) {
handleException("Failed to retrieve comment for API " + identifier.getName() + "with comment ID " + commentId, e);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAPIProductIdentifierFromUUID.
/**
* Get API Product Identifier by the product's UUID.
*
* @param uuid uuid of the API
* @return API Identifier
* @throws APIManagementException if an error occurs
*/
public APIProductIdentifier getAPIProductIdentifierFromUUID(String uuid) throws APIManagementException {
APIProductIdentifier identifier = null;
String sql = SQLConstants.GET_API_IDENTIFIER_BY_UUID_SQL;
try (Connection connection = APIMgtDBUtil.getConnection()) {
PreparedStatement prepStmt = connection.prepareStatement(sql);
prepStmt.setString(1, uuid);
try (ResultSet resultSet = prepStmt.executeQuery()) {
while (resultSet.next()) {
String provider = resultSet.getString(1);
String name = resultSet.getString(2);
String version = resultSet.getString(3);
identifier = new APIProductIdentifier(APIUtil.replaceEmailDomain(provider), name, version, uuid);
}
}
} catch (SQLException e) {
handleException("Failed to retrieve the API Product Identifier details for UUID : " + uuid, e);
}
return identifier;
}
use of org.wso2.carbon.apimgt.api.model.Identifier 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);
}
Aggregations