diff --git a/.gitignore b/.gitignore
index 92322c4..2279178 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
.idea/
target/
+logs/
diff --git a/core/pom.xml b/core/pom.xml
index 8fbd04b..0ad5d7b 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -61,6 +61,18 @@
gr.cite
cache
2.1.0
+
+
+ gr.cite
+ logging
+ 2.2.0
+ compile
+
+
+ gr.cite
+ exceptions
+ 2.2.0
+ compile
diff --git a/core/src/main/java/org/opencdmp/deposit/zenodorepository/audit/AuditableAction.java b/core/src/main/java/org/opencdmp/deposit/zenodorepository/audit/AuditableAction.java
new file mode 100644
index 0000000..100bb02
--- /dev/null
+++ b/core/src/main/java/org/opencdmp/deposit/zenodorepository/audit/AuditableAction.java
@@ -0,0 +1,14 @@
+package org.opencdmp.deposit.zenodorepository.audit;
+
+
+import gr.cite.tools.logging.EventId;
+
+public class AuditableAction {
+
+ public static final EventId Deposit_Deposit = new EventId(1000, "Deposit_Deposit");
+ public static final EventId Deposit_Authenticate = new EventId(1001, "Deposit_Authenticate");
+ public static final EventId Deposit_GetConfiguration = new EventId(1002, "Deposit_GetConfiguration");
+ public static final EventId Deposit_GetLogo = new EventId(1003, "Deposit_GetLogo");
+
+
+}
diff --git a/core/src/main/java/org/opencdmp/deposit/zenodorepository/model/builder/ZenodoBuilder.java b/core/src/main/java/org/opencdmp/deposit/zenodorepository/model/builder/ZenodoBuilder.java
index 6cbacd3..31c18f8 100644
--- a/core/src/main/java/org/opencdmp/deposit/zenodorepository/model/builder/ZenodoBuilder.java
+++ b/core/src/main/java/org/opencdmp/deposit/zenodorepository/model/builder/ZenodoBuilder.java
@@ -1,5 +1,6 @@
package org.opencdmp.deposit.zenodorepository.model.builder;
+import gr.cite.tools.exception.MyApplicationException;
import org.opencdmp.commonmodels.enums.DmpAccessType;
import org.opencdmp.commonmodels.enums.DmpUserRole;
import org.opencdmp.commonmodels.models.DmpUserModel;
@@ -162,8 +163,8 @@ public class ZenodoBuilder {
}
}
}
- case INTERNAL_ENTRIES_DESCRIPTIONS, INTERNAL_ENTRIES_DMPS, UPLOAD -> throw new RuntimeException("Invalid type " + field.getData().getFieldType());
- default -> throw new RuntimeException("Invalid type " + field.getData().getFieldType());
+ case INTERNAL_ENTRIES_DESCRIPTIONS, INTERNAL_ENTRIES_DMPS, UPLOAD -> throw new MyApplicationException("Invalid type " + field.getData().getFieldType());
+ default -> throw new MyApplicationException("Invalid type " + field.getData().getFieldType());
}
}
}
@@ -240,8 +241,8 @@ public class ZenodoBuilder {
private void applyLicenses(DmpModel dmp, ZenodoDeposit deposit){
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
- List dmpLicenses = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getResearcherReferenceCode());
- if (dmpLicenses != null && !dmpLicenses.isEmpty()) {
+ List dmpLicenses = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getLicensesReferenceCode());
+ if (!dmpLicenses.isEmpty()) {
for (ReferenceModel dmpLicense : dmpLicenses) {
if (dmpLicense != null && dmpLicense.getReference() != null && !dmpLicense.getReference().isBlank()) {
deposit.getMetadata().setLicense(dmpLicense.getReference());
diff --git a/core/src/main/java/org/opencdmp/deposit/zenodorepository/service/zenodo/ZenodoDepositServiceImpl.java b/core/src/main/java/org/opencdmp/deposit/zenodorepository/service/zenodo/ZenodoDepositServiceImpl.java
index a6c957e..99897d7 100644
--- a/core/src/main/java/org/opencdmp/deposit/zenodorepository/service/zenodo/ZenodoDepositServiceImpl.java
+++ b/core/src/main/java/org/opencdmp/deposit/zenodorepository/service/zenodo/ZenodoDepositServiceImpl.java
@@ -1,6 +1,9 @@
package org.opencdmp.deposit.zenodorepository.service.zenodo;
import com.fasterxml.jackson.databind.ObjectMapper;
+import gr.cite.tools.exception.MyApplicationException;
+import gr.cite.tools.logging.LoggerService;
+import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.depositbase.repository.DepositConfiguration;
@@ -21,7 +24,9 @@ import org.springframework.util.ResourceUtils;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.reactive.function.BodyInserters;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.WebClient;
+import reactor.core.publisher.Mono;
import java.io.FileInputStream;
import java.io.IOException;
@@ -30,6 +35,7 @@ import java.util.*;
@Component
public class ZenodoDepositServiceImpl implements ZenodoDepositService {
+ private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ZenodoDepositServiceImpl.class));
private static final String PUBLISH_ID = "conceptdoi";
private static final String CLIENT_ID = "client_id";
@@ -47,7 +53,6 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
private static final String ZENODO_METADATA = "metadata";
private static final String ZENODO_METADATA_VERSION = "version";
- private static final Logger logger = LoggerFactory.getLogger(ZenodoDepositServiceImpl.class);
private static final ObjectMapper objectMapper = new ObjectMapper();
private final ZenodoServiceProperties zenodoServiceProperties;
@@ -78,7 +83,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
String zenodoUrl = depositConfiguration.getRepositoryUrl();
// First step, post call to Zenodo, to create the entry.
- WebClient zenodoClient = WebClient.builder().build();
+ WebClient zenodoClient = this.getWebClient();
DepositConfiguration zenodoConfig = this.zenodoServiceProperties.getDepositConfiguration();
if (zenodoConfig == null) return null;
@@ -93,7 +98,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
if (previousDOI == null) {
links = deposit(zenodoToken, zenodoUrl, zenodoClient, deposit);
} else {
- unpublishedUrl = this.getUnpublishedDOI(zenodoUrl, previousDOI, zenodoToken, dmpModel.getVersion());
+ unpublishedUrl = this.getUnpublishedDOI(zenodoClient, zenodoUrl, previousDOI, zenodoToken, dmpModel.getVersion());
if (unpublishedUrl == null) {
//It requires more than one step to create a new version
//First, get the deposit related to the concept DOI
@@ -107,7 +112,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
// Second step, add the file to the entry.
FileEnvelopeModel pdfEnvelope = dmpModel.getPdfFile();
- if (links == null || !links.containsKey(ZENODO_LINKS_BUCKET)) throw new Exception("bucket not found");
+ if (links == null || !links.containsKey(ZENODO_LINKS_BUCKET)) throw new MyApplicationException("bucket not found");
String addFileUrl = links.get(ZENODO_LINKS_BUCKET) + "/" + pdfEnvelope.getFilename() + "?access_token=" + zenodoToken;
@@ -149,9 +154,10 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
publishUrl = unpublishedUrl + "?access_token=" + zenodoToken;
}
- return this.publish(publishUrl);
+ return this.publish(zenodoClient, publishUrl);
} catch (HttpClientErrorException | HttpServerErrorException ex) {
+ logger.error(ex.getMessage(), ex);
Map parsedException = objectMapper.readValue(ex.getResponseBodyAsString(), Map.class);
throw new IOException(parsedException.get("message"), ex);
}
@@ -175,7 +181,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
links = (LinkedHashMap) createResponse.getOrDefault(ZENODO_LINKS, new LinkedHashMap<>());
//Second, make the new version (not in the links?)
- if (!links.containsKey(ZENODO_LINKS_LATEST_DRAFT)) throw new Exception("previousDOI not found");
+ if (!links.containsKey(ZENODO_LINKS_LATEST_DRAFT)) throw new MyApplicationException("previousDOI not found");
String newVersionUrl = links.get(ZENODO_LINKS_LATEST_DRAFT) + "/actions/newversion" + "?access_token=" + zenodoToken;
logger.debug("new version url: " + newVersionUrl);
createResponse = zenodoClient.post().uri(newVersionUrl)
@@ -185,7 +191,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
links = createResponse == null ? new LinkedHashMap<>() : createResponse.getOrDefault(ZENODO_LINKS, new LinkedHashMap<>());
//Third, get the new deposit
- if (!links.containsKey(ZENODO_LINKS_LATEST_DRAFT)) throw new Exception("can not create latest draft");
+ if (!links.containsKey(ZENODO_LINKS_LATEST_DRAFT)) throw new MyApplicationException("can not create latest draft");
String latestDraftUrl = links.get(ZENODO_LINKS_LATEST_DRAFT) + "?access_token=" + zenodoToken;
createResponse = zenodoClient.get().uri(latestDraftUrl)
.exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference