Skip to content

Commit

Permalink
Merge pull request #308 from keeps/bf-beta7.3-dev
Browse files Browse the repository at this point in the history
version 2.0.0, release candidate 1
  • Loading branch information
chalkos authored Apr 12, 2017
2 parents 731b10e + 7c19dec commit fd94bf2
Show file tree
Hide file tree
Showing 36 changed files with 482 additions and 162 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dbptk-report-*
dbptk-app.log
dbptk-app.log.txt
exported-dbs/
dbptk-model/src/main/resources/dbptk-version.json

**/pom.xml.versionsBackup

Expand Down
2 changes: 1 addition & 1 deletion dbptk-bindings/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.databasepreservation</groupId>
<artifactId>dbptk</artifactId>
<version>2.0.0-beta7.2</version>
<version>2.0.0-rc1</version>
<relativePath>..</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
4 changes: 2 additions & 2 deletions dbptk-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<name>dbptk-core</name>
<groupId>com.databasepreservation</groupId>
<artifactId>dbptk-core</artifactId>
<version>2.0.0-beta7.2</version>
<version>2.0.0-rc1</version>
<parent>
<groupId>com.databasepreservation</groupId>
<artifactId>dbptk</artifactId>
<version>2.0.0-beta7.2</version>
<version>2.0.0-rc1</version>
<relativePath>..</relativePath>
</parent>
<properties>
Expand Down
11 changes: 9 additions & 2 deletions dbptk-core/src/main/java/com/databasepreservation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@
import com.databasepreservation.modules.siard.SIARDDKModuleFactory;
import com.databasepreservation.modules.solr.SolrModuleFactory;
import com.databasepreservation.modules.sqlServer.SQLServerJDBCModuleFactory;
import com.databasepreservation.utils.ConfigUtils;
import com.databasepreservation.utils.MiscUtils;

/**
* @author Luis Faria <lfaria@keep.pt>
* @author Bruno Ferreira <bferreira@keep.pt>
*/
public class Main {
static {
// initialize logging
ConfigUtils.initialize();
}

public static final int EXIT_CODE_OK = 0;
public static final int EXIT_CODE_GENERIC_ERROR = 1;
public static final int EXIT_CODE_COMMAND_PARSE_ERROR = 2;
Expand Down Expand Up @@ -183,8 +189,9 @@ private static int run(CLI cli) {

private static void logProgramStart() {
LOGGER.debug("#########################################################");
LOGGER.debug("# START-ID-" + execID);
LOGGER.debug("# START v" + MiscUtils.APP_VERSION);
LOGGER.debug("# START-ID-{}", execID);
LOGGER.debug("# START v{}", MiscUtils.APP_VERSION);
LOGGER.debug("# version info: {}", ConfigUtils.getVersionInfo());
LOGGER.debug("#########################################################");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<file>dbptk-app.log.txt</file>
<file>${dbptk.home}/log/dbptk-app.log.txt</file>
<append>true</append>
<encoder>
<pattern>%d [%thread] %-5level \(%logger{5}\) %msg%n%exception{full}</pattern>
Expand Down
16 changes: 14 additions & 2 deletions dbptk-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<name>dbptk-model</name>
<groupId>com.databasepreservation</groupId>
<artifactId>dbptk-model</artifactId>
<version>2.0.0-beta7.2</version>
<version>2.0.0-rc1</version>
<packaging>jar</packaging>
<parent>
<groupId>com.databasepreservation</groupId>
<artifactId>dbptk</artifactId>
<version>2.0.0-beta7.2</version>
<version>2.0.0-rc1</version>
<relativePath>..</relativePath>
</parent>
<dependencies>
Expand All @@ -29,6 +29,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
Expand All @@ -38,4 +42,12 @@
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
20 changes: 20 additions & 0 deletions dbptk-model/src/main/java/com/databasepreservation/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.databasepreservation;

/**
* @author Bruno Ferreira <bferreira@keep.pt>
*/
public class Constants {
public static final String VERSION_INFO_FILE = "dbptk-version.json";

public static final String PROPERTY_KEY_HOME = "dbptk.home";

public static final String DEFAULT_HOME_DIRECTORY = "./dbptk";

public static final String SUBDIRECTORY_LOG = "log";
public static final String LOGBACK_FILE_NAME = "logback_manual.xml";

public static final String SUBDIRECTORY_MODULES = "modules";

public static final String SUBDIRECTORY_REPORTS = "reports";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.databasepreservation.common;

import com.databasepreservation.model.structure.DatabaseStructure;
import com.databasepreservation.model.structure.SchemaStructure;
import com.databasepreservation.model.structure.TableStructure;

/**
* Receives notifications about changes in modules
*
* @author Bruno Ferreira <bferreira@keep.pt>
*/
public interface ModuleObserver {
void notifyOpenDatabase();

void notifyStructureObtained(DatabaseStructure structure);

void notifyOpenSchema(DatabaseStructure structure, SchemaStructure schema, long completedSchemas,
long completedTablesInSchema);

void notifyOpenTable(DatabaseStructure structure, TableStructure table, long completedSchemas,
long completedTablesInSchema);

/**
* Notify about progress in converting a table. Delta between 2 reports may be
* more than a single row.
*/
void notifyTableProgress(DatabaseStructure structure, TableStructure table, long completedRows, long totalRows);

void notifyCloseTable(DatabaseStructure structure, TableStructure table, long completedSchemas,
long completedTablesInSchema);

void notifyCloseSchema(DatabaseStructure structure, SchemaStructure schema, long completedSchemas,
long completedTablesInSchema);

void notifyCloseDatabase(DatabaseStructure structure);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.databasepreservation.common;

import java.util.ArrayList;
import java.util.List;

import com.databasepreservation.model.structure.DatabaseStructure;
import com.databasepreservation.model.structure.SchemaStructure;
import com.databasepreservation.model.structure.TableStructure;

/**
* Updates ModuleObservers about conversion events (e.g. progress)
*
* @author Bruno Ferreira <bferreira@keep.pt>
*/
public abstract class ObservableModule {
private final List<ModuleObserver> observers;

public ObservableModule() {
super();
this.observers = new ArrayList<>();
}

public void addModuleObserver(ModuleObserver observer) {
observers.add(observer);
}

public void removeModuleObserver(ModuleObserver observer) {
observers.remove(observer);
}

/**************************************************************************
* Events notification
*/

public void notifyOpenDatabase() {
for (ModuleObserver observer : observers) {
observer.notifyOpenDatabase();
}
}

public void notifyStructureObtained(DatabaseStructure structure) {
for (ModuleObserver observer : observers) {
observer.notifyStructureObtained(structure);
}
}

public void notifyOpenSchema(DatabaseStructure structure, SchemaStructure schema, long completedSchemas,
long completedTablesInSchema) {
for (ModuleObserver observer : observers) {
observer.notifyOpenSchema(structure, schema, completedSchemas, completedTablesInSchema);
}
}

public void notifyOpenTable(DatabaseStructure structure, TableStructure table, long completedSchemas,
long completedTablesInSchema) {
for (ModuleObserver observer : observers) {
observer.notifyOpenTable(structure, table, completedSchemas, completedTablesInSchema);
}
}

/**
* Notify about progress in converting a table. Delta between 2 reports may be
* more than a single row.
*/
public void notifyTableProgress(DatabaseStructure structure, TableStructure table, long completedRows, long totalRows) {
for (ModuleObserver observer : observers) {
observer.notifyTableProgress(structure, table, completedRows, totalRows);
}
}

public void notifyCloseTable(DatabaseStructure structure, TableStructure table, long completedSchemas,
long completedTablesInSchema) {
for (ModuleObserver observer : observers) {
observer.notifyCloseTable(structure, table, completedSchemas, completedTablesInSchema);
}
}

public void notifyCloseSchema(DatabaseStructure structure, SchemaStructure schema, long completedSchemas,
long completedTablesInSchema) {
for (ModuleObserver observer : observers) {
observer.notifyCloseSchema(structure, schema, completedSchemas, completedTablesInSchema);
}
}

public void notifyCloseDatabase(DatabaseStructure structure) {
for (ModuleObserver observer : observers) {
observer.notifyCloseDatabase(structure);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ public class NoOpReporter extends Reporter {
public NoOpReporter() {
}

public NoOpReporter(String directory) {
}

@Override
protected void initialize(String directory) {
protected void init(String directory, String name) {
// do nothing
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.databasepreservation.model.structure.ColumnStructure;
import com.databasepreservation.model.structure.TableStructure;
import com.databasepreservation.model.structure.type.Type;
import com.databasepreservation.utils.ConfigUtils;
import com.databasepreservation.utils.MiscUtils;

/**
Expand Down Expand Up @@ -59,34 +60,36 @@ public class Reporter implements Closeable {
private Path outputfile;
private BufferedWriter writer;

/**
* Creates a new reporter using the directory specified in
* Reporter.REPORT_FOLDER
*/
public Reporter() {
this(null);
this(null, null);
}

public Reporter(String directory) {
initialize(directory);
public Reporter(String directory, String name) {
init(directory, name);
}

protected void initialize(String directory) {
if (directory == null) {
directory = ".";
protected void init(String directory, String name) {
// set defaults if needed
if (StringUtils.isBlank(name)) {
name = "dbptk-report-" + new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + ".txt";
}
String filenamePrefix = "dbptk-report-";
String filenameTimestamp = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
String filenameSuffix = ".txt";
outputfile = Paths.get(directory).toAbsolutePath().resolve(filenamePrefix + filenameTimestamp + filenameSuffix);
try {
outputfile = Files.createFile(outputfile);
} catch (IOException e) {
LOGGER.warn("Could not create report file in current working directory. Attempting to use a temporary file", e);

if (StringUtils.isBlank(directory)) {
outputfile = ConfigUtils.getReportsDirectory().resolve(name);
} else {
outputfile = Paths.get(directory).toAbsolutePath().resolve(name);
}

if (Files.notExists(outputfile)) {
try {
outputfile = Files.createTempFile(filenamePrefix, filenameSuffix);
} catch (IOException e1) {
LOGGER.error("Could not create report temporary file. Reporting will not function.", e1);
outputfile = Files.createFile(outputfile);
} catch (IOException e) {
LOGGER.warn("Could not create report file in current working directory. Attempting to use a temporary file", e);
try {
outputfile = Files.createTempFile("dbptk-report-", ".txt");
} catch (IOException e1) {
LOGGER.error("Could not create report temporary file. Reporting will not function.", e1);
}
}
}

Expand Down
Loading

0 comments on commit fd94bf2

Please sign in to comment.