Skip to content

Commit

Permalink
fix to initiate null extradata objects with the correct implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mynttt committed Feb 11, 2024
1 parent afe5207 commit 2418e03
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/java/updatetool/Globals.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package updatetool;

import java.util.List;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import updatetool.common.Pair;
import updatetool.imdb.ImdbDatabaseSupport.ImdbMetadataResult;

public final class Globals {

private Globals() {}

// This is set in ImdbDatabaseSupport to understand if we use the new or old format for null valued ExtraData that is then initiated by the tool for the first time
@SuppressFBWarnings("MS_CANNOT_BE_FINAL")
public static boolean IS_NEW_EXTRA_DATA = false;

/*
* Badges
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/updatetool/common/ExtraData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import updatetool.Globals;

public abstract class ExtraData {
protected Map<String, String> mapping = new LinkedHashMap<>();

public static ExtraData of(String data) {

// New Extra Data is never null
if(data == null)
return new OldExtraData(null);
return Globals.IS_NEW_EXTRA_DATA ? new NewExtraData(null) : new OldExtraData(null);

if(data.startsWith("{")) {
return new NewExtraData(data);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/updatetool/imdb/ImdbDatabaseSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ImdbDatabaseSupport {
private final SqliteDatabaseProvider provider;
private final KeyValueStore newAgentMapping;
private final ImdbPipelineConfiguration config;
private final boolean isNewExtraData;

public static class ImdbMetadataResult {
//Id will be resolved in the pipeline and not here
Expand Down Expand Up @@ -93,6 +94,7 @@ public String toString() {
}
}

@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public ImdbDatabaseSupport(SqliteDatabaseProvider provider, KeyValueStore newAgentMapping, ImdbPipelineConfiguration config) {
this.provider = provider;
this.newAgentMapping = newAgentMapping;
Expand All @@ -101,6 +103,19 @@ public ImdbDatabaseSupport(SqliteDatabaseProvider provider, KeyValueStore newAge
if(config.executeUpdatesOverPlexSqliteBinary()) {
testPlexSqliteBinaryVersion();
}

isNewExtraData = checkExtraDataFormat();
Logger.info("NewExtraDataFormat has been identified as: {}", isNewExtraData);
Globals.IS_NEW_EXTRA_DATA = isNewExtraData;
}

private boolean checkExtraDataFormat() {
String QUERY = "SELECT COUNT(version) FROM schema_migrations WHERE version = 202309200901;";
try(var handle = provider.queryFor(QUERY)) {
return handle.result().getInt(1) == 1;
} catch (SQLException e) {
throw Utility.rethrow(e);
}
}

@SuppressFBWarnings("DM_EXIT")
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/updatetool/imdb/ImdbDockerImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ public void run() {

Logger.info("LIBRARIES => POST LIBRARY FILTERING");
libraries.forEach(l -> Logger.info("Will process library {} (ID={}) with agent: {} and {} item(s).", l.name, l.id, l.agent, l.items));
metadata = ImdbLibraryMetadata.fetchAll(libraries, new ImdbDatabaseSupport(connection, caches.get("new-agent-mapping"), config), config);
metadata = ImdbLibraryMetadata.fetchAll(libraries, new ImdbDatabaseSupport(connection, caches.get("new-agent-mapping"), config), config);

} catch(Exception e) {
Logger.error(e.getClass().getSimpleName() + " exception encountered...");
Logger.error("Please contact the maintainer of the application with the stacktrace below if you think this is unwanted behavior.");
Expand Down

0 comments on commit 2418e03

Please sign in to comment.