Skip to content

Commit

Permalink
Merge pull request #17 from diging/develop
Browse files Browse the repository at this point in the history
Prepare Release
  • Loading branch information
jdamerow authored Apr 20, 2017
2 parents 6d7f273 + e2e5c25 commit b8d9790
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 18 deletions.
5 changes: 0 additions & 5 deletions nepomuk/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
1 change: 1 addition & 0 deletions nepomuk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.settings/
/target/
/target/
/buildNumber.properties
60 changes: 58 additions & 2 deletions nepomuk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
<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.2.1-SNAPSHOT</geco.requests.version>
<geco.util.version>0.4.1</geco.util.version>
<geco.requests.version>0.5</geco.requests.version>
<geco.util.version>0.4.2</geco.util.version>
<buildNumber></buildNumber>

<admin.password>$2a$04$NXKVTx9XrpEST6CLn/ps7eP8YsK3t.5A/mvAoYpg.X8QqgOKtc1za</admin.password>
<nepomuk.base.url>http://localhost:8082/nepomuk/</nepomuk.base.url>
Expand Down Expand Up @@ -393,6 +394,61 @@
<path>/${tomcat.app}</path>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<versionRange>[0,)</versionRange>
<goals>
<goal>create</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure></revisionOnScmFailure>
<items>
<item>buildNumber\d*</item>
<item>timestamp</item>
</items>
<format>${geco.nepomuk.version}-{0} ({1,date,yyyy-MM-dd HH:mm:ss})</format>
</configuration>
</plugin>
</plugins>
</build>

<scm>
<connection>scm:svn:http://none</connection>
<url>scm:svn:https://none</url>
</scm>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ public interface IFile extends IStorableObject {

public abstract String getContentType();

public abstract void setGilesFileId(String gilesFileId);

public abstract String getGilesFileId();

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.asu.diging.gilesecosystem.nepomuk.core.domain.impl;

import javax.jdo.annotations.Index;
import javax.persistence.Entity;
import javax.persistence.Id;

Expand All @@ -9,19 +10,19 @@
@Entity
public class File implements IFile {

private String uploadId;
private String filename;
private String username;
private String documentId;
@Id
private String id;
@Index private String uploadId;
@Index private String filename;
@Index private String username;
@Index private String documentId;
@Id @Index private String id;
private String uploadDate;
private String processedDate;
private long size;
private String filepath;
private FileType fileType;
private String contentType;

@Index private String gilesFileId;

public File() {
}

Expand Down Expand Up @@ -181,5 +182,15 @@ public String getContentType() {
public void setContentType(String contentType) {
this.contentType = contentType;
}

@Override
public String getGilesFileId() {
return gilesFileId;
}

@Override
public void setGilesFileId(String gilesFileId) {
this.gilesFileId = gilesFileId;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package edu.asu.diging.gilesecosystem.nepomuk.core.exception;

public class NoUniqueResultException extends Exception {

/**
*
*/
private static final long serialVersionUID = -3769968277605578574L;

public NoUniqueResultException() {
super();
// TODO Auto-generated constructor stub
}

public NoUniqueResultException(String message, Throwable cause,
boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}

public NoUniqueResultException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}

public NoUniqueResultException(String message) {
super(message);
// TODO Auto-generated constructor stub
}

public NoUniqueResultException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import java.util.List;

import javax.persistence.TypedQuery;

import edu.asu.diging.gilesecosystem.nepomuk.core.domain.IFile;
import edu.asu.diging.gilesecosystem.nepomuk.core.domain.impl.File;
import edu.asu.diging.gilesecosystem.nepomuk.core.exception.NoUniqueResultException;
import edu.asu.diging.gilesecosystem.nepomuk.core.exception.UnstorableObjectException;
import edu.asu.diging.gilesecosystem.nepomuk.core.store.IDatabaseClient;

Expand All @@ -20,4 +24,7 @@ public interface IFilesDatabaseClient extends IDatabaseClient<IFile> {

public List<IFile> getFilesByProperty(String propName, String propValue);

public abstract IFile getFile(String uploadId, String documentId, String filename)
throws NoUniqueResultException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import edu.asu.diging.gilesecosystem.nepomuk.core.domain.IFile;
import edu.asu.diging.gilesecosystem.nepomuk.core.exception.NoUniqueResultException;
import edu.asu.diging.gilesecosystem.nepomuk.core.exception.UnstorableObjectException;

public interface IFilesManager {
Expand All @@ -29,4 +30,7 @@ public interface IFilesManager {
public abstract String getRelativePathOfFile(IFile file);

public abstract byte[] getFileContent(IFile file);

public abstract IFile getFile(String uploadId, String documentId, String filename)
throws NoUniqueResultException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import javax.annotation.PreDestroy;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import edu.asu.diging.gilesecosystem.nepomuk.core.domain.IFile;
import edu.asu.diging.gilesecosystem.nepomuk.core.domain.impl.File;
import edu.asu.diging.gilesecosystem.nepomuk.core.exception.NoUniqueResultException;
import edu.asu.diging.gilesecosystem.nepomuk.core.exception.UnstorableObjectException;
import edu.asu.diging.gilesecosystem.nepomuk.core.files.IFilesDatabaseClient;
import edu.asu.diging.gilesecosystem.nepomuk.core.store.objectdb.DatabaseClient;
Expand Down Expand Up @@ -74,6 +76,21 @@ public IFile getFile(String filename) {
}
return files.get(0);
}

@Override
public IFile getFile(String uploadId, String documentId, String filename) throws NoUniqueResultException {
String query = "SELECT t FROM " + File.class.getName() + " t WHERE t.uploadId = '" + uploadId + "' and t.documentId = '" + documentId + "' and t.filename = '" + filename + "'";
TypedQuery<File> docs = em.createQuery(query, File.class);

List<File> results = docs.getResultList();
if (results.size() > 1) {
throw new NoUniqueResultException("There are more than one result for file: " + uploadId + ", " + documentId + ", " + filename);
}
if (results.isEmpty()) {
return null;
}
return results.get(0);
}

@Override
protected String getIdPrefix() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.stereotype.Service;

import edu.asu.diging.gilesecosystem.nepomuk.core.domain.IFile;
import edu.asu.diging.gilesecosystem.nepomuk.core.exception.NoUniqueResultException;
import edu.asu.diging.gilesecosystem.nepomuk.core.exception.UnstorableObjectException;
import edu.asu.diging.gilesecosystem.nepomuk.core.files.IFilesDatabaseClient;
import edu.asu.diging.gilesecosystem.nepomuk.core.files.IFilesManager;
Expand Down Expand Up @@ -71,7 +72,11 @@ public IFile saveFile(IFile file) throws UnstorableObjectException {
return file;
}


@Override
public IFile getFile(String uploadId, String documentId, String filename) throws NoUniqueResultException {
return databaseClient.getFile(uploadId, documentId, filename);
}

@Override
public String getRelativePathOfFile(IFile file) {
IFileTypeHandler handler = fileHandlerRegistry.getHandler(file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import edu.asu.diging.gilesecosystem.nepomuk.core.service.IRequestProcessor;
import edu.asu.diging.gilesecosystem.nepomuk.core.service.ISystemMessageHandler;
import edu.asu.diging.gilesecosystem.util.properties.IPropertiesManager;
import edu.asu.diging.gilesecosystem.requests.IStorageRequest;
import edu.asu.diging.gilesecosystem.requests.impl.StorageRequest;
Expand All @@ -25,6 +26,9 @@ public class StorageRequestReceiver {

@Autowired
private IPropertiesManager propertiesManager;

@Autowired
private ISystemMessageHandler systemMessageHandler;

@KafkaListener(topics = "${topic_storage_request}")
public void receiveMessage(String message) {
Expand All @@ -34,6 +38,7 @@ public void receiveMessage(String message) {
request = mapper.readValue(message, StorageRequest.class);
} catch (IOException e) {
logger.error("Could not unmarshall request.", e);
systemMessageHandler.handleError("Could not unmarshall request.", e);
// FIXME: handel this case
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import edu.asu.diging.gilesecosystem.nepomuk.core.apps.IRegisteredApp;
import edu.asu.diging.gilesecosystem.nepomuk.core.apps.IRegisteredAppDatabaseClient;
import edu.asu.diging.gilesecosystem.nepomuk.core.service.ISystemMessageHandler;
import edu.asu.diging.gilesecosystem.nepomuk.core.service.apps.IRegisteredAppManager;
import edu.asu.diging.gilesecosystem.nepomuk.core.exception.TokenGenerationErrorException;
import edu.asu.diging.gilesecosystem.util.exceptions.UnstorableObjectException;
Expand All @@ -30,6 +31,9 @@ public class RegisteredAppsManager implements IRegisteredAppManager {
@Autowired
private ITokenService tokenService;

@Autowired
private ISystemMessageHandler systemMessageHandler;

@Override
public IRegisteredApp storeApp(IRegisteredApp app) {

Expand All @@ -40,6 +44,7 @@ public IRegisteredApp storeApp(IRegisteredApp app) {
databaseClient.store(app);
} catch (UnstorableObjectException e) {
logger.error("Could not store app.", e);
systemMessageHandler.handleError("Could not store app.", e);
return null;
}
return app;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
import edu.asu.diging.gilesecosystem.nepomuk.core.files.IFileStorageManager;
import edu.asu.diging.gilesecosystem.nepomuk.core.files.IFilesManager;
import edu.asu.diging.gilesecosystem.nepomuk.core.service.IFileTypeHandler;
import edu.asu.diging.gilesecosystem.nepomuk.core.service.ISystemMessageHandler;

public abstract class AbstractFileHandler implements IFileTypeHandler {

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

@Autowired
private IFilesManager filesManager;

@Autowired
private ISystemMessageHandler systemMessageHandler;

protected byte[] getFileContentFromUrl(URL url) throws IOException {
URLConnection con = url.openConnection();
Expand Down Expand Up @@ -58,12 +62,17 @@ public byte[] getFileContent(IFile file) {
try {
return getFileContentFromUrl(fileObject.toURI().toURL());
} catch (IOException e) {
systemMessageHandler.handleError("Could not read file.", e);
logger.error("Could not read file.", e);
return null;
}
}

public IFile processFile(IFile file, byte[] content) throws NepomukFileStorageException {
if (content == null) {
logger.warn("File " + file.getGilesFileId() + " does not have any content.");
return null;
}

Tika tika = new Tika();
String contentType = tika.detect(content);
Expand All @@ -76,6 +85,7 @@ public IFile processFile(IFile file, byte[] content) throws NepomukFileStorageEx
filesManager.saveFile(file);
} catch (UnstorableObjectException e) {
logger.error("Could not store file.", e);
systemMessageHandler.handleError("Could not store file.", e);
return null;
}
return file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void processRequest(IStorageRequest request) {
newFile.setUsername(request.getUsername());
newFile.setFilename(request.getFilename());
newFile.setFileType(request.getFileType());
newFile.setGilesFileId(request.getFileId());

byte[] content = downloadFile(request.getDownloadUrl());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SystemMessageHandler implements ISystemMessageHandler {
public void setup() {
requestFactory.config(SystemMessageRequest.class);
}

/* (non-Javadoc)
* @see edu.asu.diging.gilesecosystem.nepomuk.core.service.impl.ISystemMessageHandler#handleError(java.lang.Exception)
*/
Expand Down
Loading

0 comments on commit b8d9790

Please sign in to comment.