Fixed application management issues and improve functionalities

feature/appm-store/pbac
lasantha 7 years ago
parent 7278408b44
commit b0eafe7180

@ -105,6 +105,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (deviceType == null) {
log.error("Device type is not matched with application type");
ConnectionManagerUtil.rollbackDBTransaction();
return null;
}
application.setDevicetype(deviceType);
@ -113,6 +114,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (appId != -1) {
log.error("Application creation Failed");
ConnectionManagerUtil.rollbackDBTransaction();
return null;
} else {
if (!application.getTags().isEmpty()) {
this.applicationDAO.addTags(application.getTags(), appId, tenantId);
@ -127,7 +129,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationRelease.setCreatedAt((Timestamp) new Date());
applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO().
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;
@ -232,6 +241,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
application = ApplicationManagementDAOFactory.getApplicationDAO()
.getApplication(appType, appName, tenantId);
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application.getId());
application.setApplicationReleases(applicationReleases);
return application;
}
@ -538,6 +549,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
public ApplicationRelease updateRelease(int appId, ApplicationRelease applicationRelease) throws
ApplicationManagementException {
LifecycleState lifecycleState = getLifecycleState(appId, applicationRelease.getUuid());
return null;
}

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

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

@ -24,7 +24,6 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
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.core.exception.ValidationException;
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.common.exception.ApplicationManagementException;
@ -187,7 +186,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
}
@Override
@POST
@PUT
@Path("/image-artifacts/{appId}/{uuid}")
public Response updateApplicationImageArtifacts(
@PathParam("appId") int appId,
@ -217,8 +216,16 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
}
}
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
.updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
//todo need to implement updateRelease method
applicationManager.updateRelease(appId, applicationRelease);
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuid).build();
@ -263,6 +270,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
applicationRelease = applicationManager.validateApplicationRelease(applicationUuuid);
applicationRelease = applicationStorageManager.updateReleaseArtifacts(applicationRelease, appType,
binaryFile.getDataHandler().getInputStream());
//todo
applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK)
.entity("Successfully uploaded artifacts for the application " + applicationUuuid).build();
@ -338,11 +346,10 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
applicationRelease = applicationStorageManager
.updateImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, attachments);
//todo
applicationRelease = applicationManager.updateRelease(applicationId, applicationRelease);
return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (NotFoundException e) {
return Response.status(Response.Status.NOT_FOUND).build();
} catch (ApplicationManagementException e) {
log.error("Error while updating the application release of the application with UUID " + applicationUUID);
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);

Loading…
Cancel
Save