Skip to content

Commit

Permalink
New data system
Browse files Browse the repository at this point in the history
  • Loading branch information
Litarvan committed Apr 3, 2018
1 parent c9985a6 commit dd12d47
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 176 deletions.
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
<one line to give the program's subject and a brief idea of what it does.>
Copyright (C) <year> <subject of author>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

<program> Copyright (C) <year> <name of author>
<program> Copyright (C) <year> <subject of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
13 changes: 6 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ repositories {
}

dependencies {
compile 'com.sparkjava:spark-core:2.7.1'
compile 'com.google.inject:guice:4.1.0'
compile 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.5.2'
compile 'com.sparkjava:spark-core:2.7.2'
compile 'com.google.inject:guice:4.2.0'

compile 'com.graphql-java:graphql-java:6.0'
compile 'com.graphql-java:graphql-java:8.0'

compile 'com.google.guava:guava:23.4-jre'
compile 'com.google.guava:guava:24.1-jre'
compile 'commons-io:commons-io:2.6'
compile 'net.sf.trove4j:trove4j:3.0.3'

compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.9.1'
compile 'org.apache.logging.log4j:log4j-core:2.9.1'
compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.11.0'
compile 'org.apache.logging.log4j:log4j-core:2.11.0'

compile 'fr.litarvan.commons:litarvan-commons:1.0.0'
}
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:subject=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/fr/litarvan/sakado/server/SakadoServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,8 @@ public void start()
}
}

log.info("Starting data service...");
try
{
data.init();
}
catch (IOException e)
{
log.fatal("Couldn't init UserManager service, shutting down...", e);
System.exit(1);
}

log.info("Starting data services...");
data.init();
refresh.start();

log.info("Configuring HTTP server...");
Expand Down
66 changes: 45 additions & 21 deletions src/main/java/fr/litarvan/sakado/server/data/DataServer.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,74 @@
package fr.litarvan.sakado.server.data;

import fr.litarvan.sakado.server.data.network.NetworkClient;
import com.google.gson.Gson;
import fr.litarvan.sakado.server.data.network.FetchRequest;
import fr.litarvan.sakado.server.data.network.FetchResponse;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class DataServer
{
private String name;
private String host;
private int port;
private static final Gson gson = new Gson();

private transient NetworkClient client;
private String name;
private String url;

public DataServer()
{
}

public DataServer(String name, String host, int port)
public DataServer(String name, String url)
{
this.name = name;
this.host = host;
this.port = port;
this.url = url;
}

public void init() throws IOException
public FetchResponse fetch(FetchRequest request) throws IOException
{
this.client = new NetworkClient(host, port);
}
URL url = new URL(this.url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

public NetworkClient getClient()
{
return this.client;
connection.setDoInput(true);
connection.setDoOutput(true);

connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");

try (DataOutputStream out = new DataOutputStream(connection.getOutputStream()))
{
out.write(gson.toJson(request).getBytes(StandardCharsets.UTF_8));
}

StringBuilder content = new StringBuilder();

try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())))
{
String line;

while ((line = in.readLine()) != null)
{
content.append(line).append(System.lineSeparator());
}
}

connection.disconnect();

return gson.fromJson(content.toString(), FetchResponse.class);
}

public String getName()
{
return name;
}

public String getHost()
{
return host;
}

public int getPort()
public String getUrl()
{
return port;
return url;
}
}
17 changes: 12 additions & 5 deletions src/main/java/fr/litarvan/sakado/server/data/Establishment.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,33 @@ public List<StudentClass> getClasses()
public static class FetchMethod
{
private String server;
private Map<String, String> params;
private String url;
private String cas;

public FetchMethod()
{
}

public FetchMethod(String server, Map<String, String> params)
public FetchMethod(String server, String url, String cas)
{
this.server = server;
this.params = params;
this.url = url;
this.cas = cas;
}

public String getServer()
{
return server;
}

public Map<String, String> getParams()
public String getUrl()
{
return params;
return url;
}

public String getCas()
{
return cas;
}
}
}
28 changes: 20 additions & 8 deletions src/main/java/fr/litarvan/sakado/server/data/Homework.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ public class Homework implements Identifiable
{
private String subject;
private String content;
private long time;
private long since;
private long until;

public Homework()
{
}

public Homework(String subject, String content, long time)
public Homework(String subject, String content, long since, long until)
{
this.subject = subject;
this.content = content;
this.time = time;
this.since = since;
this.until = until;
}

public String getSubject()
Expand All @@ -48,19 +50,29 @@ public String getContent()
return content;
}

public long getTime()
public long getSince()
{
return time;
return since;
}

public Calendar getTimeAsCalendar()
public Calendar getSinceAsCalendar()
{
return CalendarUtils.fromTimestamp(time);
return CalendarUtils.fromTimestamp(since);
}

public long getUntil()
{
return until;
}

public Calendar getUntilAsCalendar()
{
return CalendarUtils.fromTimestamp(until);
}

@Override
public String getId()
{
return "H" + time + getSubject().substring(0, 2) + getContent().substring(0, 5);
return "H" + since + "" + until + getSubject().substring(0, 2) + getContent().substring(0, 5);
}
}
18 changes: 9 additions & 9 deletions src/main/java/fr/litarvan/sakado/server/data/Lesson.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@

public class Lesson implements Identifiable
{
private String name;
private String subject;
private String teacher;
private String room;

private long from;
private long to;

private boolean away;
private String status;

public Lesson()
{
}

public Lesson(String name, String teacher, String room, long from, long to, boolean away)
public Lesson(String subject, String teacher, String room, long from, long to, String status)
{
this.name = name;
this.subject = subject;
this.teacher = teacher;
this.room = room;
this.from = from;
this.to = to;
this.away = away;
this.status = status;
}

public String getName()
public String getSubject()
{
return name;
return subject;
}

public String getTeacher()
Expand Down Expand Up @@ -81,9 +81,9 @@ public Calendar getToAsCalendar()
return CalendarUtils.fromTimestamp(to);
}

public boolean isAway()
public String getStatus()
{
return away;
return status;
}

@Override
Expand Down
33 changes: 27 additions & 6 deletions src/main/java/fr/litarvan/sakado/server/data/Mark.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,49 @@
public class Mark implements Identifiable
{
private String subject;
private String mark;
private String title;
private int value;
private int max;
private long time;
private int period;

public Mark()
{
}

public Mark(String subject, String mark, long time)
public Mark(String subject, String title, int value, int max, long time, int period)
{
this.subject = subject;
this.mark = mark;
this.title = title;
this.value = value;
this.max = max;
this.time = time;
this.period = period;
}

public String getSubject()
{
return subject;
}

public String getMark()
public String getTitle()
{
return mark;
return title;
}

public int getValue()
{
return value;
}

public int getMax()
{
return max;
}

public int getPeriod()
{
return period;
}

public long getTime()
Expand All @@ -61,6 +82,6 @@ public Calendar getTimeAsCalendar()
@Override
public String getId()
{
return "M" + getTime() + getSubject().substring(0, 2) + getMark();
return "M" + getTime() + getSubject().substring(0, 2) + getValue();
}
}
Loading

0 comments on commit dd12d47

Please sign in to comment.