Change APPM update responses

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent d757f7dbb7
commit af75a20bdf

@ -66,12 +66,12 @@ public interface ApplicationManager {
/** /**
* Updates an already existing application. * Updates an already existing application.
* *
* @param applicationUpdateWrapper Application data that need to be updated.
* @param applicationId ID of the application * @param applicationId ID of the application
* @param applicationUpdateWrapper Application data that need to be updated.
* @return Updated Application * @return Updated Application
* @throws ApplicationManagementException ApplicationDTO Management Exception * @throws ApplicationManagementException ApplicationDTO Management Exception
*/ */
void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) Application updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper)
throws ApplicationManagementException; throws ApplicationManagementException;
/** /**
@ -194,13 +194,13 @@ public interface ApplicationManager {
* @param applicationArtifact {@link ApplicationArtifact} * @param applicationArtifact {@link ApplicationArtifact}
* @return If the application release is updated correctly True returns, otherwise retuen False * @return If the application release is updated correctly True returns, otherwise retuen False
*/ */
boolean updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, ApplicationRelease updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException; ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
boolean updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper, ApplicationRelease updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException; ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
boolean updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper, ApplicationRelease updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException; ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
/*** /***

@ -32,7 +32,6 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller;
import org.wso2.carbon.device.application.mgt.common.DeviceTypes; import org.wso2.carbon.device.application.mgt.common.DeviceTypes;
import org.wso2.carbon.device.application.mgt.common.LifecycleChanger; import org.wso2.carbon.device.application.mgt.common.LifecycleChanger;
import org.wso2.carbon.device.application.mgt.common.Pagination; import org.wso2.carbon.device.application.mgt.common.Pagination;
import org.wso2.carbon.device.application.mgt.common.config.MDMConfig;
import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration; import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
@ -1616,7 +1615,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) public Application updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1759,6 +1758,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return APIUtil.appDtoToAppResponse(applicationDTO);
} catch (UserStoreException e) { } catch (UserStoreException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while checking whether logged in user is ADMIN or not when updating " String msg = "Error occurred while checking whether logged in user is ADMIN or not when updating "
@ -2295,14 +2295,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public boolean updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, public ApplicationRelease updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId);
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>( AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
applicationDTO.getApplicationReleaseDTOs().get(0)); applicationDTO.getApplicationReleaseDTOs().get(0));
validateAppReleaseUpdating(applicationDTO, ApplicationType.ENTERPRISE.toString()); validateAppReleaseUpdating(applicationDTO, ApplicationType.ENTERPRISE.toString());
@ -2321,20 +2320,21 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.get().setMetaData(entAppReleaseWrapper.getMetaData()); applicationReleaseDTO.get().setMetaData(entAppReleaseWrapper.getMetaData());
} }
if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())&& applicationArtifact.getInstallerStream() != null){ if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())
&& applicationArtifact.getInstallerStream() != null) {
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
applicationReleaseDTO applicationReleaseDTO
.set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(), .set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(),
applicationArtifact)); applicationArtifact));
} }
applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact)); applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact));
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) { if (!updateStatus) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
return null;
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return updateStatus; return APIUtil.releaseDtoToRelease(applicationReleaseDTO.get());
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to update enterprise app release which " String msg = "Error occurred while getting the database connection to update enterprise app release which "
+ "has release UUID: " + releaseUuid; + "has release UUID: " + releaseUuid;
@ -2361,7 +2361,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public boolean updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper, public ApplicationRelease updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -2399,9 +2399,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) { if (!updateStatus) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
return null;
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return updateStatus; return APIUtil.releaseDtoToRelease(applicationReleaseDTO.get());
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to update public app release which " String msg = "Error occurred while getting the database connection to update public app release which "
+ "has release UUID: " + releaseUuid; + "has release UUID: " + releaseUuid;
@ -2428,7 +2429,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public boolean updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper, public ApplicationRelease updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -2462,9 +2463,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) { if (!updateStatus) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
return null;
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return updateStatus; return APIUtil.releaseDtoToRelease(applicationReleaseDTO.get());
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred while getting the database connection to update web app release which " String msg = "Error occurred while getting the database connection to update web app release which "
+ "has release UUID: " + releaseUuid; + "has release UUID: " + releaseUuid;

@ -391,9 +391,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Valid ApplicationUpdateWrapper applicationUpdateWrapper) { @Valid ApplicationUpdateWrapper applicationUpdateWrapper) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
applicationManager.updateApplication(applicationId, applicationUpdateWrapper); Application application = applicationManager.updateApplication(applicationId, applicationUpdateWrapper);
return Response.status(Response.Status.OK) return Response.status(Response.Status.OK).entity(application).build();
.entity("Application was updated successfully for ApplicationID: " + applicationId).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
log.error(e.getMessage()); log.error(e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build(); return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
@ -402,8 +401,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
+ "application"; + "application";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} } catch (ApplicationManagementException e) {
catch (ApplicationManagementException e) {
String msg = "Internal Error occurred while modifying the application."; String msg = "Internal Error occurred while modifying the application.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
@ -425,14 +423,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
if (!applicationManager.updateEntAppRelease(applicationUUID, entAppReleaseWrapper, ApplicationRelease applicationRelease = applicationManager
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) { .updateEntAppRelease(applicationUUID, entAppReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots));
if (applicationRelease == null) {
String msg ="Ent app release updating is failed. Please contact the administrator. Application release " String msg ="Ent app release updating is failed. Please contact the administrator. Application release "
+ "UUID: " + applicationUUID; + "UUID: " + applicationUUID;
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
return Response.status(Response.Status.OK).entity("Ent app release is successfully updated.").build(); return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = String msg =
"Invalid request to update ent app release for application release UUID " + applicationUUID; "Invalid request to update ent app release for application release UUID " + applicationUUID;
@ -469,14 +469,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
if (!applicationManager.updatePubAppRelease(applicationUUID, publicAppReleaseWrapper, ApplicationRelease applicationRelease = applicationManager
constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) { .updatePubAppRelease(applicationUUID, publicAppReleaseWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, screenshots));
if (applicationRelease == null) {
String msg ="Public app release updating is failed. Please contact the administrator. " String msg ="Public app release updating is failed. Please contact the administrator. "
+ "Application release UUID: " + applicationUUID + ", Supported device type:"; + "Application release UUID: " + applicationUUID + ", Supported device type:";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
return Response.status(Response.Status.OK).entity("Public app release is successfully updated.").build(); return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Invalid request to update public app release for application release UUID " + applicationUUID; String msg = "Invalid request to update public app release for application release UUID " + applicationUUID;
log.error(msg, e); log.error(msg, e);
@ -512,14 +514,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
if (!applicationManager.updateWebAppRelease(applicationUUID, webAppReleaseWrapper, ApplicationRelease applicationRelease = applicationManager
constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) { .updateWebAppRelease(applicationUUID, webAppReleaseWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, screenshots));
if (applicationRelease == null) {
String msg ="web app release updating is failed. Please contact the administrator. Application " String msg ="web app release updating is failed. Please contact the administrator. Application "
+ "release UUID: " + applicationUUID; + "release UUID: " + applicationUUID;
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
return Response.status(Response.Status.OK).entity("Web app release is successfully updated.").build(); return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Invalid request to update web app release for web app release UUID " + applicationUUID; String msg = "Invalid request to update web app release for web app release UUID " + applicationUUID;
log.error(msg, e); log.error(msg, e);

Loading…
Cancel
Save