Skip to content

Commit 0adcd79

Browse files
Refactor persistence (#113)
* save changes * Fix tests
1 parent 6dd8918 commit 0adcd79

File tree

62 files changed

+1814
-2311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1814
-2311
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<!--Quarkus-->
4141
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
4242
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
43-
<quarkus.platform.version>2.6.1.Final</quarkus.platform.version>
43+
<quarkus.platform.version>2.6.2.Final</quarkus.platform.version>
4444

4545
<!--plugings-->
4646
<maven.compiler.parameters>true</maven.compiler.parameters>

src/main/java/io/github/project/openubl/ublhub/builder/XMLBuilderManager.java

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/main/java/io/github/project/openubl/ublhub/flyway/RunFlyway.java renamed to src/main/java/io/github/project/openubl/ublhub/db/RunFlyway.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package io.github.project.openubl.ublhub.flyway;
17+
package io.github.project.openubl.ublhub.db;
1818

1919
import io.quarkus.runtime.StartupEvent;
2020
import org.eclipse.microprofile.config.inject.ConfigProperty;

src/main/java/io/github/project/openubl/ublhub/exceptions/AbstractSendFileException.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/java/io/github/project/openubl/ublhub/exceptions/FetchFileException.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/io/github/project/openubl/ublhub/exceptions/NoNamespaceException.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/java/io/github/project/openubl/ublhub/exceptions/ReadFileException.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/main/java/io/github/project/openubl/ublhub/files/FilesMutiny.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
*/
1717
package io.github.project.openubl.ublhub.files;
1818

19-
import io.github.project.openubl.ublhub.exceptions.FetchFileException;
20-
import io.github.project.openubl.ublhub.exceptions.SaveFileException;
19+
import io.github.project.openubl.ublhub.files.exceptions.PersistFileException;
20+
import io.github.project.openubl.ublhub.files.exceptions.ReadFileException;
21+
import io.github.project.openubl.ublhub.keys.DefaultKeyManager;
2122
import io.smallrye.mutiny.Uni;
23+
import org.jboss.logging.Logger;
2224

2325
import javax.enterprise.context.ApplicationScoped;
2426
import javax.inject.Inject;
@@ -27,20 +29,25 @@
2729
@ApplicationScoped
2830
public class FilesMutiny {
2931

32+
private static final Logger LOGGER = Logger.getLogger(DefaultKeyManager.class);
33+
3034
@Inject
3135
FilesManager filesManager;
3236

3337
public Uni<String> createFile(byte[] file, boolean shouldZipFile) {
34-
return Uni.createFrom().item(file)
35-
.onItem().ifNull().failWith(() -> new SaveFileException("Invalid body"))
36-
.onItem().ifNotNull().transformToUni((bytes, uniEmitter) -> {
37-
try {
38-
String fileID = filesManager.createFile(file, shouldZipFile);
39-
uniEmitter.complete(fileID);
40-
} catch (Throwable e) {
41-
uniEmitter.fail(new SaveFileException(e));
42-
}
43-
});
38+
return Uni.createFrom().emitter((emitter) -> {
39+
if (file == null) {
40+
emitter.fail(new PersistFileException("Can not save null file"));
41+
} else {
42+
try {
43+
String fileID = filesManager.createFile(file, shouldZipFile);
44+
emitter.complete(fileID);
45+
} catch (Throwable e) {
46+
LOGGER.error(e);
47+
emitter.fail(new PersistFileException(e));
48+
}
49+
}
50+
});
4451
}
4552

4653
public Uni<String> createFile(File file, boolean shouldZipFile) {
@@ -49,7 +56,8 @@ public Uni<String> createFile(File file, boolean shouldZipFile) {
4956
String fileID = filesManager.createFile(file, shouldZipFile);
5057
uniEmitter.complete(fileID);
5158
} catch (Throwable e) {
52-
uniEmitter.fail(new SaveFileException(e));
59+
LOGGER.error(e);
60+
uniEmitter.fail(new PersistFileException(e));
5361
}
5462
});
5563
}
@@ -60,7 +68,8 @@ public Uni<byte[]> getFileAsBytesAfterUnzip(String fileID) {
6068
byte[] file = filesManager.getFileAsBytesAfterUnzip(fileID);
6169
uniEmitter.complete(file);
6270
} catch (Throwable e) {
63-
uniEmitter.fail(new FetchFileException(e));
71+
LOGGER.error(e);
72+
uniEmitter.fail(new ReadFileException(e));
6473
}
6574
});
6675
}
@@ -71,7 +80,8 @@ public Uni<byte[]> getFileAsBytesWithoutUnzipping(String fileID) {
7180
byte[] file = filesManager.getFileAsBytesWithoutUnzipping(fileID);
7281
uniEmitter.complete(file);
7382
} catch (Throwable e) {
74-
uniEmitter.fail(new FetchFileException(e));
83+
LOGGER.error(e);
84+
uniEmitter.fail(new ReadFileException(e));
7585
}
7686
});
7787
}
@@ -82,7 +92,8 @@ public Uni<String> getFileLink(String fileID) {
8292
String fileLink = filesManager.getFileLink(fileID);
8393
uniEmitter.complete(fileLink);
8494
} catch (Throwable e) {
85-
uniEmitter.fail(new FetchFileException(e));
95+
LOGGER.error(e);
96+
uniEmitter.fail(new ReadFileException(e));
8697
}
8798
});
8899
}
@@ -93,7 +104,8 @@ public Uni<Void> delete(String fileID) {
93104
filesManager.delete(fileID);
94105
uniEmitter.complete(null);
95106
} catch (Throwable e) {
96-
uniEmitter.fail(new FetchFileException(e));
107+
LOGGER.error(e);
108+
uniEmitter.fail(new PersistFileException(e));
97109
}
98110
});
99111
}

src/main/java/io/github/project/openubl/ublhub/exceptions/EntityOperationException.java renamed to src/main/java/io/github/project/openubl/ublhub/files/exceptions/PersistFileException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package io.github.project.openubl.ublhub.exceptions;
17+
package io.github.project.openubl.ublhub.files.exceptions;
1818

19-
public class EntityOperationException extends Exception {
20-
public EntityOperationException(Throwable e) {
19+
public class PersistFileException extends Exception {
20+
public PersistFileException(Throwable e) {
2121
super(e);
2222
}
2323

24-
public EntityOperationException(String message) {
24+
public PersistFileException(String message) {
2525
super(message);
2626
}
2727
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package io.github.project.openubl.ublhub.exceptions;
17+
package io.github.project.openubl.ublhub.files.exceptions;
1818

19-
public class CheckTicketAtSUNATException extends AbstractSendFileException {
20-
public CheckTicketAtSUNATException(String message) {
19+
public class ReadFileException extends Exception {
20+
public ReadFileException(Throwable e) {
21+
super(e);
22+
}
23+
24+
public ReadFileException(String message) {
2125
super(message);
2226
}
2327
}

0 commit comments

Comments
 (0)