Refactor the source

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent b3874ee1ba
commit ff96884268

@ -98,7 +98,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
validateAppCreatingRequest(application); validateAppCreatingRequest(application);
validateReleaseCreatingRequest(application.getApplicationReleases().get(0)); validateAppReleasePayload(application.getApplicationReleases().get(0));
DeviceType deviceType; DeviceType deviceType;
ApplicationRelease applicationRelease; ApplicationRelease applicationRelease;
List<ApplicationRelease> applicationReleases = new ArrayList<>(); List<ApplicationRelease> applicationReleases = new ArrayList<>();
@ -205,7 +205,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = getApplicationIfAccessible(applicationId); Application application = getApplicationIfAccessible(applicationId);
validateReleaseCreatingRequest(applicationRelease); validateAppReleasePayload(applicationRelease);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Application release request is received for the application " + application.toString()); log.debug("Application release request is received for the application " + application.toString());
} }
@ -429,9 +429,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException("Invalid Application ID is received"); throw new ApplicationManagementException("Invalid Application ID is received");
} }
ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, releaseUuid); ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, releaseUuid);
if (applicationRelease == null) {
throw new ApplicationManagementException("Invalid Application Release UUID is received");
}
LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid()); LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid());
String currentState = appLifecycleState.getCurrentState(); String currentState = appLifecycleState.getCurrentState();
if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState
@ -612,18 +609,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override @Override
public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws
ApplicationManagementException { ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); validateAppReleasePayload(applicationRelease);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Updating the Application release. UUID: " + applicationRelease.getUuid() + ", " + log.debug("Updating the Application release. UUID: " + applicationRelease.getUuid() + ", " +
"Application Id: " + appId); "Application Id: " + appId);
} }
try { try {
ApplicationRelease existingAppRelease = getAppReleaseIfExists(appId, applicationRelease.getUuid());
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
// todo consider about lifecycle
applicationRelease = this.applicationReleaseDAO.updateRelease(appId, applicationRelease, tenantId); applicationRelease = this.applicationReleaseDAO.updateRelease(appId, applicationRelease, tenantId);
return applicationRelease; return applicationRelease;
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
@ -668,12 +662,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
/** /**
* To validate a create release request to make sure all the pre-conditions satisfied. * To validate a app release creating request and app updating request to make sure all the pre-conditions satisfied.
* *
* @param applicationRelease ApplicationRelease that need to be created. * @param applicationRelease ApplicationRelease that need to be created.
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
private void validateReleaseCreatingRequest(ApplicationRelease applicationRelease) private void validateAppReleasePayload(ApplicationRelease applicationRelease)
throws ApplicationManagementException { throws ApplicationManagementException {
if (applicationRelease.getVersion() == null) { if (applicationRelease.getVersion() == null) {
@ -688,8 +682,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
LifecycleState lifecycleState; LifecycleState lifecycleState;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, applicationUuid); lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationId);
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); if (lifecycleState == null) {
throw new NotFoundException(
"Couldn't find the lifecycle data for appid: " + applicationId + " and app release UUID: "
+ applicationUuid);
}
lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState())); lifecycleState.setNextStates(getNextLifecycleStates(lifecycleState.getCurrentState()));
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
throw new ApplicationManagementException("Failed to get lifecycle state", e); throw new ApplicationManagementException("Failed to get lifecycle state", e);

@ -222,7 +222,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuid).build(); .entity("Successfully uploaded artifacts for the application " + applicationUuid).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't found application release details and storage details"; String msg =
"Couldn't found application release details or storage details or lifecycle details. Application id: "
+ appId + " App release uuid: " + applicationUuid;
log.error(msg, e); log.error(msg, e);
return APIUtil.getResponse(e, Response.Status.NOT_FOUND); return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
@ -424,7 +426,13 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
lifecycleState = applicationManager.getLifecycleState(applicationId, applicationUuid); lifecycleState = applicationManager.getLifecycleState(applicationId, applicationUuid);
} catch (ApplicationManagementException e) { } catch (NotFoundException e){
String msg = "Couldn't found application lifecycle details for appid: " + applicationId
+ " and app release UUID: " + applicationUuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).build();
}
catch (ApplicationManagementException e) {
String msg = "Error occurred while getting lifecycle state."; String msg = "Error occurred while getting lifecycle state.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();

Loading…
Cancel
Save