Skip to content

Commit

Permalink
added app code
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven committed May 26, 2022
1 parent 034fdfc commit 0e5a39a
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 0 deletions.
88 changes: 88 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.svedie</groupId>
<artifactId>mayan_edms_export</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Mayan EDMS Dokument Exporter</name>
<url>http://svedie.de</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.3</version>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>Mayan EDMS Exporter</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>de.svedie.mayan_edms_export.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
79 changes: 79 additions & 0 deletions src/main/java/de/svedie/mayan_edms_export/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package de.svedie.mayan_edms_export;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
* Exports the Mayan EDMS files.
*/
public class App {

public static void main(String[] args) throws SQLException, IOException {

if (args.length < 5) {
System.out.println(
"please enter the parameters \n1. database ip and database (example:192.168.0.2/mayan) \n2. database user \n3. database password \n4. mayan document directory \n5. export directory");
System.exit(0);
}

System.out.println("programm started ...");

System.out.println("connecting to the database ...");
String url = "jdbc:postgresql://" + args[0] + "?user=" + args[1] +
"&password=" + args[2];
Connection connection = DriverManager.getConnection(url);

System.out.println("connection successfull ...");

System.out.println("querying database table documents_documentfile ...");
Statement statement = connection.createStatement();
ResultSet query = statement
.executeQuery("select file, document_id, filename from documents_documentfile order by document_id");

List<Triple<String, Integer, String>> files = new ArrayList<>();
while (query.next()) {
String file = query.getString("file");
int id = query.getInt("document_id");
String filename = query.getString("filename");

String absolutePath = Paths.get(args[3] + file).toFile().getAbsolutePath();

Triple<String, Integer, String> filetriple = new Triple<>(absolutePath, id,
filename);
files.add(filetriple);
}

if (files.size() > 0) {
System.out.println(files.size() + " records in the database found ...");
}

System.out.println("starting copy process ...");
for (Triple<String, Integer, String> file : files) {
Path newdir = Path.of(args[4]);
try {
Files.copy(Path.of(file.getFile()), newdir.resolve(file.getFilename()));
} catch (Exception e) {
System.out.println("duplicate file: " + file.getFile() + " -#- filename: " +
file.getFilename());
}
}

System.out.println("copy process finished ...");

try {
System.out.println("closing the database connection ...");
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/de/svedie/mayan_edms_export/Triple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.svedie.mayan_edms_export;

/**
* Holds the information about the files.
*/
public class Triple<F, I, N> {

private final String file;
private final Integer id;
private final String filename;

public Triple(String file, Integer id, String filename) {
this.file = file;
this.id = id;
this.filename = filename;
}

public String getFile() {
return file;
}

public Integer getId() {
return id;
}

public String getFilename() {
return filename;
}
}

0 comments on commit 0e5a39a

Please sign in to comment.