Search in sources :

Example 1 with WorkflowStatus

use of org.wso2.carbon.apimgt.impl.workflow.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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 2 with WorkflowStatus

use of org.wso2.carbon.apimgt.impl.workflow.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;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API)

Example 3 with WorkflowStatus

use of org.wso2.carbon.apimgt.impl.workflow.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;
}
Also used : BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) ResultSet(java.sql.ResultSet)

Example 4 with WorkflowStatus

use of org.wso2.carbon.apimgt.impl.workflow.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;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 5 with WorkflowStatus

use of org.wso2.carbon.apimgt.impl.workflow.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());
}
Also used : ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIListDTO) API(org.wso2.carbon.apimgt.core.models.API) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)9 ResultSet (java.sql.ResultSet)6 API (org.wso2.carbon.apimgt.core.models.API)6 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)6 WorkflowStatus (org.wso2.carbon.apimgt.impl.workflow.WorkflowStatus)6 HashSet (java.util.HashSet)5 JSONObject (org.json.simple.JSONObject)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)4 Gson (com.google.gson.Gson)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 API (org.wso2.carbon.apimgt.api.model.API)3 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)3 Workflow (org.wso2.carbon.apimgt.api.model.Workflow)3