From f3c1e864c5654038536ff141ef30a69def5fc5ae Mon Sep 17 00:00:00 2001 From: pahnjy Date: Fri, 3 Feb 2017 11:29:10 +0900 Subject: [PATCH] =?UTF-8?q?Service=20API=20=EC=B6=94=EA=B0=80=20#351?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../icbms/so/device/util/ClientProfile.java | 4 + .../icbms/so/service/logic/ServiceLogic.java | 2 + .../so/service/logic/ServiceLogicImpl.java | 14 +++ .../so/service/pr/ServicePresentation.java | 16 ++++ .../so/service/proxy/DataServiceObject.java | 96 +++++++++++++++++++ .../so/service/proxy/ServiceSDAProxy.java | 1 + .../so/service/proxy/ServiceSDAProxyImpl.java | 21 ++++ 7 files changed, 154 insertions(+) create mode 100644 so-service/src/main/java/com/pineone/icbms/so/service/proxy/DataServiceObject.java diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/util/ClientProfile.java b/so-device/src/main/java/com/pineone/icbms/so/device/util/ClientProfile.java index be9af881..0bbeacd9 100644 --- a/so-device/src/main/java/com/pineone/icbms/so/device/util/ClientProfile.java +++ b/so-device/src/main/java/com/pineone/icbms/so/device/util/ClientProfile.java @@ -37,6 +37,10 @@ public class ClientProfile { // Context Model public static final String CM_LACK_EQUIPMENT_COUNT = "cm-lack-equipment-count/?p="; public static final String CM_TEMP = "cm-temp/?p="; + public static final String PREFIX_CM_BACK_ATTACH = "?p=,"; + public static final String PREFIX_CM_COMMA = ","; + public static final String PREFIX_CM_BACK_ATTACH_NO_COMMA = "?p="; + // Location public static final String LOCATION_ENGCENTER_616 = "http://www.iotoasis.org/ontology/engcenter_616"; diff --git a/so-service/src/main/java/com/pineone/icbms/so/service/logic/ServiceLogic.java b/so-service/src/main/java/com/pineone/icbms/so/service/logic/ServiceLogic.java index b2c2e1fd..c42fbe84 100644 --- a/so-service/src/main/java/com/pineone/icbms/so/service/logic/ServiceLogic.java +++ b/so-service/src/main/java/com/pineone/icbms/so/service/logic/ServiceLogic.java @@ -2,6 +2,7 @@ import com.pineone.icbms.so.service.entity.Service; +import com.pineone.icbms.so.service.proxy.DataServiceObject; import com.pineone.icbms.so.service.ref.ConceptService; import com.pineone.icbms.so.service.ref.DeviceObject; import com.pineone.icbms.so.service.ref.Status; @@ -18,4 +19,5 @@ public interface ServiceLogic { List retrieveServiceIdList(); void executeService(String serviceId, String sessionId); List retrieveServiceList(); + String requestDataService(DataServiceObject dataServiceObject); } diff --git a/so-service/src/main/java/com/pineone/icbms/so/service/logic/ServiceLogicImpl.java b/so-service/src/main/java/com/pineone/icbms/so/service/logic/ServiceLogicImpl.java index 938e9d9d..ee5b43c6 100644 --- a/so-service/src/main/java/com/pineone/icbms/so/service/logic/ServiceLogicImpl.java +++ b/so-service/src/main/java/com/pineone/icbms/so/service/logic/ServiceLogicImpl.java @@ -3,6 +3,7 @@ import com.pineone.icbms.so.device.util.ClientProfile; import com.pineone.icbms.so.service.entity.Service; +import com.pineone.icbms.so.service.proxy.DataServiceObject; import com.pineone.icbms.so.service.proxy.ServiceProxy; import com.pineone.icbms.so.service.proxy.ServiceSDAProxy; import com.pineone.icbms.so.service.ref.ConceptService; @@ -175,6 +176,7 @@ public void executeService(String serviceId, String sessionId) { if("si-lack-equipment-noti".equals(serviceId)){ try { operation = serviceSDAProxy.getPCCountUri(session); + logger.info("Equipment Data = " + operation); } catch (BadRequestException e) { logger.warn("operation is not Count"); session = sessionStore.retrieveSessionDetail(localSessionId); @@ -183,6 +185,7 @@ public void executeService(String serviceId, String sessionId) { } else if("si-domitory-optimal-environment".equals(serviceId)){ try { operation = serviceSDAProxy.getTemperatureLookup(session); + logger.info("Environment Data = " + operation); } catch (BadRequestException e) { logger.warn("operation is not Count"); session = sessionStore.retrieveSessionDetail(localSessionId); @@ -227,4 +230,15 @@ public List retrieveServiceList() { return services; } + @Override + public String requestDataService(DataServiceObject dataServiceObject) { + String response = ""; + try{ + response = serviceSDAProxy.getDataService(dataServiceObject); + }catch (BadRequestException e){ + response = e.toString(); + } + return response; + } + } diff --git a/so-service/src/main/java/com/pineone/icbms/so/service/pr/ServicePresentation.java b/so-service/src/main/java/com/pineone/icbms/so/service/pr/ServicePresentation.java index 8704f7f1..81a7dc90 100644 --- a/so-service/src/main/java/com/pineone/icbms/so/service/pr/ServicePresentation.java +++ b/so-service/src/main/java/com/pineone/icbms/so/service/pr/ServicePresentation.java @@ -3,6 +3,7 @@ import com.pineone.icbms.so.service.entity.Service; import com.pineone.icbms.so.service.logic.ServiceLogic; +import com.pineone.icbms.so.service.proxy.DataServiceObject; import com.pineone.icbms.so.service.ref.*; import com.pineone.icbms.so.util.exception.DataLossException; import com.pineone.icbms.so.util.logprint.LogPrint; @@ -130,6 +131,21 @@ public List retrieveServiceList(){ return serviceList; } + /** + * Data Service + */ + @RequestMapping(value = "/data", method = RequestMethod.POST) + @ResponseStatus(value = HttpStatus.OK) + public String retrieveServiceList(@RequestBody DataServiceObject dataServiceObject){ + // + logger.info(LogPrint.inputInfoLogPrint() + "Data Service Start"); + logger.info(LogPrint.inputInfoLogPrint() + "DataServiceObject = " + dataServiceObject.toString()); + + String dataServiceData = serviceLogic.requestDataService(dataServiceObject); + logger.info("DataService Data = " + dataServiceData); + return dataServiceData; + } + // NOTE: Service Component 의 DB에 접근해서 service Name 리스트 조회 public List retrieveServiceNameList(){ diff --git a/so-service/src/main/java/com/pineone/icbms/so/service/proxy/DataServiceObject.java b/so-service/src/main/java/com/pineone/icbms/so/service/proxy/DataServiceObject.java new file mode 100644 index 00000000..1c51bbdf --- /dev/null +++ b/so-service/src/main/java/com/pineone/icbms/so/service/proxy/DataServiceObject.java @@ -0,0 +1,96 @@ +package com.pineone.icbms.so.service.proxy; + +public class DataServiceObject { + + public static final int DATASERIVCE_CMID = 1; + public static final int DATASERIVCE_CMID_PARAM1 = 2; + public static final int DATASERIVCE_CMID_PARAM2 = 3; + public static final int DATASERIVCE_CMID_PARAM3 = 4; + public static final int DATASERIVCE_CMID_PARAM4 = 5; + + private String cmId; + private String param1; + private String param2; + private String param3; + private String param4; + + public DataServiceObject() { + } + + public DataServiceObject(String cmId, String param1, String param2, String param3, String param4) { + this.cmId = cmId; + this.param1 = param1; + this.param2 = param2; + this.param3 = param3; + this.param4 = param4; + } + + public String getCmId() { + return cmId; + } + + public void setCmId(String cmId) { + this.cmId = cmId; + } + + public String getParam1() { + return param1; + } + + public void setParam1(String param1) { + this.param1 = param1; + } + + public String getParam2() { + return param2; + } + + public void setParam2(String param2) { + this.param2 = param2; + } + + public String getParam3() { + return param3; + } + + public void setParam3(String param3) { + this.param3 = param3; + } + + public String getParam4() { + return param4; + } + + public void setParam4(String param4) { + this.param4 = param4; + } + + public int getParam(){ + int paramCount = 0; + + if(param4 != null && !param4.isEmpty()){ + paramCount = 4; + } else if(param3 != null && !param3.isEmpty()){ + paramCount = 3; + } else if(param2 != null && !param2.isEmpty()){ + paramCount = 2; + } else if(param1 != null && !param1.isEmpty()){ + paramCount = 1; + } + + return paramCount; + } + + + @Override + public String toString() { + return "DataServiceObject{" + + "cmId='" + cmId + '\'' + + ", param1='" + param1 + '\'' + + ", param2='" + param2 + '\'' + + ", param3='" + param3 + '\'' + + ", param4='" + param4 + '\'' + + '}'; + } + +} diff --git a/so-service/src/main/java/com/pineone/icbms/so/service/proxy/ServiceSDAProxy.java b/so-service/src/main/java/com/pineone/icbms/so/service/proxy/ServiceSDAProxy.java index e5c694e9..a253b510 100644 --- a/so-service/src/main/java/com/pineone/icbms/so/service/proxy/ServiceSDAProxy.java +++ b/so-service/src/main/java/com/pineone/icbms/so/service/proxy/ServiceSDAProxy.java @@ -6,4 +6,5 @@ public interface ServiceSDAProxy { String getPCCountUri(Session session) throws BadRequestException; String getTemperatureLookup(Session session) throws BadRequestException; + String getDataService(DataServiceObject dataServiceObject) throws BadRequestException; } diff --git a/so-service/src/main/java/com/pineone/icbms/so/service/proxy/ServiceSDAProxyImpl.java b/so-service/src/main/java/com/pineone/icbms/so/service/proxy/ServiceSDAProxyImpl.java index 318a80aa..dfcb8ea4 100644 --- a/so-service/src/main/java/com/pineone/icbms/so/service/proxy/ServiceSDAProxyImpl.java +++ b/so-service/src/main/java/com/pineone/icbms/so/service/proxy/ServiceSDAProxyImpl.java @@ -94,4 +94,25 @@ public String getTemperatureLookup(Session session) throws BadRequestException { } } + + @Override + public String getDataService(DataServiceObject dataServiceObject) throws BadRequestException { + String requestUri = ""; + if(dataServiceObject.getParam() == DataServiceObject.DATASERIVCE_CMID){ + requestUri = contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + dataServiceObject.getCmId() + ClientProfile.PREFIX_CM_BACK_ATTACH; + } else if(dataServiceObject.getParam() == DataServiceObject.DATASERIVCE_CMID_PARAM2) { + requestUri = contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + dataServiceObject.getCmId() + ClientProfile.PREFIX_CM_BACK_ATTACH_NO_COMMA + dataServiceObject.getParam1() + ClientProfile.PREFIX_CM_COMMA + dataServiceObject.getParam2(); + } + + IHttpResponseMessage message = clientService.requestGetService(requestUri); + if(message.getStatusCode() == 200) { + System.out.println(message.getBodyByteArray().toString()); + logger.debug("ResponseMessage : " + message); + return clientService.responseDataToString(message); + } + else{ + throw new BadRequestException(); + } + + } }