Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite kernel in kotlin #12

Merged
merged 2 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ dmypy.json

# Pyre type checker
.pyre/

.idea

*.iml
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ WORKDIR /app
RUN mvn clean package

FROM amazoncorretto:17-alpine
ENV ROOM="Room"
ENV TEACHER="Teacher"
ENV SUMMARY="School"
ENV USERNAME="null"
ENV PASSWORD="null"
ENV SERVER="niobe.webuntis.com"
ENV SCHOOL="null"
ENV SSL="true"
ENV TOKEN="secret"

COPY --from=builder /app/target/app-jar-with-dependencies.jar /
EXPOSE 4567
CMD java -jar app-jar-with-dependencies.jar
EXPOSE 8080
CMD ["java", "-jar", "app-jar-with-dependencies.jar", "$ROOM", "$TEACHER", "$SUMMARY", "$USERNAME", "$USERNAME", "$PASSWORD", "$SERVER", "$SCHOOL", "$SSL", "$TOKEN"]

112 changes: 95 additions & 17 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
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>com.velocitypackage</groupId>
<artifactId>untiscalender</artifactId>
<groupId>com.velocitypackage.untiscalender</groupId>
<artifactId>app</artifactId>
<version>1.0</version>

<properties>
<kotlin.version>1.8.10</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -22,6 +24,11 @@
</repositories>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>com.github.untisapi</groupId>
<artifactId>untis4j</artifactId>
Expand All @@ -32,44 +39,115 @@
<artifactId>ical4j</artifactId>
<version>3.2.10</version>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.9.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>

<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core-jvm</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty-jvm</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-call-logging-jvm</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>

<build>
<finalName>app</finalName>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
<version>3.5.1</version>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<version>2.6</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<goals> <goal>single</goal> </goals>
<configuration>
<archive>
<manifest>
<mainClass>com.velocitypackage.untiscalender.Main</mainClass>
<mainClass>com.velocitypackage.untiscalender.app.AppKt</mainClass>
</manifest>
</archive>
<descriptorRefs>
Expand Down
70 changes: 0 additions & 70 deletions app/src/main/java/com/velocitypackage/untiscalender/Main.java

This file was deleted.

40 changes: 40 additions & 0 deletions app/src/main/java/com/velocitypackage/untiscalender/app/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.velocitypackage.untiscalender.app

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import org.slf4j.event.*

fun main(vararg args : String)
{
Config.defaultRoomAlias = args[0]
Config.defaultTeacherAlias = args[1]
Config.defaultSummary = args[2]
Config.username = args[3]
Config.password = args[4]
Config.server = args[5]
Config.school = args[6]
Config.ssl = args[7] == "true"
Config.token = args[8]
embeddedServer(Netty, port = 8080, module = Application::module).start(true)
}

fun Application.module()
{
install(CallLogging) {
level = Level.INFO
}
routing {
get("/by/{token}") {
if (call.parameters["token"] != Config.token) return@get call.respond(
HttpStatusCode.Unauthorized,
"Wrong access token!"
)
return@get call.respond(HttpStatusCode.OK, getUserSpecificTable().getCalender().toString())
}
}
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/velocitypackage/untiscalender/app/Config.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.velocitypackage.untiscalender.app

object Config
{
var defaultRoomAlias : String = "Room"
var defaultTeacherAlias : String = "Teacher"
var defaultSummary : String = "School"

var username : String = "null"
var password : String = "null"
var server : String = "null"
var school : String = "null"
var ssl : Boolean = true

fun getURL() : String
{
if (ssl) return "https://${server}" else return "http://${server}"
}

var token : String = "secret"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.velocitypackage.untiscalender.app

import org.bytedream.untis4j.Session
import org.bytedream.untis4j.responseObjects.Timetable

val session = Session.login(Config.username, Config.password, Config.getURL(), Config.school)

fun getUserSpecificTable() : Timetable
{
return session.getTimetableFromPersonId(session.currentSchoolYear.startDate, session.currentSchoolYear.endDate, session.infos.personId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.velocitypackage.untiscalender.app

import net.fortuna.ical4j.model.Calendar
import net.fortuna.ical4j.model.Date
import net.fortuna.ical4j.model.DateTime
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.CalScale
import net.fortuna.ical4j.model.property.Description
import net.fortuna.ical4j.model.property.ProdId
import net.fortuna.ical4j.model.property.Version
import org.bytedream.untis4j.UntisUtils
import org.bytedream.untis4j.responseObjects.Timetable
import java.time.ZoneId

fun Timetable.getCalender() : Calendar
{
val calendar = Calendar()
calendar.properties.add(ProdId("-//VelocityPackage//UntisCalender 1.0//EN"))
calendar.properties.add(Version.VERSION_2_0)
calendar.properties.add(CalScale.GREGORIAN)
for (lesson in this)
{
if (lesson.code == UntisUtils.LessonCode.CANCELLED) continue
var name = Config.defaultSummary
try
{
name = lesson.subjects.longNames[0]
} catch (_ : Exception) { }
val event = VEvent(
DateTime(Date.from(lesson.startTime.atDate(lesson.date).atZone(ZoneId.systemDefault()).toInstant())),
DateTime(Date.from(lesson.endTime.atDate(lesson.date).atZone(ZoneId.systemDefault()).toInstant())),
name
)
try
{
event.properties.add(Description("${Config.defaultRoomAlias}: ${lesson.rooms[0].longName} \n${Config.defaultTeacherAlias}: ${lesson.teachers[0].fullName}"))
} catch (_ : Exception) { }
calendar.components.add(
event
)
}
return calendar
}
Loading