mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-25 06:58:39 +00:00
added unit tests for file storage
This commit is contained in:
@@ -9,4 +9,8 @@ Export-Package: com.sap.sse.filestorage,
|
||||
com.sap.sse.filestorage.impl
|
||||
Import-Package: org.osgi.framework;version="1.8.0"
|
||||
Bundle-Activator: com.sap.sse.filestorage.impl.Activator
|
||||
Require-Bundle: org.apache.servicemix.bundles.aws-java-sdk;bundle-version="1.9.8"
|
||||
Require-Bundle: org.apache.servicemix.bundles.aws-java-sdk;bundle-version="1.9.8",
|
||||
com.fasterxml.jackson.core.jackson-databind,
|
||||
com.fasterxml.jackson.core.jackson-core,
|
||||
com.fasterxml.jackson.core.jackson-annotations,
|
||||
org.apache.commons.logging;bundle-version="1.1.3"
|
||||
|
||||
+9
-4
@@ -61,14 +61,16 @@ public class AmazonS3FileStorageServiceImpl implements FileStorageService {
|
||||
private static String getKey(String originalFileName) {
|
||||
String key = UUID.randomUUID().toString();
|
||||
if (originalFileName != null) {
|
||||
key += "/" + originalFileName;
|
||||
String ending = originalFileName.substring(originalFileName.lastIndexOf("."));
|
||||
key += ending;
|
||||
// key += "/" + originalFileName;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
private static URI getUri(String key) {
|
||||
try {
|
||||
return new URI(retrievalProtocol, bucketName + "." + baseUrl, key, null);
|
||||
return new URI(retrievalProtocol, bucketName + "." + baseUrl, "/" + key, null);
|
||||
} catch (URISyntaxException e) {
|
||||
logger.log(Level.WARNING, "Could not create URI for uploaded file with key " + key, e);
|
||||
return null;
|
||||
@@ -84,13 +86,16 @@ public class AmazonS3FileStorageServiceImpl implements FileStorageService {
|
||||
PutObjectRequest request = new PutObjectRequest(bucketName, key, is, metadata)
|
||||
.withCannedAcl(CannedAccessControlList.PublicRead);
|
||||
s3.putObject(request);
|
||||
return getUri(key);
|
||||
URI uri = getUri(key);
|
||||
logger.info("Stored file " + uri);
|
||||
return uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFile(URI uri) {
|
||||
String key = uri.getPath();
|
||||
String key = uri.getPath().substring(1); //remove initial slash
|
||||
s3.deleteObject(new DeleteObjectRequest(bucketName, key));
|
||||
logger.info("Removed file " + uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user