Add multi-language APIs into BE-common 14/83914/1
authorshentao999 <shentao@chinamobile.com>
Tue, 2 Apr 2019 02:18:24 +0000 (10:18 +0800)
committershentao999 <shentao@chinamobile.com>
Tue, 2 Apr 2019 02:18:25 +0000 (10:18 +0800)
Change-Id: Ia9fddbe81bb2eb8d3e0786fcc81f0469ed45bfa0
Issue-ID: PORTAL-376
Signed-off-by: shentao999 <shentao@chinamobile.com>
ecomp-portal-BE-common/pom.xml
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/AppsController.java
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/LanguageController.java [new file with mode: 0644]
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/DisplayText.java [new file with mode: 0644]
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUser.java
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/Language.java [new file with mode: 0644]
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImpl.java
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/LanguageService.java [new file with mode: 0644]
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/LanguageServiceImpl.java [new file with mode: 0644]
ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml

index 6cb1279..b8787f7 100644 (file)
        
                        
                </dependency>
+               <dependency>
+                       <groupId>org.projectlombok</groupId>
+                       <artifactId>lombok</artifactId>
+                       <version>1.18.4</version>
+               </dependency>
+
+               <dependency>
+                       <groupId>com.alibaba</groupId>
+                       <artifactId>fastjson</artifactId>
+                       <version>1.2.7</version>
+               </dependency>
        </dependencies>
 
 </project>
index 289c827..b5bd02b 100644 (file)
@@ -233,7 +233,7 @@ public class AppsController extends EPRestrictedBaseController {
         * @return JSON with left menu
         */
        @SuppressWarnings({ "rawtypes", "unchecked" })
-       @RequestMapping(value = { "/portalApi/leftmenuItems" }, method = RequestMethod.GET, produces = "application/json")
+       @RequestMapping(value = { "/portalApi/leftmenuItems" }, method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
        public String getLeftMenuItems(HttpServletRequest request, HttpServletResponse response) {
                String menuList = null;
                Set menuSet = (Set) AppUtils.getSession(request)
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/LanguageController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/LanguageController.java
new file mode 100644 (file)
index 0000000..f3a7928
--- /dev/null
@@ -0,0 +1,53 @@
+/**
+ * Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.onap.portalapp.portal.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import org.onap.portalapp.portal.domain.Language;
+import org.onap.portalapp.portal.service.LanguageService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+@RestController
+@RequestMapping("/auxapi")
+public class LanguageController {
+
+    @Autowired
+    private LanguageService languageService;
+
+    @RequestMapping(value = "/language",method = RequestMethod.GET)
+    public JSONObject getLanguageList() {
+        return languageService.getLanguages();
+    }
+
+    @RequestMapping(value = "/languageSetting/user/{loginId}",method = RequestMethod.POST)
+    public void setUpUserLanguage(@RequestBody JSONObject jsonLanguageId,
+                                  @PathVariable("loginId") String loginId) throws Exception {
+        Integer languageId = jsonLanguageId.getInteger("languageId");
+        languageService.setUpUserLanguage(languageId,loginId);
+    }
+
+    @RequestMapping(value = "/languageSetting/user/{loginId}",method = RequestMethod.GET)
+    public JSONObject getUserLanguage(HttpServletRequest request, HttpServletResponse response,
+                                      @PathVariable("loginId") String loginId) {
+        return languageService.getUserLanguage(loginId);
+    }
+
+}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/DisplayText.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/DisplayText.java
new file mode 100644 (file)
index 0000000..d375c02
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.onap.portalapp.portal.domain;
+
+import lombok.Data;
+
+@Data
+public class DisplayText {
+
+    private Integer id;
+    private Integer languageId;
+    private Long textId;
+    private String label;
+}
index d7cce0e..ce7495f 100644 (file)
@@ -98,7 +98,7 @@ public class EPUser extends User {
            private Long timeZoneId;
            private boolean online;
            private String chatId;
-       
+           private Integer languageId;
            private static final long serialVersionUID = 1L;
 
            private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPUser.class);
@@ -491,8 +491,16 @@ public class EPUser extends User {
                public void setChatId(String chatId) {
                        this.chatId = chatId;
                }
-
                
+               
+               public Integer getLanguageId() {
+                       return languageId;
+               }
+
+               public void setLanguageId(Integer languageId) {
+                       this.languageId = languageId;
+               }
+
        public void setPseudoEPRoles(SortedSet<EPRole> pseudoRoles) {
                this.pseudoRoles = pseudoRoles;
        }
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/Language.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/Language.java
new file mode 100644 (file)
index 0000000..f26488b
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+ * Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.onap.portalapp.portal.domain;
+
+import lombok.Data;
+
+@Data
+public class Language {
+
+    private String languageId;
+    private String languageName;
+    private String languageAlias;
+}
index 97c2b74..96db8e3 100644 (file)
@@ -41,6 +41,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -51,6 +52,7 @@ import java.util.TreeSet;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.onap.portalapp.portal.domain.CentralizedApp;
+import org.onap.portalapp.portal.domain.DisplayText;
 import org.onap.portalapp.portal.domain.EPUser;
 import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
 import org.onap.portalsdk.core.domain.MenuData;
@@ -117,6 +119,30 @@ public class EPLeftMenuServiceImpl implements EPLeftMenuService {
                        }
                }
 
+               //mulitilanguage impl
+               String loginId = user.getLoginId();
+               HashMap loginParams = new HashMap();
+               loginParams.put("login_id",loginId);
+               List<EPUser> epUsers = dataAccessService.executeNamedQuery("getEPUserByLoginId", loginParams, new HashMap());
+               Integer languageId = 1;
+               for (EPUser epUser : epUsers) {
+                       languageId = epUser.getLanguageId();
+               }
+               Iterator<MenuData> iterator = fullMenuSet.iterator();
+               HashMap params = new HashMap();
+               params.put("language_id",languageId);
+               List<DisplayText> displayTexts = dataAccessService.executeNamedQuery("displayText",params,new HashMap());
+               while (iterator.hasNext()) {
+                       MenuData menuData = iterator.next();
+                       for (int index = 0;index<displayTexts.size();index++) {
+                               DisplayText displayText = displayTexts.get(index);
+                               if (menuData.getId()==displayText.getTextId()) {
+                                       menuData.setLabel(displayText.getLabel());
+                                       break;
+                               }
+                       }
+               }
+
                SortedSet<MenuData> sortMenuSet = new TreeSet<MenuData>(new SortOrderComparator());
                for (MenuData mn : fullMenuSet) {
                        sortMenuSet.add(mn);
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/LanguageService.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/LanguageService.java
new file mode 100644 (file)
index 0000000..570d1e9
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.onap.portalapp.portal.service;
+
+import com.alibaba.fastjson.JSONObject;
+import org.onap.portalapp.portal.domain.Language;
+
+import java.util.List;
+
+public interface LanguageService {
+
+    JSONObject getLanguages();
+
+    String setUpUserLanguage(Integer languageId,String loginId) throws Exception;
+
+    JSONObject getUserLanguage(String loginId);
+}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/LanguageServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/LanguageServiceImpl.java
new file mode 100644 (file)
index 0000000..b0d8c42
--- /dev/null
@@ -0,0 +1,75 @@
+/**
+ * Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.onap.portalapp.portal.service;
+
+import com.alibaba.fastjson.JSONObject;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.domain.Language;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class LanguageServiceImpl implements LanguageService {
+
+    @Autowired
+    private DataAccessService dataAccessService;
+
+    @Override
+    public JSONObject getLanguages() {
+        List<Language> languages = (List<Language>) dataAccessService.executeNamedQuery("queryLanguage",null,new HashMap());
+        JSONObject result = new JSONObject();
+        result.put("languageList",languages);
+        return result;
+    }
+
+    @Override
+    public String setUpUserLanguage(Integer languageId, String loginId) throws Exception{
+        Map<String,Object> params = new HashMap<>();
+        params.put("login_id",loginId);
+        params.put("language_id",languageId);
+        dataAccessService.executeNamedQuery("updateFnUser",params,new HashMap());
+        return "success";
+    }
+
+    @Override
+    public JSONObject getUserLanguage(String loginId) {
+        // get language_id from fn_user by loginId
+        JSONObject result = new com.alibaba.fastjson.JSONObject();
+        HashMap params = new HashMap();
+        params.put("login_id",loginId);
+
+        List<EPUser> list = null;
+        list = dataAccessService.executeNamedQuery("getEPUserByLoginId",params,new HashMap());
+        for (EPUser user : list) {
+            int languageId = user.getLanguageId();
+            HashMap<String,String> params1 = new HashMap();
+            params1.put("language_id", String.valueOf(languageId));
+            List<Language> languages = dataAccessService.executeNamedQuery("queryLanguageByLanguageId",params1,new HashMap());
+            for (Language language : languages) {
+                result.put("languageId",languageId);
+                result.put("languageName",language.getLanguageName());
+                result.put("languageAlias",language.getLanguageAlias());
+            }
+            return result;
+        }
+        return null;
+    }
+}
index 5026421..4e8943c 100644 (file)
 <!-- Publishes mappings and queries specific to the ONAP Portal application. -->
 <hibernate-mapping package="org.onap.portalapp.portal.domain">
 
+       <!-- multilanguage -->
+       <class name="Language" table="fn_language">
+               <id name="languageId" column="language_id">
+                       <generator class="native">
+                               <param name="sequence"></param>
+                       </generator>
+               </id>
+               <property name="languageName" column="language_name" />
+               <property name="languageAlias" column="language_alias" />
+       </class>
+       
+       <class name="DisplayText" table="fn_display_text">
+               <id name="id" column="id">
+                       <generator class="native">
+                               <param name="sequence"></param>
+                       </generator>
+               </id>
+               
+               <property name="languageId" column="language_id" />
+               <property name="textId" column="text_id" />
+               <property name="label" column="text_label" />
+       </class>
+
        <!-- Widget class mapping details -->
        <class name="Widget" table="FN_WIDGET">
                <id name="id" column="WIDGET_ID">
                <property name="createdId" column="created_id" />
                <property name="modifiedId" column="modified_id" />
                <property name="timeZoneId" column="timezone" />
+               <property name="languageId" column="language_id" />
 
                <set name="EPUserApps" table="FN_USER_ROLE" lazy="false" sort="natural"
                        inverse="true">
                </many-to-one>
        </class>
 
+       <!-- multilanguage -->
+       <query name="queryLanguage">
+               <![CDATA[
+                       from Language
+               ]]>
+       </query>
+       
+       <query name="displayText">
+               <![CDATA[
+                       from DisplayText where languageId = :language_id
+               ]]>
+       </query>
+       
+       <query name="queryLanguageByLanguageId">
+               <![CDATA[
+                       from Language where languageId = :language_id
+               ]]>
+       </query>
+
        <!-- show the current user plus related users -->
        <sql-query name="relatedUsers">
                <return-scalar column="org_user_id" type="java.lang.String" />