Skip to content

Commit

Permalink
upgrade to scala 2.13 and sbt 1.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Boaz Cahlon committed Oct 16, 2021
1 parent 845d1e9 commit 1de5a67
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ This tool downloads all your Hilan payslips and creates a spreadsheet out of the
## How To Run

Download the project, open it in your favorite IDE and run `Main.scala`.
\* Java 8 and Scala 11 is required
\* Java 11 and Scala 2.13 is required

Or

Download the fat jar and run it from the shell with `java -jar pdfparser-assembly-1.0.jar`.
Download the fat jar and run it from the shell with `java -jar pdfparser-assembly-1.5.5.jar`.

### GUI
1. Run without arguments
Expand All @@ -27,5 +27,5 @@ Run with at least one argument and it will ask for the rest (you can just put -w

#### Parsing Without Downloading
If you already have all your payslips and want to parse them to a spreadsheet, run with only the path argument:
`java -jar pdfparser-assembly-1.0.jar --path /Users/you/payslip/folder`.
`java -jar pdfparser-assembly-1.5.5.jar --path /Users/you/payslip/folder`.
\* don't put other documents in the folder
22 changes: 11 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name := "pdfparser"

version := "1.0"
version := "1.5.5"

scalaVersion := "2.11.8"
scalaVersion := "2.13.6"

libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % "1.7.5",
"org.slf4j" % "slf4j-simple" % "1.7.5",
"com.itextpdf" % "itextpdf" % "5.3.2" ,
"org.slf4j" % "slf4j-api" % "1.7.32",
"org.slf4j" % "slf4j-simple" % "1.7.32",
"com.itextpdf" % "itextpdf" % "5.5.13.2" ,
"org.bouncycastle" % "bcprov-jdk15on" % "1.47" ,
"org.bouncycastle" % "bcmail-jdk15on" % "1.47" ,
"org.apache.poi" % "poi" % "3.15" ,

"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.13.0",

"net.sourceforge.htmlunit" % "htmlunit" % "2.26" ,
"net.sourceforge.htmlunit" % "htmlunit" % "2.53.0" ,

"org.specs2" %% "specs2-core" % "3.7" % "test" ,
"org.specs2" %% "specs2-junit" % "3.7" % "test" ,
"org.specs2" %% "specs2-matcher-extra" % "3.7" % "test" ,
"org.specs2" %% "specs2-mock" % "3.7" % "test" ,
"org.specs2" %% "specs2-scalacheck" % "3.7" % "test"
"org.specs2" %% "specs2-core" % "4.13.0" % "test" ,
"org.specs2" %% "specs2-junit" % "4.13.0" % "test" ,
"org.specs2" %% "specs2-matcher-extra" % "4.13.0" % "test" ,
"org.specs2" %% "specs2-mock" % "4.13.0" % "test" ,
"org.specs2" %% "specs2-scalacheck" % "4.13.0" % "test"
)

assemblyMergeStrategy in assembly := {
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion project/assembly.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
6 changes: 3 additions & 3 deletions src/main/scala/clients/AuthenticatedClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import com.gargoylesoftware.htmlunit.{HttpMethod, Page, WebClient, WebRequest}
import org.slf4j.LoggerFactory
import scrape.NoDataFoundException
import scala.collection.JavaConversions._
import scala.jdk.CollectionConverters._

import scala.util.{Failure, Success, Try}

Expand Down Expand Up @@ -52,15 +52,15 @@ class AuthenticatedClient(webClient: WebClient, username: String, orgId: String,

private def getDatesFromPaySlipJson(jsonString: String): Seq[HilanDate] = {
val json = mapper.readTree(jsonString)
json.get("PaySlipDates").iterator.map((date: JsonNode) => {
json.get("PaySlipDates").iterator.asScala.map((date: JsonNode) => {
val parts = date.get("Id").asText.split("/")
HilanDate(1, parts(0).toInt, parts(1).toInt)
}).toList
}

private def getDatesFrom106Json(jsonString: String): Seq[HilanDate] = {
val json = mapper.readTree(jsonString)
json.get("Dates").iterator.map((date: JsonNode) => {
json.get("Dates").iterator.asScala.map((date: JsonNode) => {
val year = date.asText.toInt
HilanDate(1, 1, year)
}).toList
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/data/DataExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ object DataExtractor {

def parse(payslips: Seq[String]): Map[Key, Map[Date, Value]] =
payslips.flatMap(extractRelevantData)
.groupBy(_.key).mapValues(_
.groupBy(_.date).mapValues(_
.head.value))
.groupBy(_.key).view.mapValues(_
.groupBy(_.date).view.mapValues(_
.head.value).toMap).toMap

private def extractRelevantData(payslip: String): Seq[UniqueValue] = {
val date = getDate(payslip)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/parser/Parser.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package parser

import java.io.File
import java.io.{File, FileInputStream}
import java.nio.file.Paths

import com.itextpdf.text.pdf.PdfReader
Expand All @@ -27,7 +27,7 @@ object Parser {
}

private def getPayslipText(filename: String) = {
val reader = new PdfReader(filename)
val reader = new PdfReader(new FileInputStream(filename))
val numberOfPages = reader.getNumberOfPages
val payslip = new StringBuilder
for (i <- 0 until numberOfPages) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scrape/Scraper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Scraper(authenticatedClient: AuthenticatedClient) {
if (!Files.isDirectory(Paths.get(localFolderPath))) Files.createDirectory(Paths.get(localFolderPath))
val localFileDestination = new java.io.File(Paths.get(localFolderPath, localFileName).toString)
val out = new BufferedOutputStream(new FileOutputStream(localFileDestination))
val byteArray = Stream.continually(remoteFile.read).takeWhile(_ != -1).map(_.toByte).toArray
val byteArray = LazyList.continually(remoteFile.read).takeWhile(_ != -1).map(_.toByte).toArray
out.write(byteArray)
out.flush()
out.close()
Expand Down

0 comments on commit 1de5a67

Please sign in to comment.