From 90277e1c51809201f0a31934440e60d3657b2362 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Fri, 25 Sep 2020 21:22:34 +0200 Subject: [PATCH] Add common utils and uri obfuscator --- pom.xml | 5 +++ src/main/lombok/module-info.java | 1 + .../extra/api/AlreadyAssignedException.java | 38 ++++++++++++++++ .../extra/api/FileURITranslator.java | 44 +++++++++++++++++++ .../filesponge/extra/api/URIObfuscator.java | 39 ++++++++++++++++ .../warp/filesponge/extra/package-info.java | 22 ++++++++++ 6 files changed, 149 insertions(+) create mode 100644 src/main/lombok/org/warp/filesponge/extra/api/AlreadyAssignedException.java create mode 100644 src/main/lombok/org/warp/filesponge/extra/api/FileURITranslator.java create mode 100644 src/main/lombok/org/warp/filesponge/extra/api/URIObfuscator.java create mode 100644 src/main/lombok/org/warp/filesponge/extra/package-info.java diff --git a/pom.xml b/pom.xml index 9d4b05d..21d48d7 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,11 @@ RELEASE compile + + org.warp + common-utils + 1.0.7 + diff --git a/src/main/lombok/module-info.java b/src/main/lombok/module-info.java index 142aea2..b5a91e4 100644 --- a/src/main/lombok/module-info.java +++ b/src/main/lombok/module-info.java @@ -1,5 +1,6 @@ module org.warp.filesponge { exports org.warp.filesponge.api; + exports org.warp.filesponge.extra.api; exports org.warp.filesponge.value; requires lombok; requires org.jetbrains.annotations; diff --git a/src/main/lombok/org/warp/filesponge/extra/api/AlreadyAssignedException.java b/src/main/lombok/org/warp/filesponge/extra/api/AlreadyAssignedException.java new file mode 100644 index 0000000..97d2896 --- /dev/null +++ b/src/main/lombok/org/warp/filesponge/extra/api/AlreadyAssignedException.java @@ -0,0 +1,38 @@ +/* + * FileSponge + * Copyright (C) 2020 Andrea Cavalli + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.warp.filesponge.extra.api; + +public class AlreadyAssignedException extends Exception { + + public AlreadyAssignedException() { + super(); + } + + public AlreadyAssignedException(String message) { + super(message); + } + + public AlreadyAssignedException(String message, Throwable cause) { + super(message, cause); + } + + public AlreadyAssignedException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/lombok/org/warp/filesponge/extra/api/FileURITranslator.java b/src/main/lombok/org/warp/filesponge/extra/api/FileURITranslator.java new file mode 100644 index 0000000..cc00d2a --- /dev/null +++ b/src/main/lombok/org/warp/filesponge/extra/api/FileURITranslator.java @@ -0,0 +1,44 @@ +/* + * FileSponge + * Copyright (C) 2020 Andrea Cavalli + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.warp.filesponge.extra.api; + +import java.util.Optional; +import java.util.OptionalLong; +import org.warp.filesponge.value.FileURI; + +/** + * Translate File URIs to "fileId" and back + */ +public interface FileURITranslator { + + Optional getURI(long fileId); + + OptionalLong getFileId(FileURI fileURI); + + /** + * @throws AlreadyAssignedException Throw if the uri has another fileId assigned + */ + void setFileId(FileURI fileURI, long fileId) throws AlreadyAssignedException; + + Optional delete(long fileId); + + OptionalLong delete(FileURI fileURI); + + void clear(); +} diff --git a/src/main/lombok/org/warp/filesponge/extra/api/URIObfuscator.java b/src/main/lombok/org/warp/filesponge/extra/api/URIObfuscator.java new file mode 100644 index 0000000..965104f --- /dev/null +++ b/src/main/lombok/org/warp/filesponge/extra/api/URIObfuscator.java @@ -0,0 +1,39 @@ +/* + * FileSponge + * Copyright (C) 2020 Andrea Cavalli + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.warp.filesponge.extra.api; + +import org.warp.filesponge.value.FileURI; + +/** + * Create an unique "fileId" for each File URI + */ +public interface URIObfuscator { + + FileURI deobfuscateFileId(long fileId); + + void getFileId(FileURI fileURI); + + void setURIValue(FileURI fileURI, long fileId); + + FileURI delete(long fileId); + + long delete(FileURI fileURI); + + void clear(); +} diff --git a/src/main/lombok/org/warp/filesponge/extra/package-info.java b/src/main/lombok/org/warp/filesponge/extra/package-info.java new file mode 100644 index 0000000..5769ec9 --- /dev/null +++ b/src/main/lombok/org/warp/filesponge/extra/package-info.java @@ -0,0 +1,22 @@ +/* + * FileSponge + * Copyright (C) 2020 Andrea Cavalli + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * Extra functionalities and utilities for FileSponge + */ +package org.warp.filesponge.extra; \ No newline at end of file