Skip to content

Commit e8ea632

Browse files
committed
Prepare version 1.3.0.
1 parent bfc901f commit e8ea632

File tree

11 files changed

+179
-15
lines changed

11 files changed

+179
-15
lines changed

.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
2121
<attributes>
2222
<attribute name="maven.pomderived" value="true"/>
23+
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
2324
</attributes>
2425
</classpathentry>
2526
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">

.project

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,32 @@
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.jdt.core.javabuilder</name>
1015
<arguments>
1116
</arguments>
1217
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.wst.validation.validationbuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
1323
<buildCommand>
1424
<name>org.eclipse.m2e.core.maven2Builder</name>
1525
<arguments>
1626
</arguments>
1727
</buildCommand>
1828
</buildSpec>
1929
<natures>
30+
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
31+
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
2032
<nature>org.eclipse.jdt.core.javanature</nature>
2133
<nature>org.eclipse.m2e.core.maven2Nature</nature>
34+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
2235
</natures>
2336
</projectDescription>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
23
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
34
org.eclipse.jdt.core.compiler.compliance=1.8
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
47
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
58
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
2+
<wb-module deploy-name="java-aws-s3">
3+
<wb-resource deploy-path="/" source-path="/src/main/java"/>
4+
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
5+
</wb-module>
6+
</project-modules>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faceted-project>
3+
<installed facet="java" version="1.8"/>
4+
<installed facet="jst.utility" version="1.0"/>
5+
</faceted-project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
disabled=06target
2+
eclipse.preferences.version=1

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to
66
[Semantic Versioning](http://semver.org/).
77

8+
## [1.3.0] - 2018-03-21
9+
* Allow the `IDocumentStore` to accept an `IUploadConfig` file to pass additional configuration properties
10+
while uploading a file.
11+
812
## [1.2.0] - 2017-10-06
9-
* Add a new `S3DocumentStore.getUrl(final String keyName)` function to create absolute Amazon S3 urls ;
13+
* Add a new `S3DocumentStore.getUrl(final String keyName)` function to create absolute Amazon S3 urls ;
1014
* Add an implementation for `S3Mock.deleteObject(final DeleteObjectRequest deleteObjectRequest)`.
1115

1216
## [1.1.0] - 2017-09-29

src/main/java/com/gomoob/aws/s3/documentstore/S3DocumentStore.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
*
5050
* @author Jiaming LIANG ([email protected])
5151
*/
52-
public class S3DocumentStore implements IDocumentStore {
52+
public class S3DocumentStore implements IDocumentStore<S3UploadConfig> {
5353

5454
/**
5555
* The name of the Amazon S3 Bucket to use.
@@ -71,21 +71,17 @@ public class S3DocumentStore implements IDocumentStore {
7171
* {@inheritDoc}
7272
*/
7373
@Override
74-
public IDocumentStoreFile createFromUploadedFile(final InputStream serverFileInputStream, final String keyName,
75-
final long fileSize) throws IOException {
76-
77-
// Creates the request body
78-
RequestBody requestBody = RequestBody.of(serverFileInputStream, fileSize);
79-
80-
return this.uploadToS3(requestBody, keyName, fileSize);
74+
public IDocumentStoreFile createFromUploadedFile(final String serverFilePath, final String keyName)
75+
throws IOException {
76+
return this.createFromUploadedFile(serverFilePath, keyName, new S3UploadConfig());
8177
}
8278

8379
/**
8480
* {@inheritDoc}
8581
*/
8682
@Override
87-
public IDocumentStoreFile createFromUploadedFile(final String serverFilePath, final String keyName)
88-
throws IOException {
83+
public IDocumentStoreFile createFromUploadedFile(final String serverFilePath, final String keyName,
84+
final S3UploadConfig uploadConfig) throws IOException {
8985

9086
// Checks the file
9187
File file = new File(serverFilePath);
@@ -96,7 +92,21 @@ public IDocumentStoreFile createFromUploadedFile(final String serverFilePath, fi
9692
// Creates the request body
9793
RequestBody requestBody = RequestBody.of(file);
9894

99-
return this.uploadToS3(requestBody, keyName, file.length());
95+
return this.uploadToS3(requestBody, keyName, file.length(), uploadConfig);
96+
97+
}
98+
99+
/**
100+
* {@inheritDoc}
101+
*/
102+
@Override
103+
public IDocumentStoreFile createFromUploadedFile(final InputStream serverFileInputStream, final String keyName,
104+
final long fileSize) throws IOException {
105+
106+
// Creates the request body
107+
RequestBody requestBody = RequestBody.of(serverFileInputStream, fileSize);
108+
109+
return this.uploadToS3(requestBody, keyName, fileSize, new S3UploadConfig());
100110
}
101111

102112
/**
@@ -251,16 +261,19 @@ private String extractKeyNameWithoutPrefix(final String keyNameWithPrefix) {
251261
* @param requestBody the request body to put.
252262
* @param keyName the key name of the file.
253263
* @param fileSize the size of the file.
264+
* @param uploadConfig additional upload configuration options.
254265
*
255266
* @return the document store file.
256267
*/
257-
private IDocumentStoreFile uploadToS3(final RequestBody requestBody, final String keyName, final long fileSize) {
268+
private IDocumentStoreFile uploadToS3(final RequestBody requestBody, final String keyName, final long fileSize,
269+
final S3UploadConfig uploadConfig) {
258270

259271
// Create the prefixed key name
260272
String prefixedKeyName = this.createKeyNameWithPrefix(keyName);
261273

262274
// Puts the file on Amazon S3
263-
PutObjectRequest putObjectRequest = PutObjectRequest.builder().bucket(this.bucket).key(prefixedKeyName).build();
275+
PutObjectRequest putObjectRequest = PutObjectRequest.builder().bucket(this.bucket).key(prefixedKeyName)
276+
.metadata(uploadConfig.getMetadata()).build();
264277

265278
this.s3.putObject(putObjectRequest, requestBody);
266279

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* BSD 3-Clause License
3+
*
4+
* Copyright (c) 2017, GOMOOB All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
7+
* following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
10+
* disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
13+
* disclaimer in the documentation and/or other materials provided with the distribution.
14+
*
15+
* * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
16+
* products derived from this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
package com.gomoob.aws.s3.documentstore;
27+
28+
import java.util.Map;
29+
30+
import com.gomoob.documentstore.IUploadConfig;
31+
32+
/**
33+
* An Amazon S3 upload configuration.
34+
*
35+
* @author Baptiste GAILLARD ([email protected])
36+
*/
37+
public class S3UploadConfig implements IUploadConfig {
38+
39+
/**
40+
* The Amazon S3 metadata to attach to the object to upload.
41+
*/
42+
private Map<String, String> metadata;
43+
44+
/**
45+
* Gets the Amazon S3 metadata to attach to the object to upload.
46+
*
47+
* @return the Amazon S3 metadata to attach to the object to upload.
48+
*/
49+
public Map<String, String> getMetadata() {
50+
return this.metadata;
51+
}
52+
53+
/**
54+
* Sets the Amazon S3 metadata to attach to the object to upload.
55+
*
56+
* @return this instance.
57+
*/
58+
public S3UploadConfig setMetadata(final Map<String, String> metadata) {
59+
this.metadata = metadata;
60+
return this;
61+
}
62+
}

src/main/java/com/gomoob/documentstore/IDocumentStore.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
* @author Jiaming LIANG ([email protected])
3939
*/
40-
public interface IDocumentStore {
40+
public interface IDocumentStore<UC extends IUploadConfig> {
4141

4242
/**
4343
* Creates a new file in the document store by copying an uploaded file.
@@ -58,6 +58,26 @@ public interface IDocumentStore {
5858
public IDocumentStoreFile createFromUploadedFile(final String serverFilePath, final String keyName)
5959
throws IOException;
6060

61+
/**
62+
* Creates a new file in the document store by copying an uploaded file.
63+
*
64+
* <p>
65+
* This function is used to create NEW file and throw an exception if the file to create already exists in the
66+
* store.
67+
* </p>
68+
*
69+
* @param serverFilePath the path to the uploaded file to copy into the document store.
70+
* @param keyName the key name to be given to the new file to create. The keyn ame is a string which has a format
71+
* which is the same as a relative file path.
72+
* @param uploadConfig additional upload configuration options.
73+
*
74+
* @return an object which describes the file which have been uploaded on the document store.
75+
*
76+
* @throws IOException if an input / output error occurs while downloading or creating the file.
77+
*/
78+
public IDocumentStoreFile createFromUploadedFile(final String serverFilePath, final String keyName,
79+
final UC uploadConfig) throws IOException;
80+
6181
/**
6282
* Creates a new file in the document store by copying an uploaded file.
6383
*

0 commit comments

Comments
 (0)