Skip to content

Commit

Permalink
Service API 추가 iotoasis#351
Browse files Browse the repository at this point in the history
  • Loading branch information
pahnjy01 committed Feb 3, 2017
1 parent bd1c391 commit f3c1e86
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class ClientProfile {
// Context Model
public static final String CM_LACK_EQUIPMENT_COUNT = "cm-lack-equipment-count/?p=";
public static final String CM_TEMP = "cm-temp/?p=";
public static final String PREFIX_CM_BACK_ATTACH = "?p=,";
public static final String PREFIX_CM_COMMA = ",";
public static final String PREFIX_CM_BACK_ATTACH_NO_COMMA = "?p=";


// Location
public static final String LOCATION_ENGCENTER_616 = "http://www.iotoasis.org/ontology/engcenter_616";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.pineone.icbms.so.service.entity.Service;
import com.pineone.icbms.so.service.proxy.DataServiceObject;
import com.pineone.icbms.so.service.ref.ConceptService;
import com.pineone.icbms.so.service.ref.DeviceObject;
import com.pineone.icbms.so.service.ref.Status;
Expand All @@ -18,4 +19,5 @@ public interface ServiceLogic {
List<String> retrieveServiceIdList();
void executeService(String serviceId, String sessionId);
List<Service> retrieveServiceList();
String requestDataService(DataServiceObject dataServiceObject);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.pineone.icbms.so.device.util.ClientProfile;
import com.pineone.icbms.so.service.entity.Service;
import com.pineone.icbms.so.service.proxy.DataServiceObject;
import com.pineone.icbms.so.service.proxy.ServiceProxy;
import com.pineone.icbms.so.service.proxy.ServiceSDAProxy;
import com.pineone.icbms.so.service.ref.ConceptService;
Expand Down Expand Up @@ -175,6 +176,7 @@ public void executeService(String serviceId, String sessionId) {
if("si-lack-equipment-noti".equals(serviceId)){
try {
operation = serviceSDAProxy.getPCCountUri(session);
logger.info("Equipment Data = " + operation);
} catch (BadRequestException e) {
logger.warn("operation is not Count");
session = sessionStore.retrieveSessionDetail(localSessionId);
Expand All @@ -183,6 +185,7 @@ public void executeService(String serviceId, String sessionId) {
} else if("si-domitory-optimal-environment".equals(serviceId)){
try {
operation = serviceSDAProxy.getTemperatureLookup(session);
logger.info("Environment Data = " + operation);
} catch (BadRequestException e) {
logger.warn("operation is not Count");
session = sessionStore.retrieveSessionDetail(localSessionId);
Expand Down Expand Up @@ -227,4 +230,15 @@ public List<Service> retrieveServiceList() {
return services;
}

@Override
public String requestDataService(DataServiceObject dataServiceObject) {
String response = "";
try{
response = serviceSDAProxy.getDataService(dataServiceObject);
}catch (BadRequestException e){
response = e.toString();
}
return response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.pineone.icbms.so.service.entity.Service;
import com.pineone.icbms.so.service.logic.ServiceLogic;
import com.pineone.icbms.so.service.proxy.DataServiceObject;
import com.pineone.icbms.so.service.ref.*;
import com.pineone.icbms.so.util.exception.DataLossException;
import com.pineone.icbms.so.util.logprint.LogPrint;
Expand Down Expand Up @@ -130,6 +131,21 @@ public List<Service> retrieveServiceList(){
return serviceList;
}

/**
* Data Service
*/
@RequestMapping(value = "/data", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public String retrieveServiceList(@RequestBody DataServiceObject dataServiceObject){
//
logger.info(LogPrint.inputInfoLogPrint() + "Data Service Start");
logger.info(LogPrint.inputInfoLogPrint() + "DataServiceObject = " + dataServiceObject.toString());

String dataServiceData = serviceLogic.requestDataService(dataServiceObject);
logger.info("DataService Data = " + dataServiceData);
return dataServiceData;
}


// NOTE: Service Component 의 DB에 접근해서 service Name 리스트 조회
public List<String> retrieveServiceNameList(){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.pineone.icbms.so.service.proxy;

public class DataServiceObject {

public static final int DATASERIVCE_CMID = 1;
public static final int DATASERIVCE_CMID_PARAM1 = 2;
public static final int DATASERIVCE_CMID_PARAM2 = 3;
public static final int DATASERIVCE_CMID_PARAM3 = 4;
public static final int DATASERIVCE_CMID_PARAM4 = 5;

private String cmId;
private String param1;
private String param2;
private String param3;
private String param4;

public DataServiceObject() {
}

public DataServiceObject(String cmId, String param1, String param2, String param3, String param4) {
this.cmId = cmId;
this.param1 = param1;
this.param2 = param2;
this.param3 = param3;
this.param4 = param4;
}

public String getCmId() {
return cmId;
}

public void setCmId(String cmId) {
this.cmId = cmId;
}

public String getParam1() {
return param1;
}

public void setParam1(String param1) {
this.param1 = param1;
}

public String getParam2() {
return param2;
}

public void setParam2(String param2) {
this.param2 = param2;
}

public String getParam3() {
return param3;
}

public void setParam3(String param3) {
this.param3 = param3;
}

public String getParam4() {
return param4;
}

public void setParam4(String param4) {
this.param4 = param4;
}

public int getParam(){
int paramCount = 0;

if(param4 != null && !param4.isEmpty()){
paramCount = 4;
} else if(param3 != null && !param3.isEmpty()){
paramCount = 3;
} else if(param2 != null && !param2.isEmpty()){
paramCount = 2;
} else if(param1 != null && !param1.isEmpty()){
paramCount = 1;
}

return paramCount;
}


@Override
public String toString() {
return "DataServiceObject{" +
"cmId='" + cmId + '\'' +
", param1='" + param1 + '\'' +
", param2='" + param2 + '\'' +
", param3='" + param3 + '\'' +
", param4='" + param4 + '\'' +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
public interface ServiceSDAProxy {
String getPCCountUri(Session session) throws BadRequestException;
String getTemperatureLookup(Session session) throws BadRequestException;
String getDataService(DataServiceObject dataServiceObject) throws BadRequestException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,25 @@ public String getTemperatureLookup(Session session) throws BadRequestException {
}

}

@Override
public String getDataService(DataServiceObject dataServiceObject) throws BadRequestException {
String requestUri = "";
if(dataServiceObject.getParam() == DataServiceObject.DATASERIVCE_CMID){
requestUri = contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + dataServiceObject.getCmId() + ClientProfile.PREFIX_CM_BACK_ATTACH;
} else if(dataServiceObject.getParam() == DataServiceObject.DATASERIVCE_CMID_PARAM2) {
requestUri = contextAddress.getServerAddress(ContextAddress.SDA_SERVER) + dataServiceObject.getCmId() + ClientProfile.PREFIX_CM_BACK_ATTACH_NO_COMMA + dataServiceObject.getParam1() + ClientProfile.PREFIX_CM_COMMA + dataServiceObject.getParam2();
}

IHttpResponseMessage message = clientService.requestGetService(requestUri);
if(message.getStatusCode() == 200) {
System.out.println(message.getBodyByteArray().toString());
logger.debug("ResponseMessage : " + message);
return clientService.responseDataToString(message);
}
else{
throw new BadRequestException();
}

}
}

0 comments on commit f3c1e86

Please sign in to comment.