-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
nbproject/private/ | ||
build/ | ||
nbbuild/ | ||
dist/ | ||
nbdist/ | ||
.nb-gradle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>nl.elstarit.document-conversion</groupId> | ||
<artifactId>document-conversion-api</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>document-conversion-api</name> | ||
<description>Project to convert documents to plain text</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.8.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<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> | ||
|
||
<dependency> | ||
<groupId>org.apache.tika</groupId> | ||
<artifactId>tika-core</artifactId> | ||
<version>1.16</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.5</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
12 changes: 12 additions & 0 deletions
12
src/main/java/nl/elstarit/documentconversion/api/DocumentConversionApiApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package nl.elstarit.documentconversion.api; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class DocumentConversionApiApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DocumentConversionApiApplication.class, args); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...main/java/nl/elstarit/documentconversion/api/controller/DocumentConversionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package nl.elstarit.documentconversion.api.controller; | ||
|
||
import nl.elstarit.documentconversion.api.model.DocumentConversionRequest; | ||
import nl.elstarit.documentconversion.api.model.DocumentConversionResponse; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.tika.metadata.Metadata; | ||
import org.apache.tika.parser.AutoDetectParser; | ||
import org.apache.tika.sax.BodyContentHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.InputStream; | ||
|
||
@Controller | ||
public class DocumentConversionController { | ||
|
||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DocumentConversionController.class); | ||
|
||
@RequestMapping("/convert-to-plain-text") | ||
public ResponseEntity<DocumentConversionResponse> covertToPlainText(@RequestBody DocumentConversionRequest documentConversionRequest){ | ||
BodyContentHandler handler = new BodyContentHandler(); | ||
|
||
AutoDetectParser parser = new AutoDetectParser(); | ||
Metadata metadata = new Metadata(); | ||
DocumentConversionResponse documentConversionResponse = new DocumentConversionResponse(); | ||
try{ | ||
if(documentConversionRequest.getFile() != null ) { | ||
InputStream stream = FileUtils.openInputStream(documentConversionRequest.getFile()); | ||
parser.parse(stream, handler, metadata); | ||
documentConversionResponse.setConvertedText(handler.toString()); | ||
}else{ | ||
documentConversionResponse.setMessage("No File found in request"); | ||
} | ||
}catch(Exception e){ | ||
LOG.error("Error on Document Conversion API: {}", e.getMessage()); | ||
} | ||
return new ResponseEntity<DocumentConversionResponse>(documentConversionResponse, HttpStatus.OK); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/nl/elstarit/documentconversion/api/model/DocumentConversionRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package nl.elstarit.documentconversion.api.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
import java.io.File; | ||
|
||
public class DocumentConversionRequest { | ||
|
||
@JsonIgnore | ||
private File file = null; | ||
|
||
@JsonIgnore | ||
private String media_type = ""; | ||
|
||
public void setFile(File file) { | ||
this.file = file; | ||
} | ||
public File getFile() { | ||
return file; | ||
} | ||
public void setMedia_type(String media_type) { | ||
this.media_type = media_type; | ||
} | ||
public String getMedia_type() { | ||
return media_type; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
DocumentConversionRequest that = (DocumentConversionRequest) o; | ||
|
||
if (file != null ? !file.equals(that.file) : that.file != null) return false; | ||
return media_type != null ? media_type.equals(that.media_type) : that.media_type == null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = file != null ? file.hashCode() : 0; | ||
result = 31 * result + (media_type != null ? media_type.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DocumentConversionRequest{" + | ||
"file=" + file + | ||
", media_type='" + media_type + '\'' + | ||
'}'; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/nl/elstarit/documentconversion/api/model/DocumentConversionResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package nl.elstarit.documentconversion.api.model; | ||
|
||
public class DocumentConversionResponse { | ||
|
||
private String convertedText; | ||
private String message; | ||
|
||
public String getConvertedText() { | ||
return convertedText; | ||
} | ||
|
||
public void setConvertedText(String convertedText) { | ||
this.convertedText = convertedText; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
DocumentConversionResponse that = (DocumentConversionResponse) o; | ||
|
||
return convertedText != null ? convertedText.equals(that.convertedText) : that.convertedText == null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return convertedText != null ? convertedText.hashCode() : 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DocumentConversionResponse{" + | ||
"convertedText='" + convertedText + '\'' + | ||
"message='" + message + '\'' + | ||
'}'; | ||
} | ||
} |
Empty file.
16 changes: 16 additions & 0 deletions
16
src/test/java/nl/elstarit/documentconversion/api/DocumentConversionApiApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nl.elstarit.documentconversion.api; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class DocumentConversionApiApplicationTests { | ||
|
||
@Test | ||
public void contextLoads() { | ||
} | ||
|
||
} |