Fix app hash value getting issue

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 6a52997a82
commit 7e4cc36977

@ -196,8 +196,9 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
String artifactDirectoryPath; String artifactDirectoryPath;
String md5OfApp; String md5OfApp;
String artifactPath; String artifactPath;
InputStream[] cloneInputStream = cloneInputStream(binaryFile); byte [] content = IOUtils.toByteArray(binaryFile);
md5OfApp = getMD5(binaryFile);
md5OfApp = getMD5(new ByteArrayInputStream(content));
if (md5OfApp == null) { if (md5OfApp == null) {
String msg = String msg =
"Error occurred while md5sum value retrieving process: application UUID " + applicationRelease "Error occurred while md5sum value retrieving process: application UUID " + applicationRelease
@ -208,7 +209,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
artifactDirectoryPath = storagePath + md5OfApp; artifactDirectoryPath = storagePath + md5OfApp;
if (DeviceTypes.ANDROID.toString().equalsIgnoreCase(deviceType)) { if (DeviceTypes.ANDROID.toString().equalsIgnoreCase(deviceType)) {
ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(cloneInputStream[2]); ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(new ByteArrayInputStream(content));
applicationRelease.setVersion(apkMeta.getVersionName()); applicationRelease.setVersion(apkMeta.getVersionName());
applicationRelease.setPackageName(apkMeta.getPackageName()); applicationRelease.setPackageName(apkMeta.getPackageName());
} else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) { } else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) {
@ -231,7 +232,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath); StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
artifactPath = artifactDirectoryPath + File.separator + applicationRelease.getInstallerName(); artifactPath = artifactDirectoryPath + File.separator + applicationRelease.getInstallerName();
saveFile(cloneInputStream[1], artifactPath); saveFile(new ByteArrayInputStream(content), artifactPath);
applicationRelease.setInstallerName(artifactPath); applicationRelease.setInstallerName(artifactPath);
applicationRelease.setAppHashValue(md5OfApp); applicationRelease.setAppHashValue(md5OfApp);
} catch (IOException e) { } catch (IOException e) {
@ -249,27 +250,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
return applicationRelease; return applicationRelease;
} }
private InputStream[] cloneInputStream(InputStream inputStream) throws ApplicationStorageManagementException {
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
byte[] buffer = new byte[BUFFER_SIZE];
int len;
while ((len = inputStream.read(buffer)) > -1) {
byteArrayOutputStream.write(buffer, 0, len);
}
byteArrayOutputStream.flush();
InputStream stream1 = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
InputStream stream2 = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
InputStream stream3 = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
return new InputStream[] { stream1, stream2, stream3 };
} catch (IOException e) {
throw new ApplicationStorageManagementException("Error occurred while cloning input stream ", e);
}
}
@Override @Override
public ApplicationReleaseEntity updateReleaseArtifacts(ApplicationReleaseEntity applicationRelease, String appType, public ApplicationReleaseEntity updateReleaseArtifacts(ApplicationReleaseEntity applicationRelease, String appType,
String deviceType, InputStream binaryFile) throws ApplicationStorageManagementException, String deviceType, InputStream binaryFile) throws ApplicationStorageManagementException,
@ -283,12 +263,9 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
throw new ApplicationStorageManagementException("ApplicationEntity Artifact Updating failed", e); throw new ApplicationStorageManagementException("ApplicationEntity Artifact Updating failed", e);
} }
return applicationRelease; return applicationRelease;
} }
@Override @Override
public void deleteApplicationReleaseArtifacts(String directoryPath) throws ApplicationStorageManagementException { public void deleteApplicationReleaseArtifacts(String directoryPath) throws ApplicationStorageManagementException {
File artifact = new File(directoryPath); File artifact = new File(directoryPath);
@ -327,7 +304,7 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
private String getMD5(InputStream binaryFile) throws ApplicationStorageManagementException { private String getMD5(InputStream binaryFile) throws ApplicationStorageManagementException {
String md5; String md5;
try { try {
md5 = DigestUtils.md5Hex(IOUtils.toByteArray(binaryFile)); md5 = DigestUtils.md5Hex(binaryFile);
} catch (IOException e) { } catch (IOException e) {
throw new ApplicationStorageManagementException throw new ApplicationStorageManagementException
("IO Exception while trying to get the md5sum value of application"); ("IO Exception while trying to get the md5sum value of application");

Loading…
Cancel
Save