summaryrefslogtreecommitdiffstats
path: root/holmes-actions
diff options
context:
space:
mode:
authoryoubowu <wu.youbo@zte.com.cn>2017-02-15 10:33:19 +0800
committer6092002067 <wu.youbo@zte.com.cn>2017-02-15 11:00:03 +0800
commit95bf2aae433086e88bf996773a2ffed59d69c930 (patch)
treecc34af79e6bd73fabc2ce069444e1da98f58aea6 /holmes-actions
parenta0b5d2fec59b92392997e8fc55331b6d6eddf0a2 (diff)
Add baseservice-i18 dependency
Issue-ID:HOLMES-9 Change-Id: I6ac6239560db4526cb37400528c15cb53308119e Signed-off-by: youbowu <wu.youbo@zte.com.cn>
Diffstat (limited to 'holmes-actions')
-rw-r--r--holmes-actions/pom.xml8
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java43
-rw-r--r--holmes-actions/src/main/java/org/openo/holmes/common/utils/I18nProxy.java105
3 files changed, 152 insertions, 4 deletions
diff --git a/holmes-actions/pom.xml b/holmes-actions/pom.xml
index 7e39212..756a068 100644
--- a/holmes-actions/pom.xml
+++ b/holmes-actions/pom.xml
@@ -20,10 +20,10 @@
<packaging>jar</packaging>
<artifactId>holmes-actions</artifactId>
<dependencies>
- <!--<dependency>-->
- <!--<groupId>org.openo.common-services.common-utilities</groupId>-->
- <!--<artifactId>baseservice-i18n</artifactId>-->
- <!--</dependency>-->
+ <dependency>
+ <groupId>org.openo.common-services.common-utilities</groupId>
+ <artifactId>baseservice-i18n</artifactId>
+ </dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java
new file mode 100644
index 0000000..cc58446
--- /dev/null
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/ExceptionUtil.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.common.utils;
+
+import java.util.Locale;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+public class ExceptionUtil {
+
+ private static final int EXCEPTION_CODE = 499;
+
+ private ExceptionUtil() {
+
+ }
+
+ public static String getExceptionMsg(Locale locale, Exception e) {
+ return I18nProxy.getInstance().getValue(locale, e.getMessage());
+ }
+
+ public static String getExceptionMsgByArgs(Locale locale, Exception e, String[] obj) {
+ return I18nProxy.getInstance().getValueByArgs(locale, e.getMessage(), obj);
+ }
+
+ public static WebApplicationException buildExceptionResponse(String message) {
+ Response response = Response.status(EXCEPTION_CODE).entity(message).type(MediaType.TEXT_PLAIN).build();
+ return new WebApplicationException(response);
+ }
+}
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/I18nProxy.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/I18nProxy.java
new file mode 100644
index 0000000..2eda5da
--- /dev/null
+++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/I18nProxy.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.holmes.common.utils;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Optional;
+import lombok.extern.slf4j.Slf4j;
+import org.openo.baseservice.i18n.I18n;
+
+@Slf4j
+public class I18nProxy {
+
+ /*-----------------------Engine------------------------------- */
+ public static final String ENGINE_CONTENT_ILLEGALITY = "ENGINE_CONTENT_ILLEGALITY";
+ public static final String ENGINE_DEPLOY_RULE_FAILED = "ENGINE_DEPLOY_RULE_FAILED";
+ public static final String ENGINE_DELETE_RULE_NULL = "ENGINE_DELETE_RULE_NULL";
+ public static final String ENGINE_DELETE_RULE_FAILED = "ENGINE_DELETE_RULE_FAILED";
+ public static final String ENGINE_INSERT_RULE_CACHE_FAILED = "ENGINE_INSERT_RULE_CACHE_FAILED";
+ public static final String ENGINE_DELETE_RULE_FAILED_FROM_CACHE = "ENGINE_DELETE_RULE_FAILED_FROM_CACHE";
+ public static final String ENGINE_CONTAINS_PACKAGE = "ENGINE_CONTAINS_PACKAGE";
+ public static final String ENGINE_QUERY_CACHE_FAILED = "ENGINE_QUERY_CACHE_FAILED";
+ /*-----------------------Rule Management------------------------------- */
+ public static final String RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED = "RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED";
+ public static final String RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED = "RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED";
+ public static final String RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED = "RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED";
+ public static final String RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED = "RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED";
+ public static final String RULE_MANAGEMENT_QUERY_RULE_FAILED = "RULE_MANAGEMENT_QUERY_RULE_FAILED";
+ public static final String RULE_MANAGEMENT_CREATE_RULE_FAILED = "RULE_MANAGEMENT_CREATE_RULE_FAILED";
+ public static final String RULE_MANAGEMENT_DELETE_RULE_FAILED = "RULE_MANAGEMENT_DELETE_RULE_FAILED";
+ public static final String RULE_MANAGEMENT_UPDATE_RULE_FAILED = "RULE_MANAGEMENT_UPDATE_RULE_FAILED";
+ public static final String RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY = "RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY";
+ public static final String RULE_MANAGEMENT_RULE_NAME_IS_EMPTY = "RULE_MANAGEMENT_RULE_NAME_IS_EMPTY";
+ public static final String RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE = "RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE";
+ public static final String RULE_MANAGEMENT_UNKNOWN_EXCEPTION = "RULE_MANAGEMENT_UNKNOWN_EXCEPTION";
+ public static final String RULE_MANAGEMENT_REPEAT_RULE_NAME = "RULE_MANAGEMENT_REPEAT_RULE_NAME";
+ public static final String RULE_MANAGEMENT_DATA_FORMAT_ERROR = "RULE_MANAGEMENT_DATA_FORMAT_ERROR";
+ public static final String RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR = "RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR";
+
+ private Optional<I18n> optional = null;
+
+ private I18nProxy() {
+ optional = I18n.getInstance("correlation");
+ }
+
+ private static class I18nProxyHolder {
+
+ private static final I18nProxy INSTANCE = new I18nProxy();
+
+ private I18nProxyHolder() {
+
+ }
+ }
+
+ public static I18nProxy getInstance() {
+ return I18nProxyHolder.INSTANCE;
+ }
+
+ public String getValue(Locale locale, String key) {
+ return optional.get().getLabelValue(key, locale);
+ }
+
+ public String getValueByArgs(Locale locale, String key, String[] arguments) {
+ return optional.get().getLabelValue(key, locale, arguments);
+ }
+
+ public Map<String, String> getValue(String key) {
+ return optional.get().getLabelValues(key);
+ }
+
+ public String jsonI18n(String key) {
+
+ return optional.get().getCanonicalLabelValues(key);
+ }
+
+ public String i18nWithArgs(String key, String[] args) {
+ String value = "";
+ try {
+ value = JacksonUtil.beanToJson(optional.get().getLabelValues(key, args));
+ } catch (JsonProcessingException e) {
+ log.info("get i18n error, key is :" + key, e);
+ } catch (IllegalArgumentException e) {
+ log.info("get i18n error IllegalArgumentException, key is :" + key + ",args is : " + Arrays.toString(args),
+ e);
+ }
+
+ return value;
+ }
+
+}