aboutsummaryrefslogtreecommitdiff
path: root/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAIDMessageProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAIDMessageProvider.java')
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAIDMessageProvider.java113
1 files changed, 79 insertions, 34 deletions
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAIDMessageProvider.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAIDMessageProvider.java
index 4d8a07a55..f4143e434 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAIDMessageProvider.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/MOAIDMessageProvider.java
@@ -48,47 +48,46 @@ package at.gv.egovernment.moa.id.commons.utils;
import java.util.Locale;
+import org.springframework.stereotype.Service;
+
+import at.gv.egiz.eaaf.core.api.IStatusMessenger;
+import at.gv.egiz.eaaf.core.exceptions.ProcessExecutionException;
+import at.gv.egovernment.moa.id.commons.api.exceptions.BKUException;
+import at.gv.egovernment.moa.id.commons.api.exceptions.MISSimpleClientException;
+import at.gv.egovernment.moa.id.commons.api.exceptions.MOAIDException;
import at.gv.egovernment.moa.util.Messages;
+import at.gv.egovernment.moa.util.MiscUtil;
-/**
- * A singleton wrapper around a <code>Message</code> object, providing the messages used in MOA-ID.
- *
- * @author Paul Ivancsics
- * @version $Id$
- */
-public class MOAIDMessageProvider {
+
+@Service("MOAIDMessageProvider")
+public class MOAIDMessageProvider implements IStatusMessenger {
- /** DEFAULT_MESSAGE_RESOURCES are resources/properties/id_messages */
- private static final String[] DEFAULT_MESSAGE_RESOURCES =
- { "resources/properties/id_messages" };
- /** DEFAULT_MESSAGE_LOCALES are "de", "AT" */
- private static final Locale[] DEFAULT_MESSAGE_LOCALES =
- new Locale[] { new Locale("de", "AT") };
- /** The instance for our singleton */
- private static MOAIDMessageProvider instance;
- /** The Messages */
+ //internal messanges
+ private static final String[] DEFAULT_MESSAGE_RESOURCES = { "resources/properties/id_messages" };
+ private static final Locale[] DEFAULT_MESSAGE_LOCALES = new Locale[] { new Locale("de", "AT") };
private Messages messages;
- /**
- * Returns the single instance of <code>MOAIDMessageProvider</code>.
- *
- * @return the single instance of <code>MOAIDMessageProvider</code>
- */
+ //external error codes
+ private static final String[] DEFAULT_EXTERNALERROR_RESOURCES = { "resources/properties/protocol_response_statuscodes" };
+ private static final Locale[] DEFAULT_EXTERNALERROR_LOCALES = new Locale[] { new Locale("de", "AT") };
+ private Messages externalError = null;
+
+
+ private static MOAIDMessageProvider instance = null;
+
public static MOAIDMessageProvider getInstance() {
- if (instance == null)
- instance = new MOAIDMessageProvider(DEFAULT_MESSAGE_RESOURCES, DEFAULT_MESSAGE_LOCALES);
- return instance;
- }
+ if (instance == null)
+ instance = new MOAIDMessageProvider();
+
+ return instance;
+
+ }
- /**
- * Create a <code>MOAIDMessageProvider</code>.
- *
- * @param resourceNames The names of the resources containing the messages.
- * @param locales The corresponding locales.
- */
- protected MOAIDMessageProvider(String[] resourceNames, Locale[] locales) {
- this.messages = new Messages(resourceNames, locales);
- }
+ public MOAIDMessageProvider() {
+ this.messages = new Messages(DEFAULT_MESSAGE_RESOURCES, DEFAULT_MESSAGE_LOCALES);
+ this.externalError = new Messages(DEFAULT_EXTERNALERROR_RESOURCES, DEFAULT_EXTERNALERROR_LOCALES);
+
+ }
/**
* Get the message corresponding to a given message ID.
@@ -97,8 +96,54 @@ public class MOAIDMessageProvider {
* @param parameters The parameters to fill in into the message arguments.
* @return The formatted message.
*/
+ @Override
public String getMessage(String messageId, Object[] parameters) {
return messages.getMessage(messageId, parameters);
}
+
+@Override
+public String getResponseErrorCode(Throwable throwable) {
+ String errorCode = null;
+
+ if (throwable instanceof BKUException) {
+ BKUException error = (BKUException) throwable;
+ errorCode = mapInternalErrorToExternalError(error.getMessageId()) +
+ error.getBkuErrorCode();
+
+ } else if (throwable instanceof MISSimpleClientException) {
+ MISSimpleClientException error = (MISSimpleClientException) throwable;
+
+ if (MiscUtil.isNotEmpty(error.getMISErrorCode()))
+ errorCode = mapInternalErrorToExternalError(error.getMessageId()) +
+ error.getMISErrorCode();
+ else
+ errorCode = mapInternalErrorToExternalError(error.getMessageId());
+
+ } else if (throwable instanceof MOAIDException) {
+ MOAIDException error = (MOAIDException) throwable;
+ errorCode = mapInternalErrorToExternalError(error.getMessageId());
+
+ } else if (throwable instanceof ProcessExecutionException) {
+ errorCode = IStatusMessenger.CODES_EXTERNAL_ERROR_PROCESSENGINE;
+
+ } else {
+ errorCode = IStatusMessenger.CODES_EXTERNAL_ERROR_GENERIC;
+
+ }
+
+ return errorCode;
+}
+
+
+@Override
+public String mapInternalErrorToExternalError(String intErrorCode) {
+ String extErrorCode = externalError.getMessage(intErrorCode, null);
+
+ if (MiscUtil.isEmpty(extErrorCode))
+ extErrorCode = IStatusMessenger.CODES_EXTERNAL_ERROR_GENERIC;
+
+ return extErrorCode;
+}
+
}