Search in sources :

Example 6 with DeployedAPIRevision

use of org.wso2.carbon.apimgt.api.model.DeployedAPIRevision in project carbon-apimgt by wso2.

the class APIProviderImpl method addDeployedAPIRevision.

/**
 * Adds a new APIRevisionDeployment to an existing API
 *
 * @param apiId                   API UUID
 * @param apiRevisionUUID         API Revision UUID
 * @param deployedAPIRevisionList List of APIRevisionDeployment objects
 * @throws APIManagementException if failed to add APIRevision
 */
@Override
public void addDeployedAPIRevision(String apiId, String apiRevisionUUID, List<DeployedAPIRevision> deployedAPIRevisionList) throws APIManagementException {
    List<DeployedAPIRevision> currentDeployedApiRevisionList = apiMgtDAO.getDeployedAPIRevisionByApiUUID(apiId);
    Set<DeployedAPIRevision> environmentsToRemove = new HashSet<>();
    // Deployments to add
    List<DeployedAPIRevision> environmentsToAdd = new ArrayList<>();
    List<String> envNames = new ArrayList<>();
    for (DeployedAPIRevision deployedAPIRevision : deployedAPIRevisionList) {
        // Remove duplicate entries for same revision uuid and env from incoming list
        if (!envNames.contains(deployedAPIRevision.getDeployment())) {
            envNames.add(deployedAPIRevision.getDeployment());
            environmentsToAdd.add(deployedAPIRevision);
            // Remove old deployed-revision entries of same env and apiid from existing db records
            for (DeployedAPIRevision currentapiRevisionDeployment : currentDeployedApiRevisionList) {
                if (StringUtils.equalsIgnoreCase(currentapiRevisionDeployment.getDeployment(), deployedAPIRevision.getDeployment())) {
                    environmentsToRemove.add(currentapiRevisionDeployment);
                }
            }
        }
    }
    // Discard old deployment info
    if (environmentsToRemove.size() > 0) {
        apiMgtDAO.removeDeployedAPIRevision(apiId, environmentsToRemove);
    }
    // Add new deployed revision update to db
    if (deployedAPIRevisionList.size() > 0) {
        apiMgtDAO.addDeployedAPIRevision(apiRevisionUUID, environmentsToAdd);
    }
}
Also used : DeployedAPIRevision(org.wso2.carbon.apimgt.api.model.DeployedAPIRevision) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

DeployedAPIRevision (org.wso2.carbon.apimgt.api.model.DeployedAPIRevision)6 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 ResultSet (java.sql.ResultSet)1 Timestamp (java.sql.Timestamp)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 Environment (org.wso2.carbon.apimgt.api.model.Environment)1 DeployedAPIRevisionDTO (org.wso2.carbon.apimgt.internal.service.dto.DeployedAPIRevisionDTO)1 DeployedEnvInfoDTO (org.wso2.carbon.apimgt.internal.service.dto.DeployedEnvInfoDTO)1 UnDeployedAPIRevisionDTO (org.wso2.carbon.apimgt.internal.service.dto.UnDeployedAPIRevisionDTO)1