Commit 678cecf9 authored by Daniel Eggert's avatar Daniel Eggert
Browse files

just realized i'm on a woodway :D

parent 7d33e5cb
...@@ -3,10 +3,6 @@ package de.potsdam.gfz.gms; ...@@ -3,10 +3,6 @@ package de.potsdam.gfz.gms;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
...@@ -24,17 +20,17 @@ public class DbUtils { ...@@ -24,17 +20,17 @@ public class DbUtils {
private static final String OP_BACKUP_CONFIG = "b"; private static final String OP_BACKUP_CONFIG = "b";
private static final String OP_RESTORE_CONFIG = "r"; private static final String OP_RESTORE_CONFIG = "r";
private static final String OP_UPDATE_SCENE_STATUS = "u"; // private static final String OP_UPDATE_SCENE_STATUS = "u";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Options options = new Options(); Options options = new Options();
options.addOption(Option.builder(OP_BACKUP_CONFIG).longOpt("backup-cfg").argName("file") options.addOption(Option.builder(OP_BACKUP_CONFIG).longOpt("backup-cfg").argName("file").desc("stores a copy of the gms config table in the given file")
.desc("stores a copy of the gms config table in the given file").numberOfArgs(1).build()); .numberOfArgs(1).build());
options.addOption(Option.builder(OP_RESTORE_CONFIG).longOpt("restore-cfg").argName("file") options.addOption(Option.builder(OP_RESTORE_CONFIG).longOpt("restore-cfg").argName("file").desc("restores the db config table from the given file")
.desc("restores the db config table from the given file").numberOfArgs(1).build()); .numberOfArgs(1).build());
options.addOption(Option.builder(OP_UPDATE_SCENE_STATUS).longOpt("update-scene-status").hasArg(false) // options.addOption(Option.builder(OP_UPDATE_SCENE_STATUS).longOpt("update-scene-status").hasArg(false)
.desc("updates the proc_level of the scenes to match the downloaded scenes on the harddrive").build()); // .desc("updates the proc_level of the scenes to match the downloaded scenes on the harddrive").build());
DefaultParser parser = new DefaultParser(); DefaultParser parser = new DefaultParser();
...@@ -45,8 +41,9 @@ public class DbUtils { ...@@ -45,8 +41,9 @@ public class DbUtils {
} else if (cli.hasOption(OP_RESTORE_CONFIG)) { } else if (cli.hasOption(OP_RESTORE_CONFIG)) {
System.err.println("not yet implemented"); System.err.println("not yet implemented");
restoreConfig(cli.getOptionValue(OP_RESTORE_CONFIG)); restoreConfig(cli.getOptionValue(OP_RESTORE_CONFIG));
} else if (cli.hasOption(OP_UPDATE_SCENE_STATUS)) { // } else if (cli.hasOption(OP_UPDATE_SCENE_STATUS)) {
System.err.println("not yet implemented"); // System.err.println("not yet implemented");
// updateSceneStatus();
} else { } else {
printHelp(options); printHelp(options);
} }
...@@ -89,36 +86,90 @@ public class DbUtils { ...@@ -89,36 +86,90 @@ public class DbUtils {
} }
} }
private static void updateSceneStatus() throws SQLException { /**
// reset all scenes to METADATA proc_level * won't work since there is no general way to determine the filename from the ids or vice versa
resetScenesToMetadataLevel(); * @throws SQLException
*/
SceneDatabase db = SceneDatabase.getInstance(); // private static void updateSceneStatus() throws SQLException, IOException {
// // reset all scenes to METADATA proc_level
Map<String, String> cfg = db.getConfig(); // // resetScenesToMetadataLevel();
//
final String downloadFolder = cfg.get("path_data_root") + cfg.get("foldername_download"); // SceneDatabase db = SceneDatabase.getInstance();
//
// iterate over datasets // final PreparedStatement[] psts = new PreparedStatement[3];
for (String dataset : getDatasetNames()) { // psts[0] = db.prepareCustomStatement("update scenes set proc_level='DOWNLOADED'::proc_level where satelliteid=? and fi")
// TODO: continue here //
} // Map<String, String> cfg = db.getConfig();
} //
// final Path downloadFolder = Paths.get(cfg.get("path_data_root") + cfg.get("foldername_download"));
private static void resetScenesToMetadataLevel() throws SQLException { //
System.out.println("resetting all scenes back to proc_level METADATA"); // @SuppressWarnings("unchecked")
SceneDatabase.getInstance().prepareCustomStatement("update scenes set proc_level='METADATA'::proc_level;") // final Map<String, Short>[] idMaps = new HashMap[3];
.executeUpdate(); //
} // idMaps[0] = getNameIdMap("satellites");
// idMaps[1] = getNameIdMap("sensors");
private static List<String> getDatasetNames() throws SQLException { // idMaps[2] = getNameIdMap("subsystems");
System.out.println("getting dataset names"); //
ResultSet rs = SceneDatabase.getInstance().placeCustomQuery("select name from datasets;"); // Files.walkFileTree(downloadFolder, new FileVisitor<Path>() {
List<String> datasets = new ArrayList<>(); //
while (rs.next()) { // short[] ids = new short[3];
datasets.add(rs.getString(1)); //
} // @Override
return datasets; // public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
} // if(dir.equals(downloadFolder)) {
// return FileVisitResult.CONTINUE;
// }
//
// Arrays.fill(ids, (short) 0);
// Path relPath = downloadFolder.relativize(dir);
//
// for (int i = 0; i < relPath.getNameCount(); ++i) {
// String name = relPath.getName(i).toString();
// if (!idMaps[i].containsKey(name)) {
// System.err.println("skipping dir " + name);
// return FileVisitResult.SKIP_SUBTREE;
// }
//
// ids[i] = idMaps[i].get(name);
// }
//
// return FileVisitResult.CONTINUE;
// }
//
// @Override
// public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
// System.out.println(Arrays.toString(ids) + ": " + file.getFileName().toString());
// return FileVisitResult.CONTINUE;
// }
//
// @Override
// public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
// // TODO Auto-generated method stub
// return null;
// }
//
// @Override
// public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
// // TODO Auto-generated method stub
// return null;
// }
// });
// }
// private static void resetScenesToMetadataLevel() throws SQLException {
// System.out.println("resetting all scenes back to proc_level METADATA");
// SceneDatabase.getInstance().prepareCustomStatement("update scenes set proc_level='METADATA'::proc_level;").executeUpdate();
// }
//
// private static Map<String, Short> getNameIdMap(String tableName) throws SQLException {
// System.out.println("getting name id mapping for '" + tableName + "'");
// ResultSet rs = SceneDatabase.getInstance().placeCustomQuery("select id, name from " + tableName + ";");
// Map<String, Short> mapping = new HashMap<>();
//
// while (rs.next()) {
// mapping.put(rs.getString(2), rs.getShort(1));
// }
// return mapping;
// }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment