Adding Lifecycle Management functionalities and fixed related bugs

feature/appm-store/pbac
lasantha 7 years ago
parent fb8d9dd494
commit 9b1820dca5

@ -0,0 +1,28 @@
/*
* Copyright (c) 2017, 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;
/**
* States of the Application.
*/
public enum AppLifecycleState {
CREATED, IN_REVIEW, PUBLISHED, APPROVED, UNPUBLISHED, REJECTED, DEPRECATED, REMOVED
}

@ -19,6 +19,7 @@
package org.wso2.carbon.device.application.mgt.common;
import java.sql.Timestamp;
import java.util.List;
public class LifecycleState {
@ -28,6 +29,8 @@ public class LifecycleState {
private String previousState;
private List<String> nextStates;
private String updatedBy;
private Timestamp updatedAt;
@ -102,4 +105,11 @@ public class LifecycleState {
this.appId = appId;
}
public List<String> getNextStates() {
return nextStates;
}
public void setNextStates(List<String> nextStates) {
this.nextStates = nextStates;
}
}

@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.common.services;
import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import java.util.List;
@ -31,6 +32,7 @@ public interface ApplicationManager {
/**
* Creates an application.
*
* @param application Application that need to be created.
* @return Created application
* @throws ApplicationManagementException Application Management Exception
@ -39,6 +41,7 @@ public interface ApplicationManager {
/**
* Updates an already existing application.
*
* @param application Application that need to be updated.
* @return Updated Application
* @throws ApplicationManagementException Application Management Exception
@ -47,13 +50,24 @@ public interface ApplicationManager {
/**
* Delete an application identified by the unique ID.
* @param uuid Unique ID for tha application
*
* @param applicationId ID for tha application
* @throws ApplicationManagementException Application Management Exception
*/
void deleteApplication(String uuid) throws ApplicationManagementException;
void deleteApplication(int applicationId) throws ApplicationManagementException;
/**
* Delete an application identified by the unique ID.
*
* @param applicationId ID of tha application
* @param releaseUuid UUID of tha application release
* @throws ApplicationManagementException Application Management Exception
*/
void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException;
/**
* To get the applications based on the search filter.
*
* @param filter Search filter
* @return Applications that matches the given filter criteria.
* @throws ApplicationManagementException Application Management Exception
@ -62,6 +76,7 @@ public interface ApplicationManager {
/**
* To get the applications based on the search filter.
*
* @param appId id of the application
* @return Application release which is published and release of the Application(appId).
* @throws ApplicationManagementException Application Management Exception
@ -135,5 +150,9 @@ public interface ApplicationManager {
*/
List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException;
LifecycleState getLifecycleState(int appReleaseId, String applicationUuid) throws LifecycleManagementException;
void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException;
}

@ -28,9 +28,8 @@ import java.util.List;
*/
public interface LifecycleStateManager {
List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifecycleManagementException;
LifecycleState getLifecycleState(int appReleaseId, String applicationUuid) throws LifecycleManagementException;
void addLifecycleState(LifecycleState state) throws LifecycleManagementException;
void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException;
void deleteLifecycleState(int identifier) throws LifecycleManagementException;
}

@ -29,7 +29,7 @@ import java.util.List;
*/
public interface LifecycleStateDAO {
LifecycleState getLatestLifeCycleStateByReleaseID(int identifier) throws ApplicationManagementDAOException;
LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws ApplicationManagementDAOException;
List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException;

@ -39,7 +39,7 @@ import java.util.List;
public class GenericLifecycleStateImpl extends AbstractDAOImpl implements LifecycleStateDAO {
@Override
public LifecycleState getLatestLifeCycleStateByReleaseID(int identifier) throws ApplicationManagementDAOException {
public LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws ApplicationManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
@ -50,7 +50,7 @@ public class GenericLifecycleStateImpl extends AbstractDAOImpl implements Lifecy
+ "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID=? ORDER BY UPDATED_AT DESC;";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, identifier);
stmt.setInt(1, applicationReleaseId);
rs = stmt.executeQuery();
LifecycleState lifecycleState = null;

@ -25,11 +25,15 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.exception.ValidationException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
@ -67,7 +71,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
}
@Override public Application createApplication(Application application) throws ApplicationManagementException {
@Override
public Application createApplication(Application application) throws ApplicationManagementException {
User loggedInUser = new User(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(),
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true));
@ -130,7 +135,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
@Override public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
@Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationList applicationList;
@ -159,7 +165,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
@Override public String getUuidOfLatestRelease(int appId) throws ApplicationManagementException {
@Override
public String getUuidOfLatestRelease(int appId) throws ApplicationManagementException {
try {
ConnectionManagerUtil.openDBConnection();
return applicationDAO.getUuidOfLatestRelease(appId);
@ -172,7 +179,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
private boolean isRoleExists(List<UnrestrictedRole> unrestrictedRoleList, String userName)
throws UserStoreException {
String[] roleList;
roleList = getRoleOfUser(userName);
roleList = getRolesOfUser(userName);
for (UnrestrictedRole unrestrictedRole : unrestrictedRoleList) {
for (String role : roleList) {
if (unrestrictedRole.getRole().equals(role)) {
@ -183,7 +190,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return false;
}
private String[] getRoleOfUser(String userName) throws UserStoreException {
private String[] getRolesOfUser(String userName) throws UserStoreException {
UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
String[] roleList = {};
if (userRealm != null) {
@ -194,7 +201,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
return roleList;
}
@Override public Application getApplication(String appType, String appName) throws ApplicationManagementException {
@Override
public Application getApplication(String appType, String appName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Application application;
@ -231,7 +239,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
@Override public Application getApplicationById(int applicationId) throws ApplicationManagementException {
@Override
public Application getApplicationById(int applicationId) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Application application;
@ -285,7 +294,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
@Override public List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException {
@Override
public List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = validateApplication(applicationId);
@ -300,7 +310,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleases = ApplicationManagementDAOFactory.getApplicationReleaseDAO()
.getApplicationReleases(application.getName(), application.getType(), tenantId);
for (ApplicationRelease applicationRelease : applicationReleases) {
if (!"REMOVED".equals(ApplicationManagementDAOFactory.getLifecycleStateDAO().
if (!AppLifecycleState.REMOVED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())) {
filteredApplicationReleases.add(applicationRelease);
}
@ -311,32 +321,52 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
/**
* To check whether current user is application owner or admin.
*
* @param applicationUUID UUID of the Application.
* @return true if the current user is application owner or admin, unless false.
* @throws ApplicationManagementException Application Management Exception.
*/
private boolean isApplicationOwnerOrAdmin(String applicationUUID, String userName, int tenantId)
throws ApplicationManagementException {
// try {
// if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
// return true;
// }
// } catch (UserStoreException e) {
// throw new ApplicationManagementException("Userstore exception while checking whether user is an admin", e);
// }
// try {
// ConnectionManagerUtil.openDBConnection();
// Application application = ApplicationManagementDAOFactory.getApplicationDAO()
// .getApplication(applicationUUID, tenantId, userName);
// return application.getUser().getUserName().equals(userName)
// && application.getUser().getTenantId() == tenantId;
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
return false;
@Override
public void deleteApplication(int applicationId) throws ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (validateApplication(applicationId) == null) {
throw new ApplicationManagementException("Invalid Application");
}
List<ApplicationRelease> applicationReleases = getReleases(applicationId);
if (log.isDebugEnabled()) {
log.debug("Request is received to delete applications which are related with the application id " +
applicationId);
}
for (ApplicationRelease applicationRelease : applicationReleases) {
LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid());
LifecycleState newAppLifecycleState = new LifecycleState();
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
newAppLifecycleState.setTenantId(tenantId);
newAppLifecycleState.setUpdatedBy(userName);
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
}
//todo add column into application and move application into removed state
}
@Override
public void deleteApplicationRelease(int applicationId, String releaseUuid) throws ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = validateApplication(applicationId);
if (application == null) {
throw new ApplicationManagementException("Invalid Application ID is received");
}
ApplicationRelease applicationRelease = validateApplicationRelease(releaseUuid);
if (applicationRelease == null) {
throw new ApplicationManagementException("Invalid Application Release UUID is received");
}
LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid());
LifecycleState newAppLifecycleState = new LifecycleState();
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
newAppLifecycleState.setTenantId(tenantId);
newAppLifecycleState.setUpdatedBy(userName);
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
}
/**
@ -381,6 +411,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
/**
* To validate the application existence
*
* @param application Application that need to be validated
* @throws ValidationException Validation Exception
*/
private void validateApplicationExistence(Application application) throws ApplicationManagementException {
Filter filter = new Filter();
filter.setFullMatch(true);
@ -415,6 +451,26 @@ public class ApplicationManagerImpl implements ApplicationManager {
return application;
}
/**
* To validate the pre-request of the ApplicationRelease.
*
* @param applicationUuid UUID of the Application.
* @return Application related with the UUID
*/
private ApplicationRelease validateApplicationRelease(String applicationUuid) throws ApplicationManagementException {
if (applicationUuid == null) {
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application.");
}
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager()
.getReleaseByUuid(applicationUuid);
if (applicationRelease == null) {
throw new NotFoundException(
"Application with UUID " + applicationUuid + " does not exist.");
}
return applicationRelease;
}
/**
* To get role restricted application list.
*
@ -470,7 +526,146 @@ public class ApplicationManagerImpl implements ApplicationManager {
// }
}
@Override public Application editApplication(Application application) throws ApplicationManagementException {
@Override
public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws LifecycleManagementException {
LifecycleState lifecycleState;
try {
ConnectionManagerUtil.openDBConnection();
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
Application application = validateApplication(applicationId);
//todo applicationUuid and applicationId should be passed and util method has to be changed
ApplicationRelease applicationRelease = validateApplicationRelease(applicationUuid);
lifecycleState = lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState()));
} catch (ApplicationManagementDAOException e) {
throw new LifecycleManagementException("Failed to get lifecycle state", e);
} catch (DBConnectionException e) {
throw new LifecycleManagementException("Failed to connect with Database", e);
} catch (ApplicationManagementException e) {
throw new LifecycleManagementException("Failed to get application and application management", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
return lifecycleState;
}
@Override
public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException {
try {
ConnectionManagerUtil.openDBConnection();
Application application = validateApplication(applicationId);
//todo applicationUuid and applicationId should be passed and util method has to be changed
ApplicationRelease applicationRelease = validateApplicationRelease(applicationUuid);
LifecycleStateDAO lifecycleStateDAO;
if (application != null) {
state.setAppId(applicationId);
}
if (applicationRelease != null) {
state.setReleaseId(applicationRelease.getId());
}
if (state.getCurrentState() != null && state.getPreviousState() != null && state.getUpdatedBy() != null) {
validateLifecycleState(state);
lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
lifecycleStateDAO.addLifecycleState(state);
}
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
throw new LifecycleManagementException("Failed to add lifecycle state", e);
} catch (ApplicationManagementException e) {
throw new LifecycleManagementException("Lifecycle State Validation failed", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
private List<String> getNextLifecycleStates(String currentLifecycleState) {
List<String> nextLifecycleStates = new ArrayList<>();
if (AppLifecycleState.CREATED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.IN_REVIEW.toString());
}
if (AppLifecycleState.IN_REVIEW.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.APPROVED.toString());
nextLifecycleStates.add(AppLifecycleState.REJECTED.toString());
}
if (AppLifecycleState.REJECTED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.IN_REVIEW.toString());
nextLifecycleStates.add(AppLifecycleState.REMOVED.toString());
}
if (AppLifecycleState.APPROVED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.PUBLISHED.toString());
}
if (AppLifecycleState.PUBLISHED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.UNPUBLISHED.toString());
nextLifecycleStates.add(AppLifecycleState.DEPRECATED.toString());
}
if (AppLifecycleState.UNPUBLISHED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.PUBLISHED.toString());
nextLifecycleStates.add(AppLifecycleState.REMOVED.toString());
}
if (AppLifecycleState.DEPRECATED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.REMOVED.toString());
}
return nextLifecycleStates;
}
private void validateLifecycleState(LifecycleState state) throws LifecycleManagementException {
if (AppLifecycleState.CREATED.toString().equals(state.getCurrentState())) {
throw new LifecycleManagementException("Current State Couldn't be " + state.getCurrentState());
}
if (AppLifecycleState.IN_REVIEW.toString().equals(state.getCurrentState())) {
if (!AppLifecycleState.CREATED.toString().equals(state.getPreviousState()) &&
!AppLifecycleState.REJECTED.toString().equals(state.getPreviousState())) {
throw new LifecycleManagementException("If Current State is " + state.getCurrentState() +
"Previous State should be either " + AppLifecycleState.CREATED.toString() + " or " +
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.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.DEPRECATED.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.REMOVED.toString().equals(state.getCurrentState())) {
if (!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());
}
}
}
@Override
public Application editApplication(Application application) throws ApplicationManagementException {
// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// if (application.getUuid() == null) {
@ -531,34 +726,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
return application;
}
@Override public void deleteApplication(String uuid) throws ApplicationManagementException {
// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// if (!isApplicationOwnerOrAdmin(uuid, userName, tenantId)) {
// throw new ApplicationManagementException("User '" + userName + "' of tenant - " + tenantId + " does have"
// + " the permission to delete the application with UUID " + uuid);
// }
// try {
// ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
// ConnectionManagerUtil.beginDBTransaction();
// int appId = applicationDAO.getApplicationId(uuid, tenantId);
// if (appId != -1) {
// applicationDAO.deleteTags(appId);
// applicationDAO.deleteProperties(appId);
// DataHolder.getInstance().getVisibilityManager().remove(appId);
// applicationDAO.deleteApplication(uuid, tenantId);
// }
// ConnectionManagerUtil.commitDBTransaction();
// } catch (ApplicationManagementDAOException e) {
// ConnectionManagerUtil.rollbackDBTransaction();
// String msg = "Failed to delete application: " + uuid;
// throw new ApplicationManagementException(msg, e);
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
}
@Override public void changeLifecycle(String applicationUuid, String lifecycleIdentifier)
@Override
public void changeLifecycle(String applicationUuid, String lifecycleIdentifier)
throws ApplicationManagementException {
// boolean isAvailableNextState = false;
// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -593,7 +762,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
// }
}
@Override public List<LifecycleStateTransition> getLifeCycleStates(String applicationUUID)
@Override
public List<LifecycleStateTransition> getLifeCycleStates(String applicationUUID)
throws ApplicationManagementException {
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
// String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -649,4 +819,32 @@ public class ApplicationManagerImpl implements ApplicationManager {
return null;
}
/**
* To check whether current user is application owner or admin.
*
* @param applicationUUID UUID of the Application.
* @return true if the current user is application owner or admin, unless false.
* @throws ApplicationManagementException Application Management Exception.
*/
private boolean isApplicationOwnerOrAdmin(String applicationUUID, String userName, int tenantId)
throws ApplicationManagementException {
// try {
// if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
// return true;
// }
// } catch (UserStoreException e) {
// throw new ApplicationManagementException("Userstore exception while checking whether user is an admin", e);
// }
// try {
// ConnectionManagerUtil.openDBConnection();
// Application application = ApplicationManagementDAOFactory.getApplicationDAO()
// .getApplication(applicationUUID, tenantId, userName);
// return application.getUser().getUserName().equals(userName)
// && application.getUser().getTenantId() == tenantId;
// } finally {
// ConnectionManagerUtil.closeDBConnection();
// }
return false;
}
}

@ -68,8 +68,8 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override
public ApplicationRelease uploadImageArtifacts(ApplicationRelease applicationRelease, InputStream iconFileStream,
InputStream bannerFileStream,List<InputStream> screenShotStreams) throws ResourceManagementException {
InputStream bannerFileStream, List<InputStream> screenShotStreams)
throws ResourceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String artifactDirectoryPath = null;
String iconStoredLocation;
@ -77,26 +77,22 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
String scStoredLocation;
try {
artifactDirectoryPath = storagePath + applicationRelease.getAppHashValue();
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
iconStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[0];
bannerStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[1];
if (iconFileStream != null){
if (iconFileStream != null) {
saveFile(iconFileStream, iconStoredLocation);
applicationRelease.setIconLoc(iconStoredLocation);
}
if (bannerFileStream != null){
if (bannerFileStream != null) {
saveFile(bannerFileStream, bannerStoredLocation);
applicationRelease.setBannerLoc(bannerStoredLocation);
}
if (screenShotStreams.size() > screenShotMaxCount) {
throw new ApplicationStorageManagementException("Maximum limit for the screen-shot exceeds");
}else if(!screenShotStreams.isEmpty() && screenShotStreams.size() <= screenShotMaxCount){
} else if (!screenShotStreams.isEmpty() && screenShotStreams.size() <= screenShotMaxCount) {
int count = 1;
for (InputStream screenshotStream : screenShotStreams) {
scStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[2] + count;
@ -125,7 +121,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
+ "update the screen-shot count for the application " + applicationRelease.getUuid() +
" for the tenant id " + tenantId, e);
}
}
@Override
@ -154,7 +149,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
}
@Override
public ApplicationRelease uploadReleaseArtifacts(ApplicationRelease applicationRelease , InputStream binaryFile)
public ApplicationRelease uploadReleaseArtifacts(ApplicationRelease applicationRelease, InputStream binaryFile)
throws ResourceManagementException {
String artifactDirectoryPath;
@ -162,7 +157,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
md5OfApp = getMD5(binaryFile);
//todo validate binary file.
if(md5OfApp != null){
if (md5OfApp != null) {
artifactDirectoryPath = storagePath + md5OfApp;
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
if (log.isDebugEnabled()) {
@ -179,10 +174,9 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
+ applicationRelease.getUuid(), e);
}
}else{
} else {
log.error("Verify application existence and md5sum value retrieving process");
}
return applicationRelease;
}
@ -195,7 +189,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
ApplicationRelease applicationRelease = null;
try {
applicationRelease = validateApplicationRelease(applicationUuid);
applicationRelease = uploadReleaseArtifacts(applicationRelease,binaryFile);
applicationRelease = uploadReleaseArtifacts(applicationRelease, binaryFile);
return applicationRelease;
} catch (ApplicationManagementException e) {
throw new ApplicationStorageManagementException("Application Management exception while trying to"
@ -310,6 +304,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
/**
* To validate the image artifact names.
*
* @param name Name of the image artifact.
* @throws ApplicationStorageManagementException Application Storage Management Exception
*/
@ -339,7 +334,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
isAppExist = DataHolder.getInstance().getApplicationManager().verifyApplicationExistenceById(appId);
} catch (ApplicationManagementException e) {
throw new ApplicationStorageManagementException(
"Exception while verifing the application existence for the application with ID "+ appId);
"Exception while verifing the application existence for the application with ID " + appId);
}
return isAppExist;

@ -1,33 +1,40 @@
/*
* Copyright (c) 2017, 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.
*
*/
* Copyright (c) 2017, 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.core.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.ValidateApplicationUtil;
import java.util.ArrayList;
import java.util.List;
/**
@ -38,44 +45,140 @@ public class LifecycleStateManagerImpl implements LifecycleStateManager {
private static final Log log = LogFactory.getLog(LifecycleStateManagerImpl.class);
@Override
public List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifecycleManagementException {
List<LifecycleState> lifecycleStates = null;
public LifecycleState getLifecycleState(int applicationId, String applicationUuid) throws LifecycleManagementException {
LifecycleState lifecycleState;
try {
ConnectionManagerUtil.openDBConnection();
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
lifecycleStates = lifecycleStateDAO.getLifecycleStates(appReleaseId);
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
throw new LifecycleManagementException("Failed get lifecycle states.", e);
Application application = ValidateApplicationUtil.validateApplication(applicationId);
//todo applicationUuid and applicationId should be passed and util method has to be changed
ApplicationRelease applicationRelease = ValidateApplicationUtil.validateApplicationRelease(applicationUuid);
lifecycleState = lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState()));
} catch (ApplicationManagementDAOException e) {
throw new LifecycleManagementException("Failed to get lifecycle state", e);
} catch (DBConnectionException e) {
throw new LifecycleManagementException("Failed to connect with Database", e);
} catch (ApplicationManagementException e) {
throw new LifecycleManagementException("Failed to get application and application management", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
return lifecycleStates;
return lifecycleState;
}
@Override
public void addLifecycleState(LifecycleState state) throws LifecycleManagementException {
public void addLifecycleState(int applicationId, String applicationUuid, LifecycleState state) throws LifecycleManagementException {
try {
ConnectionManagerUtil.openDBConnection();
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
Application application = ValidateApplicationUtil.validateApplication(applicationId);
//todo applicationUuid and applicationId should be passed and util method has to be changed
ApplicationRelease applicationRelease = ValidateApplicationUtil.validateApplicationRelease(applicationUuid);
LifecycleStateDAO lifecycleStateDAO;
if (application != null) {
state.setAppId(applicationId);
}
if (applicationRelease != null) {
state.setReleaseId(applicationRelease.getId());
}
if (state.getCurrentState() != null && state.getPreviousState() != null && state.getUpdatedBy() != null) {
validateLifecycleState(state);
lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
lifecycleStateDAO.addLifecycleState(state);
}
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
throw new LifecycleManagementException("Failed to add lifecycle state", e);
} catch (ApplicationManagementException e) {
throw new LifecycleManagementException("Lifecycle State Validation failed", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public void deleteLifecycleState(int identifier) throws LifecycleManagementException {
private List<String> getNextLifecycleStates(String currentLifecycleState) {
List<String> nextLifecycleStates = new ArrayList<>();
if (AppLifecycleState.CREATED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.IN_REVIEW.toString());
}
if (AppLifecycleState.IN_REVIEW.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.APPROVED.toString());
nextLifecycleStates.add(AppLifecycleState.REJECTED.toString());
}
if (AppLifecycleState.REJECTED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.IN_REVIEW.toString());
nextLifecycleStates.add(AppLifecycleState.REMOVED.toString());
}
if (AppLifecycleState.APPROVED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.PUBLISHED.toString());
}
if (AppLifecycleState.PUBLISHED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.UNPUBLISHED.toString());
nextLifecycleStates.add(AppLifecycleState.DEPRECATED.toString());
}
if (AppLifecycleState.UNPUBLISHED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.PUBLISHED.toString());
nextLifecycleStates.add(AppLifecycleState.REMOVED.toString());
}
if (AppLifecycleState.DEPRECATED.toString().equals(currentLifecycleState)) {
nextLifecycleStates.add(AppLifecycleState.REMOVED.toString());
}
return nextLifecycleStates;
}
try {
ConnectionManagerUtil.openDBConnection();
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
lifecycleStateDAO.deleteLifecycleState(identifier);
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
throw new LifecycleManagementException("Failed to add lifecycle state: " + identifier, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
private void validateLifecycleState(LifecycleState state) throws LifecycleManagementException {
if (AppLifecycleState.CREATED.toString().equals(state.getCurrentState())) {
throw new LifecycleManagementException("Current State Couldn't be " + state.getCurrentState());
}
if (AppLifecycleState.IN_REVIEW.toString().equals(state.getCurrentState())) {
if (!AppLifecycleState.CREATED.toString().equals(state.getPreviousState()) &&
!AppLifecycleState.REJECTED.toString().equals(state.getPreviousState())) {
throw new LifecycleManagementException("If Current State is " + state.getCurrentState() +
"Previous State should be either " + AppLifecycleState.CREATED.toString() + " or " +
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.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.DEPRECATED.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.REMOVED.toString().equals(state.getCurrentState())) {
if (!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());
}
}
}
}

@ -0,0 +1,78 @@
/*
* Copyright (c) 2017, 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.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.Extension;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import java.lang.reflect.Constructor;
/**
* This Util class is responsible for making sure single instance of each Extension Manager is used throughout for
* all the tasks.
*/
public class ValidateApplicationUtil {
/**
* To validate the pre-request of the ApplicationRelease.
*
* @param applicationID ID of the Application.
* @return Application related with the UUID
*/
public static Application validateApplication(int applicationID) throws ApplicationManagementException {
if (applicationID <= 0) {
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application.");
}
Application application = DataHolder.getInstance().getApplicationManager().getApplicationById(applicationID);
if (application == null) {
throw new NotFoundException("Application of the " + applicationID + " does not exist.");
}
return application;
}
/**
* To validate the pre-request of the ApplicationRelease.
*
* @param applicationUuid UUID of the Application.
* @return Application related with the UUID
*/
public static ApplicationRelease validateApplicationRelease(String applicationUuid) throws ApplicationManagementException {
if (applicationUuid == null) {
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
+ "parameter to get the relevant application.");
}
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager()
.getReleaseByUuid(applicationUuid);
if (applicationRelease == null) {
throw new NotFoundException(
"Application with UUID " + applicationUuid + " does not exist.");
}
return applicationRelease;
}
}

@ -91,8 +91,8 @@ import javax.ws.rs.core.Response;
permissions = {"/device-mgt/application/update"}
),
@Scope(
name = "Create an Application",
description = "Create an application",
name = "Login to Application Management",
description = "Login to Application Management",
key = "perm:application-mgt:login",
permissions = {"/device-mgt/application-mgt/login"}
),
@ -101,21 +101,7 @@ import javax.ws.rs.core.Response;
description = "Delete an application",
key = "perm:application:delete",
permissions = {"/device-mgt/application/delete"}
),
@Scope(
name = "Create an application category",
description = "Create an application category",
key = "perm:application-category:create",
permissions = {"/device-mgt/application/category/create"}
),
@Scope(
name = "Delete an Application category",
description = "Delete an application category",
key = "perm:application-category:delete",
permissions = {"/device-mgt/application/category/delete"}
)
}
)
@Path("/publisher/applications")
@ -315,7 +301,7 @@ public interface ApplicationManagementAPI {
@DELETE
@Consumes("application/json")
@Path("/{appuuid}")
@Path("/{appid}")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
@ -345,7 +331,7 @@ public interface ApplicationManagementAPI {
name = "UUID",
value = "Unique identifier of the Application",
required = true)
@PathParam("appuuid") String applicationUUID);
@PathParam("appid") int applicationId);
@PUT
@Consumes("application/json")
@ -459,7 +445,7 @@ public interface ApplicationManagementAPI {
Response updateApplicationArtifact(
@ApiParam(name = "id", value = "Id of the application", required = true) @PathParam("uuid") int applicationId,
@ApiParam(name = "uuid", value = "UUID of the application", required = true) @PathParam("uuid") String applicationUUID,
@Multipart("binaryFile") Attachment binaryFile );
@Multipart("binaryFile") Attachment binaryFile);
@PUT
@Path("/{appId}/{uuid}")
@ -489,7 +475,6 @@ public interface ApplicationManagementAPI {
message = "Internal Server Error. \n Error occurred while releasing the application.",
response = ErrorResponse.class)
})
Response updateApplicationRelease(
@ApiParam(name = "appId", value = "Identifier of the Application", required = true) @PathParam("appId") int applicationId,
@ApiParam(name = "UUID", value = "Unique identifier of the Application Release", required = true) @PathParam("uuid") String applicationUUID,

@ -103,7 +103,8 @@ public interface LifecycleManagementAPI {
message = "Internal Server Error. \n Error occurred while getting the lifecycle list.",
response = ErrorResponse.class)
})
Response getLifecycleStates();
Response getLifecycleState(@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid);
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ -136,7 +137,9 @@ public interface LifecycleManagementAPI {
message = "Internal Server Error. \n Error occurred adding a lifecycle state.",
response = ErrorResponse.class)
})
Response addLifecycleState(LifecycleState state);
Response addLifecycleState(@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid,
LifecycleState state);
@Path("/{identifier}")
@Produces(MediaType.APPLICATION_JSON)

@ -22,6 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.FileStreamingOutput;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI;
@ -311,50 +312,38 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return Response.status(Response.Status.OK).entity(application).build();
}
//todo this need to be rethink and fix --- > This is somthing change lifecycle
@DELETE
@Path("/{appuuid}")
public Response deleteApplication(@PathParam("appuuid") String uuid) {
@Path("/{appid}")
public Response deleteApplication(@PathParam("appid") int applicationId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
try {
applicationReleaseManager.deleteApplicationReleases(uuid);
applicationStorageManager.deleteApplicationArtifacts(uuid);
applicationManager.deleteApplication(uuid);
String responseMsg = "Successfully deleted the application: " + uuid;
applicationManager.deleteApplication(applicationId);
// todo delete storage details
// applicationStorageManager.deleteApplicationArtifacts(uuid);
String responseMsg = "Successfully deleted the application: " + applicationId;
return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (NotFoundException e) {
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting the application: " + uuid;
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
} catch (ApplicationStorageManagementException e) {
log.error("Error occurred while deleteing the image artifacts of the application with the uuid " + uuid, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
// todo I think we must remove this
@Override
@PUT
@Consumes("application/json")
@Path("/{uuid}/{version}/{channel}")
public Response updateDefaultVersion(@PathParam("uuid") String applicationUUID, @PathParam("version") String
version, @PathParam("channel") String channel, @QueryParam("isDefault") boolean isDefault) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
@DELETE
@Path("/{appid}/{uuid}")
public Response deleteApplicationRelease(@PathParam("appid") int applicationId, @PathParam("uuid") String releaseUuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
try {
applicationReleaseManager.changeDefaultRelease(applicationUUID, version, isDefault, channel);
return Response.status(Response.Status.OK)
.entity("Successfully changed the default version for the " + "release channel " + channel
+ " for the application UUID " + applicationUUID).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
applicationManager.deleteApplication(applicationId);
// todo delete release storage details
// applicationStorageManager.deleteApplicationArtifacts(uuid);
String responseMsg = "Successfully deleted the application release of: " + applicationId + "";
return Response.status(Response.Status.OK).entity(responseMsg).build();
} catch (ApplicationManagementException e) {
log.error("Application Release Management Exception while changing the default release for the release "
+ "channel " + channel + " for the application with UUID " + applicationUUID + " for the version "
+ version);
String msg = "Error occurred while deleting the application: " + applicationId;
log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
@ -422,4 +411,28 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
// todo I think we must remove this
@Override
@PUT
@Consumes("application/json")
@Path("/{uuid}/{version}/{channel}")
public Response updateDefaultVersion(@PathParam("uuid") String applicationUUID, @PathParam("version") String
version, @PathParam("channel") String channel, @QueryParam("isDefault") boolean isDefault) {
ApplicationReleaseManager applicationReleaseManager = APIUtil.getApplicationReleaseManager();
try {
applicationReleaseManager.changeDefaultRelease(applicationUUID, version, isDefault, channel);
return Response.status(Response.Status.OK)
.entity("Successfully changed the default version for the " + "release channel " + channel
+ " for the application UUID " + applicationUUID).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
log.error("Application Release Management Exception while changing the default release for the release "
+ "channel " + channel + " for the application with UUID " + applicationUUID + " for the version "
+ version);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
}

@ -29,48 +29,56 @@ import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
/**
* Lifecycle Management related jax-rs APIs.
*/
@Path("/lifecycles")
@Path("/lifecycle")
public class LifecycleManagementAPIImpl implements LifecycleManagementAPI {
private static Log log = LogFactory.getLog(LifecycleManagementAPIImpl.class);
@GET
public Response getLifecycleStates() {
return null;
// LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
// List<LifecycleState> lifecycleStates = new ArrayList<>();
// try {
// lifecycleStates = lifecycleStateManager.getLifecycleStates();
// } catch (LifecycleManagementException e) {
// String msg = "Error occurred while retrieving lifecycle states.";
// log.error(msg, e);
// return Response.status(Response.Status.BAD_REQUEST).build();
// }
// return Response.status(Response.Status.OK).entity(lifecycleStates).build();
@Path("/{appId}/{uuid}")
public Response getLifecycleState(
@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid) {
LifecycleState lifecycleState;
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
try {
lifecycleState = lifecycleStateManager.getLifecycleState(applicationId, applicationUuid);
} catch (LifecycleManagementException e) {
String msg = "Error occurred while getting lifecycle state.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.OK).entity(lifecycleState).build();
}
@POST
public Response addLifecycleState(LifecycleState state) {
@Path("/{appId}/{uuid}")
public Response addLifecycleState(
@PathParam("appId") int applicationId,
@PathParam("uuid") String applicationUuid,
LifecycleState state) {
LifecycleStateManager lifecycleStateManager = APIUtil.getLifecycleStateManager();
try {
lifecycleStateManager.addLifecycleState(state);
lifecycleStateManager.addLifecycleState(applicationId, applicationUuid, state);
} catch (LifecycleManagementException e) {
String msg = "Error occurred while adding lifecycle state.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.OK).entity("Lifecycle state added successfully.").build();
return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build();
}
//todo remove below part
@DELETE
@Path("/{identifier}")
public Response deleteLifecycleState(@PathParam("identifier") String identifier) {

@ -32,19 +32,19 @@
<!-- Application related permissions -->
<Permission>
<name>Get Application</name>
<name>Get Application Details</name>
<path>/device-mgt/application/get</path>
<url>/application-mgt/applications</url>
<method>GET</method>
</Permission>
<Permission>
<name>Create Application</name>
<name>Create an Application</name>
<path>/device-mgt/application/create</path>
<url>/application-mgt/applications</url>
<method>POST</method>
</Permission>
<Permission>
<name>Edit Application</name>
<name>Update an Application</name>
<path>/device-mgt/application/update</path>
<url>/application-mgt/applications</url>
<method>PUT</method>
@ -56,55 +56,10 @@
<method>PUT</method>
</Permission>
<Permission>
<name>Login to Application Management</name>
<name>Delete an Application</name>
<path>device-mgt/application/delete</path>
<url>/application-mgt/applications/*</url>
<method>DELETE</method>
</Permission>
<!-- Platform related permissions -->
<Permission>
<name>Get Platform</name>
<path>/device-mgt/platform/get</path>
<url>/application-mgt/platforms/*</url>
<method>GET</method>
</Permission>
<Permission>
<name>Add Platform</name>
<path>/device-mgt/platform/add</path>
<url>/application-mgt/platforms</url>
<method>POST</method>
</Permission>
<Permission>
<name>Update Platform</name>
<path>/device-mgt/platform/update</path>
<url>/application-mgt/platforms/*</url>
<method>PUT</method>
</Permission>
<Permission>
<name>Remove Platform</name>
<path>/device-mgt/platform/remove</path>
<url>/application-mgt/platforms/*</url>
<method>DELETE</method>
</Permission>
<!-- Subscription related permissions -->
<Permission>
<name>Install Application</name>
<path>/device-mgt/subscription/install</path>
<url>/application-mgt/subscription</url>
<method>POST</method>
</Permission>
<Permission>
<name>Uninstall Application</name>
<path>/device-mgt/subscription/uninstall</path>
<url>/application-mgt/subscription</url>
<method>POST</method>
</Permission>
<Permission>
<name>Get Application</name>
<path>/device-mgt/subscription/getApplication</path>
<url>/application-mgt/subscription</url>
<method>GET</method>
</Permission>
</PermissionConfiguration>

Loading…
Cancel
Save