Skip to content

Commit

Permalink
Use java-commons 1.2.0.
Browse files Browse the repository at this point in the history
- Change package names
- Use the new thumbnail service
  • Loading branch information
The4thLaw committed Feb 14, 2024
1 parent 5e6ed7b commit 482df8e
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 644 deletions.
70 changes: 39 additions & 31 deletions source/demyo-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Includes the Web server, H2 server, and startup program.</description>
<properties>
<project.rootdir>${project.basedir}/..</project.rootdir>
<windows.version>3.0.0.0</windows.version>
<windows.version>3.1.0.0</windows.version>
</properties>
<dependencies>
<!-- Needed for SystemConfiguration -->
Expand Down Expand Up @@ -99,6 +99,44 @@ Includes the Web server, H2 server, and startup program.</description>
</excludes>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<!-- This goal downloads all H2 versions used by Demyo in the past. It's needed for dev mode as well. -->
<execution>
<id>download-old-h2-versions</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<!-- Demyo 2.0 used 1.4.192 but we have no way of identifying it
and the migration to 1.4.196 could be done automatically so we'll rely
on 1.4.196 -->
<!-- Demyo 2.1, 3.0 -->
<artifactItem>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</artifactItem>
<!-- Demyo 3.1 -->
<artifactItem>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.214</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/legacy-h2-versions</outputDirectory>
<overWriteReleases>true</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
Expand All @@ -123,36 +161,6 @@ Includes the Web server, H2 server, and startup program.</description>
<prependGroupId>true</prependGroupId>
</configuration>
</execution>

<!-- This goal downloads all H2 versions used by Demyo in the past -->
<execution>
<id>download-old-h2-versions</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<!-- Demyo 2.0 used 1.4.192 but we have no way of identifying it
and the migration to 1.4.196 could be done automatically so we'll rely
on 1.4.196 -->
<!-- Demyo 2.1, 3.0 -->
<artifactItem>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</artifactItem>
<!-- Demyo 3.1 -->
<artifactItem>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.214</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/legacy-h2-versions</outputDirectory>
<overWriteReleases>true</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
16 changes: 11 additions & 5 deletions source/demyo-app/src/main/java/org/demyo/desktop/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.h2.jdbcx.JdbcDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.the4thlaw.utils.h2.H2LocalUpgrader;
import org.the4thlaw.utils.h2.H2VersionManager;
import org.the4thlaw.commons.utils.h2.H2LocalUpgrader;
import org.the4thlaw.commons.utils.h2.H2VersionManager;

import org.demyo.common.config.SystemConfiguration;
import org.demyo.common.desktop.DesktopCallbacks;
Expand Down Expand Up @@ -148,7 +148,7 @@ private static JdbcDataSource startDatabase()
LOGGER.debug("Database URL is {}", url);

// Potentially migrate the database
migrateH2IfNeeded(isNewDatabase, Paths.get(databaseFilePath), url);
migrateH2IfNeeded(isNewDatabase, Paths.get(databaseFilePath).getParent(), url);

LOGGER.info("Starting database...");
JdbcDataSource ds = new JdbcDataSource();
Expand All @@ -167,8 +167,14 @@ private static JdbcDataSource startDatabase()
}

private static void migrateH2IfNeeded(boolean isNewDatabase, Path databaseFilePath, String url) throws IOException {
Path h2CacheDirectory = SystemConfiguration.getInstance().getApplicationDirectory()
.resolve("legacy-h2-versions");
Path h2CacheDirectory;
String h2CacheProperty = System.getProperty("demyo.h2.cacheDirectoryName");
if (h2CacheProperty != null) {
h2CacheDirectory = Paths.get(h2CacheProperty);
} else {
h2CacheDirectory = SystemConfiguration.getInstance().getApplicationDirectory()
.resolve("legacy-h2-versions");
}
H2LocalUpgrader upgrader = new H2LocalUpgrader(h2CacheDirectory);
H2VersionManager vm = new H2VersionManager(DEMYO_3_0_H2_VERSION, databaseFilePath, upgrader);
vm.migrateH2IfNeeded(isNewDatabase, url, DB_USER, DB_PASSWORD);
Expand Down
9 changes: 6 additions & 3 deletions source/demyo-app/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@
</appender>


<logger name="org.demyo" level="${config.core.log.level}"
additivity="false">
<logger name="org.demyo" level="${config.core.log.level}" additivity="false">
<appender-ref ref="console" />
<appender-ref ref="demyo" />
</logger>
<logger name="org.the4thlaw" level="${config.core.log.level}" additivity="false">
<appender-ref ref="console" />
<appender-ref ref="demyo" />
</logger>
Expand All @@ -65,4 +68,4 @@
<appender-ref ref="3rdParty" />
</root>

</configuration>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import javax.validation.constraints.NotBlank;

import org.hibernate.annotations.SortComparator;
import org.the4thlaw.utils.io.FilenameUtils;
import org.the4thlaw.commons.utils.io.FilenameUtils;

import com.fasterxml.jackson.annotation.JsonView;

Expand Down
4 changes: 4 additions & 0 deletions source/demyo-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<groupId>org.the4thlaw</groupId>
<artifactId>common-utils</artifactId>
</dependency>
<dependency>
<groupId>org.the4thlaw</groupId>
<artifactId>common-services</artifactId>
</dependency>

<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.Optional;

import org.the4thlaw.commons.services.image.ImageRetrievalResponse;

import org.demyo.common.exception.DemyoException;
import org.demyo.model.Image;

Expand All @@ -14,7 +16,7 @@
public interface IImageService extends IModelService<Image> {
/**
* Gets the actual file for an image from the collection.
*
*
* @param image The image to get the file.
* @return The image file on disk.
* @throws DemyoException In case of security or I/O error.
Expand All @@ -23,7 +25,7 @@ public interface IImageService extends IModelService<Image> {

/**
* Processes the upload of an image.
*
*
* @param originalFileName The name of the uploaded image.
* @param imageFile The file stored on disk, temporarily.
* @return The created or recovered image identifier.
Expand All @@ -33,14 +35,14 @@ public interface IImageService extends IModelService<Image> {

/**
* Finds the list of all images that are currently on the disk, but not registered in Demyo.
*
*
* @return The list of images.
*/
List<String> findUnknownDiskImages();

/**
* Adds an image that is assumed to exist on the file system.
*
*
* @param path The image to add.
* @return The created image identifier.
* @throws DemyoException In case of error during addition of the specified image.
Expand All @@ -54,7 +56,7 @@ public interface IImageService extends IModelService<Image> {

/**
* Retrieves images from FilePond and stores them in the database.
*
*
* @param baseImageName The base image description to use. Depending on <code>alwaysNumber</code>, may be suffixed
* by a number.
* @param alwaysNumber Whether to always suffix the base image name or not.
Expand All @@ -67,7 +69,7 @@ List<Image> recoverImagesFromFilePond(String baseImageName, boolean alwaysNumber

/**
* Gets an image, resized if necessary.
*
*
* @param id The image ID
* @param maxWidthOpt The maximum desired width, if any
* @param lenient When lenient, we allow a minor difference in sizes, because it won't change a lot in terms of
Expand All @@ -80,7 +82,7 @@ List<Image> recoverImagesFromFilePond(String baseImageName, boolean alwaysNumber

/**
* Returns an Image and its dependent albums, authors, etc.
*
*
* @param id The image ID
* @return The Image object, populated with its dependencies.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.demyo.service;

import org.the4thlaw.commons.services.image.BaseThumbnailService.ImageSupplier;
import org.the4thlaw.commons.services.image.ImageRetrievalResponse;

import org.demyo.common.exception.DemyoException;
import org.demyo.service.impl.ThumbnailService.ImageSupplier;

/**
* Defines methods to work with thumbnails.
Expand All @@ -18,7 +20,7 @@ public interface IThumbnailService {

/**
* Gets the thumbnail for an image. Results are cached.
*
*
* @param id The image ID
* @param maxWidth The maximum desired width
* @param lenient When lenient, we allow a minor difference in sizes, because it won't change a lot in terms of
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.the4thlaw.utils.xml.XMLUtils;
import org.the4thlaw.commons.utils.xml.XMLUtils;

import org.demyo.common.config.SystemConfiguration;
import org.demyo.common.exception.DemyoErrorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.the4thlaw.utils.io.FileSecurityUtils;
import org.the4thlaw.utils.io.FilenameUtils;
import org.the4thlaw.commons.utils.io.FileSecurityUtils;
import org.the4thlaw.commons.utils.io.FilenameUtils;

import org.demyo.common.config.SystemConfiguration;
import org.demyo.common.exception.DemyoErrorCode;
Expand Down Expand Up @@ -77,7 +77,7 @@ public boolean accept(File file) {

for (File f : filesToDelete) {
LOGGER.debug("Auto-cleaning FilePond file: {}", f);
org.the4thlaw.utils.io.FileUtils.deleteQuietly(f);
org.the4thlaw.commons.utils.io.FileUtils.deleteQuietly(f);
}
}

Expand All @@ -99,7 +99,7 @@ public String process(String originalFileName, InputStream input) throws IOExcep
IOUtils.copy(input, fos);
} catch (IOException ioe) {
LOGGER.warn("Failed to store FilePond data to {}", destinationFile, ioe);
org.the4thlaw.utils.io.FileUtils.deleteQuietly(destinationFile);
org.the4thlaw.commons.utils.io.FileUtils.deleteQuietly(destinationFile);
}
// Request to delete on exit, just in case
destinationFile.toFile().deleteOnExit();
Expand All @@ -113,7 +113,7 @@ public String process(String originalFileName, InputStream input) throws IOExcep
public void revert(String id) {
Path file = uploadDirectory.resolve(id);
FileSecurityUtils.assertChildOf(uploadDirectory, file);
org.the4thlaw.utils.io.FileUtils.deleteQuietly(file);
org.the4thlaw.commons.utils.io.FileUtils.deleteQuietly(file);
}

@Override
Expand Down

0 comments on commit 482df8e

Please sign in to comment.