From 23e1700cedab8bdfd202bd887f40810a7bbd46c2 Mon Sep 17 00:00:00 2001 From: pahnjy Date: Tue, 3 Jan 2017 11:46:39 +0900 Subject: [PATCH] =?UTF-8?q?Service=EC=97=90=20=EB=94=B0=EB=A5=B8=20CM=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=B6=94=EA=B0=80=20#312?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../icbms/so/device/util/ClientProfile.java | 28 ++++++++- .../icbms/so/service/entity/SDAData.java | 63 +++++++++++++++++++ .../icbms/so/service/entity/TempLocation.java | 27 ++++++++ .../so/service/logic/ServiceLogicImpl.java | 55 +++++++++------- .../so/service/proxy/ServiceSDAProxy.java | 1 + .../so/service/proxy/ServiceSDAProxyImpl.java | 44 +++++++++++-- 6 files changed, 188 insertions(+), 30 deletions(-) create mode 100644 so-service/src/main/java/com/pineone/icbms/so/service/entity/SDAData.java create mode 100644 so-service/src/main/java/com/pineone/icbms/so/service/entity/TempLocation.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 358d5619..fc4f9da7 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 @@ -11,8 +11,13 @@ public class ClientProfile { public static final String DEVICE_SERVICE_NOTI_TYPE = "admin-noti"; // oneM2M device Data - public static final String SI_DEVICE_BEAMSCREEN = "BeamScreen"; - public static final String SI_DEVICE_BLIND = "Blind"; + public static final String SI_DEVICE_BEAMSCREEN = "BeamScreen"; + public static final String SI_DEVICE_BLIND = "Blind"; + public static final String SI_DEVICE_HEATER = "heater"; + public static final String SI_DEVICE_AIRCONDITONER = "airconditioner"; + + // oneM2M Device Control Operation + public static final String SI_DEVICE_OPERTAION = "1"; // oneM2M Container Data public static final String SI_CONTAINER_STATUS = "/status"; @@ -29,6 +34,25 @@ public class ClientProfile { // Device Data Prefix public static final String DEVICE_PRE = "device-"; + // Context Model + public static final String CM_LACK_EQUIPMENT_COUNT = "cm-lack-equipment-count/?p="; + public static final String CM_TEMP = "cm-temp/?p="; + + // Location + public static final String LOCATION_ENGCENTER_616 = "http://www.iotoasis.org/ontology/engcenter_616"; + public static final String LOCATION_CAMPUS_001 = "http://www.iotoasis.org/ontology/campus_001"; + + // SDA prefix + public static final String PREFIX_ONTOLOGY = "http://www.iotoasis.org/ontology/"; + + // SDA TEMP + public static final String TEMP_COLD = "cold"; + public static final String TEMP_HOT = "hot"; + + + + + private ClientProfile() { throw new IllegalAccessError("Utility class"); diff --git a/so-service/src/main/java/com/pineone/icbms/so/service/entity/SDAData.java b/so-service/src/main/java/com/pineone/icbms/so/service/entity/SDAData.java new file mode 100644 index 00000000..12664e8d --- /dev/null +++ b/so-service/src/main/java/com/pineone/icbms/so/service/entity/SDAData.java @@ -0,0 +1,63 @@ +package com.pineone.icbms.so.service.entity; + +import java.util.List; + +public class SDAData { + String cmd; + List contents; + String time; + String contextId; + + + public SDAData() { + } + + public SDAData(String cmd, List contents, String time, String contextId) { + this.cmd = cmd; + this.contents = contents; + this.time = time; + this.contextId = contextId; + } + + public String getCmd() { + return cmd; + } + + public void setCmd(String cmd) { + this.cmd = cmd; + } + + public List getContents() { + return contents; + } + + public void setContents(List contents) { + this.contents = contents; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getContextId() { + return contextId; + } + + public void setContextId(String contextId) { + this.contextId = contextId; + } + + @Override + public String toString() { + return "SDAData{" + + "cmd='" + cmd + '\'' + + ", contents=" + contents + + ", time='" + time + '\'' + + ", contextId='" + contextId + '\'' + + '}'; + } +} diff --git a/so-service/src/main/java/com/pineone/icbms/so/service/entity/TempLocation.java b/so-service/src/main/java/com/pineone/icbms/so/service/entity/TempLocation.java new file mode 100644 index 00000000..e30f2809 --- /dev/null +++ b/so-service/src/main/java/com/pineone/icbms/so/service/entity/TempLocation.java @@ -0,0 +1,27 @@ +package com.pineone.icbms.so.service.entity; + +public class TempLocation { + String con; + + public TempLocation() { + } + + public TempLocation(String con) { + this.con = con; + } + + public String getCon() { + return con; + } + + public void setCon(String con) { + this.con = con; + } + + @Override + public String toString() { + return "TempLocation{" + + "con='" + con + '\'' + + '}'; + } +} 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 0aa4c142..938e9d9d 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 @@ -1,7 +1,7 @@ package com.pineone.icbms.so.service.logic; -import com.pineone.icbms.so.compositevo.ref.CompositeProfile; +import com.pineone.icbms.so.device.util.ClientProfile; import com.pineone.icbms.so.service.entity.Service; import com.pineone.icbms.so.service.proxy.ServiceProxy; import com.pineone.icbms.so.service.proxy.ServiceSDAProxy; @@ -18,7 +18,6 @@ import com.pineone.icbms.so.util.session.DefaultSession; import com.pineone.icbms.so.util.session.Session; import com.pineone.icbms.so.util.session.store.SessionStore; -import com.pineone.icbms.so.virtualobject.entity.VirtualObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -171,32 +170,42 @@ public void executeService(String serviceId, String sessionId) { if(!session.isExistSessionData(DefaultSession.PRIORITY_KEY) || Priority.HIGH.equals(session.getSessionData().get(DefaultSession.PRIORITY_KEY)) || serviceData.checkActivedPeriod(currentTime)){ logger.info("Execute Service Start" + TimeStamp.currentTime()); + + String operation = serviceData.getStatus(); + if("si-lack-equipment-noti".equals(serviceId)){ + try { + operation = serviceSDAProxy.getPCCountUri(session); + } catch (BadRequestException e) { + logger.warn("operation is not Count"); + session = sessionStore.retrieveSessionDetail(localSessionId); + session.insertSessionData(DefaultSession.SERVICE_RESULT, DefaultSession.CONTROL_ERROR + " operation is null"); + } + } else if("si-domitory-optimal-environment".equals(serviceId)){ + try { + operation = serviceSDAProxy.getTemperatureLookup(session); + } catch (BadRequestException e) { + logger.warn("operation is not Count"); + session = sessionStore.retrieveSessionDetail(localSessionId); + session.insertSessionData(DefaultSession.SERVICE_RESULT, DefaultSession.CONTROL_ERROR + " operation is null"); + } + } + for(String virtualObjectId : serviceData.getVirtualObjectIdList()){ - if(virtualObjectId.startsWith(CompositeProfile.COMPOSITE_ID)) { - VirtualObject virtualObject = serviceProxy.findVirtualObject(virtualObjectId); - if(virtualObject != null && "vo-lack-equipment".equals(virtualObject.getId())){ - serviceProxy.executeCompositeVirtualObject(virtualObjectId, serviceData.getVirtualObjectService(), serviceData.getStatus(), localSessionId); - } else { - serviceProxy.executeCompositeVirtualObject(virtualObjectId, serviceData.getVirtualObjectService(), serviceData.getStatus(), localSessionId); + if(operation.equals(ClientProfile.TEMP_COLD)){ + // Heater + if(virtualObjectId.contains(ClientProfile.SI_DEVICE_HEATER)){ + serviceProxy.executeVirtualObject(virtualObjectId, ClientProfile.SI_DEVICE_OPERTAION, localSessionId); } - } else { - VirtualObject virtualObject = serviceProxy.findVirtualObject(virtualObjectId); - if(virtualObject != null && "vo-lack-equipment".equals(virtualObject.getId())){ - String operation = ""; - try { - operation = serviceSDAProxy.getPCCountUri(session); - } catch (BadRequestException e) { - logger.warn("operation is not Count"); - session = sessionStore.retrieveSessionDetail(localSessionId); - session.insertSessionData(DefaultSession.SERVICE_RESULT, DefaultSession.CONTROL_ERROR + " operation is null"); - } - serviceProxy.executeVirtualObject(virtualObjectId, operation, localSessionId); - } else { - serviceProxy.executeVirtualObject(virtualObjectId, serviceData.getStatus(), localSessionId); + } else if(operation.equals(ClientProfile.TEMP_HOT)){ + // Airconditioner + if(virtualObjectId.contains(ClientProfile.SI_DEVICE_AIRCONDITONER)){ + serviceProxy.executeVirtualObject(virtualObjectId, ClientProfile.SI_DEVICE_OPERTAION, localSessionId); } + } else { + serviceProxy.executeVirtualObject(virtualObjectId, operation, localSessionId); } - serviceData.setModifiedTime(currentTime); } + serviceData.setModifiedTime(currentTime); serviceStore.updateService(serviceData); session = sessionStore.retrieveSessionDetail(localSessionId); session.insertSessionData(DefaultSession.SERVICE_RESULT, DefaultSession.CONTROL_EXECUTION); 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 bf282011..e5c694e9 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 @@ -5,4 +5,5 @@ public interface ServiceSDAProxy { String getPCCountUri(Session session) throws BadRequestException; + String getTemperatureLookup(Session session) 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 b6cb94da..318a80aa 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 @@ -1,5 +1,10 @@ package com.pineone.icbms.so.service.proxy; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.pineone.icbms.so.device.util.ClientProfile; +import com.pineone.icbms.so.service.entity.SDAData; +import com.pineone.icbms.so.service.entity.TempLocation; import com.pineone.icbms.so.util.address.ContextAddress; import com.pineone.icbms.so.util.conversion.DataConversion; import com.pineone.icbms.so.util.exception.BadRequestException; @@ -12,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.lang.reflect.Type; import java.util.List; @Service @@ -28,20 +34,17 @@ public class ServiceSDAProxyImpl implements ServiceSDAProxy{ //NOTE : PC Count @Override public String getPCCountUri(Session session) throws BadRequestException { - // TODO : SDA 연결주소 협의 , RequestData 형태 협의 - // TODO : Session의 Location ID 필요. - String location = ""; if(session.isExistSessionData(DefaultSession.LOCATION_ID)){ String responseLocation = session.getSessionData().get(DefaultSession.LOCATION_ID); List locationList = DataConversion.stringDataToList(responseLocation); location = locationList.get(0); } else { - location = "http://www.iotoasis.org/ontology/engcenter_616"; + location = ClientProfile.LOCATION_ENGCENTER_616; } IHttpResponseMessage message = clientService.requestGetService( - contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + "cm-lack-equipment-count/?p=" + location ); + contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + ClientProfile.CM_LACK_EQUIPMENT_COUNT + location ); if(message.getStatusCode() == 200) { System.out.println(message.getBodyByteArray().toString()); logger.debug("ResponseMessage : " + message); @@ -60,4 +63,35 @@ public String getPCCountUri(Session session) throws BadRequestException { throw new BadRequestException(); } } + + @Override + public String getTemperatureLookup(Session session) throws BadRequestException { + String location = ""; + if(session.isExistSessionData(DefaultSession.LOCATION_ID)){ + String responseLocation = session.getSessionData().get(DefaultSession.LOCATION_ID); + List locationList = DataConversion.stringDataToList(responseLocation); + location = locationList.get(0); + } else { + location = ClientProfile.LOCATION_CAMPUS_001; + } + + IHttpResponseMessage message = clientService.requestGetService( + contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + ClientProfile.CM_TEMP + location ); + if(message.getStatusCode() == 200) { + System.out.println(message.getBodyByteArray().toString()); + logger.debug("ResponseMessage : " + message); + String readData = clientService.responseDataToString(message); + // Response Data Mapping + Type type = new TypeToken>() { + }.getType(); + SDAData sdaData = new Gson().fromJson(readData, type); + TempLocation tempLocation = (TempLocation)sdaData.getContents().get(0); + String tempdata = tempLocation.getCon().substring(ClientProfile.PREFIX_ONTOLOGY.length()); + return tempdata; + } + else{ + throw new BadRequestException(); + } + + } }