diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/entity/DeviceStatusData.java b/so-device/src/main/java/com/pineone/icbms/so/device/entity/DeviceStatusData.java index 06cff417..dde38826 100644 --- a/so-device/src/main/java/com/pineone/icbms/so/device/entity/DeviceStatusData.java +++ b/so-device/src/main/java/com/pineone/icbms/so/device/entity/DeviceStatusData.java @@ -10,6 +10,7 @@ public class DeviceStatusData { */ private String _commandId; + /** * Device를 제어 했을시 디바이스 Uri */ @@ -18,21 +19,21 @@ public class DeviceStatusData { /** * Device의 상태 값 */ - private String deviceStatus; + private String con; /** * Device의 상태 값의 변경 되었을시 시간 */ - private String timestamp; + private String ct; public DeviceStatusData() { } - public DeviceStatusData(String _commandId, String _uri, String deviceStatus, String timestamp) { + public DeviceStatusData(String _commandId, String _uri, String con, String ct) { this._commandId = _commandId; this._uri = _uri; - this.deviceStatus = deviceStatus; - this.timestamp = timestamp; + this.con = con; + this.ct = ct; } public String get_commandId() { @@ -52,24 +53,24 @@ public void set_uri(String _uri) { } - public String getDeviceStatus() { - return deviceStatus; + public String getCon() { + return con; } - public void setDeviceStatus(String deviceStatus) { - this.deviceStatus = deviceStatus; + public void setCon(String con) { + this.con = con; } - public String getTimestamp() { - return timestamp; + public String getCt() { + return ct; } - public void setTimestamp(String timestamp) { - this.timestamp = timestamp; + public void setCt(String ct) { + this.ct = ct; } public boolean checkDeviceStatus(String deviceStatus){ - return this.deviceStatus.equals(deviceStatus); + return this.con.equals(deviceStatus); } @@ -78,8 +79,8 @@ public String toString() { return "DeviceStatusData{" + "_commandId='" + _commandId + '\'' + ", _uri='" + _uri + '\'' + - ", deviceStatus='" + deviceStatus + '\'' + - ", timestamp='" + timestamp + '\'' + + ", con='" + con + '\'' + + ", ct='" + ct + '\'' + '}'; } } diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/entity/ResultMessage.java b/so-device/src/main/java/com/pineone/icbms/so/device/entity/ResultMessage.java index 68bbff54..7a6b89a5 100644 --- a/so-device/src/main/java/com/pineone/icbms/so/device/entity/ResultMessage.java +++ b/so-device/src/main/java/com/pineone/icbms/so/device/entity/ResultMessage.java @@ -2,12 +2,6 @@ public class ResultMessage { - public static final String RESPONSE_SUCCESS = "success"; - public static final String RESPONSE_FAILURE = "failure"; - public static final String RESPONSE_SUCCESS_CODE = "200"; - public static final String RESPONSE_FIALURE_CODE = "400"; - public static final String RESPONSE_SUCCESS_ONEM2MCODE = "2000"; - private String code; private String _commandId; private String message; diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/logic/DeviceManagerLogic.java b/so-device/src/main/java/com/pineone/icbms/so/device/logic/DeviceManagerLogic.java index bab1f60b..1fc71d86 100644 --- a/so-device/src/main/java/com/pineone/icbms/so/device/logic/DeviceManagerLogic.java +++ b/so-device/src/main/java/com/pineone/icbms/so/device/logic/DeviceManagerLogic.java @@ -28,9 +28,6 @@ public class DeviceManagerLogic implements DeviceManager { public static final Logger logger = LoggerFactory.getLogger(DeviceManagerLogic.class); - public static final String DEVICE_SERVICE_NOTI_TYPE = "admin-noti"; - public static final String DEVICE_PRE = "device-"; - @Autowired private DeviceStore deviceStore; @@ -104,12 +101,12 @@ public String deviceExecute(String deviceId,String deviceCommand, String session sessionStore.updateSession(session); logger.info("The device does not exist."); return "The device does not exist."; - } else if(device.getDeviceServices() != null && DEVICE_SERVICE_NOTI_TYPE.equals(device.getDeviceServices().get(0))){ + } else if(device.getDeviceServices() != null && ClientProfile.DEVICE_SERVICE_NOTI_TYPE.equals(device.getDeviceServices().get(0))){ sessionDataUpdate(sessionStore, session, device.getDeviceLocation(),DefaultSession.DEVICE_LOCATION); - session.insertSessionData(DefaultSession.DEVICE_RESULT, DefaultSession.CONTROL_EXECUTION + "_" + DEVICE_SERVICE_NOTI_TYPE); + session.insertSessionData(DefaultSession.DEVICE_RESULT, DefaultSession.CONTROL_EXECUTION + "_" + ClientProfile.DEVICE_SERVICE_NOTI_TYPE); // DB에 Session을 저장. sessionStore.updateSession(session); - return DEVICE_SERVICE_NOTI_TYPE; + return ClientProfile.DEVICE_SERVICE_NOTI_TYPE; } // SI를 제어할수 있는 DeviceControlMessage로 변환 @@ -132,7 +129,7 @@ public String deviceExecute(String deviceId,String deviceCommand, String session /** * Device 제어 후 제어 결과가 Success면 Device Subscription 요청 */ - if(resultMessage.getCode().equals(ResultMessage.RESPONSE_SUCCESS_ONEM2MCODE)) { + if(resultMessage.getCode().equals(ClientProfile.RESPONSE_SUCCESS_ONEM2MCODE)) { String subscriptionUri = device.getDeviceUri() + (ClientProfile.actionDeviceCommand(device.getDeviceUri()) ? ClientProfile.SI_CONTAINER_ACTION : ClientProfile.SI_CONTAINER_POWER) + ClientProfile.SI_CONTAINER_STATUS; String response = deviceSubscription(subscriptionUri, deviceControlMessage.get_commandId()); logger.debug(LogPrint.LogMethodNamePrint() + " | Device Subscription : " + " , Device Uri = " + device.getDeviceUri() + " , Result : " + response + " , Session ID = " + sessionId); @@ -140,7 +137,7 @@ public String deviceExecute(String deviceId,String deviceCommand, String session /** * Device Subscription 데이터 저장 */ - if(response.equals(ResultMessage.RESPONSE_SUCCESS_ONEM2MCODE)){ + if(response.equals(ClientProfile.RESPONSE_SUCCESS_ONEM2MCODE)){ saveDeviceSubscriptionData(deviceControlMessage.get_commandId(), deviceControlMessage.getCon()); } @@ -227,8 +224,8 @@ public void deviceUpdate(DeviceStatusData deviceStatusData) { Device device = deviceSearchById(deviceUri); DeviceSubscriptionObject deviceSubscriptionObject = deviceSubscriptionStore.retrieve(deviceStatusData.get_commandId()); - if(deviceSubscriptionObject != null && deviceSubscriptionObject.get_commandId().equals(deviceStatusData.get_commandId()) && deviceSubscriptionObject.getDeviceStatus().equals(deviceStatusData.getDeviceStatus())){ - device.setDeviceStatus(deviceStatusData.getDeviceStatus()); + if(deviceSubscriptionObject != null && deviceSubscriptionObject.get_commandId().equals(deviceStatusData.get_commandId()) && deviceSubscriptionObject.getDeviceStatus().equals(deviceStatusData.getCon())){ + device.setDeviceStatus(deviceStatusData.getCon()); deviceStore.update(device); deviceSubscriptionRelease(deviceUri + (ClientProfile.actionDeviceCommand(device.getDeviceUri()) ? ClientProfile.SI_CONTAINER_ACTION : ClientProfile.SI_CONTAINER_POWER) + ClientProfile.SI_CONTAINER_STATUS); deviceSubscriptionStore.delete(deviceSubscriptionObject.get_id()); @@ -278,7 +275,7 @@ private void deviceCreate(Device device){ long currentTime = System.currentTimeMillis(); long modifiedTime = currentTime + 30240000000L; - device.setId(DEVICE_PRE + UUID.randomUUID().toString()); + device.setId(ClientProfile.DEVICE_PRE + UUID.randomUUID().toString()); device.setDeviceCreateTime(currentTime); device.setDeviceExfiredTime(modifiedTime); // TODO : Device Command는 언제 요청으로 얻어 올까?? diff --git a/so-device/src/main/java/com/pineone/icbms/so/device/pr/DevicePresentation.java b/so-device/src/main/java/com/pineone/icbms/so/device/pr/DevicePresentation.java index fe71f9ce..4fccc33c 100644 --- a/so-device/src/main/java/com/pineone/icbms/so/device/pr/DevicePresentation.java +++ b/so-device/src/main/java/com/pineone/icbms/so/device/pr/DevicePresentation.java @@ -162,4 +162,9 @@ public DeviceTransFormObject settingDeviceRequestData(String deviceid, String co object.setSessionId(sessionId); return object; } + + + + + } 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 091226e9..358d5619 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 @@ -2,27 +2,33 @@ public class ClientProfile { + // oneM2M control Data public static final String SO_CONTROL_TYPE = "text/plain:0"; public static final String SI_CONTROL_POWER = "Power"; public static final String SI_CONTROL_ACTION = "Action"; - public static final String SI_COMMAND_ID = "cmd_"; + 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"; + // oneM2M Container Data public static final String SI_CONTAINER_STATUS = "/status"; public static final String SI_CONTAINER_POWER = "/Power"; public static final String SI_CONTAINER_ACTION = "/Action"; - // Presentation Data + // oneM2M Result Data public static final String RESPONSE_SUCCESS = "success"; public static final String RESPONSE_FAILURE = "failure"; - public static final String RESPONSE_SUCCESS_CODE = "200"; public static final String RESPONSE_FIALURE_CODE = "4000"; public static final String RESPONSE_SUCCESS_ONEM2MCODE = "2000"; + // Device Data Prefix + public static final String DEVICE_PRE = "device-"; + private ClientProfile() { throw new IllegalAccessError("Utility class"); diff --git a/so-device/src/test/java/com/pineone/icbms/so/device/logic/DeviceManagerTest.java b/so-device/src/test/java/com/pineone/icbms/so/device/logic/DeviceManagerTest.java index f158de55..b3a9212e 100644 --- a/so-device/src/test/java/com/pineone/icbms/so/device/logic/DeviceManagerTest.java +++ b/so-device/src/test/java/com/pineone/icbms/so/device/logic/DeviceManagerTest.java @@ -32,23 +32,4 @@ public void deviceExecuteTest(){ public void deviceControlResultTest(){ } - - @Test - public void getOnem2mDeviceUri(){ - // - String uri ="/herit-in/herit-cse/ONDB_SmartLight08_001/Power/status/CONTENT_INST_427988"; - String oneM2Muri = ""; - int stringlength = 3; - String[] strings = uri.split("/"); - for(String s : strings){ - System.out.println(s); - } - - for(int i =1; i<4 ; i++){ - stringlength += strings[i].length(); - } - - - } - } diff --git a/so-device/src/test/java/com/pineone/icbms/so/device/pr/DevicePresentationTest.java b/so-device/src/test/java/com/pineone/icbms/so/device/pr/DevicePresentationTest.java index 2818e759..e6454e54 100644 --- a/so-device/src/test/java/com/pineone/icbms/so/device/pr/DevicePresentationTest.java +++ b/so-device/src/test/java/com/pineone/icbms/so/device/pr/DevicePresentationTest.java @@ -1,5 +1,11 @@ package com.pineone.icbms.so.device.pr; +import org.junit.Test; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + /*@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = DeviceApplication.class) @WebAppConfiguration*/ @@ -90,4 +96,11 @@ public void teardown(){ deviceResultStore.delete("JuintTestCodeBad"); } */ + + @Test + public void tt(){ + Date now = new Date(); + DateFormat df = new SimpleDateFormat("yyyyMMdd HH24mmss"); + System.out.println(df.format(now)); + } } diff --git a/so-service/src/main/java/com/pineone/icbms/so/service/entity/Service.java b/so-service/src/main/java/com/pineone/icbms/so/service/entity/Service.java index a5040395..dae2b6f6 100644 --- a/so-service/src/main/java/com/pineone/icbms/so/service/entity/Service.java +++ b/so-service/src/main/java/com/pineone/icbms/so/service/entity/Service.java @@ -4,12 +4,6 @@ public class Service { - public Service(){}; - - public Service(String name){ - this.name = name; - } - /** * Service 식별자 * format : si-(장소명)-(vo명)-(status) @@ -66,6 +60,13 @@ public Service(String name){ */ private long filterTime; + public Service(){ + }; + + public Service(String name){ + this.name = name; + } + public String getId() { return id; } @@ -106,12 +107,12 @@ public void setStatus(String status) { this.status = status; } - public Service(String id, String name, List VirtualObjectIdList, String VirtualObjectService, String status) { + public Service(String id, String name, List virtualObjectIdList, String virtualObjectService, String status) { this.id = id; this.name = name; - this.virtualObjectIdList = VirtualObjectIdList; - this.virtualObjectService = VirtualObjectService; + this.virtualObjectIdList = virtualObjectIdList; + this.virtualObjectService = virtualObjectService; this.status = status; } 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 f850d1fd..0aa4c142 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 @@ -86,10 +86,8 @@ public List retrieveStatusList(ConceptService conceptService) { } @Override - //NOTE: Service 등록정보를 수신받고 TODO : SO DB에 저장 + //NOTE: Service 등록정보를 수신받고 SO DB에 저장 public String registerService(Service service) { -// ServiceStore serviceStore = ServiceMapStore.getInstance(); -// service.setId("SERVICE-" + service.getId()); logger.debug("Service = " + service.toString()); ResponseMessage responseMessage = ResponseMessage.newResponseMessage(); String serviceMessageStr = responseMessage.serviceResultMessage(service); @@ -100,8 +98,7 @@ public String registerService(Service service) { @Override public Service retrieveServiceDetail(String serviceId) { logger.debug("Service ID = " + serviceId); - Service service = serviceStore.retrieveServiceDetail(serviceId); - return service; + return serviceStore.retrieveServiceDetail(serviceId); } @Override @@ -130,24 +127,18 @@ public List retrieveServiceIdList() { public void executeService(String serviceId, String sessionId) { logger.debug("Execute Service ID = " + serviceId + " Session ID = " + sessionId); - // Service Filter 추가. - - // Service Control Record 검색 - // serviceControlRecord가 없으면 ServiceControlRecord 생성 - // - // DB에서 Session을 검색 Session session = null; - if(sessionId != null){ - session = sessionStore.retrieveSessionDetail(sessionId); + String localSessionId = sessionId; + if(localSessionId != null){ + session = sessionStore.retrieveSessionDetail(localSessionId); } if(session == null){ session = new DefaultSession(); - sessionId = session.getId(); + localSessionId = session.getId(); } - // TODO : Session에서 serviceIdList를 얻는다. List sessionServiceIdList = null; if(session.isExistSessionData(DefaultSession.SERVICE_KEY)){ sessionServiceIdList = DataConversion.stringDataToList(session.findSessionData(DefaultSession.SERVICE_KEY)); @@ -182,30 +173,11 @@ public void executeService(String serviceId, String sessionId) { logger.info("Execute Service Start" + TimeStamp.currentTime()); for(String virtualObjectId : serviceData.getVirtualObjectIdList()){ if(virtualObjectId.startsWith(CompositeProfile.COMPOSITE_ID)) { - // functionality중 특별히 SDA에 물어야 하는 것들에 대해서 정의 필요. - VirtualObject virtualObject = serviceProxy.findVirtualObject(virtualObjectId); - if(virtualObject != null && "vo-lack-equipment".equals(virtualObject.getId())){ - // admin-noti에 따른 추가 적인 로직 적용. - // PC 부족 알림 - // 마우스 부족 알림 - // 키보드 부족 알림. - - // 각각 ServiceModel과 Service들을 어떻게 나눌것인가? 그걸로 조건으로 수정할것인가? - /*String operation = ""; - try { - operation = serviceSDAProxy.getPCCountUri(session); - } catch (BadRequestException e) { - logger.warn("operation is not Count"); - session = sessionStore.retrieveSessionDetail(sessionId); - session.insertSessionData(DefaultSession.SERVICE_RESULT, DefaultSession.CONTROL_ERROR + " operation is null"); - } - serviceProxy.executeVirtualObject(virtualObjectId, operation, sessionId); - */ - serviceProxy.executeCompositeVirtualObject(virtualObjectId, serviceData.getVirtualObjectService(), serviceData.getStatus(), sessionId); + serviceProxy.executeCompositeVirtualObject(virtualObjectId, serviceData.getVirtualObjectService(), serviceData.getStatus(), localSessionId); } else { - serviceProxy.executeCompositeVirtualObject(virtualObjectId, serviceData.getVirtualObjectService(), serviceData.getStatus(), sessionId); + serviceProxy.executeCompositeVirtualObject(virtualObjectId, serviceData.getVirtualObjectService(), serviceData.getStatus(), localSessionId); } } else { VirtualObject virtualObject = serviceProxy.findVirtualObject(virtualObjectId); @@ -215,22 +187,22 @@ public void executeService(String serviceId, String sessionId) { operation = serviceSDAProxy.getPCCountUri(session); } catch (BadRequestException e) { logger.warn("operation is not Count"); - session = sessionStore.retrieveSessionDetail(sessionId); + session = sessionStore.retrieveSessionDetail(localSessionId); session.insertSessionData(DefaultSession.SERVICE_RESULT, DefaultSession.CONTROL_ERROR + " operation is null"); } - serviceProxy.executeVirtualObject(virtualObjectId, operation, sessionId); + serviceProxy.executeVirtualObject(virtualObjectId, operation, localSessionId); } else { - serviceProxy.executeVirtualObject(virtualObjectId, serviceData.getStatus(), sessionId); + serviceProxy.executeVirtualObject(virtualObjectId, serviceData.getStatus(), localSessionId); } } serviceData.setModifiedTime(currentTime); } serviceStore.updateService(serviceData); - session = sessionStore.retrieveSessionDetail(sessionId); + session = sessionStore.retrieveSessionDetail(localSessionId); session.insertSessionData(DefaultSession.SERVICE_RESULT, DefaultSession.CONTROL_EXECUTION); } else { logger.info("Execute Service Ignore : " + "ServiceActiveTime = " + TimeStamp.currentTime(serviceData.getModifiedTime()) + " FilterTime = " + serviceData.getFilterTime()/1000); - session = sessionStore.retrieveSessionDetail(sessionId); + session = sessionStore.retrieveSessionDetail(localSessionId); session.insertSessionData(DefaultSession.SERVICE_RESULT, DefaultSession.CONTROL_IGNORE); } diff --git a/so-servicemodel/src/main/java/com/pineone/icbms/so/servicemodel/logic/ServiceModelLogicImpl.java b/so-servicemodel/src/main/java/com/pineone/icbms/so/servicemodel/logic/ServiceModelLogicImpl.java index b674bbe9..5ec115a3 100644 --- a/so-servicemodel/src/main/java/com/pineone/icbms/so/servicemodel/logic/ServiceModelLogicImpl.java +++ b/so-servicemodel/src/main/java/com/pineone/icbms/so/servicemodel/logic/ServiceModelLogicImpl.java @@ -133,7 +133,7 @@ public void executeServiceModel(String serviceModelId, String sessionId) { // List serviceMessageList = new ArrayList<>(); for (String serviceId : serviceIdList) { // Service service = serviceModelProxy.retrieveServiceDetail(serviceId); -// ServiceMessage serviceMessage = new ServiceMessage(domainId, service.getVirtualObjectService(), service.getDeviceStatus()); +// ServiceMessage serviceMessage = new ServiceMessage(domainId, service.getVirtualObjectService(), service.getCon()); // serviceMessageList.add(serviceMessage); logger.debug("Execute Service ID = " + serviceId + " Session Id = " + sessionId); serviceModelProxy.executeService(serviceId, sessionId); @@ -217,7 +217,7 @@ private boolean locationCompare(Session session, String serviceModelLocation){ // for (String serviceName : serviceModel.getServiceIdList()) { // Service service = serviceModelProxy.retrieveServiceDetail(serviceName); //// for (Domain domain : domainList) { -//// executeDummyClass.controlService(domain.getId(), service.getVirtualObjectId(), service.getDeviceStatus()); +//// executeDummyClass.controlService(domain.getId(), service.getVirtualObjectId(), service.getCon()); // } // } // }