Skip to content

Commit

Permalink
Merge pull request #225 from lahiru823/master
Browse files Browse the repository at this point in the history
m2 - multiple version unpublish issue fixed
  • Loading branch information
lahiru823 committed Mar 9, 2016
2 parents 9def868 + c362bdc commit 62a7789
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ public void removeFromGateway(WebApp api, String tenantDomain) throws Exception
environment.getName());
}
String operation = "delete";
client.deleteNonVersionedWebApp(tenantDomain);
client.deleteVersionedWebApp(tenantDomain);
if (api.isDefaultVersion()) {
client.deleteNonVersionedWebApp(tenantDomain);
}
client.deleteVersionedWebApp(tenantDomain);
undeployCustomSequences(api, tenantDomain, environment);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,13 +843,29 @@ public void changeAPIStatus(WebApp api, APIStatus status, String userId,
String gatewayType = config.getFirstProperty(AppMConstants.API_GATEWAY_TYPE);
if (!api.isAdvertiseOnly()) { // no need to publish to gateway if webb is only for advertising
if (updateGatewayConfig) {
if (status.equals(APIStatus.PUBLISHED) || status.equals(APIStatus.DEPRECATED) ||
status.equals(APIStatus.BLOCKED)) {

//publish to gateway if skipGateway is disabled only
if (!api.getSkipGateway()) {
publishToGateway(api);
if (api.isDefaultVersion()) {
if (status.equals(APIStatus.UNPUBLISHED)) {
//when un-publishing default version, reset the default published version as null in table
APIIdentifier identifier = new APIIdentifier(api.getId().getProviderName(),
api.getId().getApiName(),
null);
WebApp webApp = new WebApp(identifier);
appMDAO.updatePublishedDefaultVersion(webApp);


//update the registry and reset default version
identifier = new APIIdentifier(api.getId().getProviderName(),
api.getId().getApiName(),
api.getId().getVersion());
webApp = getAPI(identifier);
webApp.setDefaultVersion(false);
updateApiArtifact(webApp, false, false);
}
}

if (status.equals(APIStatus.PUBLISHED) || status.equals(APIStatus.DEPRECATED) ||
status.equals(APIStatus.BLOCKED)) {

//update version
if (status.equals(APIStatus.PUBLISHED)) {
Expand All @@ -863,9 +879,15 @@ public void changeAPIStatus(WebApp api, APIStatus status, String userId,
if (defaultPublishedAppVersion == null || "".equals(defaultPublishedAppVersion)) {
appMDAO.updatePublishedDefaultVersion(api);
removeDefaultVersionFromNonPublishedApps(api);
api.setDefaultVersion(true);
}
}
}

//publish to gateway if skipGateway is disabled only
if (!api.getSkipGateway()) {
publishToGateway(api);
}
} else {
removeFromGateway(api);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,43 @@ require('/modules/publisher.js').exec(function(ctx) {

});


//get uuid of given asset for-> provider,name,lifecycle state
routeManager.register('GET', 'publisher', '/publisher/api/asset/get/uuid/list/{type}/{provider}/{name}/{lifecyclestate}',
function (context) {
var assetProvider = context.params.provider;
var assetName = context.params.name;
var lifecycleState = context.params.lifecyclestate;
var shortName = context.params.type;
var artifactManager = rxtManager.getArtifactManager(shortName);

var fn = function (asset) {
var cond1 = (asset.attributes.overview_provider == assetProvider ) ? true : false;
var cond2 = (asset.attributes.overview_name == assetName ) ? true : false;
var cond3 = (asset.lifecycleState == lifecycleState ) ? true : false;
return (cond1 && cond2 && cond3);
}

var artifacts = artifactManager.find(fn, null);
var noOfArtifacts = 0;
var UUIDs = [];
for (noOfArtifacts = 0; noOfArtifacts < artifacts.length; noOfArtifacts++) {
var artifactId = artifacts[noOfArtifacts].id;
UUIDs.push(artifactId);
}
if (UUIDs.length > 0) {
var res = {error: false, uuids: UUIDs, count: noOfArtifacts};
response.contentType = "application/json";
print(res);
} else {
var res = {error: false, uuids: UUIDs, message: 'Could not find UUID for given webapp'};
response.contentType = "application/json";
print(res);
}


});

//Get external
routeManager.register('GET', 'publisher', '/publisher/api/asset/get/external/stores/{type}/{provider}/{name}/{version}',
function (context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,18 @@ require('/modules/publisher.js').exec(function (ctx) {
} else {
// some error occurred in promoteArtifactLifeCycle function,
// revert previously unpublished artifacts to Publish state

/*
for (i = 0; i < previousArtifacts.length; i++) {
promoteArtifactLifeCycle(artifactManager, previousArtifacts[i], appType,
"Re-Publish");
// ignore errors when reverting changes
}
*/

// ignore errors when reverting changes
promoteArtifactLifeCycle(artifactManager, currentArtifact, appType,
"Re-Publish");

response.status = 500;
response.contentType = "application/json";
content.status = "Error";
Expand Down Expand Up @@ -465,8 +472,11 @@ require('/modules/publisher.js').exec(function (ctx) {
promoteArtifactLifeCycle(artifactManager, currentArtifact, appType, "Unpublish");
// revert previously unpublished artifacts to Publish state
for (i = 0; i < previousArtifacts.length; i++) {
promoteArtifactLifeCycle(artifactManager, previousArtifacts[i], appType,
"Re-Publish");
if (previousArtifacts[i].attributes.overview_version
== currentArtifact.attributes.overview_oldVersion) {
promoteArtifactLifeCycle(artifactManager, previousArtifacts[i], appType,
"Re-Publish");
}
// ignore errors when reverting changes
}
response.status = 500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $(".btn-action").click(function (e) {
var name = $(this).data("name");
var version = $(this).data("version");
var action = $(this).data("action");
var isDefault = Boolean($(this).data("isdefault"));

var status = isPublishedToExternalStore(action, provider, name, version);

Expand All @@ -37,8 +38,19 @@ $(".btn-action").click(function (e) {

if (action == "Reject") {
showCommentModel("Reason for Rejection", action, app, "webapp");
} else {
jQuery.ajax({
} else {
if (action == "Unpublish" && isDefault) {
var publishedVersionsAvailable = isPublishedVersionsAvailable(provider, name);
if (publishedVersionsAvailable) {
var faultMsg = "'" + action + "' is not permitted as this is the default version of the WebApp. "
+ "Please select other version of this WebApp as the default version and proceed.";
var status = "Not Allowed";
showMessageModel(faultMsg, status, 'webapp');
$(parent).children().attr('disabled', false);
return false;
}
}
jQuery.ajax({
url: caramel.context + '/api/lifecycle/' + action + '/webapp/' + app,
type: 'PUT',
success: function (data, text) {
Expand Down Expand Up @@ -220,4 +232,24 @@ function isPublishedToExternalStore(action, provider, name, version) {

}
return publishedInExternalStores;
}
}


function isPublishedVersionsAvailable(provider, name) {
var result;
$.ajax({
url: caramel.context + '/api/asset/get/uuid/list/' + 'webapp' + '/' + provider + '/' + name + '/'
+ 'Published',
type: 'GET',
async: false,
contentType: 'application/json',
dataType: 'json', // the type of data that you're expecting back from the server
success: function (responseData, status, xhr) {
result = (parseInt(responseData.count) > 1);
},
error: function () {
result = false;
}
});
return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
data-name="{{../../../attributes.overview_name}}"
data-provider="{{../../../attributes.overview_provider}}"
data-version="{{../../../attributes.overview_version}}"
data-isDefault="{{../../../attributes.overview_makeAsDefault}}"
class="btn {{style}} btn-action" name="addNewAssetButton">{{name}}</a>
{{/ifCond}}

Expand All @@ -121,6 +122,7 @@
data-name="{{../../attributes.overview_name}}"
data-provider="{{../../attributes.overview_provider}}"
data-version="{{../../attributes.overview_version}}"
data-isdefault="{{../../attributes.overview_makeAsDefaultVersion}}"
class="btn {{style}} btn-action" name="addNewAssetButton">{{name}}</a>
{{/ifCond}}
{{/this.lifecycleAvailableActions}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ $( document ).ready(function() {
appData['provider'] = $(this).data("provider");
appData['storeTenantDomain'] = storeTenantDomain;

$(this).hide();
var waitIconId = '#wait-' + appId;
$(waitIconId).show();

Expand All @@ -77,7 +76,6 @@ $( document ).ready(function() {
appData['provider'] = $(this).data("provider");
appData['storeTenantDomain'] = storeTenantDomain;

$(this).hide();
var waitIconId = '#wait-' + appId;
$(waitIconId).show();

Expand All @@ -87,8 +85,6 @@ $( document ).ready(function() {

var addToFavourite = function (data, appId) {
var waitIconId = '#wait-' + appId;
var rmvIconId = '#rmv-' + appId;
var addIconId = '#add-' + appId;
$.ajax({
url: API_ADD_TO_FAVOURITE,
dataType: 'JSON',
Expand All @@ -97,13 +93,17 @@ $( document ).ready(function() {
success: function (response, textStatus, xhr) {
if (response.error == false) {
$(waitIconId).hide();
$(rmvIconId).show();
var message = 'You have successfully added <b>' + data.name +
'</b> to your favourite apps';
notify(message);

document.getElementById("favRibbon-" + appId).style.visibility = "visible";
document.getElementById("listItemAddFavorite-" + appId).className = "";
document.getElementById("listItemAddFavorite-" + appId).classList.add("display-none-lg");
document.getElementById("listItemRmvFavorite-" + appId).className = "";
document.getElementById("listItemRmvFavorite-" + appId).classList.add("display-block-lg");
} else {
$(waitIconId).hide();
$(addIconId).show();
var message = 'Error occured in while adding web app: ' + data.name +
' to my favourite web apps';
notify(message);
Expand All @@ -112,7 +112,6 @@ $( document ).ready(function() {
},
error: function (response) {
$(waitIconId).hide();
$(addIconId).show();
if (response.status == 401) {
var message = 'Your session has time out.Please login again';
notify(message);
Expand All @@ -127,39 +126,37 @@ $( document ).ready(function() {

var removeFromFavourite = function (data, appId) {
var waitIconId = '#wait-' + appId;
var rmvIconId = '#rmv-' + appId;
var addIconId = '#add-' + appId;

$.ajax({
url: API_REMOVE_FROM_FAVOURITE,
type: 'POST',
data: data,
success: function (response, textStatus, xhr) {
if (response.error == false) {
$(waitIconId).hide();
$(addIconId).show();
var message = 'You have successfully removed <b>' + data.name
+ '</b> from your favourite apps';
+ '</b> from your favourite apps';
notify(message);
$('#btnRemoveFromFav').hide();
$('#btnAddToFav').show();

document.getElementById("favRibbon-" + appId).style.visibility = "hidden";
document.getElementById("listItemRmvFavorite-" + appId).className = "";
document.getElementById("listItemRmvFavorite-" + appId).classList.add("display-none-lg");
document.getElementById("listItemAddFavorite-" + appId).className = "";
document.getElementById("listItemAddFavorite-" + appId).classList.add("display-block-lg");
} else {
$(waitIconId).hide();
$(rmvIconId).show();
var message = 'Error occured when remove web app: ' + data.name
+ ' from my favourite web apps';
+ ' from my favourite web apps';
notify(message);
}
},
error: function (response) {
$(waitIconId).hide();
$(rmvIconId).show();
if (response.status == 401) {
var message = 'Your session has time out.Please login again';
notify(message);
} else {
var message = 'Error occured when remove web app: ' + data.name
+ ' from my favourite web apps';
+ ' from my favourite web apps';
notify(message);
}
}
Expand Down
Loading

0 comments on commit 62a7789

Please sign in to comment.