Skip to content

Commit

Permalink
restructure github for CRAFT final report
Browse files Browse the repository at this point in the history
  • Loading branch information
greena12 committed Jun 21, 2023
1 parent 721aa55 commit 9e0e801
Show file tree
Hide file tree
Showing 326 changed files with 33,010 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'Testing Environment'/
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
/bin/
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Api-Handler</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=17
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM maven:3.8.6-eclipse-temurin-17-alpine

ENV APP_NAME api-handler
ENV PORT 8080
ENV OUTPUT /Documents/Handler-Output

EXPOSE ${PORT}

COPY ./ ./
RUN mvn clean package spring-boot:repackage -Dmaven.skip.test=true
CMD ["java", "-jar", "target/api-handler-0.0.1.jar"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.application</groupId>
<artifactId>api-handler</artifactId>
<version>0.0.1</version>
<name>api-handler</name>
<description>Lightweight application for retrieving generalized api calls.</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220924</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>

<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package org.application.apihandler;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeSet;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@EnableAutoConfiguration
@EnableWebMvc
@Configuration
@ComponentScan
public class ApiHandlerApplication {

// define default output
// System.getProperty("user.home") +
private static final String DEFAULT_OUTPUT = "/data";//String.format("/Users/%s/Documents/DeFi-Data", System.getProperty("user.name"));

private static final HashMap<String, BufferedWriter> writers = new HashMap<String, BufferedWriter>();
private static final HashMap<String, ArrayList<HashMap<String, String>>> buffers = new HashMap<String, ArrayList<HashMap<String, String>>>();
private static final HashMap<String, TreeSet<String>> headers = new HashMap<String, TreeSet<String>>();

private static final void initialize() {
// retrieve home directory and path to default output
File dir = new File(DEFAULT_OUTPUT);
// validate that it is a directory and if not then create
if(!dir.exists() || !dir.isDirectory())
dir.mkdir();
}

public final static void lock(String name) {
if(!writers.containsKey(name)) {
try {
String file_name = DEFAULT_OUTPUT + "/" + name + ".csv";
File file = new File(file_name);
if(!file.getParentFile().exists())
file.getParentFile().mkdirs();
if(!file.exists())
file.createNewFile();
else {
file.delete();
file.createNewFile();
}
writers.put(name, new BufferedWriter(new FileWriter(file)));
buffers.put(name, new ArrayList<HashMap<String, String>>());
headers.put(name, new TreeSet<String>());
} catch (FileNotFoundException e) {
e.printStackTrace();
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
}

public final static void unlock(String name) {
if(writers.containsKey(name)) {
try {
// retrieve writer
BufferedWriter writer = writers.get(name);

// write all column headers
Iterator<String> header_itr = headers.get(name).iterator();
while(header_itr.hasNext()) {
writer.write(header_itr.next());
if(header_itr.hasNext())
writer.write(",");
}

// new line
writer.write("\n");

// write to file using formatted headers
ArrayList<HashMap<String, String>> buffer = buffers.get(name);
for(int i = 0; i < buffer.size(); i++) {
StringBuilder line = new StringBuilder();

// loop through all headers and format
for(String header : headers.get(name)) {
if(buffer.get(i).containsKey(header)) {
line.append(buffer.get(i).get(header).replaceAll(",", "|"));
}

line.append(",");
}

// write line to file
line.delete(line.length() - 1, line.length());
writer.write(line.toString());

// new line
if(i != buffer.size() - 1)
writer.write("\n");
}

// close output loop
writers.get(name).close();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}

writers.remove(name);
}

public final static void output(String name, HashMap<String, String> data) {
if(!writers.containsKey(name) || !buffers.containsKey(name) || !headers.containsKey(name)) {
lock(name);
}

// add all headers
for(String header : data.keySet())
headers.get(name).add(header);

// push data to buffers
buffers.get(name).add(data);
}

public static void main(String[] args) {
// load in output directory
initialize();

SpringApplication.run(ApiHandlerApplication.class, args);
}
}
Loading

0 comments on commit 9e0e801

Please sign in to comment.