Skip to content

Commit d07c22b

Browse files
Update DOI exceptions to be multilingual exceptions (geonetwork#8106)
* Update DOI exceptions to be multilingual exceptions * Update Messages_fre.properties (geonetwork#102) --------- Co-authored-by: François Prunayre <[email protected]>
1 parent 4141f26 commit d07c22b

File tree

8 files changed

+132
-24
lines changed

8 files changed

+132
-24
lines changed

core/src/test/resources/org/fao/geonet/api/Messages.properties

+10
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ exception.doi.recordNotConformantMissingMandatory=Record is not conform with Dat
180180
exception.doi.recordNotConformantMissingMandatory.description=Record ''{0}'' is not conform with DataCite validation rules for mandatory fields. Error is: {1}. Required fields in DataCite are: identifier, creators, titles, publisher, publicationYear, resourceType. <a href=''{2}api/records/{3}/formatters/datacite?output=xml''>Check the DataCite format output</a> and adapt the record content to add missing information.
181181
exception.doi.recordInvalid=Record converted to DataCite format is invalid.
182182
exception.doi.recordInvalid.description=Record ''{0}'' converted to DataCite format is invalid. Error is: {1}. Required fields in DataCite are: identifier, creators, titles, publisher, publicationYear, resourceType. <a href=''{2}api/records/{3}/formatters/datacite?output=xml''>Check the DataCite format output</a> and adapt the record content to add missing information.
183+
exception.doi.serverErrorCreate=Error creating DOI
184+
exception.doi.serverErrorCreate.description=Error creating DOI: {0}
185+
exception.doi.serverErrorRetrieve=Error retrieving DOI
186+
exception.doi.serverErrorRetrieve.description=Error retrieving DOI: {0}
187+
exception.doi.serverErrorDelete=Error deleting DOI
188+
exception.doi.serverErrorDelete.description=Error deleting DOI: {0}
189+
exception.doi.serverErrorUnregister=Error unregistering DOI
190+
exception.doi.serverErrorUnregister.description=Error unregistering DOI: {0}
191+
exception.doi.notSupportedOperationError=Operation not supported
192+
exception.doi.notSupportedOperationError.description={0}
183193
api.metadata.import.importedWithId=Metadata imported with ID '%s'
184194
api.metadata.import.importedWithUuid=Metadata imported with UUID '%s'
185195
api.metadata.import.importedFromXMLWithUuid=Metadata imported from XML with UUID '%s'

core/src/test/resources/org/fao/geonet/api/Messages_fre.properties

+10
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ exception.doi.recordNotConformantMissingMandatory=La fiche n''est pas conforme a
167167
exception.doi.recordNotConformantMissingMandatory.description=La fiche ''{0}'' n''est pas conforme aux r\u00E8gles de validation DataCite pour les champs obligatoires. L''erreur est: {1}. Les champs obligatoires dans DataCite sont : identifiant, cr\u00E9ateurs, titres, \u00E9diteur, publicationYear, resourceType. <a href=''{2}api/records/{3}/formatters/datacite?output=xml''>V\u00E9rifiez la sortie au format DataCite</a> et adaptez le contenu de la fiche pour ajouter les informations manquantes.
168168
exception.doi.recordInvalid=Le fiche converti n''est pas conforme au format DataCite
169169
exception.doi.recordInvalid.description=Le fiche ''{0}'' converti n''est pas conforme au format DataCite. L''erreur est: {1}. Les champs obligatoires dans DataCite sont : identifiant, cr\u00E9ateurs, titres, \u00E9diteur, ann\u00E9e de publication, type de ressource. <a href=''{2}api/records/{3}/formatters/datacite?output=xml''>V\u00E9rifier la sortie au format DataCite</a> et adapter le contenu de la fiche pour ajouter les informations manquantes.
170+
exception.doi.serverErrorCreate=Erreur lors de la cr\u00E9ation du DOI
171+
exception.doi.serverErrorCreate.description=Erreur lors de la cr\u00E9ation du DOI : {0}
172+
exception.doi.serverErrorRetrieve=Erreur lors de la r\u00E9cup\u00E9ration du DOI
173+
exception.doi.serverErrorRetrieve.description=Erreur lors de la r\u00E9cup\u00E9ration du DOI : {0}
174+
exception.doi.serverErrorDelete=Erreur lors de la suppression du DOI
175+
exception.doi.serverErrorDelete.description=Erreur lors de la suppression du DOI : {0}
176+
exception.doi.serverErrorUnregister=Erreur lors de la d\u00E9sinscription du DOI
177+
exception.doi.serverErrorUnregister.description=Erreur lors de la d\u00E9sinscription du DOI {0}
178+
exception.doi.notSupportedOperationError=Op\u00E9ration non prise en charge
179+
exception.doi.notSupportedOperationError.description={0}
170180
api.metadata.import.importedWithId=Fiche import\u00E9e avec l'ID '%s'
171181
api.metadata.import.importedWithUuid=Fiche import\u00E9e avec l'UUID '%s'
172182
api.metadata.import.importedFromXMLWithUuid=Fiche import\u00E9e depuis le fichier XML avec l'UUID '%s'

doi/src/main/java/org/fao/geonet/doi/client/BaseDoiClient.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//=============================================================================
2-
//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the
2+
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
33
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
44
//=== and United Nations Environment Programme (UNEP)
55
//===
@@ -94,14 +94,22 @@ protected void create(String url, String body, String contentType,
9494
url, body, status,
9595
httpResponse.getStatusText(), responseBody);
9696
Log.info(LOGGER_NAME, message);
97-
throw new DoiClientException(message);
97+
throw new DoiClientException(String.format(
98+
"Error creating DOI: %s",
99+
message))
100+
.withMessageKey("exception.doi.serverErrorCreate")
101+
.withDescriptionKey("exception.doi.serverErrorCreate.description", new String[]{message});
98102
} else {
99103
Log.info(LOGGER_NAME, String.format(
100104
successMessage, url));
101105
}
102106
} catch (Exception ex) {
103107
Log.error(LOGGER_NAME, " -- Error (exception): " + ex.getMessage(), ex);
104-
throw new DoiClientException(ex.getMessage());
108+
throw new DoiClientException(String.format(
109+
"Error creating DOI: %s",
110+
ex.getMessage()))
111+
.withMessageKey("exception.doi.serverErrorCreate")
112+
.withDescriptionKey("exception.doi.serverErrorCreate.description", new String[]{ex.getMessage()});
105113

106114
} finally {
107115
if (postMethod != null) {
@@ -139,13 +147,24 @@ protected String retrieve(String url)
139147
} else {
140148
Log.info(LOGGER_NAME, "Retrieve DOI metadata end -- Error: " + httpResponse.getStatusText());
141149

142-
throw new DoiClientException( httpResponse.getStatusText() +
143-
CharStreams.toString(new InputStreamReader(httpResponse.getBody())));
150+
String message = httpResponse.getStatusText() +
151+
CharStreams.toString(new InputStreamReader(httpResponse.getBody()));
152+
153+
throw new DoiClientException(String.format(
154+
"Error retrieving DOI: %s",
155+
message))
156+
.withMessageKey("exception.doi.serverErrorRetrieve")
157+
.withDescriptionKey("exception.doi.serverErrorRetrieve.description", new String[]{message});
158+
144159
}
145160

146161
} catch (Exception ex) {
147162
Log.error(LOGGER_NAME, " -- Error (exception): " + ex.getMessage(), ex);
148-
throw new DoiClientException(ex.getMessage());
163+
throw new DoiClientException(String.format(
164+
"Error retrieving DOI: %s",
165+
ex.getMessage()))
166+
.withMessageKey("exception.doi.serverErrorRetrieve")
167+
.withDescriptionKey("exception.doi.serverErrorRetrieve.description", new String[]{ex.getMessage()});
149168

150169
} finally {
151170
if (getMethod != null) {

doi/src/main/java/org/fao/geonet/doi/client/DoiDataciteClient.java

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//=============================================================================
2-
//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the
2+
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
33
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
44
//=== and United Nations Environment Programme (UNEP)
55
//===
@@ -24,8 +24,6 @@
2424

2525
import org.apache.commons.httpclient.HttpStatus;
2626
import org.apache.commons.io.IOUtils;
27-
import org.apache.http.auth.AuthScope;
28-
import org.apache.http.auth.UsernamePasswordCredentials;
2927
import org.apache.http.client.methods.HttpDelete;
3028
import org.fao.geonet.ApplicationContextHolder;
3129
import org.fao.geonet.utils.GeonetHttpRequestFactory;
@@ -179,14 +177,24 @@ public void deleteDoiMetadata(String doi)
179177
if ((status != HttpStatus.SC_NOT_FOUND) && (status != HttpStatus.SC_OK)) {
180178
Log.info(LOGGER_NAME, "Delete DOI metadata end -- Error: " + httpResponse.getStatusText());
181179

182-
throw new DoiClientException( httpResponse.getStatusText() );
180+
String message = httpResponse.getStatusText();
181+
182+
throw new DoiClientException(String.format(
183+
"Error deleting DOI: %s",
184+
message))
185+
.withMessageKey("exception.doi.serverErrorDelete")
186+
.withDescriptionKey("exception.doi.serverErrorDelete.description", new String[]{message});
183187
} else {
184188
Log.info(LOGGER_NAME, "DeleteDOI metadata end");
185189
}
186190

187191
} catch (Exception ex) {
188192
Log.error(LOGGER_NAME, " -- Error (exception): " + ex.getMessage(), ex);
189-
throw new DoiClientException(ex.getMessage());
193+
throw new DoiClientException(String.format(
194+
"Error deleting DOI: %s",
195+
ex.getMessage()))
196+
.withMessageKey("exception.doi.serverErrorDelete")
197+
.withDescriptionKey("exception.doi.serverErrorDelete.description", new String[]{ex.getMessage()});
190198

191199
} finally {
192200
if (deleteMethod != null) {
@@ -219,14 +227,25 @@ public void deleteDoi(String doi)
219227
if ((status != HttpStatus.SC_NOT_FOUND) && (status != HttpStatus.SC_OK)) {
220228
Log.info(LOGGER_NAME, "Delete DOI end -- Error: " + httpResponse.getStatusText());
221229

222-
throw new DoiClientException( httpResponse.getStatusText() );
230+
String message = httpResponse.getStatusText();
231+
232+
throw new DoiClientException(String.format(
233+
"Error deleting DOI: %s",
234+
message))
235+
.withMessageKey("exception.doi.serverErrorDelete")
236+
.withDescriptionKey("exception.doi.serverErrorDelete.description", new String[]{message});
223237
} else {
224238
Log.info(LOGGER_NAME, "DeleteDOI end");
225239
}
226240

227241
} catch (Exception ex) {
228242
Log.error(LOGGER_NAME, " -- Error (exception): " + ex.getMessage(), ex);
229-
throw new DoiClientException(ex.getMessage());
243+
244+
throw new DoiClientException(String.format(
245+
"Error deleting DOI: %s",
246+
ex.getMessage()))
247+
.withMessageKey("exception.doi.serverErrorDelete")
248+
.withDescriptionKey("exception.doi.serverErrorDelete.description", new String[]{ex.getMessage()});
230249

231250
} finally {
232251
if (deleteMethod != null) {

doi/src/main/java/org/fao/geonet/doi/client/DoiManager.java

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//=============================================================================
2-
//=== Copyright (C) 2001-2010 Food and Agriculture Organization of the
2+
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
33
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
44
//=== and United Nations Environment Programme (UNEP)
55
//===
@@ -475,7 +475,11 @@ public void unregisterDoi(AbstractMetadata metadata, ServiceContext context) thr
475475
dm.updateMetadata(context, metadata.getId() + "", recordWithoutDoi, false, true,
476476
context.getLanguage(), new ISODate().toString(), true, IndexingMode.full);
477477
} catch (Exception ex) {
478-
throw new DoiClientException(ex.getMessage());
478+
throw new DoiClientException(String.format(
479+
"Error unregistering DOI: %s",
480+
ex.getMessage()))
481+
.withMessageKey("exception.doi.serverErrorUnregister")
482+
.withDescriptionKey("exception.doi.serverErrorUnregister.description", new String[]{ex.getMessage()});
479483
}
480484
}
481485

@@ -487,8 +491,14 @@ public Element setDOIValue(String doi, String schema, Element md) throws Excepti
487491
Path styleSheet = dm.getSchemaDir(schema).resolve(DOI_ADD_XSL_PROCESS);
488492
boolean exists = Files.exists(styleSheet);
489493
if (!exists) {
490-
throw new DoiClientException(String.format("To create a DOI, the schema has to defined how to insert a DOI in the record. The schema_plugins/%s/process/%s was not found. Create the XSL transformation.",
491-
schema, DOI_ADD_XSL_PROCESS));
494+
String message = String.format("To create a DOI, the schema has to defined how to insert a DOI in the record. The schema_plugins/%s/process/%s was not found. Create the XSL transformation.",
495+
schema, DOI_ADD_XSL_PROCESS);
496+
497+
throw new DoiClientException(String.format(
498+
"Error creating DOI: %s",
499+
message))
500+
.withMessageKey("exception.doi.serverErrorCreate")
501+
.withDescriptionKey("exception.doi.serverErrorCreate.description", new String[]{message});
492502
}
493503

494504
String doiPublicUrl = client.createPublicUrl("");
@@ -507,8 +517,15 @@ public Element removeDOIValue(String doi, String schema, Element md) throws Exce
507517
Path styleSheet = dm.getSchemaDir(schema).resolve(DOI_REMOVE_XSL_PROCESS);
508518
boolean exists = Files.exists(styleSheet);
509519
if (!exists) {
510-
throw new DoiClientException(String.format("To remove a DOI, the schema has to defined how to remove a DOI in the record. The schema_plugins/%s/process/%s was not found. Create the XSL transformation.",
511-
schema, DOI_REMOVE_XSL_PROCESS));
520+
String message = String.format("To remove a DOI, the schema has to defined how to remove a DOI in the record. The schema_plugins/%s/process/%s was not found. Create the XSL transformation.",
521+
schema, DOI_REMOVE_XSL_PROCESS);
522+
523+
throw new DoiClientException(String.format(
524+
"Error deleting DOI: %s",
525+
message))
526+
.withMessageKey("exception.doi.serverErrorDelete")
527+
.withDescriptionKey("exception.doi.serverErrorDelete.description", new String[]{message});
528+
512529
}
513530

514531
Map<String, Object> params = new HashMap<>(1);
@@ -528,8 +545,14 @@ private Element convertXmlToDataCiteFormat(String schema, Element md, String doi
528545
isMedra ? DATACITE_MEDRA_XSL_CONVERSION_FILE : DATACITE_XSL_CONVERSION_FILE);
529546
final boolean exists = Files.exists(styleSheet);
530547
if (!exists) {
531-
throw new DoiClientException(String.format("To create a DOI, the record needs to be converted to the DataCite format (https://schema.datacite.org/). You need to create a formatter for this in schema_plugins/%s/%s. If the standard is a profile of ISO19139, you can simply point to the ISO19139 formatter.",
532-
schema, DATACITE_XSL_CONVERSION_FILE));
548+
String message = String.format("To create a DOI, the record needs to be converted to the DataCite format (https://schema.datacite.org/). You need to create a formatter for this in schema_plugins/%s/%s. If the standard is a profile of ISO19139, you can simply point to the ISO19139 formatter.",
549+
schema, DATACITE_XSL_CONVERSION_FILE);
550+
551+
throw new DoiClientException(String.format(
552+
"Error creating DOI: %s",
553+
message))
554+
.withMessageKey("exception.doi.serverErrorCreate")
555+
.withDescriptionKey("exception.doi.serverErrorCreate.description", new String[]{message});
533556
}
534557

535558
Map<String,Object> params = new HashMap<>();
@@ -539,7 +562,9 @@ private Element convertXmlToDataCiteFormat(String schema, Element md, String doi
539562

540563
private void checkInitialised() throws DoiClientException {
541564
if (!initialised) {
542-
throw new DoiClientException("DOI configuration is not complete. Check System Configuration and set the DOI configuration.");
565+
throw new DoiClientException("DOI configuration is not complete. Check System Configuration and set the DOI configuration.")
566+
.withMessageKey("exception.doi.configurationMissing")
567+
.withDescriptionKey("exception.doi.configurationMissing.description", new String[]{});
543568
}
544569
}
545570

doi/src/main/java/org/fao/geonet/doi/client/DoiMedraClient.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//=============================================================================
2-
//=== Copyright (C) 2001-2010 Food and Agriculture Organization of the
2+
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
33
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
44
//=== and United Nations Environment Programme (UNEP)
55
//===
@@ -58,7 +58,10 @@ public String retrieveDoi(String doi) throws DoiClientException {
5858

5959
@Override
6060
public String retrieveAllDoi(String doi) throws DoiClientException {
61-
throw new DoiClientException(MEDRA_NOT_SUPPORTED_EXCEPTION_MESSAGE);
61+
throw new DoiClientException(MEDRA_NOT_SUPPORTED_EXCEPTION_MESSAGE)
62+
.withMessageKey("exception.doi.operationNotSupported")
63+
.withDescriptionKey("exception.doi.operationNotSupported.description",
64+
new String[]{ MEDRA_NOT_SUPPORTED_EXCEPTION_MESSAGE });
6265
}
6366

6467
/**

web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages.properties

+12
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ exception.doi.recordNotConformantMissingMandatory=Record is not conform with Dat
180180
exception.doi.recordNotConformantMissingMandatory.description=Record ''{0}'' is not conform with DataCite validation rules for mandatory fields. Error is: {1}. Required fields in DataCite are: identifier, creators, titles, publisher, publicationYear, resourceType. <a href=''{2}api/records/{3}/formatters/datacite?output=xml''>Check the DataCite format output</a> and adapt the record content to add missing information.
181181
exception.doi.recordInvalid=Record converted to DataCite format is invalid.
182182
exception.doi.recordInvalid.description=Record ''{0}'' converted to DataCite format is invalid. Error is: {1}. Required fields in DataCite are: identifier, creators, titles, publisher, publicationYear, resourceType. <a href=''{2}api/records/{3}/formatters/datacite?output=xml''>Check the DataCite format output</a> and adapt the record content to add missing information.
183+
exception.doi.serverErrorCreate=Error creating DOI
184+
exception.doi.serverErrorCreate.description=Error creating DOI: {0}
185+
exception.doi.serverErrorRetrieve=Error retrieving DOI
186+
exception.doi.serverErrorRetrieve.description=Error retrieving DOI: {0}
187+
exception.doi.serverErrorDelete=Error deleting DOI
188+
exception.doi.serverErrorDelete.description=Error deleting DOI: {0}
189+
exception.doi.serverErrorUnregister=Error unregistering DOI
190+
exception.doi.serverErrorUnregister.description=Error unregistering DOI: {0}
191+
exception.doi.configurationMissing=DOI configuration is not complete
192+
exception.doi.configurationMissing.description=DOI configuration is not complete. Check System Configuration and set the DOI configuration.
193+
exception.doi.notSupportedOperationError=Operation not supported
194+
exception.doi.notSupportedOperationError.description={0}
183195
api.metadata.import.importedWithId=Metadata imported with ID '%s'
184196
api.metadata.import.importedWithUuid=Metadata imported with UUID '%s'
185197
api.metadata.import.importedFromXMLWithUuid=Metadata imported from XML with UUID '%s'

0 commit comments

Comments
 (0)