Skip to content

Commit

Permalink
Merge pull request #32 from diging/develop
Browse files Browse the repository at this point in the history
Prepare release
  • Loading branch information
jdamerow authored Nov 17, 2024
2 parents 2b32b88 + f4ff36b commit 41952b5
Show file tree
Hide file tree
Showing 23 changed files with 637 additions and 88 deletions.
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Guidelines for Pull Requests

If you haven't yet read our code review guidelines, please do so, You can find them [here](https://diging.atlassian.net/wiki/spaces/DIGING/pages/2256076801/Code+Review+Guidelines).

Please confirm the following by adding an x for each item (turn `[ ]` into `[x]`).

- [ ] I have removed all code style changes that are not necessary (e.g. changing blanks across the whole file that don’t need to be changed, adding empty lines in parts other than your own code)
- [ ] I am not making any changes to files that don’t have any effect (e.g. imports added that don’t need to be added)
- [ ] I do not have any sysout statements in my code or commented out code that isn’t needed anymore
- [ ] I am not reformatting any files in the wrong format or without cause.
- [ ] I am not changing file encoding or line endings to something else than UTF-8, LF
- [ ] My pull request does not show an insane amount of files being changed although my ticket only requires a few files being changed
- [ ] I have added Javadoc/documentation where appropriate
- [ ] I have added test cases where appropriate
- [ ] I have explained any part of my code/implementation decisions that is not be self-explanatory

## Please provide a brief description of your ticket
(you can copy the ticket if it hasn't changed)

<!-- ...Put description here... -->

## Anything else the reviewer needs to know?

<!-- ... describe here ... -->
64 changes: 64 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">

<!--
Checkstyle is highly configurable. Be sure to read the documentation at http://checkstyle.sf.net
-->

<module name = "Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format" value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message" value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true"/>
<property name="allowByTailComment" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="OneTopLevelClass"/>
<module name="NoLineWrap"/>
<module name="EmptyBlock">
<property name="option" value="TEXT"/>
<property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
</module>
<module name="OneStatementPerLine"/>
<module name="MissingSwitchDefault"/>
<module name="NoFinalizer"/>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="EmptyCatchBlock">
<property name="exceptionVariableName" value="expected|ignore"/>
</module>
<module name="UpperEll"/>

<!-- Rules from Sun's Java Style -->
<module name="IllegalImport"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="SimplifyBooleanReturn"/>
<module name="TodoComment">
<property name="format" value="(TODO)|(FIXME)"/>
<message key="todo.match" value="Resolve unexpected comment."/>
</module>

<!-- Custom -->
<module name="DefaultComesLast">
<property name="skipIfLastAndSharedWithCase" value="true"/>
</module>
<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="4"/>
</module>
</module>
</module>
44 changes: 31 additions & 13 deletions nepomuk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<org.slf4j-version>1.7.5</org.slf4j-version>
<org.springframework-version>4.3.2.RELEASE</org.springframework-version>
<spring-security-version>4.1.3.RELEASE</spring-security-version>
<geco.requests.version>0.10</geco.requests.version>
<geco.util.version>0.4.3</geco.util.version>
<geco.requests.version>0.16</geco.requests.version>
<geco.util.version>0.6</geco.util.version>
<geco.september.util.version>0.3</geco.september.util.version>
<geco.kafka-util.version>0.1</geco.kafka-util.version>
<geco.kafka-util.version>0.2</geco.kafka-util.version>
<buildNumber></buildNumber>

<admin.password>$2a$04$NXKVTx9XrpEST6CLn/ps7eP8YsK3t.5A/mvAoYpg.X8QqgOKtc1za</admin.password>
Expand Down Expand Up @@ -60,16 +60,15 @@
</repositories>

<dependencies>

<!-- Giles Ecosystem -->
<dependency>
<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>
Expand All @@ -78,8 +77,8 @@
<version>${geco.september.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>

Expand Down Expand Up @@ -408,7 +407,26 @@
<artifactId>curator-framework</artifactId>
<version>2.12.0</version>
</dependency>

<!-- API, java.xml.bind module -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>

<!-- Runtime, com.sun.xml.bind module -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>

</dependencies>

Expand All @@ -429,7 +447,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<version>3.3.2</version>
<configuration>
<webResources>
<resource>
Expand Down Expand Up @@ -462,8 +480,8 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -531,7 +549,7 @@
</build>

<scm>
<connection>scm:svn:http://none</connection>
<url>scm:svn:https://none</url>
<connection>scm:git:http://none</connection>
<url>scm:git:https://none</url>
</scm>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import edu.asu.diging.gilesecosystem.nepomuk.core.service.properties.Properties;
import edu.asu.diging.gilesecosystem.nepomuk.core.kafka.impl.StorageDeletionRequestReceiver;
import edu.asu.diging.gilesecosystem.nepomuk.core.kafka.impl.StorageRequestReceiver;
import edu.asu.diging.gilesecosystem.util.properties.IPropertiesManager;

Expand Down Expand Up @@ -65,6 +66,11 @@ public ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory() {
public StorageRequestReceiver receiver() {
return new StorageRequestReceiver();
}

@Bean
public StorageDeletionRequestReceiver deletionReceiver() {
return new StorageDeletionRequestReceiver();
}

@Override
public String getHosts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,31 @@ public abstract String getAndCreateStoragePath(String username,

public abstract String getFileFolderPathInBaseFolder(String username, String uploadId,
String fileId);

/**
* Method to delete a file from storage
*
* @param username
* username of user who uploaded an image
* @param uploadId
* id of upload a file was part of
* @param documentId
* id of document
* @param fileId
* id of file
* @param deleteEmptyFolders
* if empty folders need to be deleted
* @throws NepomukFileStorageException
*/
public abstract void deleteFile(String username, String uploadId, String documentId, String fileId) throws NepomukFileStorageException;

}
/**
* Checks if a file exists at the specified location.
* @param username The username associated with the file.
* @param uploadId The unique identifier for the upload.
* @param documentId The identifier for the document.
* @param fileName The name of the file to check.
* @return {@code true} if the file exists at the specified location, {@code false} otherwise.
*/
public abstract boolean checkIfFileExists(String username, String uploadId, String documentId, String fileName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ public abstract IFile getFile(String uploadId, String documentId, String filenam

List<String> getUsernames();

}
/**
* Delete a file given the file ID.
* @param fileId
* ID of the file to be deleted
*/
public abstract void deleteFile(String fileId);

public abstract List<IFile> getFilesByDocumentId(String documentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@ public abstract IFile getFile(String uploadId, String documentId, String filenam
throws NoUniqueResultException;

List<String> getKnownUsernames();
}

/**
* Delete a file given the file ID.
* @param fileId
* ID of the file to be deleted
*/

public abstract void deleteFile(String fileId);

public abstract List<IFile> getFilesByDocumentId(String documentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -49,8 +52,7 @@ public void saveFile(String username, String uploadId, String documentId,
@Override
public String getAndCreateStoragePath(String username, String uploadId,
String documentId) {
String path = baseDirectory + File.separator
+ getFileFolderPathInBaseFolder(username, uploadId, documentId);
String path = getStoragePath(username, uploadId, documentId);
createDirectory(path);
return path;
}
Expand Down Expand Up @@ -119,5 +121,42 @@ private boolean createDirectory(String dirPath) {
public void setFileTypeFolder(String fileTypeFolder) {
this.fileTypeFolder = fileTypeFolder;
}

private String getStoragePath(String username, String uploadId,
String documentId) {
return baseDirectory + File.separator
+ getFileFolderPathInBaseFolder(username, uploadId, documentId);
}

public void deleteFile(String username, String uploadId, String documentId, String fileName) throws NepomukFileStorageException {
String originalFilePath = getStoragePath(username, uploadId, documentId);
Path path = Paths.get(originalFilePath + File.separator + fileName);
try {
Files.delete(path);
} catch (IOException ex) {
throw new NepomukFileStorageException("Could not delete file.", ex);
}
String documentFolder = getStoragePath(username, uploadId, documentId);
File docFolder = new File(documentFolder);
if (docFolder.isDirectory() && docFolder.list().length == 0) {
// If another process adds a file to the folder just before deletion, we do not want to delete the folder.
// The goal is to ensure that the folder remains intact even if new files are added during the deletion process.
// Using the File.delete() instead of Files.delete(path) as an exception is not required to be thrown in this scenario.
boolean deleted = docFolder.delete();
if (deleted) {
Path documentFolderPath = Paths.get(documentFolder);
Path uploadFolderDirectory = documentFolderPath.getParent();
File uploadFolder = new File(uploadFolderDirectory.toString());
if (uploadFolder.isDirectory() && uploadFolder.list().length == 0) {
uploadFolder.delete();
}
}
}
}

@Override
public boolean checkIfFileExists(String username, String uploadId, String documentId, String fileName) {
Path path = Paths.get(getStoragePath(username, uploadId, documentId) + File.separator + fileName);
return Files.exists(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public List<IFile> getFilesByUploadId(String uploadId) {
return results;
}

@Override
public List<IFile> getFilesByDocumentId(String documentId) {
List<IFile> results = new ArrayList<IFile>();
searchByProperty("documentId", documentId, File.class).forEach(f -> results.add((IFile)f));
return results;
}

@Override
public List<IFile> getFilesByUsername(String username) {
List<IFile> results = new ArrayList<IFile>();
Expand Down Expand Up @@ -120,4 +127,9 @@ public List<String> getUsernames() {
TypedQuery<String> docs = em.createQuery(query, String.class);
return docs.getResultList();
}

@Override
public void deleteFile(String fileId) {
em.remove(getById(fileId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class FilesManager implements IFilesManager {
public List<IFile> getFilesByUploadId(String uploadId) {
return databaseClient.getFilesByUploadId(uploadId);
}

@Override
public List<IFile> getFilesByDocumentId(String documentId) {
return databaseClient.getFilesByDocumentId(documentId);
}

@Override
public IFile getFile(String id) {
Expand Down Expand Up @@ -86,5 +91,9 @@ public String getRelativePathOfFile(IFile file) {
public List<String> getKnownUsernames() {
return databaseClient.getUsernames();
}


@Override
public void deleteFile(String fileId) {
databaseClient.deleteFile(fileId);
}
}
Loading

0 comments on commit 41952b5

Please sign in to comment.