|
|
@ -33,6 +33,7 @@ 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.ApplicationStorageManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
|
|
|
|
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;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
|
|
@ -47,6 +48,7 @@ import java.io.FileInputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -104,9 +106,10 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
saveFile(bannerFileStream, bannerStoredLocation);
|
|
|
|
saveFile(bannerFileStream, bannerStoredLocation);
|
|
|
|
applicationRelease.setBannerLoc(bannerStoredLocation);
|
|
|
|
applicationRelease.setBannerLoc(bannerStoredLocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (screenShotStreams.size() > screenShotMaxCount) {
|
|
|
|
if (!screenShotStreams.isEmpty()) {
|
|
|
|
throw new ApplicationStorageManagementException("Maximum limit for the screen-shot exceeds");
|
|
|
|
if (screenShotStreams.size() > screenShotMaxCount) {
|
|
|
|
} else if (!screenShotStreams.isEmpty() && screenShotStreams.size() <= screenShotMaxCount) {
|
|
|
|
throw new ApplicationStorageManagementException("Maximum limit for the screen-shot exceeds");
|
|
|
|
|
|
|
|
}
|
|
|
|
int count = 1;
|
|
|
|
int count = 1;
|
|
|
|
for (InputStream screenshotStream : screenShotStreams) {
|
|
|
|
for (InputStream screenshotStream : screenShotStreams) {
|
|
|
|
scStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[2] + count;
|
|
|
|
scStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[2] + count;
|
|
|
@ -123,7 +126,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
count++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return applicationRelease;
|
|
|
|
return applicationRelease;
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ApplicationStorageManagementException("IO Exception while saving the screens hots for " +
|
|
|
|
throw new ApplicationStorageManagementException("IO Exception while saving the screens hots for " +
|
|
|
@ -149,9 +151,10 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
if (bannerFileStream != null) {
|
|
|
|
if (bannerFileStream != null) {
|
|
|
|
deleteApplicationReleaseArtifacts(applicationRelease.getBannerLoc());
|
|
|
|
deleteApplicationReleaseArtifacts(applicationRelease.getBannerLoc());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (screenShotStreams.size() > screenShotMaxCount) {
|
|
|
|
if (!screenShotStreams.isEmpty()) {
|
|
|
|
throw new ApplicationStorageManagementException("Maximum limit for the screen-shot exceeds");
|
|
|
|
if (screenShotStreams.size() > screenShotMaxCount) {
|
|
|
|
} else if (!screenShotStreams.isEmpty() && screenShotStreams.size() <= screenShotMaxCount) {
|
|
|
|
throw new ApplicationStorageManagementException("Maximum limit for the screen-shot exceeds");
|
|
|
|
|
|
|
|
}
|
|
|
|
int count = 1;
|
|
|
|
int count = 1;
|
|
|
|
while (count < screenShotStreams.size()) {
|
|
|
|
while (count < screenShotStreams.size()) {
|
|
|
|
if (count == 1) {
|
|
|
|
if (count == 1) {
|
|
|
@ -166,8 +169,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
count++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applicationRelease = uploadImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, screenShotStreams);
|
|
|
|
return uploadImageArtifacts(applicationRelease, iconFileStream, bannerFileStream, screenShotStreams);
|
|
|
|
return applicationRelease;
|
|
|
|
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
throw new ApplicationStorageManagementException("Application Storage exception while trying to"
|
|
|
|
throw new ApplicationStorageManagementException("Application Storage exception while trying to"
|
|
|
@ -177,15 +179,15 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationRelease uploadReleaseArtifact(ApplicationRelease applicationRelease, String appType, InputStream binaryFile)
|
|
|
|
public ApplicationRelease uploadReleaseArtifact(ApplicationRelease applicationRelease, String appType,
|
|
|
|
throws ResourceManagementException {
|
|
|
|
InputStream binaryFile) throws ResourceManagementException, RequestValidatingException {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (ApplicationType.WEB_CLIP.toString().equals(appType)) {
|
|
|
|
if (ApplicationType.WEB_CLIP.toString().equals(appType)) {
|
|
|
|
applicationRelease.setVersion(Constants.DEFAULT_VERSION);
|
|
|
|
applicationRelease.setVersion(Constants.DEFAULT_VERSION);
|
|
|
|
UrlValidator urlValidator = new UrlValidator();
|
|
|
|
UrlValidator urlValidator = new UrlValidator();
|
|
|
|
if (applicationRelease.getUrl() == null || !urlValidator.isValid(applicationRelease.getUrl())) {
|
|
|
|
if (applicationRelease.getUrl() == null || !urlValidator.isValid(applicationRelease.getUrl())) {
|
|
|
|
throw new ApplicationStorageManagementException("Request payload doesn't contains Web Clip URL " +
|
|
|
|
throw new RequestValidatingException("Request payload doesn't contains Web Clip URL " +
|
|
|
|
"with application release object or Web " +
|
|
|
|
"with application release object or Web " +
|
|
|
|
"Clip URL is invalid");
|
|
|
|
"Clip URL is invalid");
|
|
|
|
//todo if we throw this we must send BAD REQUEST to end user
|
|
|
|
//todo if we throw this we must send BAD REQUEST to end user
|
|
|
@ -208,32 +210,25 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
if (ApplicationType.ANDROID.toString().equals(appType)) {
|
|
|
|
if (ApplicationType.ANDROID.toString().equals(appType)) {
|
|
|
|
String prefix = "stream2file";
|
|
|
|
String prefix = "stream2file";
|
|
|
|
String suffix = ".apk";
|
|
|
|
String suffix = ".apk";
|
|
|
|
Boolean isTempDelete;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File tempFile = File.createTempFile(prefix, suffix);
|
|
|
|
File tempFile = File.createTempFile(prefix, suffix);
|
|
|
|
FileOutputStream out = new FileOutputStream(tempFile);
|
|
|
|
FileOutputStream out = new FileOutputStream(tempFile);
|
|
|
|
IOUtils.copy(binaryFile, out);
|
|
|
|
IOUtils.copy(binaryFile, out);
|
|
|
|
ApkFile apkFile = new ApkFile(tempFile);
|
|
|
|
try (ApkFile apkFile = new ApkFile(tempFile)){
|
|
|
|
ApkMeta apkMeta = apkFile.getApkMeta();
|
|
|
|
ApkMeta apkMeta = apkFile.getApkMeta();
|
|
|
|
applicationRelease.setVersion(apkMeta.getVersionName());
|
|
|
|
applicationRelease.setVersion(apkMeta.getVersionName());
|
|
|
|
isTempDelete = tempFile.delete();
|
|
|
|
Files.delete(tempFile.toPath());
|
|
|
|
if (!isTempDelete) {
|
|
|
|
|
|
|
|
log.error("Temporary created APK file deletion failed");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else if (ApplicationType.IOS.toString().equals(appType)) {
|
|
|
|
} else if (ApplicationType.IOS.toString().equals(appType)) {
|
|
|
|
String prefix = "stream2file";
|
|
|
|
String prefix = "stream2file";
|
|
|
|
String suffix = ".ipa";
|
|
|
|
String suffix = ".ipa";
|
|
|
|
Boolean isTempDelete;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File tempFile = File.createTempFile(prefix, suffix);
|
|
|
|
File tempFile = File.createTempFile(prefix, suffix);
|
|
|
|
FileOutputStream out = new FileOutputStream(tempFile);
|
|
|
|
FileOutputStream out = new FileOutputStream(tempFile);
|
|
|
|
IOUtils.copy(binaryFile, out);
|
|
|
|
IOUtils.copy(binaryFile, out);
|
|
|
|
Map<String, String> plistInfo = getIPAInfo(tempFile);
|
|
|
|
Map<String, String> plistInfo = getIPAInfo(tempFile);
|
|
|
|
applicationRelease.setVersion(plistInfo.get("CFBundleVersion"));
|
|
|
|
applicationRelease.setVersion(plistInfo.get("CFBundleVersion"));
|
|
|
|
isTempDelete = tempFile.delete();
|
|
|
|
Files.delete(tempFile.toPath());
|
|
|
|
if (!isTempDelete) {
|
|
|
|
|
|
|
|
log.error("Temporary created ipa file deletion failed");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " +
|
|
|
|
throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " +
|
|
|
|
"application types " + applicationRelease.getUuid());
|
|
|
|
"application types " + applicationRelease.getUuid());
|
|
|
@ -262,7 +257,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationRelease updateReleaseArtifacts(ApplicationRelease applicationRelease, String appType,
|
|
|
|
public ApplicationRelease updateReleaseArtifacts(ApplicationRelease applicationRelease, String appType,
|
|
|
|
InputStream binaryFile) throws ApplicationStorageManagementException {
|
|
|
|
InputStream binaryFile) throws ApplicationStorageManagementException, RequestValidatingException {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
deleteApplicationReleaseArtifacts(applicationRelease.getAppStoredLoc());
|
|
|
|
deleteApplicationReleaseArtifacts(applicationRelease.getAppStoredLoc());
|
|
|
@ -284,15 +279,20 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
File artifact = new File(artifactPath);
|
|
|
|
File artifact = new File(artifactPath);
|
|
|
|
|
|
|
|
|
|
|
|
if (artifact.exists()) {
|
|
|
|
if (artifact.exists()) {
|
|
|
|
StorageManagementUtil.deleteDir(artifact);
|
|
|
|
try {
|
|
|
|
|
|
|
|
StorageManagementUtil.deleteDir(artifact);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
|
|
|
|
"Error occured while deleting application release artifacts", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new ApplicationStorageManagementException("Tried to delete application release, but it doesn't exist " +
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
"in the system");
|
|
|
|
"Tried to delete application release, but it doesn't exist in the system");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public void deleteAllApplicationReleaseArtifacts(List<String> directoryPaths)
|
|
|
|
public void deleteAllApplicationReleaseArtifacts(List<String> directoryPaths) throws ApplicationStorageManagementException {
|
|
|
|
throws ApplicationStorageManagementException {
|
|
|
|
for (String directoryBasePath : directoryPaths) {
|
|
|
|
for (String directoryBasePath : directoryPaths) {
|
|
|
|
deleteApplicationReleaseArtifacts(directoryBasePath);
|
|
|
|
deleteApplicationReleaseArtifacts(directoryBasePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -346,6 +346,11 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
NSString parameter = (NSString) rootDict.objectForKey(Constants.CF_BUNDLE_VERSION);
|
|
|
|
NSString parameter = (NSString) rootDict.objectForKey(Constants.CF_BUNDLE_VERSION);
|
|
|
|
ipaInfo.put(Constants.CF_BUNDLE_VERSION, parameter.toString());
|
|
|
|
ipaInfo.put(Constants.CF_BUNDLE_VERSION, parameter.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ipaDirectory != null) {
|
|
|
|
|
|
|
|
// remove unzip folder
|
|
|
|
|
|
|
|
deleteDir(new File(ipaDirectory + File.separator + Constants.PAYLOAD));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
} catch (ParseException e) {
|
|
|
|
String msg = "Error occurred while parsing the plist data";
|
|
|
|
String msg = "Error occurred while parsing the plist data";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -361,11 +366,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
String msg = "Error occurred while unzipping the ipa file";
|
|
|
|
String msg = "Error occurred while unzipping the ipa file";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (ipaDirectory != null) {
|
|
|
|
|
|
|
|
// remove unzip folder
|
|
|
|
|
|
|
|
deleteDir(new File(ipaDirectory + File.separator + Constants.PAYLOAD));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ipaInfo;
|
|
|
|
return ipaInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -380,7 +380,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
private void unzip(String zipFilePath, String destDirectory)
|
|
|
|
private void unzip(String zipFilePath, String destDirectory)
|
|
|
|
throws IOException, ApplicationStorageManagementException {
|
|
|
|
throws IOException, ApplicationStorageManagementException {
|
|
|
|
File destDir = new File(destDirectory);
|
|
|
|
File destDir = new File(destDirectory);
|
|
|
|
Boolean isDirCreated;
|
|
|
|
boolean isDirCreated;
|
|
|
|
|
|
|
|
|
|
|
|
if (!destDir.exists()) {
|
|
|
|
if (!destDir.exists()) {
|
|
|
|
isDirCreated = destDir.mkdir();
|
|
|
|
isDirCreated = destDir.mkdir();
|
|
|
@ -389,33 +389,31 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
"retrieval");
|
|
|
|
"retrieval");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath))) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ZipEntry entry = zipIn.getNextEntry();
|
|
|
|
|
|
|
|
// iterates over entries in the zip file
|
|
|
|
|
|
|
|
while (entry != null) {
|
|
|
|
|
|
|
|
String filePath = destDirectory + File.separator + entry.getName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!entry.isDirectory()) {
|
|
|
|
|
|
|
|
// if the entry is a file, extracts it
|
|
|
|
|
|
|
|
extractFile(zipIn, filePath);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if the entry is a directory, make the directory
|
|
|
|
|
|
|
|
File dir = new File(filePath);
|
|
|
|
|
|
|
|
isDirCreated = dir.mkdir();
|
|
|
|
|
|
|
|
if (!isDirCreated) {
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
|
|
|
|
"Directory Creation Is Failed while iOS app vertion " + "retrieval");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
|
|
|
|
|
|
|
|
ZipEntry entry = zipIn.getNextEntry();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// iterates over entries in the zip file
|
|
|
|
|
|
|
|
while (entry != null) {
|
|
|
|
|
|
|
|
String filePath = destDirectory + File.separator + entry.getName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!entry.isDirectory()) {
|
|
|
|
|
|
|
|
// if the entry is a file, extracts it
|
|
|
|
|
|
|
|
extractFile(zipIn, filePath);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if the entry is a directory, make the directory
|
|
|
|
|
|
|
|
File dir = new File(filePath);
|
|
|
|
|
|
|
|
isDirCreated = dir.mkdir();
|
|
|
|
|
|
|
|
if (!isDirCreated) {
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
|
|
|
|
"Directory Creation Is Failed while iOS app vertion " +
|
|
|
|
|
|
|
|
"retrieval");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
zipIn.closeEntry();
|
|
|
|
|
|
|
|
entry = zipIn.getNextEntry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
zipIn.closeEntry();
|
|
|
|
|
|
|
|
entry = zipIn.getNextEntry();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zipIn.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -425,13 +423,12 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
* @param filePath file path
|
|
|
|
* @param filePath file path
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
|
|
|
|
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
|
|
|
|
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
|
|
|
|
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))) {
|
|
|
|
byte[] bytesIn = new byte[BUFFER_SIZE];
|
|
|
|
byte[] bytesIn = new byte[BUFFER_SIZE];
|
|
|
|
int read;
|
|
|
|
int read;
|
|
|
|
|
|
|
|
while ((read = zipIn.read(bytesIn)) != -1) {
|
|
|
|
while ((read = zipIn.read(bytesIn)) != -1) {
|
|
|
|
bos.write(bytesIn, 0, read);
|
|
|
|
bos.write(bytesIn, 0, read);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bos.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|