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;
import java.io.FileInputStream;
import java.io.FileOutputStream;
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.Entry;
import java.util.Properties;
......@@ -24,17 +20,17 @@ public class DbUtils {
private static final String OP_BACKUP_CONFIG = "b";
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 {
Options options = new Options();
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").numberOfArgs(1).build());
options.addOption(Option.builder(OP_RESTORE_CONFIG).longOpt("restore-cfg").argName("file")
.desc("restores the db config table from the given file").numberOfArgs(1).build());
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());
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")
.numberOfArgs(1).build());
options.addOption(Option.builder(OP_RESTORE_CONFIG).longOpt("restore-cfg").argName("file").desc("restores the db config table from the given file")
.numberOfArgs(1).build());
// 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());
DefaultParser parser = new DefaultParser();
......@@ -45,8 +41,9 @@ public class DbUtils {
} else if (cli.hasOption(OP_RESTORE_CONFIG)) {
System.err.println("not yet implemented");
restoreConfig(cli.getOptionValue(OP_RESTORE_CONFIG));
} else if (cli.hasOption(OP_UPDATE_SCENE_STATUS)) {
System.err.println("not yet implemented");
// } else if (cli.hasOption(OP_UPDATE_SCENE_STATUS)) {
// System.err.println("not yet implemented");
// updateSceneStatus();
} else {
printHelp(options);
}
......@@ -89,36 +86,90 @@ public class DbUtils {
}
}
private static void updateSceneStatus() throws SQLException {
// reset all scenes to METADATA proc_level
resetScenesToMetadataLevel();
SceneDatabase db = SceneDatabase.getInstance();
Map<String, String> cfg = db.getConfig();
final String downloadFolder = cfg.get("path_data_root") + cfg.get("foldername_download");
// iterate over datasets
for (String dataset : getDatasetNames()) {
// TODO: continue here
}
}
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 List<String> getDatasetNames() throws SQLException {
System.out.println("getting dataset names");
ResultSet rs = SceneDatabase.getInstance().placeCustomQuery("select name from datasets;");
List<String> datasets = new ArrayList<>();
while (rs.next()) {
datasets.add(rs.getString(1));
}
return datasets;
}
/**
* won't work since there is no general way to determine the filename from the ids or vice versa
* @throws SQLException
*/
// private static void updateSceneStatus() throws SQLException, IOException {
// // reset all scenes to METADATA proc_level
// // resetScenesToMetadataLevel();
//
// SceneDatabase db = SceneDatabase.getInstance();
//
// final PreparedStatement[] psts = new PreparedStatement[3];
// psts[0] = db.prepareCustomStatement("update scenes set proc_level='DOWNLOADED'::proc_level where satelliteid=? and fi")
//
// Map<String, String> cfg = db.getConfig();
//
// final Path downloadFolder = Paths.get(cfg.get("path_data_root") + cfg.get("foldername_download"));
//
// @SuppressWarnings("unchecked")
// final Map<String, Short>[] idMaps = new HashMap[3];
//
// idMaps[0] = getNameIdMap("satellites");
// idMaps[1] = getNameIdMap("sensors");
// idMaps[2] = getNameIdMap("subsystems");
//
// Files.walkFileTree(downloadFolder, new FileVisitor<Path>() {
//
// short[] ids = new short[3];
//
// @Override
// 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;
// }
}
Markdown is supported
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