use of org.wso2.carbon.apimgt.api.WorkflowStatus in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateAPIWorkflowStatus.
/**
* Update an existing API workflow state
*
* @param apiID The {@link String} of the API that needs to be updated
* @param workflowStatus workflow status
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void updateAPIWorkflowStatus(String apiID, APILCWorkflowStatus workflowStatus) throws APIMgtDAOException {
final String query = "UPDATE AM_API SET LAST_UPDATED_TIME = ?, LC_WORKFLOW_STATUS=? WHERE UUID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
connection.setAutoCommit(false);
statement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now()));
statement.setString(2, workflowStatus.toString());
statement.setString(3, apiID);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "updating workflow status for API: " + apiID + " to Status: " + workflowStatus.name();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "updating workflow status for API: " + apiID + " to Status: " + workflowStatus.name();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.carbon.apimgt.api.WorkflowStatus in project carbon-apimgt by wso2.
the class ApiDAOImpl method constructAPISummaryList.
private List<API> constructAPISummaryList(Connection connection, PreparedStatement statement) throws SQLException {
List<API> apiList = new ArrayList<>();
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
String apiPrimaryKey = rs.getString("UUID");
API apiSummary = new API.APIBuilder(rs.getString("PROVIDER"), rs.getString("NAME"), rs.getString("VERSION")).id(apiPrimaryKey).context(rs.getString("CONTEXT")).description(rs.getString("DESCRIPTION")).lifeCycleStatus(rs.getString("CURRENT_LC_STATUS")).lifecycleInstanceId(rs.getString("LIFECYCLE_INSTANCE_ID")).workflowStatus(rs.getString("LC_WORKFLOW_STATUS")).securityScheme(rs.getInt("SECURITY_SCHEME")).threatProtectionPolicies(getThreatProtectionPolicies(connection, apiPrimaryKey)).build();
apiList.add(apiSummary);
}
}
return apiList;
}
use of org.wso2.carbon.apimgt.api.WorkflowStatus in project carbon-apimgt by wso2.
the class ApiDAOImpl method constructAPIFromResultSet.
private API constructAPIFromResultSet(Connection connection, PreparedStatement statement) throws SQLException, IOException, APIMgtDAOException {
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setTechnicalOwner(rs.getString("TECHNICAL_OWNER"));
businessInformation.setTechnicalOwnerEmail(rs.getString("TECHNICAL_EMAIL"));
businessInformation.setBusinessOwner(rs.getString("BUSINESS_OWNER"));
businessInformation.setBusinessOwnerEmail(rs.getString("BUSINESS_EMAIL"));
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(rs.getBoolean("CORS_ENABLED"));
String allowOrigins = rs.getString("CORS_ALLOW_ORIGINS");
corsConfiguration.setAllowOrigins(DAOUtil.commaSeperatedStringToList(allowOrigins));
corsConfiguration.setAllowCredentials(rs.getBoolean("CORS_ALLOW_CREDENTIALS"));
String allowHeaders = rs.getString("CORS_ALLOW_HEADERS");
corsConfiguration.setAllowHeaders(DAOUtil.commaSeperatedStringToList(allowHeaders));
String allowMethods = rs.getString("CORS_ALLOW_METHODS");
corsConfiguration.setAllowMethods(DAOUtil.commaSeperatedStringToList(allowMethods));
String apiPrimaryKey = rs.getString("UUID");
return new API.APIBuilder(rs.getString("PROVIDER"), rs.getString("NAME"), rs.getString("VERSION")).id(apiPrimaryKey).context(rs.getString("CONTEXT")).isDefaultVersion(rs.getBoolean("IS_DEFAULT_VERSION")).description(rs.getString("DESCRIPTION")).visibility(API.Visibility.valueOf(rs.getString("VISIBILITY"))).visibleRoles(getVisibleRoles(connection, apiPrimaryKey)).isResponseCachingEnabled(rs.getBoolean("IS_RESPONSE_CACHED")).cacheTimeout(rs.getInt("CACHE_TIMEOUT")).hasOwnGateway(rs.getBoolean("HAS_OWN_GATEWAY")).tags(getTags(connection, apiPrimaryKey)).labels(getLabelIdsForAPI(connection, apiPrimaryKey)).wsdlUri(ApiResourceDAO.getTextValueForCategory(connection, apiPrimaryKey, ResourceCategory.WSDL_TEXT)).transport(getTransports(connection, apiPrimaryKey)).endpoint(getEndPointsForApi(connection, apiPrimaryKey)).apiPermission(getPermissionsStringForApi(connection, apiPrimaryKey)).permissionMap(getPermissionMapForApi(connection, apiPrimaryKey)).businessInformation(businessInformation).lifecycleInstanceId(rs.getString("LIFECYCLE_INSTANCE_ID")).lifeCycleStatus(rs.getString("CURRENT_LC_STATUS")).corsConfiguration(corsConfiguration).createdBy(rs.getString("CREATED_BY")).updatedBy(rs.getString("UPDATED_BY")).createdTime(rs.getTimestamp("CREATED_TIME").toLocalDateTime()).lastUpdatedTime(rs.getTimestamp("LAST_UPDATED_TIME").toLocalDateTime()).uriTemplates(getUriTemplates(connection, apiPrimaryKey)).policies(getSubscripitonPolciesByAPIId(connection, apiPrimaryKey)).copiedFromApiId(rs.getString("COPIED_FROM_API")).workflowStatus(rs.getString("LC_WORKFLOW_STATUS")).securityScheme(rs.getInt("SECURITY_SCHEME")).apiPolicy(getApiPolicyByAPIId(connection, apiPrimaryKey)).threatProtectionPolicies(getThreatProtectionPolicies(connection, apiPrimaryKey)).build();
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.WorkflowStatus in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultAPI.
public static API.APIBuilder createDefaultAPI() {
Set<String> transport = new HashSet<>();
transport.add(HTTP);
transport.add(HTTPS);
Set<String> tags = new HashSet<>();
tags.add(TAG_CLIMATE);
Set<Policy> policies = new HashSet<>();
policies.add(goldSubscriptionPolicy);
policies.add(silverSubscriptionPolicy);
policies.add(bronzeSubscriptionPolicy);
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner(NAME_BUSINESS_OWNER_1);
businessInformation.setBusinessOwnerEmail(EMAIL_BUSINESS_OWNER_1);
businessInformation.setTechnicalOwner(NAME_TECHNICAL_OWNER_1);
businessInformation.setTechnicalOwnerEmail(EMAIL_TECHNICAL_OWNER_1);
String permissionJson = "[{\"groupId\" : \"developer\", \"permission\" : " + "[\"READ\",\"UPDATE\"]},{\"groupId\" : \"admin\", \"permission\" : [\"READ\",\"UPDATE\"," + "\"DELETE\", \"MANAGE_SUBSCRIPTION\"]}]";
Set<String> visibleRoles = new HashSet<>();
visibleRoles.add("testRple");
List<String> labels = new ArrayList<>();
labels.add("testLabel");
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList(APIMgtConstants.FunctionsConstants.GET, APIMgtConstants.FunctionsConstants.POST, APIMgtConstants.FunctionsConstants.DELETE));
corsConfiguration.setAllowHeaders(Arrays.asList(ALLOWED_HEADER_AUTHORIZATION, ALLOWED_HEADER_CUSTOM));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Arrays.asList("*"));
Map<String, Endpoint> endpointMap = new HashMap<>();
endpointMap.put("TestEndpoint", createMockEndpoint());
API.APIBuilder apiBuilder = new API.APIBuilder(ADMIN, "WeatherAPI", API_VERSION).id(UUID.randomUUID().toString()).context("weather").description("Get Weather Info").lifeCycleStatus(APIStatus.CREATED.getStatus()).lifecycleInstanceId(UUID.randomUUID().toString()).endpoint(Collections.emptyMap()).wsdlUri("http://localhost:9443/echo?wsdl").isResponseCachingEnabled(false).cacheTimeout(60).isDefaultVersion(false).apiPolicy(unlimitedApiPolicy).transport(transport).tags(tags).policies(policies).visibility(API.Visibility.PUBLIC).visibleRoles(visibleRoles).businessInformation(businessInformation).corsConfiguration(corsConfiguration).createdTime(LocalDateTime.now()).createdBy(ADMIN).updatedBy(ADMIN).lastUpdatedTime(LocalDateTime.now()).apiPermission(permissionJson).uriTemplates(getMockUriTemplates()).apiDefinition(apiDefinition).workflowStatus(WORKFLOW_STATUS).labels(labels).endpoint(endpointMap);
Map map = new HashMap();
map.put(DEVELOPER_ROLE_ID, 6);
map.put(ADMIN_ROLE_ID, 15);
apiBuilder.permissionMap(map);
return apiBuilder;
}
use of org.wso2.carbon.apimgt.api.WorkflowStatus in project carbon-apimgt by wso2.
the class TestMappingUtilTestCase method testAPIListToAPIListInfoMapping.
@Test(description = "API list to API list info mapping")
void testAPIListToAPIListInfoMapping() {
API api1 = SampleTestObjectCreator.createDefaultAPI().id("newId1").name("newName1").context("newContext1").description("newDesc1").provider("newProvider1").lifeCycleStatus("newStatus1").version("newVersion1").workflowStatus("newWorkflowStatus1").build();
API api2 = SampleTestObjectCreator.createDefaultAPI().id("newId2").name("newName2").context("newContext2").description("newDesc2").provider("newProvider2").lifeCycleStatus("newStatus2").version("newVersion2").workflowStatus("newWorkflowStatus2").build();
List<API> apis = new ArrayList<>();
apis.add(api1);
apis.add(api2);
APIListDTO apiListDTO = MappingUtil.toAPIListDTO(apis);
assertEquals((Integer) apis.size(), apiListDTO.getCount());
assertEquals(api1.getId(), apiListDTO.getList().get(0).getId());
assertEquals(api1.getName(), apiListDTO.getList().get(0).getName());
assertEquals(api1.getContext(), apiListDTO.getList().get(0).getContext());
assertEquals(api1.getDescription(), apiListDTO.getList().get(0).getDescription());
assertEquals(api1.getProvider(), apiListDTO.getList().get(0).getProvider());
assertEquals(api1.getLifeCycleStatus(), apiListDTO.getList().get(0).getLifeCycleStatus());
assertEquals(api1.getVersion(), apiListDTO.getList().get(0).getVersion());
assertEquals(api1.getWorkflowStatus(), apiListDTO.getList().get(0).getWorkflowStatus());
assertEquals(api2.getId(), apiListDTO.getList().get(1).getId());
assertEquals(api2.getName(), apiListDTO.getList().get(1).getName());
assertEquals(api2.getContext(), apiListDTO.getList().get(1).getContext());
assertEquals(api2.getDescription(), apiListDTO.getList().get(1).getDescription());
assertEquals(api2.getProvider(), apiListDTO.getList().get(1).getProvider());
assertEquals(api2.getLifeCycleStatus(), apiListDTO.getList().get(1).getLifeCycleStatus());
assertEquals(api2.getVersion(), apiListDTO.getList().get(1).getVersion());
assertEquals(api2.getWorkflowStatus(), apiListDTO.getList().get(1).getWorkflowStatus());
}
Aggregations