Improve APPM app saving functionality

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent 128c226cd3
commit d9a04e099e

@ -28,65 +28,88 @@ import java.io.InputStream;
import java.util.List; import java.util.List;
/** /**
* This manages all the storage related requirements of ApplicationDTO. * This manages all the storage related requirements of Application.
*/ */
public interface ApplicationStorageManager { public interface ApplicationStorageManager {
/** /**
* To upload image artifacts related with an ApplicationDTO. * To upload image artifacts related with an Application.
* *
* @param applicationRelease ApplicationReleaseDTO Object * @param applicationRelease Application Release Object
* @param iconFile Icon File input stream * @param iconFile InputStream of the icon file.
* @param bannerFile Banner File input stream * @param bannerFile InputStream of the banner file.
* @throws ResourceManagementException Resource Management Exception. * @return {@link ApplicationReleaseDTO}
* @throws ResourceManagementException if it finds an empty screenshot array or IOException throws while handling
* input streams.
*/ */
ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease, ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationRelease, InputStream iconFile,
InputStream iconFile, InputStream bannerFile, List<InputStream> screenshots) throws ResourceManagementException; InputStream bannerFile, List<InputStream> screenshots, int tenantId) throws ResourceManagementException;
/**
* To get App Installer data such as version, package name etc.
*
* @param binaryFile Binary file of the application.
* @param deviceType Compatible device type of the application.
* @return {@link ApplicationInstaller}
* @throws ApplicationStorageManagementException if device type is incorrect or error occurred while parsing binary
* data.
*/
ApplicationInstaller getAppInstallerData(InputStream binaryFile, String deviceType) ApplicationInstaller getAppInstallerData(InputStream binaryFile, String deviceType)
throws ApplicationStorageManagementException; throws ApplicationStorageManagementException;
/** /**
* To upload release artifacts for an Application. * To upload release artifacts for an Application.
* *
* @param applicationRelease ApplicationDTO Release Object. * @param applicationRelease Application Release Object.
* @param deviceType Compatible device type of the application. * @param deviceType Compatible device type of the application.
* @param binaryFile Binary File for the release. * @param binaryFile Binary File for the release.
* @param tenantId Tenant Id
* @throws ResourceManagementException if IO Exception occured while saving the release artifacts in the server. * @throws ResourceManagementException if IO Exception occured while saving the release artifacts in the server.
*/ */
void uploadReleaseArtifact(ApplicationReleaseDTO applicationRelease, String deviceType, InputStream binaryFile) void uploadReleaseArtifact(ApplicationReleaseDTO applicationRelease, String deviceType, InputStream binaryFile,
throws ResourceManagementException; int tenantId) throws ResourceManagementException;
/** /**
* To upload release artifacts for an ApplicationDTO. * To upload release artifacts for an Application.
* *
* @param applicationReleaseDTO applicationRelease ApplicationDTO release of a particular application. * @param applicationReleaseDTO application Release of a particular application.
* @param deletingAppHashValue Hash value of the deleting application release. * @param deletingAppHashValue Hash value of the deleting application release.
* @throws ApplicationStorageManagementException Resource Management Exception. * @param tenantId Tenant Id
* @throws ApplicationStorageManagementException if IO Exception occurs while copying image artifacts and deleting
* application release installer file.
*/ */
void copyImageArtifactsAndDeleteInstaller(String deletingAppHashValue, void copyImageArtifactsAndDeleteInstaller(String deletingAppHashValue,
ApplicationReleaseDTO applicationReleaseDTO) throws ApplicationStorageManagementException; ApplicationReleaseDTO applicationReleaseDTO, int tenantId) throws ApplicationStorageManagementException;
/** /**
* To delete the artifacts related with particular ApplicationDTO Release. * To delete the artifacts related with particular Application Release.
* *
* @throws ApplicationStorageManagementException Not Found Exception. * @param appReleaseHashVal Hash value of the application release.
* @param folderName Folder name of the application stored.
* @param fileName Name of the application release artifact.
* @throws ApplicationStorageManagementException if artifact doesn't exist.
*/ */
void deleteAppReleaseArtifact(String appReleaseHashVal, String folderName, String fileName) throws ApplicationStorageManagementException; void deleteAppReleaseArtifact(String appReleaseHashVal, String folderName, String fileName, int tenantId)
throws ApplicationStorageManagementException;
/** /**
* To delete all release artifacts related with particular ApplicationDTO Release. * To delete all release artifacts related with particular Application Release.
* *
* @param directoryPaths Hash values of the ApplicationDTO. * @param directoryPaths Hash values of the Application.
* @throws ApplicationStorageManagementException ApplicationDTO Storage Management Exception * @param tenantId Tenant Id
* @throws ApplicationStorageManagementException if artifact doesn't exist or IO exception occurred while deleting
* application artifact.
*/ */
void deleteAllApplicationReleaseArtifacts(List<String> directoryPaths) throws ApplicationStorageManagementException; void deleteAllApplicationReleaseArtifacts(List<String> directoryPaths, int tenantId)
throws ApplicationStorageManagementException;
/*** /**
* Get the InputStream of the file which is located in filePath * Get the InputStream of the file which is located in filePath
*
* @param hashVal Hash Value of the application release. * @param hashVal Hash Value of the application release.
* @return {@link InputStream} * @return {@link InputStream}
* @throws ApplicationStorageManagementException throws if an error occurs when accessing the file. * @throws ApplicationStorageManagementException throws if an error occurs when accessing the file.
*/ */
InputStream getFileStream(String hashVal, String folderName, String fileName) throws ApplicationStorageManagementException; InputStream getFileStream(String hashVal, String folderName, String fileName, int tenantId)
throws ApplicationStorageManagementException;
} }

@ -139,14 +139,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.debug("Ent. Application create request is received. Application name: " + applicationWrapper.getName() log.debug("Ent. Application create request is received. Application name: " + applicationWrapper.getName()
+ " Device type: " + applicationWrapper.getDeviceType()); + " Device type: " + applicationWrapper.getDeviceType());
} }
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper); ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
//uploading application artifacts //uploading application artifacts
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts( ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
applicationDTO.getApplicationReleaseDTOs().get(0), applicationArtifact, applicationDTO.getApplicationReleaseDTOs().get(0), applicationArtifact,
applicationWrapper.getDeviceType(), false); applicationWrapper.getDeviceType(), tenantId, false);
applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
return addAppDataIntoDB(applicationDTO); return addAppDataIntoDB(applicationDTO, tenantId);
} }
@Override @Override
@ -156,6 +157,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.debug("Web clip create request is received. App name: " + webAppWrapper.getName() + " Device type: " log.debug("Web clip create request is received. App name: " + webAppWrapper.getName() + " Device type: "
+ Constants.ANY); + Constants.ANY);
} }
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper); ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper);
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
applicationReleaseDTO.setUuid(UUID.randomUUID().toString()); applicationReleaseDTO.setUuid(UUID.randomUUID().toString());
@ -163,14 +165,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
//uploading application artifacts //uploading application artifacts
try { try {
applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(addImageArtifacts(applicationReleaseDTO, applicationArtifact)); applicationDTO.getApplicationReleaseDTOs()
.add(addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId));
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
String msg = "Error Occured when uploading artifacts of the web clip: " + webAppWrapper.getName(); String msg = "Error Occured when uploading artifacts of the web clip: " + webAppWrapper.getName();
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
//insert application data into database //insert application data into database
return addAppDataIntoDB(applicationDTO); return addAppDataIntoDB(applicationDTO, tenantId);
} }
@Override @Override
@ -184,7 +187,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
String publicAppStorePath = ""; String publicAppStorePath = "";
if (DeviceTypes.ANDROID.toString().toLowerCase().equals(publicAppWrapper.getDeviceType())) { if (DeviceTypes.ANDROID.toString().equalsIgnoreCase(publicAppWrapper.getDeviceType())) {
publicAppStorePath = Constants.GOOGLE_PLAY_STORE_URL; publicAppStorePath = Constants.GOOGLE_PLAY_STORE_URL;
} else if (DeviceTypes.IOS.toString().equals(publicAppWrapper.getDeviceType())) { } else if (DeviceTypes.IOS.toString().equals(publicAppWrapper.getDeviceType())) {
publicAppStorePath = Constants.APPLE_STORE_URL; publicAppStorePath = Constants.APPLE_STORE_URL;
@ -210,13 +213,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
if (exitingRelease != null && exitingRelease.size() > 0) { if (exitingRelease != null && !exitingRelease.isEmpty()) {
applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().clear();
applicationReleaseDTO.setUuid(exitingRelease.get(0).getUuid()); applicationReleaseDTO.setUuid(exitingRelease.get(0).getUuid());
applicationReleaseDTO.setCurrentState(exitingRelease.get(0).getCurrentState()); applicationReleaseDTO.setCurrentState(exitingRelease.get(0).getCurrentState());
try { try {
applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact); applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId);
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId); applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId);
@ -237,7 +240,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} else { } else {
//uploading application artifacts //uploading application artifacts
try { try {
applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact); applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId);
applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
@ -246,7 +249,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
//insert application data into database //insert application data into database
return addAppDataIntoDB(applicationDTO); return addAppDataIntoDB(applicationDTO, tenantId);
} }
} }
@ -290,16 +293,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName()); applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationStorageManager.uploadReleaseArtifact(applicationReleaseDTO, customAppWrapper.getDeviceType(), applicationStorageManager.uploadReleaseArtifact(applicationReleaseDTO, customAppWrapper.getDeviceType(),
binaryDuplicate); binaryDuplicate, tenantId);
} catch (IOException e) { } catch (IOException e) {
String msg = "Error occurred when uploading release artifact into the server."; String msg = "Error occurred when uploading release artifact into the server.";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact); applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId);
applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().clear();
applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO);
return addAppDataIntoDB(applicationDTO); return addAppDataIntoDB(applicationDTO, tenantId);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application artifact into the server. Application name: " String msg = "Error occurred while uploading application artifact into the server. Application name: "
+ customAppWrapper.getName() + " Device type: " + customAppWrapper.getDeviceType(); + customAppWrapper.getName() + " Device type: " + customAppWrapper.getDeviceType();
@ -313,10 +316,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
private void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException { private void deleteApplicationArtifacts(List<String> directoryPaths, int tenantId) throws ApplicationManagementException {
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
try { try {
applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths); applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths, tenantId);
} catch (ApplicationStorageManagementException e) { } catch (ApplicationStorageManagementException e) {
String msg = "Error occurred when deleting application artifacts. directory paths: ." + directoryPaths String msg = "Error occurred when deleting application artifacts. directory paths: ." + directoryPaths
.toString(); .toString();
@ -374,7 +377,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationStorageManager applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate); .uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate, tenantId);
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying app release data."; String msg = "Error occurred when getting database connection for verifying app release data.";
@ -455,9 +458,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.setAppHashValue(md5OfApp); applicationReleaseDTO.setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationStorageManager applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate); .uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate,
tenantId);
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue, applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
applicationReleaseDTO); applicationReleaseDTO, tenantId);
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying application " String msg = "Error occurred when getting database connection for verifying application "
@ -486,7 +490,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
private ApplicationReleaseDTO addImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, private ApplicationReleaseDTO addImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO,
ApplicationArtifact applicationArtifact) throws ResourceManagementException { ApplicationArtifact applicationArtifact, int tenantId) throws ResourceManagementException {
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
applicationReleaseDTO.setIconName(applicationArtifact.getIconName()); applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
@ -510,24 +514,24 @@ public class ApplicationManagerImpl implements ApplicationManager {
// Upload images // Upload images
applicationReleaseDTO = applicationStorageManager applicationReleaseDTO = applicationStorageManager
.uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(), .uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(),
applicationArtifact.getBannerStream(), new ArrayList<>(screenshots.values())); applicationArtifact.getBannerStream(), new ArrayList<>(screenshots.values()), tenantId);
return applicationReleaseDTO; return applicationReleaseDTO;
} }
private ApplicationReleaseDTO updateImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, private ApplicationReleaseDTO updateImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO,
ApplicationArtifact applicationArtifact) throws ResourceManagementException{ ApplicationArtifact applicationArtifact, int tenantId) throws ResourceManagementException{
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
if (!StringUtils.isEmpty(applicationArtifact.getIconName())) { if (!StringUtils.isEmpty(applicationArtifact.getIconName())) {
applicationStorageManager applicationStorageManager
.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), Constants.ICON_ARTIFACT, .deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), Constants.ICON_ARTIFACT,
applicationReleaseDTO.getIconName()); applicationReleaseDTO.getIconName(), tenantId);
applicationReleaseDTO.setIconName(applicationArtifact.getIconName()); applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
} }
if (!StringUtils.isEmpty(applicationArtifact.getBannerName())){ if (!StringUtils.isEmpty(applicationArtifact.getBannerName())){
applicationStorageManager applicationStorageManager
.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), Constants.BANNER_ARTIFACT, .deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), Constants.BANNER_ARTIFACT,
applicationReleaseDTO.getBannerName()); applicationReleaseDTO.getBannerName(), tenantId);
applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName()); applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName());
} }
@ -544,17 +548,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (counter == 1) { if (counter == 1) {
applicationStorageManager applicationStorageManager
.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), folderPath, .deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), folderPath,
applicationReleaseDTO.getScreenshotName1()); applicationReleaseDTO.getScreenshotName1(), tenantId);
applicationReleaseDTO.setScreenshotName1(scName); applicationReleaseDTO.setScreenshotName1(scName);
} else if (counter == 2) { } else if (counter == 2) {
applicationStorageManager applicationStorageManager
.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), folderPath, .deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), folderPath,
applicationReleaseDTO.getScreenshotName2()); applicationReleaseDTO.getScreenshotName2(), tenantId);
applicationReleaseDTO.setScreenshotName2(scName); applicationReleaseDTO.setScreenshotName2(scName);
} else if (counter == 3) { } else if (counter == 3) {
applicationStorageManager applicationStorageManager
.deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), folderPath, .deleteAppReleaseArtifact(applicationReleaseDTO.getAppHashValue(), folderPath,
applicationReleaseDTO.getScreenshotName3()); applicationReleaseDTO.getScreenshotName3(), tenantId);
applicationReleaseDTO.setScreenshotName3(scName); applicationReleaseDTO.setScreenshotName3(scName);
} }
counter++; counter++;
@ -564,7 +568,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
// Upload images // Upload images
applicationReleaseDTO = applicationStorageManager applicationReleaseDTO = applicationStorageManager
.uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(), .uploadImageArtifacts(applicationReleaseDTO, applicationArtifact.getIconStream(),
applicationArtifact.getBannerStream(), screenshotStreams); applicationArtifact.getBannerStream(), screenshotStreams, tenantId);
return applicationReleaseDTO; return applicationReleaseDTO;
} }
@ -694,11 +698,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
* required to do the validation of request and check the existence of application releaseDTO. * required to do the validation of request and check the existence of application releaseDTO.
* *
* @param applicationDTO Application DTO object. * @param applicationDTO Application DTO object.
* @param tenantId Tenant Id
* @return {@link Application} * @return {@link Application}
* @throws ApplicationManagementException which throws if error occurs while during application management. * @throws ApplicationManagementException which throws if error occurs while during application management.
*/ */
private Application addAppDataIntoDB(ApplicationDTO applicationDTO) throws ApplicationManagementException { private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
List<String> unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); List<String> unrestrictedRoles = applicationDTO.getUnrestrictedRoles();
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
@ -712,7 +716,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (appId == -1) { if (appId == -1) {
log.error("Application data storing is Failed."); log.error("Application data storing is Failed.");
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()),
tenantId);
return null; return null;
} else { } else {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -783,7 +788,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg, e); log.error(msg, e);
try { try {
applicationStorageManager.deleteAllApplicationReleaseArtifacts( applicationStorageManager.deleteAllApplicationReleaseArtifacts(
Collections.singletonList(applicationReleaseDTO.getAppHashValue())); Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
} catch (ApplicationStorageManagementException ex) { } catch (ApplicationStorageManagementException ex) {
String errorLog = String errorLog =
"Error occurred when deleting application artifacts. Application artifacts are tried to " "Error occurred when deleting application artifacts. Application artifacts are tried to "
@ -797,7 +802,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
String msg = "Error occurred while adding application or application release. application name: " String msg = "Error occurred while adding application or application release. application name: "
+ applicationDTO.getName() + "."; + applicationDTO.getName() + ".";
log.error(msg, e); log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (LifecycleManagementException e) { } catch (LifecycleManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -805,7 +810,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
"Error occurred when getting initial lifecycle state. application name: " + applicationDTO.getName() "Error occurred when getting initial lifecycle state. application name: " + applicationDTO.getName()
+ "."; + ".";
log.error(msg, e); log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred while getting database connection."; String msg = "Error occurred while getting database connection.";
@ -816,7 +821,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
String msg = "Error occurred while adding unrestricted roles. application name: " + applicationDTO.getName() String msg = "Error occurred while adding unrestricted roles. application name: " + applicationDTO.getName()
+ "."; + ".";
log.error(msg, e); log.error(msg, e);
deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
String msg = "Error occurred while disabling AutoCommit."; String msg = "Error occurred while disabling AutoCommit.";
@ -853,7 +858,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts( ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper), applicationArtifact, deviceType.getName(), APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper), applicationArtifact, deviceType.getName(),
true); tenantId, true);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
String initialstate = lifecycleStateManager.getInitialState(); String initialstate = lifecycleStateManager.getInitialState();
@ -918,12 +923,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
private ApplicationReleaseDTO uploadEntAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, private ApplicationReleaseDTO uploadEntAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO,
ApplicationArtifact applicationArtifact, String deviceTypeName, boolean isNewRelease) ApplicationArtifact applicationArtifact, String deviceTypeName, int tenantId, boolean isNewRelease)
throws ApplicationManagementException { throws ApplicationManagementException {
try { try {
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(deviceTypeName, releaseDTO, ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(deviceTypeName, releaseDTO,
applicationArtifact, isNewRelease); applicationArtifact, isNewRelease);
return addImageArtifacts(applicationReleaseDTO, applicationArtifact); return addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
String msg = "Error occurred while uploading application release artifacts."; String msg = "Error occurred while uploading application release artifacts.";
log.error(msg, e); log.error(msg, e);
@ -1243,7 +1248,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
deletingAppHashVals.add(applicationReleaseDTO.getAppHashValue()); deletingAppHashVals.add(applicationReleaseDTO.getAppHashValue());
deletingAppReleaseIds.add(applicationReleaseDTO.getId()); deletingAppReleaseIds.add(applicationReleaseDTO.getId());
} }
applicationStorageManager.deleteAllApplicationReleaseArtifacts(deletingAppHashVals); applicationStorageManager.deleteAllApplicationReleaseArtifacts(deletingAppHashVals, tenantId);
this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds); this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds);
this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds); this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds);
this.applicationDAO.deleteApplicationTags(applicationId, tenantId); this.applicationDAO.deleteApplicationTags(applicationId, tenantId);
@ -1355,7 +1360,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ForbiddenException(msg); throw new ForbiddenException(msg);
} }
applicationStorageManager.deleteAllApplicationReleaseArtifacts( applicationStorageManager.deleteAllApplicationReleaseArtifacts(
Collections.singletonList(applicationReleaseDTO.getAppHashValue())); Collections.singletonList(applicationReleaseDTO.getAppHashValue()), tenantId);
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId()); lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId()); applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId());
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
@ -1412,7 +1417,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ " into updatable state and retry the operation."); + " into updatable state and retry the operation.");
} }
applicationReleaseDTO = this.applicationReleaseDAO applicationReleaseDTO = this.applicationReleaseDAO
.updateRelease(updateImageArtifacts(applicationReleaseDTO, applicationArtifact), tenantId); .updateRelease(updateImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId), tenantId);
if (applicationReleaseDTO == null) { if (applicationReleaseDTO == null) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Application release updating count is 0 for application release UUID: " + uuid; String msg = "Application release updating count is 0 for application release UUID: " + uuid;
@ -2396,7 +2401,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
.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, tenantId));
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) { if (!updateStatus) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -2463,7 +2468,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.get().setMetaData(publicAppReleaseWrapper.getMetaData()); applicationReleaseDTO.get().setMetaData(publicAppReleaseWrapper.getMetaData());
} }
applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact)); applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact, tenantId));
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) { if (!updateStatus) {
@ -2528,7 +2533,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleaseDTO.get().setMetaData(webAppReleaseWrapper.getMetaData()); applicationReleaseDTO.get().setMetaData(webAppReleaseWrapper.getMetaData());
} }
applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact)); applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact, tenantId));
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) { if (!updateStatus) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -2625,9 +2630,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) { try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationStorageManager applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO.get(), deviceTypeObj.getName(), .uploadReleaseArtifact(applicationReleaseDTO.get(), deviceTypeObj.getName(),
binaryDuplicate); binaryDuplicate, tenantId);
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue, applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
applicationReleaseDTO.get()); applicationReleaseDTO.get(), tenantId);
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying application" String msg = "Error occurred when getting database connection for verifying application"
@ -2652,7 +2657,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new ApplicationStorageManagementException(msg, e); throw new ApplicationStorageManagementException(msg, e);
} }
} }
applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact)); applicationReleaseDTO.set(updateImageArtifacts(applicationReleaseDTO.get(), applicationArtifact, tenantId));
boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null; boolean updateStatus = applicationReleaseDAO.updateRelease(applicationReleaseDTO.get(), tenantId) != null;
if (!updateStatus) { if (!updateStatus) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();

@ -59,14 +59,15 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override @Override
public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, public ApplicationReleaseDTO uploadImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO,
InputStream iconFileStream, InputStream bannerFileStream, List<InputStream> screenShotStreams) InputStream iconFileStream, InputStream bannerFileStream, List<InputStream> screenShotStreams, int tenantId)
throws ResourceManagementException { throws ResourceManagementException {
String iconStoredLocation; String iconStoredLocation;
String bannerStoredLocation; String bannerStoredLocation;
String scStoredLocation = null; String scStoredLocation = null;
try { try {
String artifactStoringBaseDirPath = storagePath + applicationReleaseDTO.getAppHashValue(); String artifactStoringBaseDirPath =
storagePath + tenantId + File.separator + applicationReleaseDTO.getAppHashValue();
StorageManagementUtil.createArtifactDirectory(artifactStoringBaseDirPath); StorageManagementUtil.createArtifactDirectory(artifactStoringBaseDirPath);
if (iconFileStream != null) { if (iconFileStream != null) {
@ -144,11 +145,12 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override @Override
public void uploadReleaseArtifact(ApplicationReleaseDTO applicationReleaseDTO, public void uploadReleaseArtifact(ApplicationReleaseDTO applicationReleaseDTO,
String deviceType, InputStream binaryFile) throws ResourceManagementException { String deviceType, InputStream binaryFile, int tenantId) throws ResourceManagementException {
try { try {
byte [] content = IOUtils.toByteArray(binaryFile); byte [] content = IOUtils.toByteArray(binaryFile);
String artifactDirectoryPath = String artifactDirectoryPath =
storagePath + applicationReleaseDTO.getAppHashValue() + File.separator + Constants.APP_ARTIFACT; storagePath + tenantId + File.separator + applicationReleaseDTO.getAppHashValue() + File.separator
+ Constants.APP_ARTIFACT;
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath); StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
String artifactPath = artifactDirectoryPath + File.separator + applicationReleaseDTO.getInstallerName(); String artifactPath = artifactDirectoryPath + File.separator + applicationReleaseDTO.getInstallerName();
saveFile(new ByteArrayInputStream(content), artifactPath); saveFile(new ByteArrayInputStream(content), artifactPath);
@ -162,7 +164,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override @Override
public void copyImageArtifactsAndDeleteInstaller(String deletingAppHashValue, public void copyImageArtifactsAndDeleteInstaller(String deletingAppHashValue,
ApplicationReleaseDTO applicationReleaseDTO) throws ApplicationStorageManagementException { ApplicationReleaseDTO applicationReleaseDTO, int tenantId) throws ApplicationStorageManagementException {
try { try {
String appHashValue = applicationReleaseDTO.getAppHashValue(); String appHashValue = applicationReleaseDTO.getAppHashValue();
@ -171,42 +173,41 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
String screenshot1 = applicationReleaseDTO.getScreenshotName1(); String screenshot1 = applicationReleaseDTO.getScreenshotName1();
String screenshot2 = applicationReleaseDTO.getScreenshotName2(); String screenshot2 = applicationReleaseDTO.getScreenshotName2();
String screenshot3 = applicationReleaseDTO.getScreenshotName3(); String screenshot3 = applicationReleaseDTO.getScreenshotName3();
String basePath = storagePath + tenantId + File.separator;
if (bannerName != null) { if (bannerName != null) {
StorageManagementUtil StorageManagementUtil.copy(basePath + deletingAppHashValue + File.separator + Constants.BANNER_ARTIFACT
.copy(storagePath + deletingAppHashValue + File.separator + Constants.BANNER_ARTIFACT + File.separator + bannerName,
+ File.separator + bannerName, basePath + appHashValue + File.separator + Constants.BANNER_ARTIFACT + File.separator
storagePath + appHashValue + File.separator + Constants.BANNER_ARTIFACT + File.separator + bannerName);
+ bannerName);
} }
if (iconName != null) { if (iconName != null) {
StorageManagementUtil.copy(storagePath + deletingAppHashValue + File.separator + Constants.ICON_ARTIFACT StorageManagementUtil.copy(basePath + deletingAppHashValue + File.separator + Constants.ICON_ARTIFACT
+ File.separator + iconName, + File.separator + iconName,
storagePath + appHashValue + File.separator + Constants.ICON_ARTIFACT + File.separator basePath + appHashValue + File.separator + Constants.ICON_ARTIFACT + File.separator + iconName);
+ iconName);
} }
if (screenshot1 != null) { if (screenshot1 != null) {
StorageManagementUtil StorageManagementUtil
.copy(storagePath + deletingAppHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 1 .copy(basePath + deletingAppHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 1
+ File.separator + screenshot1, + File.separator + screenshot1,
storagePath + appHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 1 basePath + appHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 1
+ File.separator + screenshot1); + File.separator + screenshot1);
} }
if (screenshot2 != null) { if (screenshot2 != null) {
StorageManagementUtil StorageManagementUtil
.copy(storagePath + deletingAppHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 2 .copy(basePath + deletingAppHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 2
+ File.separator + screenshot2, + File.separator + screenshot2,
storagePath + appHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 2 basePath + appHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 2
+ File.separator + screenshot2); + File.separator + screenshot2);
} }
if (screenshot3 != null) { if (screenshot3 != null) {
StorageManagementUtil StorageManagementUtil
.copy(storagePath + deletingAppHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 3 .copy(basePath + deletingAppHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 3
+ File.separator + screenshot3, + File.separator + screenshot3,
storagePath + appHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 3 basePath + appHashValue + File.separator + Constants.SCREENSHOT_ARTIFACT + 3
+ File.separator + screenshot3); + File.separator + screenshot3);
} }
deleteAppReleaseArtifact( storagePath + deletingAppHashValue); deleteAppReleaseArtifact( basePath + deletingAppHashValue);
} catch (IOException e) { } catch (IOException e) {
String msg = "Application installer updating is failed because of I/O issue"; String msg = "Application installer updating is failed because of I/O issue";
log.error(msg, e); log.error(msg, e);
@ -217,24 +218,28 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
@Override @Override
public void deleteAppReleaseArtifact(String appReleaseHashVal, String folderName, String fileName) public void deleteAppReleaseArtifact(String appReleaseHashVal, String folderName, String fileName, int tenantId)
throws ApplicationStorageManagementException { throws ApplicationStorageManagementException {
String artifactPath = storagePath + appReleaseHashVal + File.separator + folderName + File.separator + fileName; String artifactPath = storagePath + tenantId + File.separator + appReleaseHashVal + File.separator + folderName
+ File.separator + fileName;
deleteAppReleaseArtifact(artifactPath); deleteAppReleaseArtifact(artifactPath);
} }
@Override @Override
public void deleteAllApplicationReleaseArtifacts(List<String> directoryPaths) public void deleteAllApplicationReleaseArtifacts(List<String> directoryPaths, int tenantId)
throws ApplicationStorageManagementException { throws ApplicationStorageManagementException {
for (String directoryBasePath : directoryPaths) { String basePath = storagePath + tenantId + File.separator;
deleteAppReleaseArtifact(storagePath + directoryBasePath); for (String directoryPath : directoryPaths) {
deleteAppReleaseArtifact(basePath + directoryPath);
} }
} }
@Override @Override
public InputStream getFileStream(String hashVal, String folderName, String fileName) public InputStream getFileStream(String hashVal, String folderName, String fileName, int tenantId)
throws ApplicationStorageManagementException { throws ApplicationStorageManagementException {
String filePath = storagePath + hashVal + File.separator + folderName + File.separator + fileName; String filePath =
storagePath + tenantId + File.separator + hashVal + File.separator + folderName + File.separator
+ fileName;
try { try {
return StorageManagementUtil.getInputStream(filePath); return StorageManagementUtil.getInputStream(filePath);
} catch (IOException e) { } catch (IOException e) {

@ -74,7 +74,7 @@ public class AppmDataHandlerImpl implements AppmDataHandler {
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
InputStream inputStream = applicationStorageManager InputStream inputStream = applicationStorageManager
.getFileStream(appReleaseHashValue, folderName, artifactName); .getFileStream(appReleaseHashValue, folderName, artifactName, tenantId);
if (inputStream == null) { if (inputStream == null) {
String msg = "Couldn't file the file in the file system."; String msg = "Couldn't file the file in the file system.";
log.error(msg); log.error(msg);

@ -840,7 +840,7 @@ public interface ApplicationManagementPublisherAPI {
@Multipart(value = "screenshot3") Attachment screenshot3); @Multipart(value = "screenshot3") Attachment screenshot3);
@PUT @PUT
@Path("/pub-app-release/{uuid}") @Path("/public-app-release/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation( @ApiOperation(

Loading…
Cancel
Save