Skip to content

Commit 3e436ae

Browse files
Merge pull request #11 from dynamiatools/7.x
7.2.1 depdendncies upgrade
2 parents 58cef20 + 981b444 commit 3e436ae

File tree

6 files changed

+48
-35
lines changed

6 files changed

+48
-35
lines changed

sources/core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
<parent>
2323
<artifactId>tools.dynamia.modules.entityfiles.parent</artifactId>
2424
<groupId>tools.dynamia.modules</groupId>
25-
<version>7.2.0</version>
25+
<version>7.2.1</version>
2626
</parent>
2727
<name>Dynamia Modules - EntityFiles - Core</name>
2828
<artifactId>tools.dynamia.modules.entityfiles</artifactId>
29-
<version>7.2.0</version>
29+
<version>7.2.1</version>
3030
<url>https://www.dynamia.tools/modules/entityfiles</url>
3131

3232
<build>

sources/core/src/main/java/tools/dynamia/modules/entityfile/domain/EntityFile.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public class EntityFile extends BaseEntity implements URLable {
8080
private Long accountId;
8181
private String externalRef;
8282

83+
@Transient
84+
private boolean uploading;
85+
8386
public String getStoredFileName() {
8487
return storedFileName;
8588
}
@@ -298,4 +301,12 @@ public void url(String url) {
298301
public void name(String name) {
299302
setStoredFileName(name);
300303
}
304+
305+
public boolean isUploading() {
306+
return uploading;
307+
}
308+
309+
public void setUploading(boolean uploading) {
310+
this.uploading = uploading;
311+
}
301312
}

sources/pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<groupId>tools.dynamia.modules</groupId>
2323
<artifactId>tools.dynamia.modules.entityfiles.parent</artifactId>
2424
<packaging>pom</packaging>
25-
<version>7.2.0</version>
25+
<version>7.2.1</version>
2626
<name>Dynamia Modules - EntityFiles</name>
2727
<url>https://dynamia.tools/modules/entityfiles</url>
2828
<description>DynamiaTools extension to attach files to entities</description>
@@ -63,9 +63,9 @@
6363

6464
<properties>
6565
<file.encoding>UTF-8</file.encoding>
66-
<dynamiatools.version>5.2.1</dynamiatools.version>
67-
<springboot.version>3.3.3</springboot.version>
68-
<aws.version>2.28.11</aws.version>
66+
<dynamiatools.version>5.3.1</dynamiatools.version>
67+
<springboot.version>3.4.1</springboot.version>
68+
<aws.version>2.29.47</aws.version>
6969
<java.version>17</java.version>
7070
<maven.compiler>3.13.0</maven.compiler>
7171
<source.encoding>UTF-8</source.encoding>
@@ -99,7 +99,7 @@
9999
<plugin>
100100
<groupId>org.apache.maven.plugins</groupId>
101101
<artifactId>maven-javadoc-plugin</artifactId>
102-
<version>3.10.0</version>
102+
<version>3.11.2</version>
103103
<configuration>
104104
<failOnError>false</failOnError>
105105
<doclint>none</doclint>
@@ -122,7 +122,7 @@
122122
<dependency>
123123
<groupId>commons-io</groupId>
124124
<artifactId>commons-io</artifactId>
125-
<version>2.16.1</version>
125+
<version>2.18.0</version>
126126
</dependency>
127127

128128
<dependency>
@@ -175,7 +175,7 @@
175175
<plugin>
176176
<groupId>org.apache.maven.plugins</groupId>
177177
<artifactId>maven-gpg-plugin</artifactId>
178-
<version>3.1.0</version>
178+
<version>3.2.4</version>
179179
<executions>
180180
<execution>
181181
<id>sign-artifacts</id>

sources/s3/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
<parent>
2424
<groupId>tools.dynamia.modules</groupId>
2525
<artifactId>tools.dynamia.modules.entityfiles.parent</artifactId>
26-
<version>7.2.0</version>
26+
<version>7.2.1</version>
2727
</parent>
2828

2929
<name>Dynamia Modules - EntityFiles - S3</name>
3030
<artifactId>tools.dynamia.modules.entityfiles.s3</artifactId>
31-
<version>7.2.0</version>
31+
<version>7.2.1</version>
3232
<url>https://www.dynamia.tools/modules/entityfiles</url>
3333

3434
<build>

sources/s3/src/main/java/tools/dynamia/modules/entityfiles/s3/S3EntityFileStorage.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public void upload(EntityFile entityFile, UploadedFileInfo fileInfo) {
153153
logger.info("Uploading input stream from " + fileInfo.getFullName() + " to " + key);
154154
body = AsyncRequestBody.fromInputStream(fileInfo.getInputStream(), length, executorService);
155155
}
156+
entityFile.setUploading(true);
156157
getClient().putObject(request, body)
157158
.whenComplete((response, throwable) -> {
158159
if (throwable != null) {
@@ -165,6 +166,7 @@ public void upload(EntityFile entityFile, UploadedFileInfo fileInfo) {
165166
if (fileToUpload != null && fileToUpload.delete()) {
166167
logger.info("Deleted temporal file: " + fileToUpload);
167168
}
169+
entityFile.setUploading(false);
168170
});
169171

170172

@@ -258,19 +260,28 @@ protected String getAccountFolderName(Long accountId) {
258260
*/
259261
protected String generateThumbnailURL(EntityFile entityFile, int w, int h) {
260262
if (entityFile.getType() == EntityFileType.IMAGE || EntityFileType.getFileType(entityFile.getExtension()) == EntityFileType.IMAGE) {
263+
if (entityFile.isUploading()) {
264+
try {
265+
Thread.sleep(1000);
266+
} catch (InterruptedException e) {
267+
268+
}
269+
}
270+
261271
String urlKey = entityFile.getUuid() + w + "x" + h;
262272
String url = URL_CACHE.get(urlKey);
263273
if (url == null) {
274+
String bucketName = getBucketName();
264275
String folder = getAccountFolderName(entityFile.getAccountId());
265276
String fileName = getFileName(entityFile);
266277
String thumbfileName = w + "x" + h + "/" + fileName;
267278

268-
if (!objectExists(getBucketName(), folder + thumbfileName)) {
269-
createAndUploadThumbnail(entityFile, getBucketName(), folder, fileName, thumbfileName, w, h);
279+
if (!objectExists(bucketName, folder + thumbfileName)) {
280+
url = createAndUploadThumbnail(entityFile, bucketName, folder, fileName, thumbfileName, w, h);
281+
}
282+
if (url != null) {
283+
URL_CACHE.add(urlKey, url);
270284
}
271-
272-
url = generateStaticURL(getBucketName(), folder + thumbfileName);
273-
URL_CACHE.add(urlKey, url);
274285
}
275286
return url;
276287
} else {
@@ -281,24 +292,19 @@ protected String generateThumbnailURL(EntityFile entityFile, int w, int h) {
281292
/**
282293
* Create and upload thumbnail
283294
*/
284-
protected void createAndUploadThumbnail(EntityFile entityFile, String bucketName, String folder, String fileName, String thumbfileName,
285-
int w, int h) {
295+
protected String createAndUploadThumbnail(EntityFile entityFile, String bucketName, String folder, String fileName, String thumbfileName,
296+
int w, int h) {
286297
try {
287298

288299
File localDestination = File.createTempFile(System.currentTimeMillis() + "file", entityFile.getName());
289300
File localThumbDestination = File.createTempFile(System.currentTimeMillis() + "thumb", entityFile.getName());
290-
291-
292301
var url = download(entityFile).getUrl();
293302
Files.copy(new URL(url).openStream(), localDestination.toPath(), StandardCopyOption.REPLACE_EXISTING);
294-
295303
ImageUtil.resizeImage(localDestination, localThumbDestination, entityFile.getExtension(), w, h);
296304

297-
298305
// metadata
299306
var metadata = Map.of(
300307
"thumbnail", "true",
301-
"description", entityFile.getDescription(),
302308
"uuid", entityFile.getUuid(),
303309
"width", String.valueOf(w),
304310
"height", String.valueOf(h));
@@ -307,25 +313,21 @@ protected void createAndUploadThumbnail(EntityFile entityFile, String bucketName
307313
PutObjectRequest request = PutObjectRequest.builder()
308314
.bucket(bucketName)
309315
.key(key)
316+
.metadata(metadata)
310317
.contentLength(localThumbDestination.length())
311318
.contentType("image/" + entityFile.getExtension())
312319
.acl(ObjectCannedACL.PUBLIC_READ)
313320
.build();
314321

315322

316-
getClient().putObject(request, AsyncRequestBody.fromFile(localThumbDestination))
317-
.whenComplete((putObjectResponse, throwable) -> {
318-
if (throwable != null) {
319-
logger.error("Error uploading thumbnail " + localDestination, throwable);
320-
} else {
321-
logger.info("Thumbnail uploaded " + key);
322-
}
323-
324-
localThumbDestination.delete();
325-
});
323+
var future = getClient().putObject(request, AsyncRequestBody.fromFile(localThumbDestination));
324+
var response = future.get();
325+
localThumbDestination.delete();
326326

327+
return generateStaticURL(bucketName, key);
327328
} catch (Exception e) {
328329
logger.error("Error creating thumbnail for " + entityFile.getName() + " " + w + "x" + h + " " + fileName, e);
330+
return null;
329331
}
330332
}
331333

sources/ui/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
<parent>
2323
<artifactId>tools.dynamia.modules.entityfiles.parent</artifactId>
2424
<groupId>tools.dynamia.modules</groupId>
25-
<version>7.2.0</version>
25+
<version>7.2.1</version>
2626
</parent>
2727
<name>Dynamia Modules - EntityFiles UI</name>
2828
<artifactId>tools.dynamia.modules.entityfiles.ui</artifactId>
29-
<version>7.2.0</version>
29+
<version>7.2.1</version>
3030
<url>https://www.dynamia.tools/modules/entityfiles</url>
3131

3232
<build>

0 commit comments

Comments
 (0)