Skip to content

Commit

Permalink
Merge pull request #295 from pahnjy/develop
Browse files Browse the repository at this point in the history
Device Subscription에 따른 로직 변경 #291
  • Loading branch information
pahnjy authored Dec 9, 2016
2 parents 4b6f6bc + 00e8dfc commit 0436e71
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class DeviceStatusData {
*/
private String _commandId;


/**
* Device를 제어 했을시 디바이스 Uri
*/
Expand All @@ -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() {
Expand All @@ -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);
}


Expand All @@ -78,8 +79,8 @@ public String toString() {
return "DeviceStatusData{" +
"_commandId='" + _commandId + '\'' +
", _uri='" + _uri + '\'' +
", deviceStatus='" + deviceStatus + '\'' +
", timestamp='" + timestamp + '\'' +
", con='" + con + '\'' +
", ct='" + ct + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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로 변환
Expand All @@ -132,15 +129,15 @@ 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);

/**
* Device Subscription 데이터 저장
*/
if(response.equals(ResultMessage.RESPONSE_SUCCESS_ONEM2MCODE)){
if(response.equals(ClientProfile.RESPONSE_SUCCESS_ONEM2MCODE)){
saveDeviceSubscriptionData(deviceControlMessage.get_commandId(), deviceControlMessage.getCon());
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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는 언제 요청으로 얻어 올까??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,9 @@ public DeviceTransFormObject settingDeviceRequestData(String deviceid, String co
object.setSessionId(sessionId);
return object;
}





}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


}

}
Original file line number Diff line number Diff line change
@@ -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*/
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

public class Service {

public Service(){};

public Service(String name){
this.name = name;
}

/**
* Service 식별자
* format : si-(장소명)-(vo명)-(status)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -106,12 +107,12 @@ public void setStatus(String status) {
this.status = status;
}

public Service(String id, String name, List<String> VirtualObjectIdList, String VirtualObjectService, String status) {
public Service(String id, String name, List<String> 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;
}

Expand Down
Loading

0 comments on commit 0436e71

Please sign in to comment.