Skip to content

Commit

Permalink
Update DOI exceptions to be multilingual exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
josegar74 committed May 29, 2024
1 parent c50cff7 commit dd9f5fb
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 24 deletions.
10 changes: 10 additions & 0 deletions core/src/test/resources/org/fao/geonet/api/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ exception.doi.recordNotConformantMissingMandatory=Record is not conform with Dat
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.
exception.doi.recordInvalid=Record converted to DataCite format is invalid.
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.
exception.doi.serverErrorCreate=Error creating DOI
exception.doi.serverErrorCreate.description=Error creating DOI: {0}
exception.doi.serverErrorRetrieve=Error retrieving DOI
exception.doi.serverErrorRetrieve.description=Error retrieving DOI: {0}
exception.doi.serverErrorDelete=Error deleting DOI
exception.doi.serverErrorDelete.description=Error deleting DOI: {0}
exception.doi.serverErrorUnregister=Error unregistering DOI
exception.doi.serverErrorUnregister.description=Error unregistering DOI: {0}
exception.doi.notSupportedOperationError=Operation not supported
exception.doi.notSupportedOperationError.description={0}
api.metadata.import.importedWithId=Metadata imported with ID '%s'
api.metadata.import.importedWithUuid=Metadata imported with UUID '%s'
api.metadata.import.importedFromXMLWithUuid=Metadata imported from XML with UUID '%s'
Expand Down
10 changes: 10 additions & 0 deletions core/src/test/resources/org/fao/geonet/api/Messages_fre.properties
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ exception.doi.recordNotConformantMissingMandatory=La fiche n''est pas conforme a
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.
exception.doi.recordInvalid=Le fiche converti n''est pas conforme au format DataCite
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.
exception.doi.serverErrorCreate=Error creating DOI
exception.doi.serverErrorCreate.description=Error creating DOI: {0}
exception.doi.serverErrorRetrieve=Error retrieving DOI
exception.doi.serverErrorRetrieve.description=Error retrieving DOI: {0}
exception.doi.serverErrorDelete=Error deleting DOI
exception.doi.serverErrorDelete.description=Error deleting DOI: {0}
exception.doi.serverErrorUnregister=Error unregistering DOI
exception.doi.serverErrorUnregister.description=Error unregistering DOI: {0}
exception.doi.notSupportedOperationError=Operation not supported
exception.doi.notSupportedOperationError.description={0}
api.metadata.import.importedWithId=Fiche import\u00E9e avec l'ID '%s'
api.metadata.import.importedWithUuid=Fiche import\u00E9e avec l'UUID '%s'
api.metadata.import.importedFromXMLWithUuid=Fiche import\u00E9e depuis le fichier XML avec l'UUID '%s'
Expand Down
31 changes: 25 additions & 6 deletions doi/src/main/java/org/fao/geonet/doi/client/BaseDoiClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//=============================================================================
//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
//=== and United Nations Environment Programme (UNEP)
//===
Expand Down Expand Up @@ -94,14 +94,22 @@ protected void create(String url, String body, String contentType,
url, body, status,
httpResponse.getStatusText(), responseBody);
Log.info(LOGGER_NAME, message);
throw new DoiClientException(message);
throw new DoiClientException(String.format(
"Error creating DOI: %s",
message))
.withMessageKey("exception.doi.serverErrorCreate")
.withDescriptionKey("exception.doi.serverErrorCreate.description", new String[]{message});
} else {
Log.info(LOGGER_NAME, String.format(
successMessage, url));
}
} catch (Exception ex) {
Log.error(LOGGER_NAME, " -- Error (exception): " + ex.getMessage(), ex);
throw new DoiClientException(ex.getMessage());
throw new DoiClientException(String.format(
"Error creating DOI: %s",
ex.getMessage()))
.withMessageKey("exception.doi.serverErrorCreate")
.withDescriptionKey("exception.doi.serverErrorCreate.description", new String[]{ex.getMessage()});

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

throw new DoiClientException( httpResponse.getStatusText() +
CharStreams.toString(new InputStreamReader(httpResponse.getBody())));
String message = httpResponse.getStatusText() +
CharStreams.toString(new InputStreamReader(httpResponse.getBody()));

throw new DoiClientException(String.format(
"Error retrieving DOI: %s",
message))
.withMessageKey("exception.doi.serverErrorRetrieve")
.withDescriptionKey("exception.doi.serverErrorRetrieve.description", new String[]{message});

}

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

} finally {
if (getMethod != null) {
Expand Down
33 changes: 26 additions & 7 deletions doi/src/main/java/org/fao/geonet/doi/client/DoiDataciteClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//=============================================================================
//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
//=== and United Nations Environment Programme (UNEP)
//===
Expand All @@ -24,8 +24,6 @@

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

throw new DoiClientException( httpResponse.getStatusText() );
String message = httpResponse.getStatusText();

throw new DoiClientException(String.format(
"Error deleting DOI: %s",
message))
.withMessageKey("exception.doi.serverErrorDelete")
.withDescriptionKey("exception.doi.serverErrorDelete.description", new String[]{message});
} else {
Log.info(LOGGER_NAME, "DeleteDOI metadata end");
}

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

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

throw new DoiClientException( httpResponse.getStatusText() );
String message = httpResponse.getStatusText();

throw new DoiClientException(String.format(
"Error deleting DOI: %s",
message))
.withMessageKey("exception.doi.serverErrorDelete")
.withDescriptionKey("exception.doi.serverErrorDelete.description", new String[]{message});
} else {
Log.info(LOGGER_NAME, "DeleteDOI end");
}

} catch (Exception ex) {
Log.error(LOGGER_NAME, " -- Error (exception): " + ex.getMessage(), ex);
throw new DoiClientException(ex.getMessage());

throw new DoiClientException(String.format(
"Error deleting DOI: %s",
ex.getMessage()))
.withMessageKey("exception.doi.serverErrorDelete")
.withDescriptionKey("exception.doi.serverErrorDelete.description", new String[]{ex.getMessage()});

} finally {
if (deleteMethod != null) {
Expand Down
43 changes: 34 additions & 9 deletions doi/src/main/java/org/fao/geonet/doi/client/DoiManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//=============================================================================
//=== Copyright (C) 2001-2010 Food and Agriculture Organization of the
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
//=== and United Nations Environment Programme (UNEP)
//===
Expand Down Expand Up @@ -475,7 +475,11 @@ public void unregisterDoi(AbstractMetadata metadata, ServiceContext context) thr
dm.updateMetadata(context, metadata.getId() + "", recordWithoutDoi, false, true,
context.getLanguage(), new ISODate().toString(), true, IndexingMode.full);
} catch (Exception ex) {
throw new DoiClientException(ex.getMessage());
throw new DoiClientException(String.format(
"Error unregistering DOI: %s",
ex.getMessage()))
.withMessageKey("exception.doi.serverErrorUnregister")
.withDescriptionKey("exception.doi.serverErrorUnregister.description", new String[]{ex.getMessage()});
}
}

Expand All @@ -487,8 +491,14 @@ public Element setDOIValue(String doi, String schema, Element md) throws Excepti
Path styleSheet = dm.getSchemaDir(schema).resolve(DOI_ADD_XSL_PROCESS);
boolean exists = Files.exists(styleSheet);
if (!exists) {
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.",
schema, DOI_ADD_XSL_PROCESS));
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.",
schema, DOI_ADD_XSL_PROCESS);

throw new DoiClientException(String.format(
"Error creating DOI: %s",
message))
.withMessageKey("exception.doi.serverErrorCreate")
.withDescriptionKey("exception.doi.serverErrorCreate.description", new String[]{message});
}

String doiPublicUrl = client.createPublicUrl("");
Expand All @@ -507,8 +517,15 @@ public Element removeDOIValue(String doi, String schema, Element md) throws Exce
Path styleSheet = dm.getSchemaDir(schema).resolve(DOI_REMOVE_XSL_PROCESS);
boolean exists = Files.exists(styleSheet);
if (!exists) {
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.",
schema, DOI_REMOVE_XSL_PROCESS));
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.",
schema, DOI_REMOVE_XSL_PROCESS);

throw new DoiClientException(String.format(
"Error deleting DOI: %s",
message))
.withMessageKey("exception.doi.serverErrorDelete")
.withDescriptionKey("exception.doi.serverErrorDelete.description", new String[]{message});

}

Map<String, Object> params = new HashMap<>(1);
Expand All @@ -528,8 +545,14 @@ private Element convertXmlToDataCiteFormat(String schema, Element md, String doi
isMedra ? DATACITE_MEDRA_XSL_CONVERSION_FILE : DATACITE_XSL_CONVERSION_FILE);
final boolean exists = Files.exists(styleSheet);
if (!exists) {
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.",
schema, DATACITE_XSL_CONVERSION_FILE));
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.",
schema, DATACITE_XSL_CONVERSION_FILE);

throw new DoiClientException(String.format(
"Error creating DOI: %s",
message))
.withMessageKey("exception.doi.serverErrorCreate")
.withDescriptionKey("exception.doi.serverErrorCreate.description", new String[]{message});
}

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

private void checkInitialised() throws DoiClientException {
if (!initialised) {
throw new DoiClientException("DOI configuration is not complete. Check System Configuration and set the DOI configuration.");
throw new DoiClientException("DOI configuration is not complete. Check System Configuration and set the DOI configuration.")
.withMessageKey("exception.doi.configurationMissing")
.withDescriptionKey("exception.doi.configurationMissing.description", new String[]{});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//=============================================================================
//=== Copyright (C) 2001-2010 Food and Agriculture Organization of the
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
//=== and United Nations Environment Programme (UNEP)
//===
Expand Down Expand Up @@ -58,7 +58,10 @@ public String retrieveDoi(String doi) throws DoiClientException {

@Override
public String retrieveAllDoi(String doi) throws DoiClientException {
throw new DoiClientException(MEDRA_NOT_SUPPORTED_EXCEPTION_MESSAGE);
throw new DoiClientException(MEDRA_NOT_SUPPORTED_EXCEPTION_MESSAGE)
.withMessageKey("exception.doi.operationNotSupported")
.withDescriptionKey("exception.doi.operationNotSupported.description",
new String[]{ MEDRA_NOT_SUPPORTED_EXCEPTION_MESSAGE });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ exception.doi.recordNotConformantMissingMandatory=Record is not conform with Dat
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.
exception.doi.recordInvalid=Record converted to DataCite format is invalid.
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.
exception.doi.serverErrorCreate=Error creating DOI
exception.doi.serverErrorCreate.description=Error creating DOI: {0}
exception.doi.serverErrorRetrieve=Error retrieving DOI
exception.doi.serverErrorRetrieve.description=Error retrieving DOI: {0}
exception.doi.serverErrorDelete=Error deleting DOI
exception.doi.serverErrorDelete.description=Error deleting DOI: {0}
exception.doi.serverErrorUnregister=Error unregistering DOI
exception.doi.serverErrorUnregister.description=Error unregistering DOI: {0}
exception.doi.configurationMissing=DOI configuration is not complete
exception.doi.configurationMissing.description=DOI configuration is not complete. Check System Configuration and set the DOI configuration.
exception.doi.notSupportedOperationError=Operation not supported
exception.doi.notSupportedOperationError.description={0}
api.metadata.import.importedWithId=Metadata imported with ID '%s'
api.metadata.import.importedWithUuid=Metadata imported with UUID '%s'
api.metadata.import.importedFromXMLWithUuid=Metadata imported from XML with UUID '%s'
Expand Down
Loading

0 comments on commit dd9f5fb

Please sign in to comment.