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);
validateReleaseCreatingRequest(application.getApplicationReleases().get(0));
validateAppReleasePayload(application.getApplicationReleases().get(0));
DeviceType deviceType;
ApplicationRelease applicationRelease;
List<ApplicationRelease> applicationReleases = new ArrayList<>();
@ -205,7 +205,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = getApplicationIfAccessible(applicationId);
validateReleaseCreatingRequest(applicationRelease);
validateAppReleasePayload(applicationRelease);
if (log.isDebugEnabled()) {
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");
}
ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, releaseUuid);
if (applicationRelease == null) {
throw new ApplicationManagementException("Invalid Application Release UUID is received");
}
LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid());
String currentState = appLifecycleState.getCurrentState();
if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState
@ -612,18 +609,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws
ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
validateAppReleasePayload(applicationRelease);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (log.isDebugEnabled()) {
log.debug("Updating the Application release. UUID: " + applicationRelease.getUuid() + ", " +
"Application Id: " + appId);
}
try {
ApplicationRelease existingAppRelease = getAppReleaseIfExists(appId, applicationRelease.getUuid());
ConnectionManagerUtil.openDBConnection();
// todo consider about lifecycle
applicationRelease = this.applicationReleaseDAO.updateRelease(appId, applicationRelease, tenantId);
return applicationRelease;
} finally {
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.
* @throws ApplicationManagementException Application Management Exception.
*/
private void validateReleaseCreatingRequest(ApplicationRelease applicationRelease)
private void validateAppReleasePayload(ApplicationRelease applicationRelease)
throws ApplicationManagementException {
if (applicationRelease.getVersion() == null) {
@ -688,8 +682,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
LifecycleState lifecycleState;
try {
ConnectionManagerUtil.openDBConnection();
ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, applicationUuid);
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationId);
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()));
} catch (ApplicationManagementDAOException 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)
.entity("Successfully uploaded artifacts for the application " + applicationUuid).build();
} 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);
return APIUtil.getResponse(e, Response.Status.NOT_FOUND);
} catch (ApplicationManagementException e) {
@ -424,7 +426,13 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
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.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();

Loading…
Cancel
Save