Skip to content

Commit

Permalink
Add Dockerfile for application.
Browse files Browse the repository at this point in the history
Add Application Event listeners for debugging.
Add H2 DB for Sprint 0
Add first Kdoc Entity
Add sample schema and data for testing
  • Loading branch information
davedavis committed Feb 21, 2022
1 parent 72094cf commit ce94d88
Show file tree
Hide file tree
Showing 14 changed files with 357 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ build/
/.mvn/
/mvnw
/mvnw.cmd
/secrets/
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM maven:3.8.4-openjdk-11-slim as BUILDER
ARG VERSION=0.0.1-SNAPSHOT
WORKDIR /build/
COPY pom.xml /build/
COPY src /build/src/

RUN mvn clean package
COPY target/Klutter-${VERSION}.jar target/application.jar

FROM openjdk:11.0.8-jre-slim
WORKDIR /app/

COPY --from=BUILDER /build/target/application.jar /app/
CMD java -jar /app/application.jar
6 changes: 5 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ https://davedavis.atlassian.net/jira/software/c/projects/PDFIT/boards/4/backlog
-


## ToDo
Add user, title, excerpt, byline, content, ease, grade and tag array to model.



## Ideas
- WaveNet service
- WaveNet service
- Text analytics and sentiment analysis service
32 changes: 31 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@
<properties>
<java.version>11</java.version>
</properties>




<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
Expand All @@ -35,7 +45,6 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
Expand Down Expand Up @@ -117,7 +126,28 @@
<version>5.1.0</version>
</dependency>

<!--Asure Analytics for text analysis-->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-textanalytics</artifactId>
<version>5.1.5</version>
</dependency>


<!-- Some text utils -->
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-text -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>

<!-- Swagger dependency for API documentation -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>



Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.klutter.declutterservice;
package io.klutter;

import io.github.bonigarcia.wdm.WebDriverManager;
import io.whelk.flesch.kincaid.ReadabilityCalculator;
import net.dankito.readability4j.Readability4J;
import okhttp3.HttpUrl;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.safety.Safelist;
Expand All @@ -17,9 +16,9 @@

@RestController
@RequestMapping("/api/v1")
public class DeclutterService {
public class DocumentService {

@RequestMapping("/declutter")
@RequestMapping("/documents")
public String index() throws IOException {

String url = "https://realpython.com/python-sockets/";
Expand Down Expand Up @@ -68,6 +67,10 @@ public String index() throws IOException {
// Check it's working
System.out.println(ease + " " + grade);

// Testing the sizing of the document for Azure
// System.out.println(">>>>>>>>>>>>>>>>>>>>>> " + extractedContentPlainText.length());
// System.out.println(">>>>>>>>>>>>>>>>>>>>>> " + WordUtils.wrap(extractedContentPlainText, 40));

// ToDo: Add user, title, excerpt, byline, content, ease, grade and tag array to model.

// Return the clean HTML
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/io/klutter/KlutterApplication.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
package io.klutter;

import io.klutter.dao.KdocRepository;
import io.klutter.entity.Kdoc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;

//Add the scanBasePackages parameter to the annotation as I added my services in
//separate packages so, they need to be configured on application start.
@SpringBootApplication(scanBasePackages = {"io.klutter.declutterservice", "io.klutter.pdfservice"} )
@SpringBootApplication(scanBasePackages = {"io.klutter.declutterservice", "io.klutter.pdfservice", "io.klutter.dao"} )
public class KlutterApplication {

private final KdocRepository kdocRepository;

public KlutterApplication(KdocRepository kdocRepository) {
this.kdocRepository = kdocRepository;
}

public static void main(String[] args) {
SpringApplication.run(KlutterApplication.class, args);
System.out.println("Application Running: http://localhost:8080");
}

// So I can visualize data access working.
// So I can wait for Spring to set up the DB before I start playing around with DB.
@EventListener(ApplicationReadyEvent.class)
public void EventListenerExecute() {
Iterable<Kdoc> kdocs = this.kdocRepository.findAll();
kdocs.forEach(System.out::println);
}

}
22 changes: 22 additions & 0 deletions src/main/java/io/klutter/SpringFoxConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.klutter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class SpringFoxConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}

}
12 changes: 12 additions & 0 deletions src/main/java/io/klutter/dao/KdocRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.klutter.dao;

import io.klutter.entity.Kdoc;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface KdocRepository extends CrudRepository<Kdoc, Long> {

// Additional non-CRUD related methods.

}
134 changes: 134 additions & 0 deletions src/main/java/io/klutter/entity/Kdoc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package io.klutter.entity;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "Kdoc")
public class Kdoc implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "title")
private String title;

@Column(name = "url")
private String url;

@Column(name = "excerpt")
private String excerpt;

@Column(name = "byline")
private String byline;

@Column(name = "content")
private String content;

@Column(name = "ease")
private Float ease;

@Column(name = "grade")
private Float grade;

@Column(name = "pdf")
@Lob
private String pdf;


public Kdoc() {
}

public Kdoc(String url, String title, String excerpt, String byline, String content, Float ease, Float grade, String pdf) {
this.title = title;
this.url = url;
this.excerpt = excerpt;
this.byline = byline;
this.content = content;
this.ease = ease;
this.grade = grade;
this.pdf = pdf;
}

public Long getId() {
return id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getUrl() { return url;}

public void setUrl(String url) { this.url = url; }

public String getExcerpt() {
return excerpt;
}

public void setExcerpt(String excerpt) {
this.excerpt = excerpt;
}

public String getByline() {
return byline;
}

public void setByline(String byline) {
this.byline = byline;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public Float getEase() {
return ease;
}

public void setEase(Float ease) {
this.ease = ease;
}

public Float getGrade() {
return grade;
}

public void setGrade(Float grade) {
this.grade = grade;
}

public String getPdf() {
return pdf;
}

public void setPdf(String pdf) {
this.pdf = pdf;
}


@Override
public String toString() {
return "Kdoc{" +
"id=" + id +
", title='" + title + '\'' +
", url='" + url + '\'' +
", excerpt='" + excerpt + '\'' +
", byline='" + byline + '\'' +
", content='" + content + '\'' +
", ease=" + ease +
", grade=" + grade +
", pdf='" + pdf + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.klutter.textanalytics;


// Encapsulation of 3rd party API from Azure. This API tends to change over time (typical MS)
// this way, I can isolate the impacteded code if something changes.

public class TextAnalyticsService {
}
13 changes: 13 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
logging.level.org.hibernate.tool.hbm2ddl=DEBUG
logging.level.org.hibernate.SQL=DEBUG

# So Swagger doesn't give out.
spring.mvc.pathmatch.matching-strategy=ant_path_matcher


# ToDo: Remove for production
# For logging H2 during dev.
logging.level.org.springframework.jdbc.datasource.init.ScriptUtils=debug

# Tell JPA that I'll handle the schema, just connect to the DB.
spring.jpa.hibernate.ddl-auto=none

2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server:
port: 8080
3 changes: 3 additions & 0 deletions src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring:
application:
name: Klutter
Loading

0 comments on commit ce94d88

Please sign in to comment.