Skip to content

Commit

Permalink
upgrade libraries and adjust code to suit
Browse files Browse the repository at this point in the history
  • Loading branch information
andponlin committed Mar 14, 2022
1 parent 5334e1a commit 705b4e6
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 79 deletions.
2 changes: 1 addition & 1 deletion haikudepotserver-api2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* Copyright 2018, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

package db.haikudepot.support;

import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import org.flywaydb.core.api.migration.jdbc.JdbcMigration;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -23,7 +24,7 @@
* changes and would get complicated.</p>
*/

public abstract class EnsureScreenshotHash implements JdbcMigration {
public abstract class EnsureScreenshotHash extends BaseJavaMigration {

protected static final Logger LOGGER = LoggerFactory.getLogger(EnsureScreenshotHash.class);

Expand All @@ -36,7 +37,11 @@ public abstract class EnsureScreenshotHash implements JdbcMigration {
public abstract String createScreenshotIdStatement();

@Override
public void migrate(Connection connection) throws Exception {
public void migrate(Context context) throws Exception {
migrate(context.getConnection());
}

protected void migrate(Connection connection) throws Exception {

int total = countScreenshotsWithoutHash(connection);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -70,7 +70,7 @@ public void run(
try(
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')
CSVWriter writer = new CSVWriter(outputStreamWriter)
) {

// headers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand All @@ -9,6 +9,7 @@
import com.google.common.net.MediaType;
import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;
import com.opencsv.exceptions.CsvValidationException;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.configuration.server.ServerRuntime;
import org.haiku.haikudepotserver.dataobjects.Pkg;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void run(
try(
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',');
CSVWriter writer = new CSVWriter(outputStreamWriter);
InputStream inputStream = jobDataWithByteSourceOptional.get().getByteSource().openStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
CSVReader reader = new CSVReader(inputStreamReader);
Expand Down Expand Up @@ -190,6 +191,8 @@ public void run(
return null;
});

} catch (CsvValidationException e) {
throw new JobRunnerException("unable to validate the csv data", e);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -101,7 +101,7 @@ public void run(

Optional<JobDataWithByteSource> jobDataWithByteSourceOptional = jobService.tryObtainData(specification.getInputDataGuid());

if(!jobDataWithByteSourceOptional.isPresent()) {
if(jobDataWithByteSourceOptional.isEmpty()) {
throw new IllegalStateException("the job data was not able to be found for guid; " + specification.getInputDataGuid());
}

Expand All @@ -110,7 +110,7 @@ public void run(
try (
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')) {
CSVWriter writer = new CSVWriter(outputStreamWriter)) {

String[] headings = new String[]{"path", "action", "message"};
writer.writeNext(headings);
Expand Down Expand Up @@ -238,7 +238,7 @@ private ArchiveEntryResult processMatchingFileEntryFromArchive(
Optional<org.haiku.haikudepotserver.dataobjects.MediaType> mediaType =
org.haiku.haikudepotserver.dataobjects.MediaType.getByExtension(context, leafnameExtension);

if (!mediaType.isPresent()) {
if (mediaType.isEmpty()) {
return new ArchiveEntryResult(Action.INVALID, "unknown file-extension");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -77,7 +77,7 @@ public void run(
try(
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')
CSVWriter writer = new CSVWriter(outputStreamWriter)
) {
final List<PkgIconConfiguration> pkgIconConfigurations = pkgIconService.getInUsePkgIconConfigurations(context);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -35,11 +35,11 @@
public class PkgLocalizationCoverageExportSpreadsheetJobRunner
extends AbstractJobRunner<PkgLocalizationCoverageExportSpreadsheetJobSpecification> {

private static Logger LOGGER = LoggerFactory.getLogger(PkgLocalizationCoverageExportSpreadsheetJobRunner.class);
private final static Logger LOGGER = LoggerFactory.getLogger(PkgLocalizationCoverageExportSpreadsheetJobRunner.class);

private ServerRuntime serverRuntime;
private PkgService pkgService;
private NaturalLanguageService naturalLanguageService;
final private ServerRuntime serverRuntime;
final private PkgService pkgService;
final private NaturalLanguageService naturalLanguageService;

public PkgLocalizationCoverageExportSpreadsheetJobRunner(
ServerRuntime serverRuntime,
Expand Down Expand Up @@ -92,7 +92,7 @@ public void run(
try(
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')
CSVWriter writer = new CSVWriter(outputStreamWriter)
) {

final String[] cells = new String[1 + naturalLanguages.size()];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -68,7 +68,7 @@ public void run(JobService jobService, PkgProminenceAndUserRatingSpreadsheetJobS
try(
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')
CSVWriter writer = new CSVWriter(outputStreamWriter)
) {

writer.writeNext(new String[]{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -106,7 +106,7 @@ public void run(
try (
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')) {
CSVWriter writer = new CSVWriter(outputStreamWriter)) {

Map<String, ScreenshotImportMetadatas> metadatas = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -66,7 +66,7 @@ public void run(
try (
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')
CSVWriter writer = new CSVWriter(outputStreamWriter)
) {
String[] headings = new String[]{
"pkg-name",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -103,7 +103,7 @@ public void run(
try(
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')
CSVWriter writer = new CSVWriter(outputStreamWriter)
) {

final String[] cells = new String[4 + naturalLanguages.size()];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020, Andrew Lindesay
* Copyright 2016-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand All @@ -23,7 +23,6 @@
import org.haiku.haikudepotserver.support.DateTimeHelper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
Expand Down Expand Up @@ -59,7 +58,7 @@ public void run(
try(
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')
CSVWriter writer = new CSVWriter(outputStreamWriter)
) {

writer.writeNext(new String[]{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -65,11 +65,15 @@ private void migrate() {
Preconditions.checkNotNull(getDataSource());
Preconditions.checkState(!Strings.isNullOrEmpty(getSchema()));

Flyway flyway = new Flyway();
flyway.setSchemas(getSchema());
flyway.setLocations(String.format("db/%s/migration", getSchema()));
flyway.setValidateOnMigrate(null==validateOnMigrate || validateOnMigrate);
flyway.setDataSource(dataSource);
Flyway flyway = Flyway
.configure()
.schemas(getSchema())
.dataSource(dataSource)
.locations(String.format("db/%s/migration", getSchema()))
.validateOnMigrate(null == validateOnMigrate || validateOnMigrate)
.table("schema_version")
// ^ note this was an older Flyway table name
.load();

LOGGER.info("will migrate database to latest version...");
flyway.migrate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018, Andrew Lindesay
* Copyright 2018-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

Expand Down Expand Up @@ -75,7 +75,7 @@ public void run(JobService jobService, UserRatingSpreadsheetJobSpecification spe
try(
OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')
CSVWriter writer = new CSVWriter(outputStreamWriter)
) {

Optional<Pkg> paramPkgOptional = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2014-2016, Andrew Lindesay
* Copyright 2014-2022, Andrew Lindesay
* Distributed under the terms of the MIT License.
*/

package org.haiku.haikudepotserver.userrating.model;

import org.flywaydb.core.internal.util.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.haiku.haikudepotserver.job.model.AbstractJobSpecification;
import org.haiku.haikudepotserver.job.model.JobSpecification;

Expand Down Expand Up @@ -50,7 +50,7 @@ public boolean appliesToAllPkgs() {
public boolean isEquivalent(JobSpecification other) {
if(super.isEquivalent(other)) {
UserRatingDerivationJobSpecification other2 = (UserRatingDerivationJobSpecification) other;
return ObjectUtils.nullSafeEquals(other2.getPkgName(), getPkgName());
return StringUtils.equals(other2.getPkgName(), getPkgName());
}

return false;
Expand Down
Loading

0 comments on commit 705b4e6

Please sign in to comment.