Skip to content

Commit

Permalink
property 로직 변경 iotoasis#289
Browse files Browse the repository at this point in the history
  • Loading branch information
pahnjy01 committed Dec 6, 2016
1 parent 5b73974 commit 080d83f
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public int retrieveCurrentValue(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService
(contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CURRENT_VALUE + "/" + domain.getName());
(contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_CURRENT_VALUE + "/" + domain.getName());
String response = new Gson().toJson(message);
int currentValue = Integer.parseInt(response);
return currentValue;
Expand All @@ -52,7 +52,7 @@ public int retrievePastValue(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_PAST_VALUE + "/" + domain.getName());
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_PAST_VALUE + "/" + domain.getName());
String response = new Gson().toJson(message);
int pastValue = Integer.parseInt(response);
return pastValue;
Expand All @@ -65,7 +65,7 @@ public int retrieveAllDeviceUseAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_USE_AMOUNT + "/" + domain.getName());
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_USE_AMOUNT + "/" + domain.getName());
String response = new Gson().toJson(message);
int useAmount = Integer.parseInt(response);
return useAmount;
Expand All @@ -77,7 +77,7 @@ public int retrieveObjectValue(Domain domain) {
//
// contextAddress = ContextAddress.newContextAddress();
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_OBJECT_VALUE + "/" + domain.getName());
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_OBJECT_VALUE + "/" + domain.getName());
String response = new Gson().toJson(message);
int objectValue = Integer.parseInt(response);
return objectValue;
Expand All @@ -90,7 +90,7 @@ public int retrieveCurrentClassPCAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CURRENT_PC + "/" + domain.getName());
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_CURRENT_PC + "/" + domain.getName());
String response = new Gson().toJson(message);
int currentPC = Integer.parseInt(response);
return currentPC;
Expand All @@ -103,7 +103,7 @@ public int retrieveNextClassPCAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_NEXT_PC + "/" + domain.getName());
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_NEXT_PC + "/" + domain.getName());
String response = new Gson().toJson(message);
int nextPC = Integer.parseInt(response);
return nextPC;
Expand All @@ -116,7 +116,7 @@ public int retrieveCurrentClassMouseAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CURRENT_MOUSE + "/" + domain.getName());
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_CURRENT_MOUSE + "/" + domain.getName());
String response = new Gson().toJson(message);
int currentMouse = Integer.parseInt(response);
return currentMouse;
Expand All @@ -129,7 +129,7 @@ public int retrieveNextClassMouseAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_NEXT_MOUSE + "/" + domain.getName());
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_NEXT_MOUSE + "/" + domain.getName());
String response = new Gson().toJson(message);
int nextMouse = Integer.parseInt(response);
return nextMouse;
Expand All @@ -142,7 +142,7 @@ public int retrieveCurrentClassKeyBoardAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CURRENT_KEYBOARD + "/" + domain.getName());
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_CURRENT_KEYBOARD + "/" + domain.getName());
String response = new Gson().toJson(message);
int currentKeyBoard = Integer.parseInt(response);
return currentKeyBoard;
Expand All @@ -155,7 +155,7 @@ public int retrieveNextClassKeyBoardAmount(Domain domain) {
// contextAddress = ContextAddress.newContextAddress();
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_NEXT_KEYBOARD + "/" + domain.getName());
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_NEXT_KEYBOARD + "/" + domain.getName());
String response = new Gson().toJson(message);
int nextKeyBoard = Integer.parseInt(response);
return nextKeyBoard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String registerContextInformation(ContextInformation contextInformation){
logger.debug("ContextInformation = " + contextInformation.toString());
// contextAddress = ContextAddress.newContextAddress();
IHttpResponseMessage message = clientService.requestPostService
(contextAddress.getSDAAddress() + AddressStore.REGISTER_CONTEXTINFORMATION, sendData);
(contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.REGISTER_CONTEXTINFORMATION, sendData);
String response = new Gson().toJson(message);
return response;
}
Expand All @@ -54,7 +54,7 @@ public List<String> retrieveContextInformationListFromSDA(){
//
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CONTEXTINFORMATION);
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_CONTEXTINFORMATION);
String readData = new Gson().toJson(message);
Type type = new TypeToken<List<String>>(){}.getType();
List<String> contextInformationNameList = new Gson().fromJson(readData,type);
Expand All @@ -67,7 +67,7 @@ public ContextInformation retrieveGeneralContextDetail(String contextId){
logger.info(LogPrint.outputInfoLogPrint());
logger.debug("ContextId = " + contextId);
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CONTEXTINFORMATION + "/" + contextId);
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_CONTEXTINFORMATION + "/" + contextId);
String readData = new Gson().toJson(message);
Type type = new TypeToken<ContextInformation>(){}.getType();
ContextInformation contextInformation = new Gson().fromJson(readData,type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String registerContextModel(ContextModel contextModel) {
logger.debug("ContextModel = " + contextModel.toString());

String sendData = DataConversion.objectToString(contextModel);
String response = clientService.requestPostServiceReceiveString(contextAddress.getSDAAddress() + AddressStore.REGISTER_CONTEXTMODEL, sendData);
String response = clientService.requestPostServiceReceiveString(contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.REGISTER_CONTEXTMODEL, sendData);
return response;
}

Expand All @@ -59,7 +59,7 @@ public List<ContextModel> retrieveContextModelListFromSDA() {
//
logger.info(LogPrint.outputInfoLogPrint());
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CONTEXTMODEL);
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_CONTEXTMODEL);
String readData = new Gson().toJson(message);
Type type = new TypeToken<List<ContextModel>>(){}.getType();
List<ContextModel> contextModelList = new Gson().fromJson(readData,type);
Expand All @@ -73,7 +73,7 @@ public ContextModel retrieveContextModelDetail(String contextModelId) {
//
logger.info(LogPrint.outputInfoLogPrint() + ", ContextModelId = " + contextModelId);
logger.debug("ContextModelId = " + contextModelId);
String readData = clientService.requestGetServiceReceiveString(contextAddress.getSDAAddress() + AddressStore.RETRIEVE_CONTEXTMODEL + "/" + contextModelId);
String readData = clientService.requestGetServiceReceiveString(contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.RETRIEVE_CONTEXTMODEL + "/" + contextModelId);
Type type = new TypeToken<ContextModel>(){}.getType();
ContextModel contextModel = new Gson().fromJson(readData, type);

Expand Down Expand Up @@ -219,7 +219,7 @@ public List<String> retrieveContextModelEvent(String contextModelId) {

private List<Content> getContents(String contextModelId) throws BadRequestException {
IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + contextModelId + "/?p=," );
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + contextModelId + "/?p=," );
if(message.getStatusCode() == 200) {
System.out.println(message.getBodyByteArray().toString());
logger.debug("ResponseMessage : " + message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void deviceRegister(String deviceUri, String time){
logger.debug("Device Uri = " + deviceUri + " Time = " + time);
// 디바이스 ID로 SDA에 데이터 요청.
// TODO: SDA에 Device Uri만으로 Device정보 연동 규격 필요.
Device device = deviceRequest(contextAddress.getSIAddress() + AddressStore.SDA_DEVICE + deviceUri);
Device device = deviceRequest(contextAddress.getServerAddress(ContextAddress.SI_SERVER) + AddressStore.SDA_DEVICE + deviceUri);
logger.debug("Device = " + device.toString());
// 디바이스 저장.
deviceCreate(device);
Expand Down Expand Up @@ -126,7 +126,7 @@ public String deviceExecute(String deviceId,String deviceCommand, String session
}

// Device 제어 요청 보냄.
ResultMessage resultMessage = deviceControlProxy.deviceControlRequest(contextAddress.getSIAddress() + AddressStore.SI_CONTOL_URI,deviceControlMessage);
ResultMessage resultMessage = deviceControlProxy.deviceControlRequest(contextAddress.getServerAddress(ContextAddress.SI_SERVER) + AddressStore.SI_CONTOL_URI,deviceControlMessage);
logger.debug(LogPrint.LogMethodNamePrint() + " | Device Control Result : " + " , Device Uri = " + device.getDeviceUri() + " , Result : " + resultMessage + " , Session ID = " + sessionId);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public String findDeviceOperation(String deviceId, String deviceService) {
logger.info((LogPrint.outputInfoLogPrint())+ "DeviceID = " + deviceId);
logger.debug("DeviceID = " + deviceId + "DeviceService = " + deviceService);

String requestUri = contextAddress.getSDAAddress() + AddressStore.SDA_DEVICE + AddressStore.SDA_DEVICE_OPERATION;
String requestUri = contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.SDA_DEVICE + AddressStore.SDA_DEVICE_OPERATION;
JSONObject obj = new JSONObject();
obj.put("deviceId", deviceId);
obj.put("deviceService", deviceService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public String deviceSubscriptionRequest(String deviceUri) {
logger.debug(LogPrint.LogMethodNamePrint() + " | DeviceUri = " + deviceUri);

DeviceSubscriptionData deviceSubscriptionData = new DeviceSubscriptionData();
deviceSubscriptionData.set_notificationUri(contextAddress.getSOAddress() + AddressStore.SO_DEVICE_STATUS);
deviceSubscriptionData.set_notificationUri(contextAddress.getServerAddress(ContextAddress.SO_SERVER) + AddressStore.SO_DEVICE_STATUS);
deviceSubscriptionData.set_uri(deviceUri);

String requestBody = new Gson().toJson(deviceSubscriptionData);
// DeviceLogic에 생성되거나 제어되면 서브스크립트 걸어야 겠군.
// 현제 정책이 안되어 있어서. 등록되면 걸지.. 제어시 걸지는 고려 필요.

String responseData = clientService.requestPostServiceReceiveString(contextAddress.getSIAddress() + AddressStore.SI_SUBSCRIPTION_URI, requestBody);
String responseData = clientService.requestPostServiceReceiveString(contextAddress.getServerAddress(ContextAddress.SI_SERVER) + AddressStore.SI_SUBSCRIPTION_URI, requestBody);
// ResponseData{ "code" : "2000", "message" : "", "content" : "" }
logger.debug(LogPrint.LogMethodNamePrint() + " | Subscription Request : Response Data = " + responseData);
ResultMessage resultMessage = new ResultMessage();
Expand All @@ -97,7 +97,7 @@ public String deviceSubscriptionReleaseRequest(String deviceUri) {
String requestBody = new Gson().toJson(deviceSubscriptionData);
// DeviceLogic에 생성되거나 제어되면 서브스크립트 걸어야 겠군.
// 현제 정책이 안되어 있어서. 등록되면 걸지.. 제어시 걸지는 고려 필요.
String responseData = clientService.requestPostServiceReceiveString(contextAddress.getSIAddress() + AddressStore.SI_SUBSCRIPTION_RELEASE_URI, requestBody);
String responseData = clientService.requestPostServiceReceiveString(contextAddress.getServerAddress(ContextAddress.SI_SERVER) + AddressStore.SI_SUBSCRIPTION_RELEASE_URI, requestBody);
logger.debug(LogPrint.LogMethodNamePrint() + " | Device SubscriptionRelease Request Result = " + responseData);
logger.info("<================ Device SubscriptionRelease Request End ================>");
return responseData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public List<Domain> retrieveDomainFromSDA(){
logger.info(LogPrint.outputInfoLogPrint());
// contextAddress = ContextAddress.newContextAddress();
IHttpResponseMessage message = clientService.requestGetService
(contextAddress.getSDAAddress() + AddressStore.REGISTER_CONTEXTINFORMATION);
(contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + AddressStore.REGISTER_CONTEXTINFORMATION);
String readData = new Gson().toJson(message);
Type type = new TypeToken<List<Domain>>(){}.getType();
List<Domain> domainList = new Gson().fromJson(readData,type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String getPCCountUri(Session session) throws BadRequestException {
}

IHttpResponseMessage message = clientService.requestGetService(
contextAddress.getSDAAddress() + "cm-lack-equipment-count/?p=" + location );
contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + "cm-lack-equipment-count/?p=" + location );
if(message.getStatusCode() == 200) {
System.out.println(message.getBodyByteArray().toString());
logger.debug("ResponseMessage : " + message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ public class AddressStore {
//SO Data
public static final String SO_DEVICE_STATUS = "/so/device/status";


private AddressStore() {
throw new IllegalAccessError("AddressStore class");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,29 @@

@Service
public class ContextAddress {
public static final String SERVER_PROPERTIES = "server.properties";
public static final String SDA_SERVER = "Sda_Connection";
public static final String SI_SERVER = "SI_Connection";
public static final String SO_SERVER = "SO_Connection";

// private ContextAddress(){};
// public static ContextAddress newContextAddress(){
// ContextAddress contextAddress = new ContextAddress();
// return contextAddress;
// }

public String getSDAAddress(){
//
String sdaConnection = null;
Properties sdaInfo = new Properties();
InputStream inputStream = ContextAddress.class.getClassLoader().getResourceAsStream("server.properties");
try{
sdaInfo.load(inputStream);
sdaConnection = sdaInfo.getProperty("Sda_Connection");
} catch (IOException e) {
e.printStackTrace();
}
return sdaConnection;
}

public String getSIAddress(){
//
String siConnection = null;
Properties siInfo = new Properties();
InputStream inputStream = ContextAddress.class.getClassLoader().getResourceAsStream("server.properties");
try{
siInfo.load(inputStream);
siConnection = siInfo.getProperty("SI_Connection");
} catch (IOException e) {
e.printStackTrace();
}
return siConnection;
}

public String getSOAddress(){
public String getServerAddress(String server){
//
String soConnection = null;
Properties siInfo = new Properties();
InputStream inputStream = ContextAddress.class.getClassLoader().getResourceAsStream("server.properties");

InputStream inputStream = ContextAddress.class.getClassLoader().getResourceAsStream(SERVER_PROPERTIES);

try{
siInfo.load(inputStream);
soConnection = siInfo.getProperty("SO_Connection");
switch (server){
case SDA_SERVER : soConnection = siInfo.getProperty(SDA_SERVER);
break;
case SI_SERVER : soConnection = siInfo.getProperty(SI_SERVER);
break;
case SO_SERVER : soConnection = siInfo.getProperty(SO_SERVER);
break;
default: soConnection = siInfo.getProperty(SI_SERVER);
}
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ public interface VirtualObjectManager {
List<VirtualObject> searchVirtualObjectList();
String requestControlDevice(String voId, String operation, String sessionId);
void produceVirtualObject(VirtualObject virtualObject);
// String controlDevice(List<ServiceControl> serviceControls);
}
Loading

0 comments on commit 080d83f

Please sign in to comment.