Skip to content

Commit

Permalink
Merge pull request #21 from diging/develop
Browse files Browse the repository at this point in the history
prepare release
  • Loading branch information
jdamerow authored Jul 12, 2018
2 parents 24d511a + 005476d commit 53267ec
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 120 deletions.
28 changes: 15 additions & 13 deletions cepheus/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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"
<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>edu.asu.diging.giles-eco</groupId>
Expand All @@ -11,10 +12,10 @@
<org.slf4j-version>1.7.5</org.slf4j-version>
<org.springframework-version>4.3.1.RELEASE</org.springframework-version>
<spring-security-version>4.1.3.RELEASE</spring-security-version>
<geco.requests.version>0.6</geco.requests.version>
<geco.util.version>0.4.2</geco.util.version>
<geco.requests.version>0.8</geco.requests.version>
<geco.util.version>0.5</geco.util.version>
<geco.cepheus.version>0.2.2-SNAPSHOT</geco.cepheus.version>
<geco.kafka-util.version>0.1</geco.kafka-util.version>
<geco.kafka-util.version>0.2</geco.kafka-util.version>
<geco.september.util.version>0.2</geco.september.util.version>

<admin.password>admin</admin.password>
Expand All @@ -40,29 +41,30 @@
<pdf.conversion.type>RGB</pdf.conversion.type>
<pdf.conversion.format>tiff</pdf.conversion.format>

<!-- Zookeeper -->
<zookeeper.host>localhost</zookeeper.host>
<zookeeper.port>2181</zookeeper.port>
</properties>

<dependencies>

<!-- Giles Ecosystem -->
<dependency>
<groupId>edu.asu.diging.giles-eco</groupId>
<artifactId>requests</artifactId>
<groupId>edu.asu.diging</groupId>
<artifactId>giles-eco-requests</artifactId>
<version>${geco.requests.version}</version>
</dependency>

<dependency>
<groupId>edu.asu.diging.giles-eco</groupId>
<artifactId>util</artifactId>
<groupId>edu.asu.diging</groupId>
<artifactId>giles-eco-util</artifactId>
<version>${geco.util.version}</version>
</dependency>

<dependency>
<groupId>edu.asu.diging.giles-eco</groupId>
<artifactId>kafka-util</artifactId>
<groupId>edu.asu.diging</groupId>
<artifactId>giles-eco-kafka-util</artifactId>
<version>${geco.kafka-util.version}</version>
</dependency>

<dependency>
<groupId>edu.asu.diging.giles-eco</groupId>
<artifactId>september-util</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.kafka.annotation.KafkaListener;
Expand All @@ -16,16 +14,19 @@
import edu.asu.diging.gilesecosystem.cepheus.service.pdf.IImageExtractionManager;
import edu.asu.diging.gilesecosystem.requests.IImageExtractionRequest;
import edu.asu.diging.gilesecosystem.requests.impl.ImageExtractionRequest;
import edu.asu.diging.gilesecosystem.septemberutil.properties.MessageType;
import edu.asu.diging.gilesecosystem.septemberutil.service.ISystemMessageHandler;

@PropertySource("classpath:/config.properties")
public class ExtractionRequestReceiver {

private final Logger logger = LoggerFactory.getLogger(getClass());

@Autowired
private ISystemMessageHandler messageHandler;

@Autowired
private IImageExtractionManager imageExtractionManager;
@KafkaListener(id="cepheus.extraction", topics = {"${topic_extract_images_request}"})

@KafkaListener(id = "cepheus.extraction", topics = { "${topic_extract_images_request}" })
public void receiveMessage(String message, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {
extractImage(message);
}
Expand All @@ -36,16 +37,15 @@ private void extractImage(String message) {
try {
request = mapper.readValue(message, ImageExtractionRequest.class);
} catch (IOException e) {
logger.error("Could not unmarshall request.", e);
messageHandler.handleMessage("Could not unmarshell request", e, MessageType.ERROR);
// FIXME: handle this case
return;
}

try {
imageExtractionManager.extractImages(request);
} catch (CepheusExtractionException e) {
logger.error("Could not extract text.");
// FIXME: send to monitoring app
messageHandler.handleMessage("Could not extract text.", e, MessageType.ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,59 @@
import javax.servlet.http.HttpServletResponse;

import org.apache.tika.Tika;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import edu.asu.diging.gilesecosystem.septemberutil.properties.MessageType;
import edu.asu.diging.gilesecosystem.septemberutil.service.ISystemMessageHandler;
import edu.asu.diging.gilesecosystem.util.files.IFileStorageManager;

@RestController
public class DownloadFileController {

private final Logger logger = LoggerFactory.getLogger(getClass());


public final static String FILENAME_PLACEHOLDER = "{filename:.+}";
public final static String DOCUMENT_ID_PLACEHOLDER = "{documentId}";
public final static String REQUEST_ID_PLACEHOLDER = "{requestId}";
public final static String GET_FILE_URL = "/rest/texts/" + REQUEST_ID_PLACEHOLDER + "/" + DOCUMENT_ID_PLACEHOLDER + "/" + FILENAME_PLACEHOLDER;

public final static String GET_FILE_URL = "/rest/texts/" + REQUEST_ID_PLACEHOLDER + "/" + DOCUMENT_ID_PLACEHOLDER
+ "/" + FILENAME_PLACEHOLDER;

@Autowired
private IFileStorageManager storageManager;

@Autowired
private ISystemMessageHandler messageHandler;

@RequestMapping(value = GET_FILE_URL)
public ResponseEntity<String> getFile(
@PathVariable String filename, @PathVariable String documentId, @PathVariable String requestId,
HttpServletResponse response,
HttpServletRequest request) {
public ResponseEntity<String> getFile(@PathVariable String filename, @PathVariable String documentId,
@PathVariable String requestId, HttpServletResponse response, HttpServletRequest request) {

byte[] content = storageManager.getFileContent(requestId, documentId, null, filename);

if (content == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
storageManager.deleteFile(requestId, documentId, null, filename, true);

String contentType = null;
if (content != null) {
Tika tika = new Tika();
contentType = tika.detect(content);
}
}

if (contentType != null) {
response.setContentType(contentType);
}
response.setContentLength(content.length);
response.setHeader("Content-disposition", "filename=\"" + filename + "\"");
response.setHeader("Content-disposition", "filename=\"" + filename + "\"");
try {
response.getOutputStream().write(content);
response.getOutputStream().close();
} catch (IOException e) {
logger.error("Could not write to output stream.", e);
messageHandler.handleMessage("Could not write to output stream.", e, MessageType.ERROR);
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
import edu.asu.diging.gilesecosystem.cepheus.service.Properties;
import edu.asu.diging.gilesecosystem.util.files.IFileStorageManager;
import edu.asu.diging.gilesecosystem.util.properties.IPropertiesManager;
import edu.asu.diging.gilesecosystem.septemberutil.properties.MessageType;
import edu.asu.diging.gilesecosystem.septemberutil.service.ISystemMessageHandler;

public class AExtractionManager {

protected final Logger logger = LoggerFactory.getLogger(getClass());

@Autowired
protected IFileStorageManager fileStorageManager;



@Autowired
private ISystemMessageHandler messageHandler;

@Autowired
protected IPropertiesManager propertiesManager;

Expand All @@ -41,18 +45,16 @@ public byte[] downloadFile(String url) {
headers.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));
HttpEntity<String> entity = new HttpEntity<String>(headers);

ResponseEntity<byte[]> response = restTemplate.exchange(url, HttpMethod.GET,
entity, byte[].class);
ResponseEntity<byte[]> response = restTemplate.exchange(url, HttpMethod.GET, entity, byte[].class);
if (response.getStatusCode().equals(HttpStatus.OK)) {
return response.getBody();
}
return null;
}

protected Page saveTextToFile(int pageNr, String requestId,
String documentId, String pageText, String filename, String fileExtentions) {
String docFolder = fileStorageManager.getAndCreateStoragePath(requestId,
documentId, null);

protected Page saveTextToFile(int pageNr, String requestId, String documentId, String pageText, String filename,
String fileExtentions) {
String docFolder = fileStorageManager.getAndCreateStoragePath(requestId, documentId, null);

if (pageNr > -1) {
filename = filename + "." + pageNr;
Expand All @@ -68,7 +70,7 @@ protected Page saveTextToFile(int pageNr, String requestId,
try {
fileObject.createNewFile();
} catch (IOException e) {
logger.error("Could not create file.", e);
messageHandler.handleMessage("Could not create file.", e, MessageType.ERROR);
return null;
}

Expand All @@ -79,7 +81,7 @@ protected Page saveTextToFile(int pageNr, String requestId,
bfWriter.close();
writer.close();
} catch (IOException e) {
logger.error("Could not write text to file.", e);
messageHandler.handleMessage("Could not write text to file.", e, MessageType.ERROR);
return null;
}

Expand All @@ -88,25 +90,25 @@ protected Page saveTextToFile(int pageNr, String requestId,
page.size = fileObject.length();
return page;
}

protected String getRestEndpoint() {
String restEndpoint = propertiesManager.getProperty(Properties.CEPHEUS_URL);
if (restEndpoint.endsWith("/")) {
restEndpoint = restEndpoint.substring(0, restEndpoint.length()-1);
restEndpoint = restEndpoint.substring(0, restEndpoint.length() - 1);
}
return restEndpoint;
}

class Page {
public String path;
public String filename;
public String contentType;
public long size;

public Page(String path, String filename) {
super();
this.path = path;
this.filename = filename;
}
}
}
}
Loading

0 comments on commit 53267ec

Please sign in to comment.