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);
}
}
Aggregations