Skip to content

Commit

Permalink
Service에 따른 CM 요청 추가 iotoasis#312
Browse files Browse the repository at this point in the history
  • Loading branch information
pahnjy01 committed Jan 3, 2017
1 parent 85455d3 commit 23e1700
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.pineone.icbms.so.service.entity;

import java.util.List;

public class SDAData<T> {
String cmd;
List<T> contents;
String time;
String contextId;


public SDAData() {
}

public SDAData(String cmd, List<T> 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<T> getContents() {
return contents;
}

public void setContents(List<T> 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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

public interface ServiceSDAProxy {
String getPCCountUri(Session session) throws BadRequestException;
String getTemperatureLookup(Session session) throws BadRequestException;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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<String> 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);
Expand All @@ -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<String> 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<SDAData<TempLocation>>() {
}.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();
}

}
}

0 comments on commit 23e1700

Please sign in to comment.