Refactor the source

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 1cce5d7e34
commit c950223283

@ -0,0 +1,27 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.common;
/**
* Possible Subscription Type of the application.
*/
public enum ApplicationSubscriptionType {
FREE, PAID
}

@ -27,6 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.ApplicationSubscriptionType;
import org.wso2.carbon.device.application.mgt.common.ApplicationType; import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleState; import org.wso2.carbon.device.application.mgt.common.LifecycleState;
@ -399,7 +400,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationManagementDAOFactory.getApplicationDAO().deleteApplication(applicationId); ApplicationManagementDAOFactory.getApplicationDAO().deleteApplication(applicationId);
} catch (UserStoreException e) { } catch (UserStoreException e) {
e.printStackTrace(); String msg = "Error occured while check whether current user has the permission to delete an application";
log.error(msg);
throw new ApplicationManagementException(msg,e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -756,62 +759,61 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (AppLifecycleState.CREATED.toString().equals(state.getCurrentState())) { if (AppLifecycleState.CREATED.toString().equals(state.getCurrentState())) {
throw new LifecycleManagementException("Current State Couldn't be " + state.getCurrentState()); throw new LifecycleManagementException("Current State Couldn't be " + state.getCurrentState());
} }
if (AppLifecycleState.IN_REVIEW.toString().equals(state.getCurrentState())) { if (AppLifecycleState.IN_REVIEW.toString().equals(state.getCurrentState()) && !AppLifecycleState.CREATED
if (!AppLifecycleState.CREATED.toString().equals(state.getPreviousState()) && .toString().equals(state.getPreviousState()) && !AppLifecycleState.REJECTED.toString()
!AppLifecycleState.REJECTED.toString().equals(state.getPreviousState())) { .equals(state.getPreviousState())) {
throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + throw new LifecycleManagementException(
"Previous State should be either " + "If Current State is " + state.getCurrentState() + "Previous State should be either "
AppLifecycleState.CREATED.toString() + " or " + + AppLifecycleState.CREATED.toString() + " or " + AppLifecycleState.REJECTED.toString());
AppLifecycleState.REJECTED.toString());
}
}
if (AppLifecycleState.APPROVED.toString().equals(state.getCurrentState())) {
if (!AppLifecycleState.IN_REVIEW.toString().equals(state.getPreviousState())) {
throw new LifecycleManagementException("If Current State is " + state.getCurrentState() +
"Previous State should be " +
AppLifecycleState.IN_REVIEW.toString());
}
}
if (AppLifecycleState.PUBLISHED.toString().equals(state.getCurrentState())) {
if (!AppLifecycleState.APPROVED.toString().equals(state.getPreviousState()) &&
!AppLifecycleState.UNPUBLISHED.toString().equals(state.getPreviousState())) {
throw new LifecycleManagementException("If Current State is " + state.getCurrentState() +
"Previous State should be either " +
AppLifecycleState.APPROVED.toString() + " or " +
AppLifecycleState.UNPUBLISHED.toString());
}
}
if (AppLifecycleState.UNPUBLISHED.toString().equals(state.getCurrentState())) {
if (!AppLifecycleState.PUBLISHED.toString().equals(state.getPreviousState())) {
throw new LifecycleManagementException("If Current State is " + state.getCurrentState() +
"Previous State should be " +
AppLifecycleState.PUBLISHED.toString());
}
} }
if (AppLifecycleState.REJECTED.toString().equals(state.getCurrentState())) { if (AppLifecycleState.APPROVED.toString().equals(state.getCurrentState()) && !AppLifecycleState.IN_REVIEW
if (!AppLifecycleState.IN_REVIEW.toString().equals(state.getPreviousState())) { .toString().equals(state.getPreviousState())) {
throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + throw new LifecycleManagementException(
"Previous State should be " + "If Current State is " + state.getCurrentState() + "Previous State should be "
AppLifecycleState.IN_REVIEW.toString()); + AppLifecycleState.IN_REVIEW.toString());
} }
if (AppLifecycleState.PUBLISHED.toString().equals(state.getCurrentState()) && !AppLifecycleState.APPROVED
.toString().equals(state.getPreviousState()) && !AppLifecycleState.UNPUBLISHED.toString()
.equals(state.getPreviousState())) {
throw new LifecycleManagementException(
"If Current State is " + state.getCurrentState() + "Previous State should be either "
+ AppLifecycleState.APPROVED.toString() + " or " + AppLifecycleState.UNPUBLISHED
.toString());
} }
if (AppLifecycleState.DEPRECATED.toString().equals(state.getCurrentState())) { if (AppLifecycleState.UNPUBLISHED.toString().equals(state.getCurrentState()) && !AppLifecycleState.PUBLISHED
if (!AppLifecycleState.PUBLISHED.toString().equals(state.getPreviousState())) { .toString().equals(state.getPreviousState())) {
throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + throw new LifecycleManagementException(
"Previous State should be " + "If Current State is " + state.getCurrentState() + "Previous State should be "
AppLifecycleState.PUBLISHED.toString()); + AppLifecycleState.PUBLISHED.toString());
} }
if (AppLifecycleState.REJECTED.toString().equals(state.getCurrentState()) && !AppLifecycleState.IN_REVIEW
.toString().equals(state.getPreviousState())) {
throw new LifecycleManagementException(
"If Current State is " + state.getCurrentState() + "Previous State should be "
+ AppLifecycleState.IN_REVIEW.toString());
} }
if (AppLifecycleState.REMOVED.toString().equals(state.getCurrentState())) { if (AppLifecycleState.DEPRECATED.toString().equals(state.getCurrentState()) && !AppLifecycleState.PUBLISHED
if (!AppLifecycleState.DEPRECATED.toString().equals(state.getPreviousState()) && .toString().equals(state.getPreviousState())) {
!AppLifecycleState.REJECTED.toString().equals(state.getPreviousState()) &&
!AppLifecycleState.UNPUBLISHED.toString().equals(state.getPreviousState())) { throw new LifecycleManagementException(
throw new LifecycleManagementException("If Current State is " + state.getCurrentState() + "If Current State is " + state.getCurrentState() + "Previous State should be "
"Previous State should be either " + + AppLifecycleState.PUBLISHED.toString());
AppLifecycleState.DEPRECATED.toString() + " or " +
AppLifecycleState.REJECTED.toString() + " or " +
AppLifecycleState.UNPUBLISHED.toString());
} }
if (AppLifecycleState.REMOVED.toString().equals(state.getCurrentState()) && !AppLifecycleState.DEPRECATED
.toString().equals(state.getPreviousState()) && !AppLifecycleState.REJECTED.toString()
.equals(state.getPreviousState()) && !AppLifecycleState.UNPUBLISHED.toString()
.equals(state.getPreviousState())) {
throw new LifecycleManagementException(
"If Current State is " + state.getCurrentState() + "Previous State should be either "
+ AppLifecycleState.DEPRECATED.toString() + " or " + AppLifecycleState.REJECTED.toString()
+ " or " + AppLifecycleState.UNPUBLISHED.toString());
} }
} }
@ -820,8 +822,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application existingApplication = validateApplication(application.getId()); Application existingApplication = validateApplication(application.getId());
ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
List<UnrestrictedRole> addingRoleList; List<UnrestrictedRole> addingRoleList;
List<UnrestrictedRole> removingRoleList; List<UnrestrictedRole> removingRoleList;
List<Tag> addingTags; List<Tag> addingTags;
@ -838,54 +838,45 @@ public class ApplicationManagerImpl implements ApplicationManager {
"please remove this application and publish " + "please remove this application and publish " +
"new application with type: " + application.getType()); "new application with type: " + application.getType());
} }
if (existingApplication.getSubType() != application.getSubType()) { if (!existingApplication.getSubType().equals(application.getSubType())) {
if ("PAID".equals(existingApplication.getSubType())) { if (ApplicationSubscriptionType.PAID.toString().equals(existingApplication.getSubType()) && (
if (application.getPaymentCurrency() != null || !application.getPaymentCurrency().equals("")) { !"".equals(application.getPaymentCurrency()) || application.getPaymentCurrency() != null)) {
throw new ApplicationManagementException("If you are going to change Non-Free app as Free app, " + throw new ApplicationManagementException("If you are going to change Non-Free app as Free app, "
"currency attribute in the application updating " + + "currency attribute in the application updating " + "payload should be null or \"\"");
"payload should be null or \"\""); } else if (ApplicationSubscriptionType.FREE.toString().equals(existingApplication.getSubType()) && (
} application.getPaymentCurrency() == null || "".equals(application.getPaymentCurrency()))) {
} else if ("FREE".equals(existingApplication.getSubType())) { throw new ApplicationManagementException("If you are going to change Free app as Non-Free app, "
if (application.getPaymentCurrency() == null || application.getPaymentCurrency().equals("")) { + "currency attribute in the application payload " + "should not be null or \"\"");
throw new ApplicationManagementException("If you are going to change Free app as Non-Free app, " +
"currency attribute in the application payload " +
"should not be null or \"\"");
}
} }
} }
if (existingApplication.getIsRestricted() != application.getIsRestricted()) { if (existingApplication.getIsRestricted() != application.getIsRestricted()) {
if (existingApplication.getIsRestricted() == 0 && existingApplication.getUnrestrictedRoles() == null) { if (existingApplication.getIsRestricted() == 0 && existingApplication.getUnrestrictedRoles() == null) {
if (application.getUnrestrictedRoles() == null || application.getUnrestrictedRoles().isEmpty()) { if (application.getUnrestrictedRoles() == null || application.getUnrestrictedRoles().isEmpty()) {
throw new ApplicationManagementException("If you are going to add role restriction for non role " + throw new ApplicationManagementException("If you are going to add role restriction for non role "
"restricted Application, Unrestricted role list " + + "restricted Application, Unrestricted role list " + "won't be empty or null");
"won't be empty or null");
} }
visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), application.getId(), tenantId); visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), application.getId(), tenantId);
} else if (existingApplication.getIsRestricted() == 1 && existingApplication.getUnrestrictedRoles() != } else if (existingApplication.getIsRestricted() == 1
null) { && existingApplication.getUnrestrictedRoles() != null) {
if (application.getUnrestrictedRoles() != null || !application.getUnrestrictedRoles().isEmpty()) { if (application.getUnrestrictedRoles() != null && !application.getUnrestrictedRoles().isEmpty()) {
throw new ApplicationManagementException("If you are going to remove role restriction from role " + throw new ApplicationManagementException("If you are going to remove role restriction from role "
"restricted Application, Unrestricted role list " + + "restricted Application, Unrestricted role list should be empty or null");
"should be empty or null");
} }
visibilityDAO.deleteUnrestrictedRoles(existingApplication.getUnrestrictedRoles(), application.getId(), visibilityDAO.deleteUnrestrictedRoles(existingApplication.getUnrestrictedRoles(), application.getId(),
tenantId); tenantId);
} }
} else if (existingApplication.getIsRestricted() == application.getIsRestricted()) { } else if (existingApplication.getIsRestricted() == application.getIsRestricted()
if (existingApplication.getIsRestricted() == 1) { && existingApplication.getIsRestricted() == 1) {
addingRoleList = getDifference(application.getUnrestrictedRoles(), existingApplication addingRoleList = getDifference(application.getUnrestrictedRoles(),
.getUnrestrictedRoles()); existingApplication.getUnrestrictedRoles());
removingRoleList = getDifference(existingApplication removingRoleList = getDifference(existingApplication.getUnrestrictedRoles(),
.getUnrestrictedRoles(), application.getUnrestrictedRoles()); application.getUnrestrictedRoles());
if (!addingRoleList.isEmpty()) { if (!addingRoleList.isEmpty()) {
visibilityDAO.addUnrestrictedRoles(addingRoleList, application.getId(), tenantId); visibilityDAO.addUnrestrictedRoles(addingRoleList, application.getId(), tenantId);
} }
if (!removingRoleList.isEmpty()) { if (!removingRoleList.isEmpty()) {
visibilityDAO.deleteUnrestrictedRoles(removingRoleList, application.getId(), tenantId); visibilityDAO.deleteUnrestrictedRoles(removingRoleList, application.getId(), tenantId);
}
} }
} }
addingTags = getDifference(existingApplication.getTags(), application.getTags()); addingTags = getDifference(existingApplication.getTags(), application.getTags());

@ -166,11 +166,11 @@ public interface ApplicationManagementAPI {
@Valid Filter filter, @Valid Filter filter,
@ApiParam( @ApiParam(
name = "offset", name = "offset",
value = "Provide from which position apps should return", defaultValue = "20") value = "Provide from which position apps should return", defaultValue = "0")
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@ApiParam( @ApiParam(
name = "limit", name = "limit",
value = "Provide how many apps it should return", defaultValue = "0") value = "Provide how many apps it should return", defaultValue = "20")
@QueryParam("limit") int limit @QueryParam("limit") int limit
); );

@ -61,9 +61,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
if (limit == 0) {
limit = DEFAULT_LIMIT;
}
filter.setOffset(offset); filter.setOffset(offset);
filter.setLimit(limit); filter.setLimit(limit);

Loading…
Cancel
Save