From 344a5a37e4b70f67d0345c4314f4cfbdb3058794 Mon Sep 17 00:00:00 2001 From: Daniel Gerhardt <code@dgerhardt.net> Date: Fri, 1 Feb 2019 18:14:11 +0100 Subject: [PATCH] Remove obsolete Java application --- .gitignore | 1 - pom.xml | 77 ------ .../de/thm/arsnova/setuptool/Application.java | 227 ------------------ src/main/resources/application-context.xml | 20 -- 4 files changed, 325 deletions(-) delete mode 100644 pom.xml delete mode 100644 src/main/java/de/thm/arsnova/setuptool/Application.java delete mode 100644 src/main/resources/application-context.xml diff --git a/.gitignore b/.gitignore index a76e3f3..bc3c72e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .* -target/* *.pyc diff --git a/pom.xml b/pom.xml deleted file mode 100644 index aa82d34..0000000 --- a/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ -<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.thm.arsnova</groupId> - <artifactId>setuptool</artifactId> - <version>0.0.1-SNAPSHOT</version> - <description> </description> - <repositories> - <repository> - <id>thmrepo</id> - <name>THM Maven Repository</name> - <url>http://maven.mni.thm.de/content/repositories</url> - </repository> - <repository> - <id>thmreposnapshots</id> - <name>THM Maven Snapshot Repository</name> - <url>http://maven.mni.thm.de/content/repositories/snapshots</url> - </repository> - <repository> - <id>thmmirror</id> - <name>THM Maven Mirror</name> - <url>http://maven.mni.thm.de/content/groups/public</url> - </repository> - <repository> - <id>sonatypesnapshots</id> - <name>Sonatype Snapshot Repository</name> - <url>https://oss.sonatype.org/content/repositories/snapshots/</url> - </repository> - </repositories> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.5.1</version> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-assembly-plugin</artifactId> - <version>2.3</version> - <configuration> - <archive> - <manifest> - <mainClass>de.thm.arsnova.setuptool.Application</mainClass> - </manifest> - </archive> - <descriptorRefs> - <descriptorRef>jar-with-dependencies</descriptorRef> - </descriptorRefs> - <finalName>setuptool</finalName> - <appendAssemblyId>false</appendAssemblyId> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>3.1.2.RELEASE</version> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <version>4.2.1</version> - </dependency> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-mapper-lgpl</artifactId> - <version>1.9.9</version> - </dependency> - </dependencies> -</project> \ No newline at end of file diff --git a/src/main/java/de/thm/arsnova/setuptool/Application.java b/src/main/java/de/thm/arsnova/setuptool/Application.java deleted file mode 100644 index 5db80ff..0000000 --- a/src/main/java/de/thm/arsnova/setuptool/Application.java +++ /dev/null @@ -1,227 +0,0 @@ -package de.thm.arsnova.setuptool; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.JarURLConnection; -import java.util.Collections; -import java.util.Map; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.util.EntityUtils; -import org.codehaus.jackson.map.ObjectMapper; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.core.io.ClassPathResource; -import org.springframework.stereotype.Component; - -@Component -public class Application { - - private String databaseHost; - private String databasePort; - private String databaseName; - private String databaseUser; - private String databasePasswd; - - private final HttpClient httpClient = new DefaultHttpClient(); - - @Value("${couchdb.host}") - public final void setDatabaseHost(String databaseHost) { - this.databaseHost = databaseHost; - } - - @Value("${couchdb.port}") - public final void setDatabasePort(String databasePort) { - this.databasePort = databasePort; - } - - @Value("${couchdb.name}") - public final void setDatabaseName(String databaseName) { - this.databaseName = databaseName; - } - - @Value("${couchdb.username}") - public final void setDatabaseUsername(String databaseUser) { - this.databaseUser = databaseUser; - } - - @Value("${couchdb.password}") - public final void setDatabasePasswd(String databasePasswd) { - this.databasePasswd = databasePasswd; - } - - public static void main(String[] args) throws IOException { - ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml"); - Application app = context.getBean(Application.class); - - app.startup(); - } - - public void startup() { - // Create Database if not exists - if (this.createDatabase()) { - System.out.println("Database exists or has been created"); - } - - try { - JarURLConnection url = (JarURLConnection) new ClassPathResource("views").getURL().openConnection(); - JarFile jar = url.getJarFile(); - for (JarEntry entry : Collections.list(jar.entries())) { - if (! entry.getName().startsWith("views/")) continue; - if (entry.isDirectory()) continue; - - String fileName = entry.getName(); - String viewName = fileName.substring(fileName.indexOf("/") + 1); - System.out.println("> Processing view '" + viewName + "'"); - - String contents = readFileContents(jar.getInputStream(entry)); - setupView(viewName, contents); - } - } catch (Exception e) { - System.out.println("An error occured on view setup process"); - } - } - - private String readFileContents(InputStream inputStream) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - StringBuilder sb = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - sb.append(line); - } - reader.close(); - return sb.toString(); - } - - private void setupView(String documentName, String viewCode) { - if (documentExists(documentName)) { - deleteDocument(documentName); - createDocument(documentName, viewCode); - System.out.println("Design document '" + documentName + "' has been updated"); - return; - } - - if (createDocument(documentName, viewCode)) - System.out.println("Design document '" + documentName + "' has been created"); - } - - private String getDocumentUri(String documentName) { - return this.getDatabaseUri() + "/_design/" + documentName; - } - - private boolean documentExists(String documentName) { - try { - HttpGet get = new HttpGet(this.getDocumentUri(documentName)); - HttpResponse response = httpClient.execute(get); - EntityUtils.consume(response.getEntity()); - if (response.getStatusLine().getStatusCode() == 200) - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - - return false; - } - - private String documentRev(String documentName) { - try { - HttpGet get = new HttpGet(this.getDocumentUri(documentName)); - HttpResponse getResponse = httpClient.execute(get); - String document = EntityUtils.toString(getResponse.getEntity()); - EntityUtils.consume(getResponse.getEntity()); - ObjectMapper mapper = new ObjectMapper(); - @SuppressWarnings("unchecked") - Map<String, Object> documentData = mapper.readValue(document, Map.class); - return documentData.get("_rev").toString(); - } catch (Exception e) { - } - return null; - } - - private boolean deleteDocument(String documentName) { - try { - HttpDelete delete = new HttpDelete(this.getDocumentUri(documentName) + "?rev=" + documentRev(documentName)); - HttpResponse response = httpClient.execute(delete); - EntityUtils.consume(response.getEntity()); - if (response.getStatusLine().getStatusCode() == 204) - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - - return false; - } - - private boolean createDocument(String documentName, String contents) { - try { - HttpPost post = new HttpPost(this.getDatabaseUri()); - StringEntity entity = new StringEntity(contents, ContentType.create("application/json", "UTF-8")); - post.setEntity(entity); - HttpResponse response = httpClient.execute(post); - EntityUtils.consume(response.getEntity()); - if (response.getStatusLine().getStatusCode() == 201) - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - - return false; - } - - private String getDatabaseUri() { - if (databaseUser.isEmpty() && databasePasswd.isEmpty()) { - return "http://" + databaseHost + ":" + databasePort + "/" + databaseName; - } - - return "http://" + databaseUser + ":" + databasePasswd + "@" + databaseHost + ":" + databasePort + "/" - + databaseName; - } - - private boolean databaseExists() { - try { - HttpGet get = new HttpGet(this.getDatabaseUri()); - HttpResponse response = httpClient.execute(get); - EntityUtils.consume(response.getEntity()); - if (response.getStatusLine().getStatusCode() == 200) - return true; - } catch (Exception e) { - return false; - } - - return false; - } - - private boolean createDatabase() { - if (databaseExists()) - return true; - - try { - HttpPut put = new HttpPut(this.getDatabaseUri()); - put.setHeader("Content-Type", "application/json"); - HttpResponse response = httpClient.execute(put); - EntityUtils.consume(response.getEntity()); - if (response.getStatusLine().getStatusCode() == 201) - return true; - } catch (Exception e) { - return false; - } - - return false; - } -} diff --git a/src/main/resources/application-context.xml b/src/main/resources/application-context.xml deleted file mode 100644 index 75ca351..0000000 --- a/src/main/resources/application-context.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:context="http://www.springframework.org/schema/context" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> - - <context:component-scan base-package="de.thm.arsnova" /> - - <bean id="propertyPlaceholderConfigurer" - class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> - <property name="locations"> - <list> - <value>file:///etc/arsnova/arsnova.properties</value> - </list> - </property> - <property name="ignoreUnresolvablePlaceholders" value="false"/> - <property name="ignoreResourceNotFound" value="true"/> - </bean> -</beans> -- GitLab