Fixed application management issues and improve functionalities

merge-requests/7/head
lasantha 7 years ago
parent 7278408b44
commit b0eafe7180

@ -105,6 +105,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (deviceType == null) { if (deviceType == null) {
log.error("Device type is not matched with application type"); log.error("Device type is not matched with application type");
ConnectionManagerUtil.rollbackDBTransaction();
return null; return null;
} }
application.setDevicetype(deviceType); application.setDevicetype(deviceType);
@ -113,6 +114,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (appId != -1) { if (appId != -1) {
log.error("Application creation Failed"); log.error("Application creation Failed");
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
return null;
} else { } else {
if (!application.getTags().isEmpty()) { if (!application.getTags().isEmpty()) {
this.applicationDAO.addTags(application.getTags(), appId, tenantId); this.applicationDAO.addTags(application.getTags(), appId, tenantId);
@ -127,7 +129,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationRelease.setCreatedAt((Timestamp) new Date()); applicationRelease.setCreatedAt((Timestamp) new Date());
applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO(). applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO().
createRelease(applicationRelease, application.getId()); createRelease(applicationRelease, application.getId());
//todo add lifecycle and add this into application LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setAppId(application.getId());
lifecycleState.setReleaseId(applicationRelease.getId());
lifecycleState.setUpdatedBy(loggedInUser.getUserName());
lifecycleState.setTenantId(loggedInUser.getTenantId());
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState);
} }
return application; return application;
@ -232,6 +241,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
application = ApplicationManagementDAOFactory.getApplicationDAO() application = ApplicationManagementDAOFactory.getApplicationDAO()
.getApplication(appType, appName, tenantId); .getApplication(appType, appName, tenantId);
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application.getId());
application.setApplicationReleases(applicationReleases);
return application; return application;
} }
@ -538,6 +549,8 @@ 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 {
LifecycleState lifecycleState = getLifecycleState(appId, applicationRelease.getUuid());
return null; return null;
} }

@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
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.ApplicationType; import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
@ -192,9 +193,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
"application types " + applicationRelease.getUuid()); "application types " + applicationRelease.getUuid());
} }
if (md5OfApp != null) { if (md5OfApp != null) {
artifactDirectoryPath = storagePath + md5OfApp; artifactDirectoryPath = storagePath + md5OfApp;
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath); StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
@ -225,7 +223,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
public ApplicationRelease updateReleaseArtifacts(ApplicationRelease applicationRelease, String appType, public ApplicationRelease updateReleaseArtifacts(ApplicationRelease applicationRelease, String appType,
InputStream binaryFile) throws ApplicationStorageManagementException { InputStream binaryFile) throws ApplicationStorageManagementException {
if (binaryFile != null) {
try { try {
deleteApplicationReleaseArtifacts(applicationRelease.getAppStoredLoc()); deleteApplicationReleaseArtifacts(applicationRelease.getAppStoredLoc());
applicationRelease = uploadReleaseArtifact(applicationRelease, appType, binaryFile); applicationRelease = uploadReleaseArtifact(applicationRelease, appType, binaryFile);
@ -234,7 +231,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
throw new ApplicationStorageManagementException("Application Artifact Updating failed", e); throw new ApplicationStorageManagementException("Application Artifact Updating failed", e);
} }
}
return applicationRelease; return applicationRelease;

@ -352,9 +352,12 @@ public interface ApplicationManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response updateApplicationImageArtifacts( Response updateApplicationImageArtifacts(
@ApiParam(name = "appId", value = "ID of the application", required = true) @PathParam("appId") int applicatioId, @ApiParam(name = "appId", value = "ID of the application", required = true)
@ApiParam(name = "uuid", value = "UUID of the application", required = true) @PathParam("uuid") String applicationUUID, @PathParam("appId") int applicatioId,
@Multipart(value = "icon") Attachment iconFile, @Multipart(value = "banner") Attachment bannerFile, @ApiParam(name = "uuid", value = "UUID of the application", required = true)
@PathParam("uuid") String applicationUUID,
@Multipart(value = "icon") Attachment iconFile,
@Multipart(value = "banner") Attachment bannerFile,
@Multipart(value = "screenshot") List<Attachment> screenshots); @Multipart(value = "screenshot") List<Attachment> screenshots);
@PUT @PUT

@ -24,7 +24,6 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
import org.wso2.carbon.device.application.mgt.core.exception.ValidationException;
import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil; import org.wso2.carbon.device.application.mgt.publisher.api.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI; import org.wso2.carbon.device.application.mgt.publisher.api.services.ApplicationManagementAPI;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
@ -187,7 +186,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
@Override @Override
@POST @PUT
@Path("/image-artifacts/{appId}/{uuid}") @Path("/image-artifacts/{appId}/{uuid}")
public Response updateApplicationImageArtifacts( public Response updateApplicationImageArtifacts(
@PathParam("appId") int appId, @PathParam("appId") int appId,
@ -217,8 +216,16 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
} }
applicationRelease = applicationManager.validateApplicationRelease(applicationUuid); applicationRelease = applicationManager.validateApplicationRelease(applicationUuid);
LifecycleState lifecycleState = applicationManager.getLifecycleState(appId, applicationRelease.getUuid());
if (AppLifecycleState.PUBLISHED.toString().equals(lifecycleState.getCurrentState()) ||
AppLifecycleState.DEPRECATED.toString().equals(lifecycleState.getCurrentState())) {
return Response.status(Response.Status.FORBIDDEN).entity("Can't Update the application release in " +
"PUBLISHED or DEPRECATED state. Hence please demote the application and update the application " +
"release").build();
}
applicationRelease = applicationStorageManager applicationRelease = applicationStorageManager
.updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments); .updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
//todo need to implement updateRelease method
applicationManager.updateRelease(appId, applicationRelease); applicationManager.updateRelease(appId, applicationRelease);
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();
@ -263,6 +270,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
applicationRelease = applicationManager.validateApplicationRelease(applicationUuuid); applicationRelease = applicationManager.validateApplicationRelease(applicationUuuid);
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease, appType, applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease, appType,
binaryFile.getDataHandler().getInputStream()); binaryFile.getDataHandler().getInputStream());
//todo
applicationManager.updateRelease(applicationId, applicationRelease); applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuuid).build(); .entity("Successfully uploaded artifacts for the application " + applicationUuuid).build();
@ -338,11 +346,10 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
applicationRelease = applicationStorageManager applicationRelease = applicationStorageManager
.updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments); .updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
//todo
applicationRelease = applicationManager.updateRelease(applicationId, applicationRelease); applicationRelease = applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK).entity(applicationRelease).build(); return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Error while updating the application release of the application with UUID " + applicationUUID); log.error("Error while updating the application release of the application with UUID " + applicationUUID);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);

Loading…
Cancel
Save