aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhaoyehua <zhaoyh6@asiainfo.com>2021-03-10 15:17:42 +0800
committerzhaoyehua <zhaoyh6@asiainfo.com>2021-03-10 15:18:08 +0800
commit7643cc5b373b167000d676c48d741e830081f3ab (patch)
tree0b384c72573d00f3aa040d19b30f566be65858a8
parent1089fdceb23db729cf895e020138b8310f4c9a52 (diff)
feat:Implementation and docking of natural language parsing function of UUI server.
Issue-ID: USECASEUI-525 Change-Id: I1c864bff4206a08e6f8fa08db73ff06abc4b5b6c Signed-off-by: zhaoyehua <zhaoyh6@asiainfo.com>
-rw-r--r--server/pom.xml12
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentModel.java101
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java258
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/intent/IntentService.java30
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentServiceImpl.java389
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/util/ZipUtil.java106
-rw-r--r--server/src/main/resources/application.properties4
7 files changed, 898 insertions, 2 deletions
diff --git a/server/pom.xml b/server/pom.xml
index ddbf44e9..f167dd7e 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -379,6 +379,18 @@
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.10.0</version>
+ </dependency>
+
</dependencies>
<build>
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentModel.java b/server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentModel.java
new file mode 100644
index 00000000..d8033bb7
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentModel.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2017 CTC, 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.usecaseui.server.bean.intent;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="intent_model")
+public class IntentModel implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name = "id")
+ private int id;
+
+ @Column(name = "model_name")
+ private String modelName;
+
+ @Column(name = "file_path")
+ private String filePath;
+
+ @Column(name = "create_time")
+ private String createTime;
+
+ @Column(name = "size")
+ private Float size;
+
+ @Column(name = "active")
+ private Integer active;
+
+ public IntentModel() {
+
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getModelName() {
+ return modelName;
+ }
+
+ public void setModelName(String modelName) {
+ this.modelName = modelName;
+ }
+
+ public String getFilePath() {
+ return filePath;
+ }
+
+ public void setFilePath(String filePath) {
+ this.filePath = filePath;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public Float getSize() {
+ return size;
+ }
+
+ public void setSize(Float size) {
+ this.size = size;
+ }
+
+ public Integer getActive() {
+ return active;
+ }
+
+ public void setActive(Integer active) {
+ this.active = active;
+ }
+} \ No newline at end of file
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java b/server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java
new file mode 100644
index 00000000..5347a4e1
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java
@@ -0,0 +1,258 @@
+/*
+ * Copyright (C) 2017 CTC, 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.usecaseui.server.controller;
+
+import java.io.File;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Resource;
+
+import org.onap.usecaseui.server.bean.HttpResponseResult;
+import org.onap.usecaseui.server.bean.intent.IntentModel;
+import org.onap.usecaseui.server.service.intent.IntentService;
+import org.onap.usecaseui.server.util.DateUtils;
+import org.onap.usecaseui.server.util.HttpUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@RestController
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+@CrossOrigin(origins = "*")
+@RequestMapping("/intent")
+public class IntentController {
+ private final Logger logger = LoggerFactory.getLogger(IntentController.class);
+ private final static String UPLOADPATH = "/home/uui/upload/";
+ private final static String NLPLOADPATH = "/home/run/bert-master/upload/";
+
+ @Resource(name = "IntentService")
+ private IntentService intentService;
+
+ private ObjectMapper omAlarm = new ObjectMapper();
+
+ @GetMapping(value="/listModel",produces = "application/json;charset=utf8")
+ public String getModels() throws JsonProcessingException {
+ List<IntentModel> listModels = intentService.listModels();
+ return omAlarm.writeValueAsString(listModels);
+ }
+
+ @RequestMapping("/uploadModel")
+ @ResponseBody
+ public String uploadModel (@RequestParam("file") MultipartFile file) {
+ String fileName = file.getOriginalFilename();
+
+ String filePath = UPLOADPATH + fileName ;
+
+ File dest = new File(filePath);
+
+ if(!dest.getParentFile().exists()) {
+ dest.getParentFile().mkdirs();
+ logger.info("create dir, name=" + dest.getParentFile().getName());
+ }
+ try {
+
+ file.transferTo(dest);
+ logger.info("upload file, name = " + dest.getName());
+ IntentModel model = new IntentModel();
+ model.setModelName(fileName);
+ model.setFilePath(filePath);
+ model.setCreateTime(DateUtils.dateToString(new Date()));
+ float size = dest.length();
+ float sizeM = size/1024;
+ model.setSize(sizeM);
+ model.setActive(0);
+ intentService.addModel(model);
+
+ logger.info("save model, " + model.toString());
+ return "1";
+ } catch (Exception e) {
+ logger.error("Details:" + e.getMessage());
+ return "0";
+ }
+ }
+
+ private String deleteModelFile(String modelId){
+ String result = "0";
+ try{
+ IntentModel model = intentService.getModel(modelId);
+ if( model==null){
+ return result;
+ }
+
+ String fileName = model.getModelName();
+ String filePath = UPLOADPATH + fileName;
+ logger.info("delete model file: " + filePath);
+ File dest = new File(filePath);
+ if(dest.exists()){
+ dest.delete();
+ logger.info("delete file OK: " + filePath);
+ if (filePath.endsWith(".zip")) {
+ String unzipPath = filePath.substring(0, filePath.length() - 1 - 4);
+ File unZipFile = new File(unzipPath);
+ if (unZipFile.exists()) {
+ unZipFile.delete();
+ }
+ }
+ }{
+ logger.info("file not found: " + filePath);
+ }
+ result = "1";
+ }catch (Exception e){
+ logger.error("Details:" + e.getMessage());
+ return "0";
+ }
+ return result;
+ }
+
+ @GetMapping(value = {"/activeModel"}, produces = "application/json")
+ public String activeModel(@RequestParam String modelId){
+ String result = "0";
+ try{
+ logger.info("update model record status: id=" + modelId);
+ IntentModel model = intentService.activeModel(modelId);
+
+ logger.info("active NLP model, model=" + model.getFilePath());
+ String dirPath = intentService.activeModelFile(model);
+ if (dirPath != null) {
+ dirPath = dirPath.replace(UPLOADPATH, NLPLOADPATH);
+ load(dirPath);
+ }
+
+
+ result = "1";
+ }catch (Exception e) {
+ logger.error("Details:" + e.getMessage());
+ return "0";
+ }
+
+ return result;
+ }
+
+ private String load(String dirPath) {
+
+ String url = "http://uui-nlp.onap:33011/api/online/load";
+ HashMap<String, String> headers = new HashMap<>();
+ String bodyStr = "{" + "\"path\": \""+dirPath+"\"" + "}";
+ logger.info("request body: " + bodyStr);
+
+ HttpResponseResult result = HttpUtil.sendPostRequestByJson(url, headers, bodyStr);
+ String respContent = result.getResultContent();
+
+ logger.info("NLP api respond: " + String.valueOf(result.getResultCode()));
+ logger.info(respContent);
+
+ JSONObject map = JSON.parseObject(respContent);
+
+ String status = map.getString("Status");
+ logger.info("load result: " + status);
+
+ return status;
+ }
+
+ @DeleteMapping(value = {"/deleteModel"}, produces = "application/json")
+ public String deleteModel(@RequestParam String modelId){
+ String result = "0";
+ try{
+ result = deleteModelFile(modelId);
+
+ logger.info("delete model record: id=" + modelId);
+ result = intentService.deleteModel(modelId);
+ }catch (Exception e) {
+ logger.error("Details:" + e.getMessage());
+ return "0";
+ }
+
+ return result;
+ }
+
+ @ResponseBody
+ @PostMapping(value = {"/predict"}, consumes = MediaType.APPLICATION_JSON_VALUE,
+ produces = "application/json; charset=utf-8")
+ public String predict(@RequestBody Object body) throws ParseException {
+ String text = (String)((Map)body).get("text");
+ //System.out.println(text);
+
+ String url = "http://uui-nlp.onap:33011/api/online/predict";
+ HashMap<String, String> headers = new HashMap<>();
+ String bodyStr = "{\"title\": \"predict\", \"text\": \"" + text
+ + "\"}";
+ logger.info("request body: " + bodyStr);
+
+ HttpResponseResult result = HttpUtil.sendPostRequestByJson(url, headers, bodyStr);
+ String respContent = result.getResultContent();
+
+ logger.info("NLP api respond: " + String.valueOf(result.getResultCode()));
+ logger.info(respContent);
+
+ JSONObject map = JSON.parseObject(respContent);
+
+ JSONObject map2 = new JSONObject();
+
+ for (Map.Entry<String, Object> entry:map.entrySet()) {
+ logger.debug(entry.getKey()+","+entry.getValue());
+ String key = tranlateFieldName(entry.getKey());
+ String valueStr = (String) entry.getValue();
+ String value = intentService.calcFieldValue(key, valueStr);
+ map2.put(key, value);
+ }
+
+ logger.info("translate result: " + map2.toJSONString());
+
+ return map2.toJSONString();
+ }
+
+
+
+ private static String tranlateFieldName(String key){
+ String ret = "";
+ if(key==null || key.trim().equals(""))
+ return ret;
+
+ HashMap<String, String> map = new HashMap<>();
+ map.put("Communication service","name");
+ map.put("Maximum user devices","maxNumberofUEs");
+ map.put("Downlink data rate","expDataRateDL");
+ map.put("Time delay","latency");
+ map.put("Uplink data rate","expDataRateUL");
+ map.put("Resource","resourceSharingLevel");
+ map.put("Mobility","uEMobilityLevel");
+ map.put("Region","coverageArea");
+
+ ret = map.get(key.trim());
+ return ret;
+ }
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentService.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentService.java
new file mode 100644
index 00000000..d1d2848b
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentService.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2017 CTC, 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.usecaseui.server.service.intent;
+
+import java.util.List;
+
+import org.onap.usecaseui.server.bean.intent.IntentModel;
+
+public interface IntentService {
+ public String addModel(IntentModel model);
+ List<IntentModel> listModels();
+ public String deleteModel(String modelId);
+ public IntentModel getModel(String modelId);
+ public IntentModel activeModel(String modelId);
+ String activeModelFile(IntentModel model);
+ String calcFieldValue(String key, String strValue);
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentServiceImpl.java
new file mode 100644
index 00000000..1f08f15c
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentServiceImpl.java
@@ -0,0 +1,389 @@
+/*
+ * Copyright (C) 2017 CTC, 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.usecaseui.server.service.intent.impl;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.transaction.Transactional;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.onap.usecaseui.server.bean.intent.IntentModel;
+import org.onap.usecaseui.server.service.intent.IntentService;
+import org.onap.usecaseui.server.util.ZipUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Service;
+
+@Service("IntentService")
+@Transactional
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+public class IntentServiceImpl implements IntentService {
+ private static final Logger logger = LoggerFactory.getLogger(IntentServiceImpl.class);
+
+ private final static String UPLOADPATH = "/home/uui/upload/";
+
+ @Autowired
+ private SessionFactory sessionFactory;
+
+ private Session getSession() {
+ return sessionFactory.openSession();
+ }
+
+ private final static int MAX_NUMBER_OF_UES = 100000;
+ private final static int MIN_NUMBER_OF_UES = 1;
+ private final static int MAX_EXP_DATA_RATE_DL = 3000;
+ private final static int MIN_EXP_DATA_RATE_DL = 100;
+ private final static int MAX_EXP_DATA_RATE_UL = 3000;
+ private final static int MIN_EXP_DATA_RATE_UL = 100;
+ private final static int MAX_LATENCY = 200;
+ private final static int MIN_LATENCY = 10;
+
+
+ private final static List<String> GB_COMPANY = Arrays.asList(new String[] {"gbps", "gb"});
+ private final static List<String> MB_COMPANY = Arrays.asList(new String[] {"mbps", "mb"});
+
+ @Override
+ public String addModel(IntentModel model) {
+ try(Session session = getSession()){
+ if (null == model){
+ logger.error("IntentServiceImpl addModel model is null!");
+ return "0";
+ }
+ Transaction tx = session.beginTransaction();
+ session.save(model);
+ tx.commit();
+ session.flush();
+ return "1";
+ } catch (Exception e) {
+ logger.error("Details:" + e.getMessage());
+ return "0";
+ }
+
+
+ }
+
+ public List<IntentModel> listModels(){
+ try(Session session = getSession()){
+ StringBuffer hql =new StringBuffer("from IntentModel a where 1=1 ");
+ Query query = session.createQuery(hql.toString());
+ //query.setString("sortType",sortType);
+ List<IntentModel> list= query.list();
+ return list;
+ } catch (Exception e) {
+ logger.error("Details:" + e.getMessage());
+ return Collections.emptyList();
+ }
+ }
+
+ public IntentModel getModel(String modelId){
+ //Transaction tx = null;
+ IntentModel result = null;
+
+ try(Session session = getSession()) {
+ //tx = session.beginTransaction();
+
+ result = (IntentModel)session.createQuery("from IntentModel where id = :modelId")
+ .setParameter("modelId", Integer.parseInt(modelId)).uniqueResult();
+ logger.info("get model OK, id=" + modelId);
+
+ } catch (Exception e) {
+ logger.error("getodel occur exception:"+e);
+
+ }
+
+ return result;
+ }
+
+ public String deleteModel(String modelId){
+ Transaction tx = null;
+ String result="0";
+ if(modelId==null || modelId.trim().equals(""))
+ return result;
+
+ try(Session session = getSession()) {
+ tx = session.beginTransaction();
+
+ IntentModel model = new IntentModel();
+ model.setId(Integer.parseInt(modelId));
+ session.delete(model);
+ tx.commit();
+ logger.info("delete model OK, id=" + modelId);
+
+ result="1";
+ } catch (Exception e) {
+ if(tx!=null){
+ tx.rollback();
+ }
+ logger.error("deleteModel occur exception:"+e);
+
+ }
+ return result;
+ }
+
+ public IntentModel activeModel(String modelId){
+ Transaction tx = null;
+ IntentModel result=null;
+ if(modelId==null || modelId.trim().equals(""))
+ return result;
+
+ try(Session session = getSession()) {
+ tx = session.beginTransaction();
+ List<IntentModel> list = session.createQuery("from IntentModel where active=1").list();
+ if(list!=null && list.size()>0){
+ for (IntentModel m : list) {
+ m.setActive(0);
+ session.save(m);
+ }
+ }
+
+ IntentModel model = (IntentModel)session.createQuery("from IntentModel where id = :modelId")
+ .setParameter("modelId", Integer.parseInt(modelId)).uniqueResult();
+ model.setActive(1);
+ session.save(model);
+ tx.commit();
+ logger.info("active model OK, id=" + modelId);
+
+ result = model;
+ } catch (Exception e) {
+ if(tx!=null){
+ tx.rollback();
+ }
+ logger.error("deleteModel occur exception:"+e);
+
+ }
+ return result;
+ }
+
+ @Override
+ public String activeModelFile(IntentModel model) {
+ if (model == null) {
+ return null;
+ }
+ String filePath = model.getFilePath();
+ if (filePath == null) {
+ return null;
+ }
+ else if (filePath.endsWith(".zip")){
+ try {
+ File file = new File(filePath);
+ String parentPath = file.getParent();
+ String unzipPath = filePath.substring(0, filePath.length() - 4);
+ File unZipFile = new File(unzipPath);
+ if (!unZipFile.exists()) {
+ ZipUtil.unzip(file,parentPath);
+ }
+ return unzipPath;
+
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return filePath;
+ }
+
+ public String calcFieldValue(String key, String strValue){
+ String ret = "";
+
+
+ if(strValue==null)
+ strValue = "";
+ else
+ ret = strValue.trim();
+
+ if("resourceSharingLevel".equalsIgnoreCase(key)){
+ ret = formatValueForResourcesSharingLevel(strValue);
+ }
+ else if("uEMobilityLevel".equalsIgnoreCase(key)){
+ ret = formatValueForUEMobilitylevel(strValue);
+ }
+ else if("coverageArea".equalsIgnoreCase(key)){
+
+ ret = formatValueForCoverageArea(strValue);
+ }
+ else if ("maxNumberofUEs".equalsIgnoreCase(key)) {
+ ret = formatValueForMaxNumberofUEs(strValue);
+ }
+ else if ("expDataRateDL".equalsIgnoreCase(key)) {
+ ret = formatValueForExpDataRateDL(strValue);
+ }
+ else if ("expDataRateUL".equalsIgnoreCase(key)) {
+ ret = formatValueForExpDataRateUL(strValue);
+ }
+ else if ("latency".equalsIgnoreCase(key)) {
+ ret = formatValueForLatency(strValue);
+
+ }
+
+ return ret;
+ }
+
+ private String formatValueForLatency(String strValue) {
+ String ret;
+ if ("default".equalsIgnoreCase(strValue)) {
+ ret = MAX_LATENCY + "";
+ }
+ else if ("low".equalsIgnoreCase(strValue)) {
+ ret = MIN_LATENCY + "";
+ }
+ else {
+ Pattern pattern = Pattern.compile("(\\d+)([\\w ]*)");
+ Matcher matcher = pattern.matcher(strValue);
+
+
+ int dataRate = 10;
+ if (matcher.matches()) {
+ dataRate = Integer.parseInt(matcher.group(1));
+ String company = matcher.group(2).trim().toLowerCase();
+ if ("s".equalsIgnoreCase(company)) {
+ dataRate = dataRate * 1000;
+ }
+ else if (!"ms".equalsIgnoreCase(company)) {
+ dataRate = MAX_LATENCY;
+ }
+ dataRate = dataRate < MIN_LATENCY ? MIN_LATENCY : (dataRate > MAX_LATENCY ? MAX_LATENCY : dataRate);
+ }
+ ret = dataRate + "";
+ }
+ return ret;
+ }
+
+ private String formatValueForExpDataRateUL(String strValue) {
+ String ret;
+ Pattern pattern = Pattern.compile("(\\d+)([\\w ]*)");
+ Matcher matcher = pattern.matcher(strValue);
+
+
+ int dataRate = 100;
+ if (matcher.matches()) {
+ dataRate = Integer.parseInt(matcher.group(1));
+ String company = matcher.group(2).trim().toLowerCase();
+ if (GB_COMPANY.contains(company)) {
+ dataRate = dataRate * 1000;
+ }
+ else if (!MB_COMPANY.contains(company)) {
+ dataRate = 100;
+ }
+ dataRate = dataRate < MIN_EXP_DATA_RATE_UL ? MIN_EXP_DATA_RATE_UL : (dataRate > MAX_EXP_DATA_RATE_UL ? MAX_EXP_DATA_RATE_UL : dataRate);
+ }
+ ret = dataRate + "";
+ return ret;
+ }
+
+ private String formatValueForExpDataRateDL(String strValue) {
+ String ret;
+ Pattern pattern = Pattern.compile("(\\d+)([\\w ]*)");
+ Matcher matcher = pattern.matcher(strValue);
+
+ int dataRate = 100;
+ if (matcher.matches()) {
+ dataRate = Integer.parseInt(matcher.group(1));
+ String company = matcher.group(2).trim().toLowerCase();
+ if (GB_COMPANY.contains(company)) {
+ dataRate = dataRate * 1000;
+ }
+ else if (!MB_COMPANY.contains(company)) {
+ dataRate = 100;
+ }
+ dataRate = dataRate < MIN_EXP_DATA_RATE_DL ? MIN_EXP_DATA_RATE_DL : (dataRate > MAX_EXP_DATA_RATE_DL ? MAX_EXP_DATA_RATE_DL : dataRate);
+ }
+
+ ret = dataRate + "";
+ return ret;
+ }
+
+ private String formatValueForMaxNumberofUEs(String strValue) {
+ String ret;
+ Pattern pattern = Pattern.compile("(\\d+)");
+ Matcher matcher = pattern.matcher(strValue);
+ int maxNumber = 1;
+ if (matcher.matches()) {
+ maxNumber = Integer.parseInt(matcher.group(1));
+ maxNumber = maxNumber < MIN_NUMBER_OF_UES ? MIN_NUMBER_OF_UES : (maxNumber > MAX_NUMBER_OF_UES ? MAX_NUMBER_OF_UES : maxNumber);
+ }
+ ret = maxNumber + "";
+ return ret;
+ }
+
+ private String formatValueForCoverageArea(String strValue) {
+ String ret;
+ Map<String, Object> areaMap = new HashMap<>();
+ areaMap.put("wanshoulu", "Beijing Haidian District Wanshoulu Street");
+ areaMap.put("zhongguancun", "Beijing Haidian District Zhongguancun");
+ areaMap.put("haidian", "Beijing Haidian District Haidian Street");
+ areaMap.put("xisanqi", "Beijing Haidian District Xisanqi Street");
+ areaMap.put("chengbei", "Beijing Changping District Chengbei Street");
+ areaMap.put("chengnan", "Beijing Changping District Chengnan Street");
+ areaMap.put("tiantongyuan north", "Beijing Changping District Tiantongyuan North Street");
+ areaMap.put("tiantongyuan south", "Beijing Changping District Tiantongyuan South Street");
+ areaMap.put("guang'anmenwai", "Beijing Xicheng District Guang'anmenwai Street");
+ areaMap.put("xuanwumen", "Beijing Xicheng District Xuanwumen Street");
+ areaMap.put("west changan", "Beijing Xicheng District West Changan Street");
+ areaMap.put("financial", "Beijing Xicheng District Financial Street");
+ areaMap.put("lujiazui", "Shanghai udongxin District Lujiazui Street");
+ areaMap.put("zhoujiadu", "Shanghai udongxin District Zhoujiadu Street");
+ areaMap.put("tangqiao", "Shanghai udongxin District Tangqiao Street");
+ areaMap.put("nanquanlu", "Shanghai udongxin District Nanquanlu Street");
+ areaMap.put("jiangning lu", "Shanghai Jingan District Jiangning Lu Street");
+ areaMap.put("jing'an temple", "Shanghai Jingan District Jing'an Temple Street");
+ areaMap.put("ningjing west road", "Shanghai Jingan District Ningjing West Road");
+
+ ret = "Beijing Beijing Haiding Wanshoulu";
+ for (Map.Entry<String, Object> entry : areaMap.entrySet()) {
+
+ if (strValue.toLowerCase().contains(entry.getKey())) {
+ ret = entry.getValue().toString();
+ }
+ }
+ return ret;
+ }
+
+ private String formatValueForUEMobilitylevel(String strValue) {
+ String ret;
+ ret = "stationary";
+ if(strValue.contains("Nomadic")){
+ ret = "nomadic";
+ }
+ else if(strValue.contains("restricted")){
+ ret = "Spatially Restricted Mobility";
+ }
+ else if(strValue.contains("fully")){
+ ret = "Fully Mobility";
+ }
+ return ret;
+ }
+
+ private String formatValueForResourcesSharingLevel(String strValue) {
+ String ret;
+ ret = "no-shared";
+ if("shared".equalsIgnoreCase(strValue)){
+ ret = "shared";
+ }
+ return ret;
+ }
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/util/ZipUtil.java b/server/src/main/java/org/onap/usecaseui/server/util/ZipUtil.java
new file mode 100644
index 00000000..e3a67751
--- /dev/null
+++ b/server/src/main/java/org/onap/usecaseui/server/util/ZipUtil.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2017 CTC, 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.usecaseui.server.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.tools.zip.ZipEntry;
+import org.apache.tools.zip.ZipFile;
+import org.apache.tools.zip.ZipOutputStream;
+
+public class ZipUtil {
+
+ public static void zip(String src, String zip) throws IOException {
+ zip(new File(src), new File(zip));
+ }
+
+ public static void zip(String src, File zip) throws IOException {
+ zip(new File(src), zip);
+ }
+
+ public static void zip(File src, String zip) throws IOException {
+ zip(src, new File(zip));
+ }
+
+ public static void zip(File src, File zip) throws IOException {
+ List<ZipEntry> list = foreach(src);
+ ZipOutputStream out = new ZipOutputStream(zip);
+ for (ZipEntry en : list) {
+ File fo = new File(src.getParent(), en.getName());
+ out.putNextEntry(en);
+ FileInputStream in = new FileInputStream(fo);
+ byte[] buffer = new byte[1024*8];
+ for(int len=0;(len=in.read(buffer))!=-1;){
+ out.write(buffer, 0, len);
+ }
+ in.close();
+ out.flush();
+ }
+ out.close();
+ }
+
+ public static void unzip(String zip,String out) throws Exception {
+ unzip(new File(zip), new File(out));
+ }
+
+ public static void unzip(String zip,File out) throws Exception {
+ unzip(new File(zip), out);
+ }
+
+ public static void unzip(File zip,String out) throws Exception {
+ unzip(zip, new File(out));
+ }
+
+ public static void unzip(File zip,File out) throws Exception {
+ ZipFile zipFile = new ZipFile(zip,"GB18030");
+ for (Enumeration<ZipEntry> entries = zipFile.getEntries(); entries.hasMoreElements();) {
+ ZipEntry entry = entries.nextElement();
+ File file = new File(out,entry.getName());
+ if (entry.isDirectory()) {
+ file.mkdirs();
+ } else {
+ File parent = file.getParentFile();
+ if (!parent.exists()) {
+ parent.mkdirs();
+ }
+ IOUtils.copy(zipFile.getInputStream(entry), new FileOutputStream(file));
+ }
+ }
+ zipFile.close();
+ }
+ private static List<ZipEntry> foreach(File file) {
+ return foreach(file, "");
+ }
+ private static List<ZipEntry> foreach(File file, String path) {
+ List<ZipEntry> list = new ArrayList<ZipEntry>();
+ if (file.isDirectory()) {
+ path += file.getName() + File.separator;
+ for (File fo : file.listFiles()) {
+ list.addAll(foreach(fo, path));
+ }
+ } else if (file.isFile()) {
+ list.add(new ZipEntry(path + file.getName()));
+ }
+ return list;
+ }
+}
diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties
index 732122a1..b27e3502 100644
--- a/server/src/main/resources/application.properties
+++ b/server/src/main/resources/application.properties
@@ -16,8 +16,8 @@
## General App Properties
server.servlet.contextPath=/api/usecaseui-server/v1
server.port=8082
-spring.http.multipart.max-file-size=128MB
-spring.http.multipart.max-request-size=128MB
+spring.http.multipart.max-file-size=512MB
+spring.http.multipart.max-request-size=512MB
## App DB Properties
spring.datasource.url=jdbc:postgresql://localhost:5432/uui