├── LICENSE ├── README.md └── javaSDK ├── pom.xml └── src ├── main ├── java │ └── cmcc │ │ └── iot │ │ └── onenet │ │ └── javasdk │ │ ├── api │ │ ├── AbstractAPI.java │ │ ├── bindata │ │ │ ├── AddBindataApi.java │ │ │ └── GetBindataApi.java │ │ ├── cmds │ │ │ ├── GetCmdsHistoryApi.java │ │ │ ├── QueryCmdsRespApi.java │ │ │ ├── QueryCmdsStatus.java │ │ │ └── SendCmdsApi.java │ │ ├── datapoints │ │ │ ├── AddDatapointsApi.java │ │ │ └── GetDatapointsListApi.java │ │ ├── datastreams │ │ │ ├── AddDatastreamsApi.java │ │ │ ├── DeleteDatastreamsApi.java │ │ │ ├── FindDatastreamListApi.java │ │ │ ├── GetDatastreamApi.java │ │ │ └── ModifyDatastramsApi.java │ │ ├── device │ │ │ ├── AddDevicesApi.java │ │ │ ├── DeleteDeviceApi.java │ │ │ ├── FindDevicesListApi.java │ │ │ ├── FindKeyRelDeviceListApi.java │ │ │ ├── GetDeviceApi.java │ │ │ ├── GetDevicesStatus.java │ │ │ ├── GetLatesDeviceData.java │ │ │ ├── ModifyDevicesApi.java │ │ │ ├── ModifyKeyRelDeviceListApi.java │ │ │ └── RegisterDeviceApi.java │ │ ├── dtu │ │ │ ├── AddDtuParser.java │ │ │ ├── DeleteDtuParser.java │ │ │ ├── FindDtuParserList.java │ │ │ └── ModifyDtuParser.java │ │ ├── key │ │ │ ├── AddKeyApi.java │ │ │ ├── DeleteKeyApi.java │ │ │ ├── FindKeyList.java │ │ │ └── ModifyKeyApi.java │ │ ├── mqtt │ │ │ ├── CreateMqttTopicApi.java │ │ │ ├── DeleteUserTopic.java │ │ │ ├── FindTopicDevices.java │ │ │ ├── GetDevicesTopicsApi.java │ │ │ ├── GetUserTopics.java │ │ │ └── SendMqttApi.java │ │ └── triggers │ │ │ ├── AddTriggersApi.java │ │ │ ├── DeleteTriggersApi.java │ │ │ ├── FindTriggersListApi.java │ │ │ ├── GetTriggersApi.java │ │ │ └── ModifyTriggersApi.java │ │ ├── exception │ │ └── OnenetApiException.java │ │ ├── http │ │ ├── BasicHttpMethod.java │ │ ├── HttpDeleteMethod.java │ │ ├── HttpGetMethod.java │ │ ├── HttpPostMethod.java │ │ └── HttpPutMethod.java │ │ ├── model │ │ ├── Data.java │ │ ├── Datapoints.java │ │ ├── Devices.java │ │ ├── Location.java │ │ ├── Permissions.java │ │ └── key.java │ │ ├── request │ │ └── RequestInfo.java │ │ ├── response │ │ ├── BasicResponse.java │ │ ├── bindata │ │ │ └── NewBindataResponse.java │ │ ├── cmds │ │ │ ├── CmdsList.java │ │ │ ├── CmdsResponse.java │ │ │ └── NewCmdsResponse.java │ │ ├── datapoints │ │ │ └── DatapointsList.java │ │ ├── datastreams │ │ │ ├── DatastreamsResponse.java │ │ │ └── NewdatastramsResponse.java │ │ ├── device │ │ │ ├── DeciceLatestDataPoint.java │ │ │ ├── DeviceList.java │ │ │ ├── DeviceResponse.java │ │ │ ├── DevicesStatusList.java │ │ │ ├── KeyRelDeviceList.java │ │ │ ├── ModifyKeyRelDeviceResponse.java │ │ │ ├── NewDeviceResponse.java │ │ │ └── RegDeviceResponse.java │ │ ├── dtu │ │ │ ├── DtuParserList.java │ │ │ └── NewParserResponse.java │ │ ├── key │ │ │ ├── KeyList.java │ │ │ └── NewKeyResponse.java │ │ ├── mqtt │ │ │ └── TopicDeviceList.java │ │ └── triggers │ │ │ ├── NewTriggersResponse.java │ │ │ ├── TriggerDeviceDetailItem.java │ │ │ ├── TriggersList.java │ │ │ └── TriggersResponse.java │ │ └── utils │ │ ├── Config.java │ │ └── OrderConstant.java └── resources │ └── config.properties └── test └── java ├── cmcc └── iot │ └── onenet │ └── javasdk │ └── ApiTest.java └── com └── cmcciot └── onenet └── api └── ApiTest.java /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JAVA-HTTP-SDK 2 | OneNET JAVA-HTTP-SDK 3 | 本项目是 中移物联网公司 为方便Java开发者接入 OneNET 平台而开发的SDK。关于OneNET请进入[OneNet](http://open.iot.10086.cn) 4 | 主站了解详情。如果要了解OneNet API请进入 [文档中心](http://open.iot.10086.cn/doc) 参考API文档。 5 | 本程序是中移物联的OneNET公众版Java版本的SDK(完整版本)。Java SDK版本为1.5以上,maven版本为Apache Maven 3.3.9。 6 | 本SDK包含了OneNET平台的设备、数据流、数据点、触发器和api key的增删改查,以及二进制数据存取、命令执行、Mqtt相关功能。 7 | 8 | 本程序一共包含SDK代码和其单元测试(cmcc.iot.onenet.javasdk.ApiTest.java)。SDK使用案例请直接参照单元测试即可。 9 | 10 | ## 如何使用 11 | ### 示例 12 | 以设备新增为例 13 | ```Java 14 | public void testAdddevices() { 15 | String key = "9ylHzkz25nre41i=SuJR=F=k5kU="; 16 | String title = "devices_test"; 17 | String desc = "devices_test"; 18 | String protocol = "HTTP"; 19 | Location location =new Location(106,29,370);//设备位置{"纬度", "经度", "高度"}(可选) 20 | List tags = new ArrayList(); 21 | tags.add("china"); 22 | tags.add("mobile"); 23 | String auth_info = "201503041a5829151"; 24 | /**** 25 | * 设备新增 26 | * 参数顺序与构造函数顺序一致 27 | * @param title: 设备名,String 28 | * @param protocol: 接入协议(可选,默认为HTTP),String 29 | * @param desc: 设备描述(可选),String 30 | * @param tags: 设备标签(可选,可为一个或多个),List 31 | * @param location: 设备位置{"纬度", "精度", "高度"}(可选),Location类型 32 | * @param isPrivate: 设备私密性,Boolean类型(可选,默认为ture) 33 | * @param authInfo: 设备唯一编号 ,Object 34 | * @param other: 其他信息,Map 35 | * (可选,可自定义) 36 | * @param interval: MODBUS设备 下发命令周期,Integer类型,秒(可选) 37 | * @param key: masterkey,String 38 | */ 39 | AddDevicesApi api = new AddDevicesApi(title, protocol, desc, tags, location, null, auth_info, null, null, key); 40 | BasicResponse response = api.executeApi(); 41 | System.out.println("errno:"+response.errno+" error:"+response.error); 42 | System.out.println(response.getJson()); 43 | 44 | } 45 | ``` 46 | 47 | ### 注意事项: 48 | 49 | 更多示例请参考ApiTest中的代码,运行前请确认resources中的config.properties请求的IP地址正确 50 | -------------------------------------------------------------------------------- /javaSDK/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cmcc.iot.onenet.javasdk 6 | javaSDK 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | javaSDK 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | junit 20 | junit 21 | 4.12 22 | test 23 | 24 | 25 | com.fasterxml.jackson.core 26 | jackson-databind 27 | 2.6.7.4 28 | 29 | 30 | org.apache.httpcomponents 31 | httpmime 32 | 4.3.6 33 | 34 | 35 | org.json 36 | json 37 | 20141113 38 | test 39 | 40 | 41 | org.apache.commons 42 | commons-lang3 43 | 3.1 44 | 45 | 46 | org.apache.commons 47 | commons-io 48 | 1.3.2 49 | 50 | 51 | org.slf4j 52 | slf4j-api 53 | 1.7.20 54 | 55 | 56 | ch.qos.logback 57 | logback-classic 58 | 1.2.3 59 | 60 | 61 | com.fasterxml.jackson.datatype 62 | jackson-datatype-joda 63 | 2.8.7 64 | 65 | 66 | 67 | javaSDK 68 | 69 | 70 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/AbstractAPI.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api; 2 | 3 | 4 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 5 | import com.fasterxml.jackson.databind.DeserializationFeature; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | 8 | import java.text.DateFormat; 9 | import java.text.SimpleDateFormat; 10 | import java.util.Locale; 11 | import java.util.TimeZone; 12 | 13 | public abstract class AbstractAPI { 14 | public String key; 15 | public String url; 16 | public Method method; 17 | public ObjectMapper mapper = initObjectMapper(); 18 | 19 | private ObjectMapper initObjectMapper() { 20 | ObjectMapper objectMapper = new ObjectMapper(); 21 | //关闭字段不识别报错 22 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 23 | //调整默认时区为北京时间 24 | TimeZone timeZone = TimeZone.getTimeZone("GMT+8"); 25 | DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); 26 | dateFormat.setTimeZone(timeZone); 27 | objectMapper.setDateFormat(dateFormat); 28 | objectMapper.setTimeZone(timeZone); 29 | return objectMapper; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/bindata/AddBindataApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.bindata; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.response.bindata.NewBindataResponse; 18 | import cmcc.iot.onenet.javasdk.utils.Config; 19 | 20 | public class AddBindataApi extends AbstractAPI{ 21 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 22 | private String devId; 23 | private String datastreamId; 24 | private String filename; 25 | private String filepath; 26 | private HttpPostMethod HttpMethod; 27 | /** 28 | * @param devId:数据所属设备(必选),String 29 | * @param datastreamId:该数据所属已经存在的数据流(必选),String 30 | * @param key:masterkey 或者 该设备的设备key 31 | * @param filename:文件名,String 32 | * @param filepath:路径,String 33 | */ 34 | public AddBindataApi(String devId, String datastreamId,String key, String filename,String filepath) { 35 | this.devId = devId; 36 | this.datastreamId = datastreamId; 37 | this.key=key; 38 | this.filename=filename; 39 | this.filepath=filepath; 40 | this.method=Method.POST; 41 | 42 | Map headmap = new HashMap(); 43 | HttpMethod= new HttpPostMethod(method); 44 | headmap.put("api-key", key); 45 | HttpMethod.setHeader(headmap); 46 | this.url=Config.getString("test.url")+"/bindata"; 47 | Map urlmap = new HashMap(); 48 | if(devId!=null){ 49 | urlmap.put("device_id", devId); 50 | } 51 | if(datastreamId!=null){ 52 | urlmap.put("datastream_id", datastreamId); 53 | } 54 | Map fileMap=new HashMap(); 55 | fileMap.put(filename, filepath); 56 | ((HttpPostMethod)HttpMethod).setEntity(null,fileMap); 57 | HttpMethod.setcompleteUrl(url,urlmap); 58 | } 59 | 60 | public BasicResponse executeApi(){ 61 | BasicResponse response=null; 62 | try { 63 | HttpResponse httpResponse=HttpMethod.execute(); 64 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 65 | response.setJson(mapper.writeValueAsString(response)); 66 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewBindataResponse.class); 67 | response.setData(newData); 68 | return response; 69 | 70 | } catch (Exception e) { 71 | logger.error("json error {}", e.getMessage()); 72 | throw new OnenetApiException(e.getMessage()); 73 | }finally { 74 | try { 75 | HttpMethod.httpClient.close(); 76 | } catch (Exception e) { 77 | logger.error("http close error: {}", e.getMessage()); 78 | throw new OnenetApiException(e.getMessage()); 79 | } 80 | } 81 | 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/bindata/GetBindataApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.bindata; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.apache.http.util.EntityUtils; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 12 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 13 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 14 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 15 | import cmcc.iot.onenet.javasdk.utils.Config; 16 | 17 | public class GetBindataApi extends AbstractAPI{ 18 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 19 | private HttpGetMethod HttpMethod; 20 | private String index; 21 | /** 22 | * @param index:二进制数据索引号,String 23 | * @param key:masterkey 或者 该设备的设备key 24 | */ 25 | public GetBindataApi(String index,String key) { 26 | this.index = index; 27 | this.key=key; 28 | this.method= Method.GET; 29 | this.HttpMethod=new HttpGetMethod(method); 30 | Map headmap = new HashMap(); 31 | headmap.put("api-key", key); 32 | HttpMethod.setHeader(headmap); 33 | this.url = Config.getString("test.url") + "/bindata" + "/" + index; 34 | HttpMethod.setcompleteUrl(url,null); 35 | } 36 | 37 | public String executeApi() { 38 | String response=null; 39 | try { 40 | HttpResponse httpResponse=HttpMethod.execute(); 41 | response = EntityUtils.toString(httpResponse.getEntity()); 42 | return response; 43 | } catch (Exception e) { 44 | logger.error("error: {}" , e.getMessage()); 45 | throw new OnenetApiException(e.getMessage()); 46 | }finally { 47 | try { 48 | HttpMethod.httpClient.close(); 49 | } catch (Exception e) { 50 | logger.error("http close error: {}", e.getMessage()); 51 | throw new OnenetApiException(e.getMessage()); 52 | } 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/cmds/GetCmdsHistoryApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.cmds; 2 | 3 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 4 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 5 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 6 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 7 | import cmcc.iot.onenet.javasdk.response.cmds.CmdsList; 8 | import cmcc.iot.onenet.javasdk.utils.Config; 9 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 10 | import org.apache.commons.io.IOUtils; 11 | import org.apache.http.HttpResponse; 12 | import org.apache.http.util.Asserts; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import java.io.InputStream; 17 | import java.text.SimpleDateFormat; 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | /** 22 | * 23 | * @Description 查询历史命令分页列表 24 | * @author luowz 25 | * @date 2018/12/28 15:20 26 | * @version 1.0 27 | * 28 | **/ 29 | public class GetCmdsHistoryApi extends AbstractAPI{ 30 | 31 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 32 | private HttpGetMethod HttpMethod; 33 | /*** 34 | * 设备id 35 | **/ 36 | // private String devId; 37 | // /*** 38 | // * master-key 39 | // **/ 40 | // private String key; 41 | // /*** 42 | // * 指定开始时间,必选 43 | // **/ 44 | // private String start; 45 | // /*** 46 | // * 指定结束时间,可选 47 | // **/ 48 | // private String end; 49 | // /*** 50 | // * 时间间隔,可选,默认不传,单位秒,最大一周(duration和end只能选一个) 51 | // **/ 52 | // private Integer duration; 53 | // /*** 54 | // * 命令条数,默认10,最大6000 55 | // **/ 56 | // private Integer limit; 57 | // /*** 58 | // * 命令条数,默认10,最大6000 59 | // **/ 60 | // private String cursor; 61 | // 62 | // /*** 63 | // * 值为DESC|ASC时间排序方式,DESC:降序,ASC升序,默认降序 64 | // **/ 65 | // private String sort; 66 | // 67 | 68 | 69 | /** 70 | * 根据响应状态查询,可选 71 | * 1:命令已创建| Command Created 72 | * 2:命令已发往设备| Command Sent 73 | * 3:命令发往设备失败| Send Command Failed 74 | * 4:设备正常响应| Command Response Received 75 | * 5:命令执行超时| Command Response Timeout 76 | * 6:设备响应消息过长 | Command Response Too Large 77 | */ 78 | // private Integer status; 79 | 80 | /** 81 | * 查询历史命令分页列表请求构造方法 82 | * @param devId 83 | * @param key 84 | * @param start 85 | * @param end 86 | * @param duration 87 | * @param limit 88 | * @param cursor 89 | * @param sort 90 | * @param status 91 | */ 92 | public GetCmdsHistoryApi(String devId, String key, String start, String end, Integer duration, Integer limit, String cursor, String sort, Integer status) { 93 | // this.devId = devId; 94 | // this.key = key; 95 | // this.start = start; 96 | // this.end = end; 97 | // this.duration = duration; 98 | // this.limit = limit; 99 | // this.cursor = cursor; 100 | // this.sort = sort; 101 | // this.status = status; 102 | 103 | this.method = Method.GET; 104 | Map headmap = new HashMap(); 105 | Map urlmap = new HashMap(); 106 | this.HttpMethod = new HttpGetMethod(method); 107 | Asserts.notBlank(devId,"devId"); 108 | this.url = Config.getString("test.url") + "/cmds/history/"+devId; 109 | Asserts.notBlank(key,"api-key"); 110 | headmap.put("api-key", key); 111 | if(start!=null){ 112 | urlmap.put("start",start); 113 | } 114 | if(end!=null){ 115 | urlmap.put("end",end); 116 | } 117 | if(duration!=null){ 118 | urlmap.put("duration",duration); 119 | } 120 | if(limit!=null){ 121 | urlmap.put("limit",limit); 122 | } 123 | if(cursor!=null){ 124 | urlmap.put("cursor",cursor); 125 | } 126 | if(cursor!=null){ 127 | urlmap.put("cursor",cursor); 128 | } 129 | if(sort!=null){ 130 | urlmap.put("sort",sort); 131 | } 132 | if(status!=null){ 133 | urlmap.put("status",status); 134 | } 135 | this.HttpMethod.setHeader(headmap); 136 | this.HttpMethod.setcompleteUrl(this.url,urlmap); 137 | } 138 | 139 | public BasicResponse executeApi() { 140 | BasicResponse response; 141 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 142 | try { 143 | HttpResponse httpResponse = HttpMethod.execute(); 144 | InputStream instreams = httpResponse.getEntity().getContent(); 145 | String str = IOUtils.toString(instreams, "UTF-8"); 146 | response = mapper.readValue(str, BasicResponse.class); 147 | response.setJson(str); 148 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), CmdsList.class); 149 | response.setData(newData); 150 | return response; 151 | } catch (Exception e) { 152 | logger.error("error: {}", e.getMessage()); 153 | throw new OnenetApiException(e.getMessage()); 154 | } finally { 155 | try { 156 | HttpMethod.httpClient.close(); 157 | } catch (Exception e) { 158 | logger.error("http close error: {}", e.getMessage()); 159 | throw new OnenetApiException(e.getMessage()); 160 | } 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/cmds/QueryCmdsRespApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.cmds; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.apache.http.util.EntityUtils; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.response.cmds.CmdsResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class QueryCmdsRespApi extends AbstractAPI { 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private HttpGetMethod HttpMethod; 24 | private String cmdUuid; 25 | 26 | /** 27 | * @param cmdUuid:命令id,String 28 | * @param key:masterkey或者设备apikey 29 | */ 30 | public QueryCmdsRespApi(String cmdUuid, String key) { 31 | this.cmdUuid = cmdUuid; 32 | this.key = key; 33 | this.method = Method.GET; 34 | this.HttpMethod = new HttpGetMethod(method); 35 | 36 | Map headmap = new HashMap(); 37 | headmap.put("api-key", key); 38 | HttpMethod.setHeader(headmap); 39 | this.url = Config.getString("test.url") + "/cmds/" + cmdUuid + "/resp"; 40 | HttpMethod.setcompleteUrl(url, null); 41 | } 42 | 43 | public String executeApi() { 44 | String resp = null; 45 | try { 46 | HttpResponse httpResponse = HttpMethod.execute(); 47 | resp = EntityUtils.toString(httpResponse.getEntity()); 48 | return resp; 49 | } catch (Exception e) { 50 | logger.error("json error {}", e.getMessage()); 51 | throw new OnenetApiException(e.getMessage()); 52 | } finally { 53 | try { 54 | HttpMethod.httpClient.close(); 55 | } catch (Exception e) { 56 | logger.error("http close error: {}", e.getMessage()); 57 | throw new OnenetApiException(e.getMessage()); 58 | } 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/cmds/QueryCmdsStatus.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.cmds; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.response.cmds.CmdsResponse; 18 | import cmcc.iot.onenet.javasdk.utils.Config; 19 | 20 | public class QueryCmdsStatus extends AbstractAPI { 21 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 22 | private HttpGetMethod HttpMethod; 23 | private String cmdUuid; 24 | 25 | 26 | /** 27 | * @param cmdUuid:命令id,String 28 | * @param key:masterkey或者设备apikey 29 | */ 30 | public QueryCmdsStatus(String cmdUuid,String key) { 31 | this.cmdUuid = cmdUuid; 32 | this.key=key; 33 | this.method= Method.GET; 34 | this.HttpMethod=new HttpGetMethod(method); 35 | 36 | Map headmap = new HashMap(); 37 | headmap.put("api-key", key); 38 | HttpMethod.setHeader(headmap); 39 | this.url = Config.getString("test.url") + "/cmds/" + cmdUuid; 40 | HttpMethod.setcompleteUrl(url,null); 41 | } 42 | 43 | 44 | public BasicResponse executeApi() { 45 | BasicResponse response=null; 46 | try { 47 | HttpResponse httpResponse=HttpMethod.execute(); 48 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 49 | response.setJson(mapper.writeValueAsString(response)); 50 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), CmdsResponse.class); 51 | response.setData(newData); 52 | return response; 53 | } catch (Exception e) { 54 | logger.error("json error {}", e.getMessage()); 55 | throw new OnenetApiException(e.getMessage()); 56 | }finally { 57 | try { 58 | HttpMethod.httpClient.close(); 59 | } catch (Exception e) { 60 | logger.error("http close error: {}", e.getMessage()); 61 | throw new OnenetApiException(e.getMessage()); 62 | } 63 | } 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/cmds/SendCmdsApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.cmds; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.response.cmds.NewCmdsResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class SendCmdsApi extends AbstractAPI { 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private String devId; 24 | private Integer qos; 25 | private Integer timeOut; 26 | private Integer type; 27 | private Object contents;//用户自定义数据 28 | private HttpPostMethod HttpMethod; 29 | /** 30 | * @param devId:接收该数据的设备ID(必选),String 31 | * @param qos:是否需要响应,默认为0,Integer 32 | * 0:不需要响应,即最多发送一次,不关心设备是否响应; 33 | * 1:需要响应,如果设备收到命令后没有响应,则会在下一次设备登陆时若命令在有效期内(有效期定义参见timeout参数)则会继续发送。 34 | * 对响应时间无限制,多次响应以最后一次为准。 35 | * 本参数仅当type=0时有效; 36 | * @param timeOut:命令有效时间,默认0,Integer 37 | * 0:在线命令,若设备在线,下发给设备,若设备离线,直接丢弃; 38 | * >0: 离线命令,若设备在线,下发给设备,若设备离线,在当前时间加timeout时间内为有效期,有效期内,若设备上线,则下发给设备。单位:秒,有效围:0~2678400。 39 | * 本参数仅当type=0时有效; 40 | * @param type://默认0。0:发送CMD_REQ包,1:发送PUSH_DATA包 41 | * @param contents:用户自定义数据:json、string、二进制数据(小于64K) 42 | * @param key:masterkey或者设备apikey 43 | */ 44 | public SendCmdsApi(String devId, Integer qos, Integer timeOut, Integer type, Object contents,String key) { 45 | this.devId = devId; 46 | this.qos = qos; 47 | this.timeOut = timeOut; 48 | this.type = type; 49 | this.contents=contents; 50 | this.key = key; 51 | this.method = Method.POST; 52 | 53 | Map headmap = new HashMap(); 54 | Map urlmap = new HashMap(); 55 | HttpMethod= new HttpPostMethod(method); 56 | headmap.put("api-key", key); 57 | HttpMethod.setHeader(headmap); 58 | this.url=Config.getString("test.url")+"/cmds"; 59 | if(devId!=null){ 60 | urlmap.put("device_id", devId); 61 | } 62 | if(qos!=null){ 63 | urlmap.put("qos", qos); 64 | } 65 | if(timeOut!=null){ 66 | urlmap.put("timeout", timeOut); 67 | } 68 | if(type!=null){ 69 | urlmap.put("type", type); 70 | } 71 | //body参数处理 72 | if(contents instanceof byte[]){ 73 | ((HttpPostMethod)HttpMethod).setEntity((byte[])contents); 74 | } 75 | if(contents instanceof String){ 76 | ((HttpPostMethod)HttpMethod).setEntity((String)contents); 77 | } 78 | HttpMethod.setcompleteUrl(url,urlmap); 79 | } 80 | 81 | public BasicResponse executeApi(){ 82 | BasicResponse response=null; 83 | try { 84 | HttpResponse httpResponse=HttpMethod.execute(); 85 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 86 | response.setJson(mapper.writeValueAsString(response)); 87 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewCmdsResponse.class); 88 | response.setData(newData); 89 | return response; 90 | 91 | } catch (Exception e) { 92 | logger.error("json error {}", e.getMessage()); 93 | throw new OnenetApiException(e.getMessage()); 94 | }finally { 95 | try { 96 | HttpMethod.httpClient.close(); 97 | } catch (Exception e) { 98 | logger.error("http close error: {}", e.getMessage()); 99 | throw new OnenetApiException(e.getMessage()); 100 | } 101 | } 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/datapoints/AddDatapointsApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.datapoints; 2 | 3 | import java.util.HashMap; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.apache.http.HttpResponse; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import com.fasterxml.jackson.databind.ObjectMapper; 13 | 14 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 15 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 16 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 17 | import cmcc.iot.onenet.javasdk.model.Datapoints; 18 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 19 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 20 | import cmcc.iot.onenet.javasdk.utils.Config; 21 | 22 | public class AddDatapointsApi extends AbstractAPI{ 23 | private Map> map; 24 | private String data; 25 | private Integer type; 26 | private String devId; 27 | private HttpPostMethod HttpMethod; 28 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 29 | /** 30 | * @param map :数据点内容,Map> 31 | * @param data:提供简写方式上传数据,String 32 | * 示例: 33 | * type=4 34 | * data="{\"temperature\":{\"2015-03-22T22:31:12\":22.5}}"; 35 | * type=5 36 | * data=",;temperature,2015-03-22T22:31:12,22.5;pm2.5,89"; 37 | * @param type:上传数据类型(可选,默认为完整JSON型,见HTTP内容示例) 38 | * @param devId:设备ID,String 39 | * @param key:masterkey 或者 设备apikey 40 | */ 41 | public AddDatapointsApi(Map> map, String data, Integer type, String devId,String key) { 42 | super(); 43 | this.map = map; 44 | this.data = data; 45 | this.type = type; 46 | this.devId = devId; 47 | this.key=key; 48 | this.method=Method.POST; 49 | 50 | Map headmap = new HashMap(); 51 | HttpMethod= new HttpPostMethod(method); 52 | headmap.put("api-key", key); 53 | HttpMethod.setHeader(headmap); 54 | this.url=Config.getString("test.url")+"/devices/"+devId+"/datapoints"; 55 | Map urlmap = new HashMap(); 56 | if(type!=null){ 57 | urlmap.put("type", type); 58 | } 59 | // body参数 60 | String json=null; 61 | try { 62 | if(map!=null){ 63 | json = mapper.writeValueAsString(map); 64 | } 65 | else{ 66 | json=data;//支持其他类型 67 | } 68 | } catch (Exception e) { 69 | logger.error("json error", e.getMessage()); 70 | throw new OnenetApiException(e.getMessage()); 71 | } 72 | ((HttpPostMethod)HttpMethod).setEntity(json); 73 | HttpMethod.setcompleteUrl(url,urlmap); 74 | } 75 | 76 | public BasicResponse executeApi() { 77 | BasicResponse response = null; 78 | try { 79 | HttpResponse httpResponse = HttpMethod.execute(); 80 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 81 | response.setJson(mapper.writeValueAsString(response)); 82 | return response; 83 | } catch (Exception e) { 84 | logger.error("json error {}", e.getMessage()); 85 | throw new OnenetApiException(e.getMessage()); 86 | }finally { 87 | try { 88 | HttpMethod.httpClient.close(); 89 | } catch (Exception e) { 90 | logger.error("http close error: {}", e.getMessage()); 91 | throw new OnenetApiException(e.getMessage()); 92 | } 93 | } 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/datapoints/GetDatapointsListApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.datapoints; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.apache.http.HttpResponse; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import com.fasterxml.jackson.core.type.TypeReference; 13 | import com.fasterxml.jackson.databind.ObjectMapper; 14 | 15 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 16 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 17 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 18 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 19 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 20 | import cmcc.iot.onenet.javasdk.response.datapoints.DatapointsList; 21 | import cmcc.iot.onenet.javasdk.response.datastreams.DatastreamsResponse; 22 | import cmcc.iot.onenet.javasdk.utils.Config; 23 | 24 | public class GetDatapointsListApi extends AbstractAPI{ 25 | private HttpGetMethod HttpMethod; 26 | private String datastreamIds; 27 | private String start; 28 | private String end; 29 | private String devId; 30 | private Integer duration; 31 | private Integer limit; 32 | private String cursor; 33 | private Integer interval; 34 | private String metd; 35 | private Integer first; 36 | private String sort; 37 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 38 | /** 39 | * 数据点查询 40 | * @param datastreamIds:查询的数据流,多个数据流之间用逗号分隔(可选),String 41 | * @param start:提取数据点的开始时间(可选),String 42 | * @param end:提取数据点的结束时间(可选),String 43 | * @param devId:设备ID,String 44 | * @param duration:查询时间区间(可选,单位为秒),Integer 45 | * start+duration:按时间顺序返回从start开始一段时间内的数据点 46 | * end+duration:按时间倒序返回从end回溯一段时间内的数据点 47 | * @param limit:限定本次请求最多返回的数据点数,0 headmap = new HashMap(); 74 | Map urlmap = new HashMap(); 75 | headmap.put("api-key", key); 76 | HttpMethod.setHeader(headmap); 77 | this.url = Config.getString("test.url") + "/devices/" + devId + "/datapoints"; 78 | // url参数 79 | if (datastreamIds != null) { 80 | urlmap.put("datastream_id", datastreamIds); 81 | } 82 | if (start != null) { 83 | urlmap.put("start", start); 84 | } 85 | if (end != null) { 86 | urlmap.put("end", end); 87 | } 88 | if (duration != null) { 89 | urlmap.put("duration", duration); 90 | } 91 | if (limit != null) { 92 | urlmap.put("limit", limit); 93 | } 94 | if (cursor != null) { 95 | urlmap.put("cursor", cursor); 96 | } 97 | if (interval != null) { 98 | urlmap.put("interval", interval); 99 | } 100 | if (metd != null) { 101 | urlmap.put("method", metd); 102 | } 103 | if (first != null) { 104 | urlmap.put("first", first); 105 | } 106 | if (sort != null) { 107 | urlmap.put("sort", sort); 108 | } 109 | HttpMethod.setcompleteUrl(url, urlmap); 110 | } 111 | 112 | public BasicResponse executeApi() { 113 | BasicResponse response; 114 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 115 | try { 116 | HttpResponse httpResponse = HttpMethod.execute(); 117 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 118 | response.setJson(mapper.writeValueAsString(response)); 119 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()),DatapointsList.class); 120 | response.setData(newData); 121 | 122 | } catch (Exception e) { 123 | e.printStackTrace(); 124 | logger.error("error: {}", e.getMessage()); 125 | throw new OnenetApiException(e.getMessage()); 126 | } 127 | return response; 128 | 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/datastreams/AddDatastreamsApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.datastreams; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.response.datastreams.NewdatastramsResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class AddDatastreamsApi extends AbstractAPI{ 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private String id; 24 | private String devId; 25 | private List tags; 26 | private String unit; 27 | private String unitSymbol; 28 | private String cmd; 29 | private Integer interval; 30 | private String formula; 31 | private HttpPostMethod HttpMethod; 32 | /** 33 | * 数据流新增 34 | * @param id:数据流名称 ,String 35 | * @param devId:设备ID,String 36 | * @param tags:数据流标签(可选,可以为一个或多个),List 37 | * @param unit:单位(可选),String 38 | * @param unitSymbol:单位符号(可选),String 39 | * @param cmd:MODBUS设备填写,周期下发命令,16进制字节字符串 40 | * @param interval:MODBUS设备填写,采集间隔,秒,Integer 41 | * @param formula:MODBUS设备填写,寄存器计算公式(可选),String 42 | * @param key:masterkey 或者 设备apikey 43 | */ 44 | public AddDatastreamsApi(String id, String devId, List tags, String unit, String unitSymbol, String cmd, 45 | Integer interval, String formula, String key) { 46 | super(); 47 | this.id = id; 48 | this.devId = devId; 49 | this.tags = tags; 50 | this.unit = unit; 51 | this.unitSymbol = unitSymbol; 52 | this.cmd = cmd; 53 | this.interval = interval; 54 | this.formula = formula; 55 | this.key=key; 56 | this.method=Method.POST; 57 | Map headmap = new HashMap(); 58 | HttpMethod= new HttpPostMethod(method); 59 | headmap.put("api-key", key); 60 | HttpMethod.setHeader(headmap); 61 | this.url=Config.getString("test.url")+"/devices/"+devId+"/datastreams"; 62 | // body参数 63 | Map bodymap = new HashMap(); 64 | if(this.id!=null){ 65 | bodymap.put("id", id); 66 | } 67 | if(this.tags!=null){ 68 | bodymap.put("tags", tags); 69 | } 70 | if(this.unit!=null){ 71 | bodymap.put("unit", unit); 72 | } 73 | if(this.unitSymbol!=null){ 74 | bodymap.put("unit_symbol", unitSymbol); 75 | } 76 | if(this.cmd!=null){ 77 | bodymap.put("cmd", cmd); 78 | } 79 | if(this.interval!=null){ 80 | bodymap.put("interval", interval); 81 | } 82 | if(this.formula!=null){ 83 | bodymap.put("formula", formula); 84 | } 85 | String json=null; 86 | ObjectMapper remapper = new ObjectMapper(); 87 | try { 88 | json = remapper.writeValueAsString(bodymap); 89 | } catch (Exception e) { 90 | logger.error("json error {}", e.getMessage()); 91 | throw new OnenetApiException(e.getMessage()); 92 | } 93 | ((HttpPostMethod)HttpMethod).setEntity(json); 94 | HttpMethod.setcompleteUrl(url,null); 95 | } 96 | 97 | 98 | 99 | public BasicResponse executeApi(){ 100 | BasicResponse response=null; 101 | try { 102 | HttpResponse httpResponse=HttpMethod.execute(); 103 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 104 | response.setJson(mapper.writeValueAsString(response)); 105 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewdatastramsResponse.class); 106 | response.setData(newData); 107 | return response; 108 | 109 | } catch (Exception e) { 110 | System.out.println(e.getMessage()); 111 | logger.error("json error {}", e.getMessage()); 112 | throw new OnenetApiException(e.getMessage()); 113 | }finally { 114 | try { 115 | HttpMethod.httpClient.close(); 116 | } catch (Exception e) { 117 | logger.error("http close error: {}", e.getMessage()); 118 | throw new OnenetApiException(e.getMessage()); 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/datastreams/DeleteDatastreamsApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.datastreams; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpDeleteMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.utils.Config; 18 | 19 | public class DeleteDatastreamsApi extends AbstractAPI{ 20 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 21 | private String devId; 22 | private HttpDeleteMethod HttpMethod; 23 | private String datastreamId; 24 | /** 25 | * @param devId 26 | * @param datastreamId 27 | * @param key 28 | */ 29 | public DeleteDatastreamsApi(String devId, String datastreamId,String key) { 30 | this.devId = devId; 31 | this.datastreamId = datastreamId; 32 | this.key=key; 33 | this.method = Method.DELETE; 34 | Map headmap = new HashMap(); 35 | HttpMethod = new HttpDeleteMethod(method); 36 | headmap.put("api-key", key); 37 | HttpMethod.setHeader(headmap); 38 | this.url = Config.getString("test.url") + "/devices/" + devId+"/datastreams/"+datastreamId; 39 | HttpMethod.setcompleteUrl(url,null); 40 | } 41 | 42 | 43 | public BasicResponse executeApi() { 44 | BasicResponse response = null; 45 | try { 46 | HttpResponse httpResponse = HttpMethod.execute(); 47 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 48 | response.setJson(mapper.writeValueAsString(response)); 49 | return response; 50 | } catch (Exception e) { 51 | logger.error("json error {}", e.getMessage()); 52 | throw new OnenetApiException(e.getMessage()); 53 | }finally { 54 | try { 55 | HttpMethod.httpClient.close(); 56 | } catch (Exception e) { 57 | logger.error("http close error: {}", e.getMessage()); 58 | throw new OnenetApiException(e.getMessage()); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/datastreams/FindDatastreamListApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.datastreams; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.apache.http.HttpResponse; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import com.fasterxml.jackson.core.type.TypeReference; 13 | import com.fasterxml.jackson.databind.ObjectMapper; 14 | 15 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 16 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 17 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 18 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 19 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 20 | import cmcc.iot.onenet.javasdk.response.datastreams.DatastreamsResponse; 21 | import cmcc.iot.onenet.javasdk.utils.Config; 22 | 23 | public class FindDatastreamListApi extends AbstractAPI { 24 | private HttpGetMethod HttpMethod; 25 | private String datastreamids; 26 | private String devId; 27 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 28 | /** 29 | * 查询多个数据流 30 | * @param datastreamids:数据流名称 ,String 31 | * @param devId:设备ID,String 32 | * @param key:masterkey 或者 设备apikey 33 | */ 34 | public FindDatastreamListApi(String datastreamids, String devId, String key) { 35 | this.datastreamids = datastreamids; 36 | this.devId = devId; 37 | this.key = key; 38 | this.method = Method.GET; 39 | this.HttpMethod = new HttpGetMethod(method); 40 | Map headmap = new HashMap(); 41 | Map urlmap = new HashMap(); 42 | headmap.put("api-key", key); 43 | HttpMethod.setHeader(headmap); 44 | this.url = Config.getString("test.url") + "/devices/" + devId + "/datastreams"; 45 | // url参数 46 | if (datastreamids != null) { 47 | urlmap.put("datastream_ids", datastreamids); 48 | } 49 | HttpMethod.setcompleteUrl(url, urlmap); 50 | } 51 | 52 | 53 | 54 | public BasicResponse> executeApi() { 55 | BasicResponse response; 56 | /*ObjectMapper mapper = new ObjectMapper(); 57 | mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));*/ 58 | try { 59 | HttpResponse httpResponse = HttpMethod.execute(); 60 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 61 | response.setJson(mapper.writeValueAsString(response)); 62 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), new TypeReference>(){}); 63 | response.setData(newData); 64 | return response; 65 | } catch (Exception e) { 66 | logger.error("error: {}" , e.getMessage()); 67 | throw new OnenetApiException(e.getMessage()); 68 | }finally { 69 | try { 70 | HttpMethod.httpClient.close(); 71 | } catch (Exception e) { 72 | logger.error("http close error: {}", e.getMessage()); 73 | throw new OnenetApiException(e.getMessage()); 74 | } 75 | } 76 | 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/datastreams/GetDatastreamApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.datastreams; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.response.datastreams.DatastreamsResponse; 19 | import cmcc.iot.onenet.javasdk.response.device.DeviceResponse; 20 | import cmcc.iot.onenet.javasdk.utils.Config; 21 | 22 | public class GetDatastreamApi extends AbstractAPI{ 23 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 24 | private HttpGetMethod HttpMethod; 25 | private String datastreamId; 26 | private String devId; 27 | /** 28 | * 查询单个数据流 29 | * @param devId 30 | * @param datastreamId 31 | * @param key 32 | */ 33 | public GetDatastreamApi( String devId,String datastreamId,String key) { 34 | this.datastreamId = datastreamId; 35 | this.devId = devId; 36 | this.key = key; 37 | this.method = Method.GET; 38 | this.HttpMethod=new HttpGetMethod(method); 39 | Map headmap = new HashMap(); 40 | headmap.put("api-key", key); 41 | HttpMethod.setHeader(headmap); 42 | this.url = Config.getString("test.url") + "/devices/"+ devId+"/datastreams/"+datastreamId; 43 | HttpMethod.setcompleteUrl(url,null); 44 | 45 | } 46 | 47 | public BasicResponse executeApi() { 48 | BasicResponse response; 49 | // ObjectMapper mapper = new ObjectMapper(); 50 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 51 | try { 52 | HttpResponse httpResponse=HttpMethod.execute(); 53 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 54 | response.setJson(mapper.writeValueAsString(response)); 55 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), DatastreamsResponse.class); 56 | response.setData(newData); 57 | return response; 58 | } catch (Exception e) { 59 | logger.error("json error {}", e.getMessage()); 60 | throw new OnenetApiException(e.getMessage()); 61 | } 62 | finally { 63 | try { 64 | HttpMethod.httpClient.close(); 65 | } catch (Exception e) { 66 | logger.error("http close error: {}", e.getMessage()); 67 | throw new OnenetApiException(e.getMessage()); 68 | } 69 | } 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/datastreams/ModifyDatastramsApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.datastreams; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpPutMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.utils.Config; 19 | 20 | public class ModifyDatastramsApi extends AbstractAPI { 21 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 22 | private String uuid; 23 | private String devId; 24 | private List tags; 25 | private String unit; 26 | private String unitSymbol; 27 | private String cmd; 28 | private Integer interval; 29 | private String formula; 30 | private HttpPutMethod HttpMethod; 31 | 32 | /** 33 | * 数据流更新 34 | * @param uuid:数据流名称 ,String 35 | * @param devId:设备ID,String 36 | * @param tags:数据流标签(可选,可以为一个或多个) 37 | * @param unit:单位(可选),String 38 | * @param unitSymbol:单位符号(可选),String 39 | * @param cmd:MODBUS设备填写,周期下发命令,16进制字节字符串 40 | * @param interval:MODBUS设备填写,采集间隔,秒,Integer 41 | * @param formula:MODBUS设备填写,寄存器计算公式(可选),String 42 | * @param key:masterkey 或者 设备apikey 43 | */ 44 | public ModifyDatastramsApi(String uuid, String devId, List tags, String unit, String unitSymbol, String cmd, 45 | Integer interval, String formula, String key) { 46 | super(); 47 | this.uuid = uuid; 48 | this.devId = devId; 49 | this.tags = tags; 50 | this.unit = unit; 51 | this.unitSymbol = unitSymbol; 52 | this.cmd = cmd; 53 | this.interval = interval; 54 | this.formula = formula; 55 | this.key = key; 56 | this.method = Method.PUT; 57 | 58 | Map headmap = new HashMap(); 59 | HttpMethod = new HttpPutMethod(method); 60 | headmap.put("api-key", key); 61 | HttpMethod.setHeader(headmap); 62 | this.url = Config.getString("test.url") + "/devices/" + devId + "/datastreams/" + uuid; 63 | // body参数 64 | Map bodymap = new HashMap(); 65 | if (this.tags != null) { 66 | bodymap.put("tags", tags); 67 | } 68 | if (this.unit != null) { 69 | bodymap.put("unit", unit); 70 | } 71 | if (this.unitSymbol != null) { 72 | bodymap.put("unit_symbol", unitSymbol); 73 | } 74 | if (this.cmd != null) { 75 | bodymap.put("cmd", cmd); 76 | } 77 | if (this.interval != null) { 78 | bodymap.put("interval", interval); 79 | } 80 | if (this.formula != null) { 81 | bodymap.put("formula", formula); 82 | } 83 | String json = null; 84 | ObjectMapper remapper = new ObjectMapper(); 85 | try { 86 | json = remapper.writeValueAsString(bodymap); 87 | } catch (Exception e) { 88 | logger.error("json error {}", e.getMessage()); 89 | throw new OnenetApiException(e.getMessage()); 90 | } 91 | ((HttpPutMethod) HttpMethod).setEntity(json); 92 | HttpMethod.setcompleteUrl(url, null); 93 | } 94 | 95 | 96 | public BasicResponse executeApi() { 97 | BasicResponse response = null; 98 | try { 99 | HttpResponse httpResponse = HttpMethod.execute(); 100 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 101 | response.setJson(mapper.writeValueAsString(response)); 102 | return response; 103 | } catch (Exception e) { 104 | logger.error("json error {}", e.getMessage()); 105 | throw new OnenetApiException(e.getMessage()); 106 | } 107 | finally { 108 | try { 109 | HttpMethod.httpClient.close(); 110 | } catch (Exception e) { 111 | logger.error("http close error: {}", e.getMessage()); 112 | throw new OnenetApiException(e.getMessage()); 113 | } 114 | } 115 | 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/AddDevicesApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import com.fasterxml.jackson.databind.ObjectMapper; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.model.Location; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.response.device.NewDeviceResponse; 18 | import cmcc.iot.onenet.javasdk.utils.Config; 19 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 20 | 21 | public class AddDevicesApi extends AbstractAPI { 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private String title; 24 | private String protocol; 25 | private String desc; 26 | private String idsn; 27 | private List tags; 28 | private Location location; 29 | private Boolean isPrivate; 30 | private Object authInfo; 31 | private Map other; 32 | private Integer interval; 33 | private HttpPostMethod HttpMethod; 34 | 35 | 36 | /**** 37 | * 设备新增 38 | * 参数顺序与构造函数顺序一致 39 | * @param title: 设备名,String 40 | * @param protocol: 接入协议(可选,默认为HTTP),String 41 | * @param desc: 设备描述(可选),String 42 | * @param tags: 设备标签(可选,可为一个或多个),List 43 | * @param location: 设备位置{"纬度", "经度", "高度"}(可选),Location类型 44 | * @param isPrivate: 设备私密性,Boolean类型 45 | * @param authInfo: 设备唯一编号 ,String或json 46 | * @param other: 其他信息,Map 47 | * @param interval: MODBUS设备 下发命令周期,Integer类型 48 | * @param key: masterkey,String 49 | */ 50 | 51 | public AddDevicesApi(String title, String protocol, String desc, List tags, Location location, 52 | Boolean isPrivate, Object authInfo, Map other, Integer interval, 53 | String key) { 54 | this.title = title; 55 | this.protocol = protocol; 56 | this.desc = desc; 57 | this.tags = tags; 58 | this.location = location; 59 | this.isPrivate = isPrivate; 60 | this.authInfo = authInfo; 61 | this.other = other; 62 | this.interval = interval; 63 | this.key = key; 64 | this.method = Method.POST; 65 | Map headmap = new HashMap(); 66 | HttpMethod= new HttpPostMethod(method); 67 | headmap.put("api-key", key); 68 | HttpMethod.setHeader(headmap); 69 | this.url=Config.getString("test.url")+"/devices"; 70 | // body参数 71 | Map bodymap = new HashMap(); 72 | if (title != null) { 73 | bodymap.put("title", title); 74 | } 75 | if (desc != null) { 76 | bodymap.put("desc", desc); 77 | } 78 | if (tags != null) { 79 | bodymap.put("tags", tags); 80 | } 81 | 82 | if (idsn != null) { 83 | bodymap.put("idsn", idsn); 84 | } 85 | if (location != null) { 86 | bodymap.put("location", location.toMap()); 87 | } 88 | if (protocol != null) { 89 | bodymap.put("protocol", protocol); 90 | } 91 | if (authInfo != null) { 92 | bodymap.put("auth_info", authInfo); 93 | 94 | } 95 | if (interval !=null) { 96 | bodymap.put("interval", interval); 97 | } 98 | if (other != null) { 99 | bodymap.put("other", other); 100 | } 101 | if (isPrivate != null) { 102 | bodymap.put("private", isPrivate); 103 | } 104 | String json=null; 105 | ObjectMapper remapper = new ObjectMapper(); 106 | try { 107 | json = remapper.writeValueAsString(bodymap); 108 | } catch (Exception e) { 109 | logger.error("json error", e.getMessage()); 110 | throw new OnenetApiException(e.getMessage()); 111 | } 112 | ((HttpPostMethod)HttpMethod).setEntity(json); 113 | HttpMethod.setcompleteUrl(url,null); 114 | } 115 | 116 | 117 | public BasicResponse executeApi(){ 118 | ObjectMapper mapper = new ObjectMapper(); 119 | BasicResponse response=null; 120 | try { 121 | HttpResponse httpResponse=HttpMethod.execute(); 122 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 123 | response.setJson(mapper.writeValueAsString(response)); 124 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewDeviceResponse.class); 125 | response.setData(newData); 126 | return response; 127 | 128 | } catch (Exception e) { 129 | logger.error("json error {}", e.getMessage()); 130 | throw new OnenetApiException(e.getMessage()); 131 | }finally { 132 | try { 133 | HttpMethod.httpClient.close(); 134 | } catch (Exception e) { 135 | logger.error("http close error: {}", e.getMessage()); 136 | throw new OnenetApiException(e.getMessage()); 137 | } 138 | } 139 | 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/DeleteDeviceApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import com.fasterxml.jackson.databind.ObjectMapper; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 12 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 13 | import cmcc.iot.onenet.javasdk.http.HttpDeleteMethod; 14 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 15 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 16 | import cmcc.iot.onenet.javasdk.utils.Config; 17 | 18 | public class DeleteDeviceApi extends AbstractAPI { 19 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 20 | private String devId; 21 | private HttpDeleteMethod HttpMethod; 22 | 23 | /** 24 | * 设备删除 25 | * @param devId: 设备ID,String 26 | * @param key: //masterkey 或者 设备key 27 | */ 28 | public DeleteDeviceApi(String devId,String key) { 29 | this.devId = devId; 30 | this.key=key; 31 | this.method = Method.DELETE; 32 | Map headmap = new HashMap(); 33 | HttpMethod = new HttpDeleteMethod(method); 34 | headmap.put("api-key", key); 35 | HttpMethod.setHeader(headmap); 36 | this.url = Config.getString("test.url") + "/devices" + "/" + devId; 37 | HttpMethod.setcompleteUrl(url,null); 38 | } 39 | 40 | 41 | public BasicResponse executeApi() { 42 | BasicResponse response = null; 43 | try { 44 | HttpResponse httpResponse = HttpMethod.execute(); 45 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 46 | response.setJson(mapper.writeValueAsString(response)); 47 | return response; 48 | } catch (Exception e) { 49 | logger.error("json error {}", e.getMessage()); 50 | throw new OnenetApiException(e.getMessage()); 51 | }finally { 52 | try { 53 | HttpMethod.httpClient.close(); 54 | } catch (Exception e) { 55 | logger.error("http close error: {}", e.getMessage()); 56 | throw new OnenetApiException(e.getMessage()); 57 | } 58 | } 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/FindDevicesListApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | import java.io.InputStream; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import org.apache.commons.io.IOUtils; 10 | import org.apache.http.HttpResponse; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 15 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 16 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 17 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 18 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 19 | import cmcc.iot.onenet.javasdk.response.device.DeviceList; 20 | import cmcc.iot.onenet.javasdk.utils.Config; 21 | 22 | public class FindDevicesListApi extends AbstractAPI { 23 | private String keywords; 24 | private Object authinfo; 25 | private String devid; 26 | private Date begin; 27 | private Date end; 28 | private String tag; 29 | private Boolean isPrivate; 30 | private Boolean isOnline; 31 | private Integer page; 32 | private Integer perpage; 33 | private HttpGetMethod HttpMethod; 34 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 35 | 36 | /** 37 | * 模糊查询设备 38 | * 参数顺序与构造函数顺序一致 39 | * @param @deprecated keywords:匹配关键字(可选,从id和title字段中左匹配),String 40 | * @param authinfo:鉴权信息(可选,对应注册时的sn参数,唯一设备编号),Object 41 | * @param devid: 指定设备ID,多个用逗号分隔,最多100个(可选),String 42 | * @param begin:起始时间,包括当天(可选),Date 43 | * @param end:结束时间,包括当天(可选),Date 44 | * @param tags:标签(可选) 45 | * @param isPrivate: 设备私密性,Boolean类型 46 | * @param page:指定页码,最大页数为10000(可选),Integer 47 | * @param perpage:指定每页输出设备个数,默认30,最多100(可选),Integer 48 | * @param isOnline:在线状态(可选) 49 | * @param title:设备名称关键字,字符串,左匹配,大小写不敏感(可选) 50 | * @param imei:设备imei关键字,字符串,左匹配,大小写不敏感(可选) 51 | * @param key:masterkey 52 | */ 53 | public FindDevicesListApi(String keywords, Object authinfo, String devid, Date begin, Date end, String tags, 54 | Boolean isPrivate, Integer page, Integer perpage, Boolean isOnline,String title,String imei, String key) { 55 | this.keywords = keywords; 56 | this.authinfo = authinfo; 57 | this.devid = devid; 58 | this.begin = begin; 59 | this.end = end; 60 | this.tag = tags; 61 | this.isPrivate = isPrivate; 62 | this.page = page; 63 | this.perpage = perpage; 64 | this.method = Method.GET; 65 | this.key = key; 66 | this.isOnline = isOnline; 67 | Map headmap = new HashMap(); 68 | Map urlmap = new HashMap(); 69 | this.HttpMethod = new HttpGetMethod(method); 70 | this.url = Config.getString("test.url") + "/devices"; 71 | // url参数 72 | if (keywords != null) { 73 | urlmap.put("key_words", keywords); 74 | } 75 | if (authinfo != null) { 76 | urlmap.put("auth_info", authinfo); 77 | } 78 | if (tags != null) { 79 | urlmap.put("tag", tags); 80 | } 81 | if (isOnline != null) { 82 | urlmap.put("online", isOnline); 83 | } 84 | if (isPrivate != null) { 85 | urlmap.put("private", isPrivate); 86 | } 87 | if (page != null) { 88 | urlmap.put("page", page); 89 | } 90 | if (perpage != null) { 91 | urlmap.put("per_page", perpage); 92 | } 93 | if (devid != null) { 94 | urlmap.put("device_id", devid); 95 | } 96 | if (begin != null) { 97 | urlmap.put("begin", begin); 98 | } 99 | if (end != null) { 100 | urlmap.put("end", end); 101 | } 102 | headmap.put("api-key", key); 103 | HttpMethod.setHeader(headmap); 104 | HttpMethod.setcompleteUrl(url,urlmap); 105 | } 106 | 107 | public BasicResponse executeApi() { 108 | BasicResponse response; 109 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 110 | try { 111 | HttpResponse httpResponse = HttpMethod.execute(); 112 | InputStream instreams = httpResponse.getEntity().getContent(); 113 | String str = IOUtils.toString(instreams, "UTF-8"); 114 | response = mapper.readValue(str, BasicResponse.class); 115 | response.setJson(str); 116 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), DeviceList.class); 117 | response.setData(newData); 118 | return response; 119 | } catch (Exception e) { 120 | logger.error("error: {}" , e.getMessage()); 121 | throw new OnenetApiException(e.getMessage()); 122 | }finally { 123 | try { 124 | HttpMethod.httpClient.close(); 125 | } catch (Exception e) { 126 | logger.error("http close error: {}", e.getMessage()); 127 | throw new OnenetApiException(e.getMessage()); 128 | } 129 | } 130 | 131 | 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/FindKeyRelDeviceListApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 4 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 5 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 6 | import cmcc.iot.onenet.javasdk.request.RequestInfo; 7 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 8 | import cmcc.iot.onenet.javasdk.response.device.KeyRelDeviceList; 9 | import cmcc.iot.onenet.javasdk.utils.Config; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.apache.http.HttpResponse; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import java.text.SimpleDateFormat; 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | /** 20 | * 21 | * @Description api-key关联/未关联的设备分页列表查询 22 | * @author luowz 23 | * @date 2019/1/2 19:12 24 | * @version 1.0 25 | * 26 | **/ 27 | public class FindKeyRelDeviceListApi extends AbstractAPI{ 28 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 29 | private Integer page; 30 | private Integer perPage; 31 | private String deviceId; 32 | private String deviceTitle; 33 | private Boolean isRlated; 34 | private String apiKey; 35 | private HttpGetMethod HttpMethod; 36 | 37 | public FindKeyRelDeviceListApi(Integer page, Integer perPage, String deviceId,String deviceTitle, Boolean isRlated, String apiKey, String masterKey) { 38 | this.page = page; 39 | this.perPage = perPage; 40 | this.deviceId = deviceId; 41 | this.deviceTitle = deviceTitle; 42 | this.isRlated = isRlated; 43 | this.apiKey = apiKey; 44 | this.key = masterKey; 45 | this.method = RequestInfo.Method.GET; 46 | this.HttpMethod=new HttpGetMethod(method); 47 | this.url = Config.getString("test.url") + "/keys/"+apiKey+"/devices" ; 48 | Map headmap = new HashMap(); 49 | Map urlmap = new HashMap(); 50 | if(page!=null){ 51 | urlmap.put("page", page); 52 | } 53 | if(perPage!=null){ 54 | urlmap.put("per_page", perPage); 55 | } 56 | if(StringUtils.isNotBlank(deviceId)){ 57 | urlmap.put("device_id", deviceId); 58 | } 59 | if(StringUtils.isNotBlank(deviceTitle)){ 60 | urlmap.put("device_title", deviceTitle); 61 | } 62 | if(isRlated!=null){ 63 | urlmap.put("is_related", isRlated); 64 | } 65 | headmap.put("api-key", masterKey); 66 | HttpMethod.setHeader(headmap); 67 | HttpMethod.setcompleteUrl(url,urlmap); 68 | } 69 | 70 | 71 | public BasicResponse executeApi() { 72 | BasicResponse response; 73 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 74 | try { 75 | HttpResponse httpResponse=HttpMethod.execute(); 76 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 77 | response.setJson(mapper.writeValueAsString(response)); 78 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), KeyRelDeviceList.class); 79 | response.setData(newData); 80 | return response; 81 | } catch (Exception e) { 82 | logger.error("json error {}", e.getMessage()); 83 | throw new OnenetApiException(e.getMessage()); 84 | } 85 | finally { 86 | try { 87 | HttpMethod.httpClient.close(); 88 | } catch (Exception e) { 89 | logger.error("http close error: {}", e.getMessage()); 90 | throw new OnenetApiException(e.getMessage()); 91 | } 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/GetDeviceApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.apache.http.util.EntityUtils; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import com.fasterxml.jackson.databind.ObjectMapper; 13 | 14 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 15 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 16 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 17 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 18 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 19 | import cmcc.iot.onenet.javasdk.response.device.DeviceList; 20 | import cmcc.iot.onenet.javasdk.response.device.DeviceResponse; 21 | import cmcc.iot.onenet.javasdk.utils.Config; 22 | 23 | public class GetDeviceApi extends AbstractAPI { 24 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 25 | private HttpGetMethod HttpMethod; 26 | private String devId; 27 | 28 | /** 29 | * 精确查询单个设备 30 | * 参数顺序与构造函数顺序一致 31 | * @param devId:设备名,String 32 | * @param key:masterkey 或者 设备apikey,String 33 | */ 34 | public GetDeviceApi(String devId, String key) { 35 | this.devId = devId; 36 | this.key = key; 37 | this.method = Method.GET; 38 | this.HttpMethod=new HttpGetMethod(method); 39 | this.url = Config.getString("test.url") + "/devices" + "/" + devId; 40 | Map headmap = new HashMap(); 41 | headmap.put("api-key", key); 42 | HttpMethod.setHeader(headmap); 43 | 44 | HttpMethod.setcompleteUrl(url,null); 45 | } 46 | 47 | 48 | public BasicResponse executeApi() { 49 | BasicResponse response; 50 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 51 | try { 52 | HttpResponse httpResponse=HttpMethod.execute(); 53 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 54 | response.setJson(mapper.writeValueAsString(response)); 55 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), DeviceResponse.class); 56 | response.setData(newData); 57 | return response; 58 | } catch (Exception e) { 59 | logger.error("json error {}", e.getMessage()); 60 | throw new OnenetApiException(e.getMessage()); 61 | } 62 | finally { 63 | try { 64 | HttpMethod.httpClient.close(); 65 | } catch (Exception e) { 66 | logger.error("http close error: {}", e.getMessage()); 67 | throw new OnenetApiException(e.getMessage()); 68 | } 69 | } 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/GetDevicesStatus.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 12 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 13 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 14 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 15 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 16 | import cmcc.iot.onenet.javasdk.response.device.DevicesStatusList; 17 | import cmcc.iot.onenet.javasdk.utils.Config; 18 | 19 | public class GetDevicesStatus extends AbstractAPI { 20 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 21 | private HttpGetMethod HttpMethod; 22 | private String devIds; 23 | /** 24 | * 批量查询设备状态 25 | * 参数顺序与构造函数顺序一致 26 | * @param devIds:设备id用逗号隔开, 限制1000个设备,String 27 | * @param key :masterkey 28 | */ 29 | public GetDevicesStatus(String devIds,String key) { 30 | this.devIds = devIds; 31 | this.key = key; 32 | this.method = Method.GET; 33 | this.HttpMethod=new HttpGetMethod(method); 34 | this.url = Config.getString("test.url") + "/devices/status" ; 35 | Map headmap = new HashMap(); 36 | Map urlmap = new HashMap(); 37 | if(devIds!=null){ 38 | urlmap.put("devIds", devIds); 39 | } 40 | headmap.put("api-key", key); 41 | HttpMethod.setHeader(headmap); 42 | HttpMethod.setcompleteUrl(url,urlmap); 43 | } 44 | 45 | public BasicResponse executeApi() { 46 | BasicResponse response; 47 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 48 | try { 49 | HttpResponse httpResponse=HttpMethod.execute(); 50 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 51 | response.setJson(mapper.writeValueAsString(response)); 52 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), DevicesStatusList.class); 53 | response.setData(newData); 54 | return response; 55 | } catch (Exception e) { 56 | logger.error("json error {}", e.getMessage()); 57 | throw new OnenetApiException(e.getMessage()); 58 | } 59 | finally { 60 | try { 61 | HttpMethod.httpClient.close(); 62 | } catch (Exception e) { 63 | logger.error("http close error: {}", e.getMessage()); 64 | throw new OnenetApiException(e.getMessage()); 65 | } 66 | } 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/GetLatesDeviceData.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 12 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 13 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 14 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 15 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 16 | import cmcc.iot.onenet.javasdk.response.device.DeciceLatestDataPoint; 17 | import cmcc.iot.onenet.javasdk.utils.Config; 18 | 19 | public class GetLatesDeviceData extends AbstractAPI{ 20 | 21 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 22 | private HttpGetMethod HttpMethod; 23 | private String devIds; 24 | 25 | /** 26 | * 批量查询设备最新数据 27 | * 参数顺序与构造函数顺序一致 28 | * @param devIds :设备id用逗号隔开, 限制1000个设备,String 29 | * @param key:masterkey 30 | */ 31 | 32 | public GetLatesDeviceData(String devIds, String key) { 33 | this.devIds = devIds; 34 | this.key = key; 35 | this.method = Method.GET; 36 | this.HttpMethod=new HttpGetMethod(method); 37 | this.url = Config.getString("test.url") + "/devices/datapoints"; 38 | Map headmap = new HashMap(); 39 | Map urlmap = new HashMap(); 40 | if(devIds!=null){ 41 | urlmap.put("devIds", devIds); 42 | } 43 | headmap.put("api-key", key); 44 | HttpMethod.setHeader(headmap); 45 | HttpMethod.setcompleteUrl(url,urlmap); 46 | } 47 | 48 | public BasicResponse executeApi() { 49 | BasicResponse response; 50 | try { 51 | HttpResponse httpResponse=HttpMethod.execute(); 52 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 53 | response.setJson(mapper.writeValueAsString(response)); 54 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), DeciceLatestDataPoint.class); 55 | response.setData(newData); 56 | return response; 57 | } catch (Exception e) { 58 | logger.error("json error {}", e.getMessage()); 59 | throw new OnenetApiException(e.getMessage()); 60 | } 61 | finally { 62 | try { 63 | HttpMethod.httpClient.close(); 64 | } catch (Exception e) { 65 | logger.error("http close error: {}", e.getMessage()); 66 | throw new OnenetApiException(e.getMessage()); 67 | } 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/ModifyDevicesApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.apache.http.HttpResponse; 9 | import com.fasterxml.jackson.databind.ObjectMapper; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpPutMethod; 16 | import cmcc.iot.onenet.javasdk.model.Location; 17 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 18 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class ModifyDevicesApi extends AbstractAPI{ 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private String devId; 24 | private String title; 25 | private String protocol; 26 | private String desc; 27 | private String idsn; 28 | private List tags; 29 | private Location location; 30 | private Boolean isPrivate; 31 | private Object authInfo; 32 | private Map other; 33 | private Integer interval; 34 | private HttpPutMethod HttpMethod; 35 | private Object isPrivateSet; 36 | 37 | 38 | /*** 39 | * 设备更新 40 | * 参数顺序与构造函数顺序一致 41 | * @param devId: 设备ID,String 42 | * @param title: 设备名,String 43 | * @param protocol: 接入协议(可选,默认为HTTP),String 44 | * @param desc: 设备描述(可选),String 45 | * @param tags: 设备标签(可选,可为一个或多个),List 46 | * @param location: 设备位置{"纬度", "精度", "高度"}(可选),Location类型 47 | * @param isPrivate: 设备私密性,Boolean类型 48 | * @param authInfo: 设备唯一编号 ,String 49 | * @param other: 其他信息,Map 50 | * @param interval: MODBUS设备 下发命令周期,Integer类型 51 | * @param key :masterkey 或者 设备apikey 52 | */ 53 | public ModifyDevicesApi(String devId,String title, String protocol, String desc, List tags, Location location, 54 | Boolean isPrivate, Object authInfo, Map other,Integer interval, String key) { 55 | this.devId=devId; 56 | this.title = title; 57 | this.protocol = protocol; 58 | this.desc = desc; 59 | this.tags = tags; 60 | this.location = location; 61 | this.isPrivate = isPrivate; 62 | this.authInfo = authInfo; 63 | this.other = other; 64 | this.interval = interval; 65 | this.key = key; 66 | this.method = Method.PUT; 67 | Map headmap = new HashMap(); 68 | HttpMethod= new HttpPutMethod(method); 69 | headmap.put("api-key", key); 70 | HttpMethod.setHeader(headmap); 71 | this.url=Config.getString("test.url")+"/devices"+"/"+devId; 72 | // body参数 73 | 74 | Map bodymap = new HashMap(); 75 | if (title != null) { 76 | bodymap.put("title", title); 77 | } 78 | if (desc != null) { 79 | bodymap.put("desc", desc); 80 | } 81 | if (tags != null) { 82 | bodymap.put("tags", tags); 83 | } 84 | 85 | if (location != null) { 86 | bodymap.put("location", location.toMap()); 87 | } 88 | if (isPrivate!=null) { 89 | bodymap.put("private", isPrivate); 90 | } 91 | if (protocol != null) { 92 | bodymap.put("protocol", protocol); 93 | } 94 | if (authInfo != null) { 95 | bodymap.put("auth_info", authInfo); 96 | 97 | } 98 | if (interval !=null) { 99 | bodymap.put("interval", interval); 100 | } 101 | if (other != null) { 102 | bodymap.put("other", other); 103 | } 104 | String json=null; 105 | ObjectMapper remapper = new ObjectMapper(); 106 | try { 107 | json = remapper.writeValueAsString(bodymap); 108 | } catch (Exception e) { 109 | logger.error("json error", e.getMessage()); 110 | throw new OnenetApiException(e.getMessage()); 111 | } 112 | ((HttpPutMethod)HttpMethod).setEntity(json); 113 | HttpMethod.setcompleteUrl(url,null); 114 | } 115 | 116 | public BasicResponse executeApi(){ 117 | BasicResponse response=null; 118 | try { 119 | HttpResponse httpResponse=HttpMethod.execute(); 120 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 121 | response.setJson(mapper.writeValueAsString(response)); 122 | return response; 123 | } catch (Exception e) { 124 | logger.error("json error {}", e.getMessage()); 125 | throw new OnenetApiException(e.getMessage()); 126 | } 127 | finally { 128 | try { 129 | HttpMethod.httpClient.close(); 130 | } catch (Exception e) { 131 | logger.error("http close error: {}", e.getMessage()); 132 | throw new OnenetApiException(e.getMessage()); 133 | } 134 | } 135 | 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/ModifyKeyRelDeviceListApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 4 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 5 | import cmcc.iot.onenet.javasdk.http.HttpPutMethod; 6 | import cmcc.iot.onenet.javasdk.request.RequestInfo; 7 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 8 | import cmcc.iot.onenet.javasdk.response.device.ModifyKeyRelDeviceResponse; 9 | import cmcc.iot.onenet.javasdk.utils.Config; 10 | import com.fasterxml.jackson.core.JsonProcessingException; 11 | import org.apache.commons.io.IOUtils; 12 | import org.apache.http.HttpResponse; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import java.io.InputStream; 17 | import java.util.HashMap; 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | /** 22 | * 23 | * @Description 4.7.6修改apikey关联设备列表 24 | * @author luowz 25 | * @date 2019/1/2 19:52 26 | * @version 1.0 27 | * 28 | **/ 29 | public class ModifyKeyRelDeviceListApi extends AbstractAPI{ 30 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 31 | 32 | private HttpPutMethod HttpMethod; 33 | 34 | private String apiKey; 35 | private List addDevIds; 36 | private List delDevIds; 37 | 38 | public ModifyKeyRelDeviceListApi(List addDevIds, List delDevIds, String apiKey, String masterKey) { 39 | this.apiKey = apiKey; 40 | this.addDevIds = addDevIds; 41 | this.delDevIds = delDevIds; 42 | this.key = masterKey; 43 | this.method = RequestInfo.Method.PUT; 44 | this.HttpMethod = new HttpPutMethod(method); 45 | this.url = Config.getString("test.url") + "/keys/"+apiKey+"/devices" ; 46 | Map headmap = new HashMap(); 47 | Map body = new HashMap(); 48 | if(addDevIds!=null&&!addDevIds.isEmpty()){ 49 | body.put("add_dev_ids",addDevIds); 50 | } 51 | if(delDevIds!=null&&!delDevIds.isEmpty()){ 52 | body.put("del_dev_ids",delDevIds); 53 | } 54 | String json = null; 55 | try { 56 | json = mapper.writeValueAsString(body); 57 | } catch (JsonProcessingException e) { 58 | logger.error("json error {}", e.getMessage()); 59 | throw new OnenetApiException(e.getMessage()); 60 | } 61 | headmap.put("api-key", masterKey); 62 | HttpMethod.setHeader(headmap); 63 | HttpMethod.setcompleteUrl(url,null); 64 | HttpMethod.setEntity(json); 65 | } 66 | 67 | 68 | public BasicResponse executeApi(){ 69 | BasicResponse response; 70 | try { 71 | HttpResponse httpResponse = HttpMethod.execute(); 72 | InputStream instreams = httpResponse.getEntity().getContent(); 73 | String str = IOUtils.toString(instreams, "UTF-8"); 74 | response = mapper.readValue(str, BasicResponse.class); 75 | response.setJson(str); 76 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), ModifyKeyRelDeviceResponse.class); 77 | response.setData(newData); 78 | return response; 79 | } catch (Exception e) { 80 | logger.error("json error {}", e.getMessage()); 81 | throw new OnenetApiException(e.getMessage()); 82 | } 83 | finally { 84 | try { 85 | HttpMethod.httpClient.close(); 86 | } catch (Exception e) { 87 | logger.error("http close error: {}", e.getMessage()); 88 | throw new OnenetApiException(e.getMessage()); 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/device/RegisterDeviceApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.device; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.response.device.NewDeviceResponse; 18 | import cmcc.iot.onenet.javasdk.response.device.RegDeviceResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class RegisterDeviceApi extends AbstractAPI{ 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private String code; 24 | private HttpPostMethod HttpMethod; 25 | private String sn; 26 | private String mac; 27 | private String title; 28 | 29 | /** 30 | * 31 | * @param code:设备注册码(必填),String 32 | * @param mac:设备唯一mac标识,最长32字符 33 | * @param sn:设备唯一标识String类型,最长512字符 34 | * @param title:设备名(可选) 最长32个字符 35 | * @param key:设备注册码(必填) 36 | */ 37 | public RegisterDeviceApi(String code,String mac, String sn, String title,String key) { 38 | this.code = code; 39 | this.key = mac; 40 | this.sn=sn; 41 | this.title=title; 42 | this.key=key; 43 | this.mac=mac; 44 | this.method = Method.POST; 45 | Map headmap = new HashMap(); 46 | Map urlmap = new HashMap(); 47 | HttpMethod= new HttpPostMethod(method); 48 | headmap.put("api-key", key); 49 | HttpMethod.setHeader(headmap); 50 | url=Config.getString("test.url")+"/register_de"; 51 | 52 | Map bodymap = new HashMap(); 53 | if(sn!=null){ 54 | bodymap.put("sn", sn); 55 | } 56 | if(mac!=null){ 57 | bodymap.put("mac", mac); 58 | } 59 | if(title!=null){ 60 | bodymap.put("title", title); 61 | } 62 | String json=null; 63 | ObjectMapper remapper = new ObjectMapper(); 64 | try { 65 | json = remapper.writeValueAsString(bodymap); 66 | } catch (Exception e) { 67 | logger.error("json error:{}", e.getMessage()); 68 | throw new OnenetApiException(e.getMessage()); 69 | } 70 | if(code!=null){ 71 | urlmap.put("register_code", code); 72 | } 73 | ((HttpPostMethod)HttpMethod).setEntity(json); 74 | HttpMethod.setcompleteUrl(url,urlmap); 75 | } 76 | 77 | 78 | public BasicResponse executeApi(){ 79 | BasicResponse response=null; 80 | try { 81 | HttpResponse httpResponse=HttpMethod.execute(); 82 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 83 | response.setJson(mapper.writeValueAsString(response)); 84 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), RegDeviceResponse.class); 85 | response.setData(newData); 86 | return response; 87 | } catch (Exception e) { 88 | logger.error("json error {}", e.getMessage()); 89 | throw new OnenetApiException(e.getMessage()); 90 | } 91 | finally { 92 | try { 93 | HttpMethod.httpClient.close(); 94 | } catch (Exception e) { 95 | logger.error("http close error: {}", e.getMessage()); 96 | throw new OnenetApiException(e.getMessage()); 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/dtu/AddDtuParser.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.dtu; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.response.dtu.NewParserResponse; 18 | import cmcc.iot.onenet.javasdk.utils.Config; 19 | 20 | public class AddDtuParser extends AbstractAPI { 21 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 22 | private String name; 23 | private String filepath; 24 | private HttpPostMethod HttpMethod; 25 | 26 | /** 27 | * TCP透传新增 28 | * @param name : 名字,String 29 | * @param filepath:路径,String 30 | * @param key :必须为masterkey 31 | */ 32 | public AddDtuParser(String name, String filepath, String key) { 33 | super(); 34 | this.name = name; 35 | this.filepath = filepath; 36 | this.key = key; 37 | this.method = Method.POST; 38 | Map headmap = new HashMap(); 39 | HttpMethod = new HttpPostMethod(method); 40 | headmap.put("api-key", key); 41 | HttpMethod.setHeader(headmap); 42 | this.url = Config.getString("test.url") + "/dtu/parser"; 43 | Map fileMap = new HashMap(); 44 | fileMap.put("parser", filepath); 45 | Map stringMap = new HashMap(); 46 | stringMap.put("name", name); 47 | ((HttpPostMethod) HttpMethod).setEntity(stringMap, fileMap); 48 | HttpMethod.setcompleteUrl(url, null); 49 | } 50 | public BasicResponse executeApi(){ 51 | ObjectMapper mapper = new ObjectMapper(); 52 | BasicResponse response=null; 53 | try { 54 | HttpResponse httpResponse=HttpMethod.execute(); 55 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 56 | response.setJson(mapper.writeValueAsString(response)); 57 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewParserResponse.class); 58 | response.setData(newData); 59 | return response; 60 | 61 | } catch (Exception e) { 62 | logger.error("json error {}", e.getMessage()); 63 | throw new OnenetApiException(e.getMessage()); 64 | }finally { 65 | try { 66 | HttpMethod.httpClient.close(); 67 | } catch (Exception e) { 68 | logger.error("http close error: {}", e.getMessage()); 69 | throw new OnenetApiException(e.getMessage()); 70 | } 71 | } 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/dtu/DeleteDtuParser.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.dtu; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 11 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 12 | import cmcc.iot.onenet.javasdk.http.HttpDeleteMethod; 13 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 14 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 15 | import cmcc.iot.onenet.javasdk.utils.Config; 16 | 17 | public class DeleteDtuParser extends AbstractAPI { 18 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 19 | private Integer id; 20 | private HttpDeleteMethod HttpMethod; 21 | 22 | /** 23 | * TCP透传parser删除 24 | * @param id:parser_id,Integer 25 | * @param key:masterkey 或者 设备key 26 | */ 27 | public DeleteDtuParser(Integer id, String key) { 28 | this.id = id; 29 | this.key = key; 30 | this.method = Method.DELETE; 31 | Map headmap = new HashMap(); 32 | HttpMethod = new HttpDeleteMethod(method); 33 | headmap.put("api-key", key); 34 | HttpMethod.setHeader(headmap); 35 | if (id == null) { 36 | throw new OnenetApiException("parser id is required "); 37 | } 38 | this.url = Config.getString("test.url") + "/dtu/parser/" +id; 39 | HttpMethod.setcompleteUrl(url, null); 40 | } 41 | public BasicResponse executeApi() { 42 | BasicResponse response = null; 43 | try { 44 | HttpResponse httpResponse = HttpMethod.execute(); 45 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 46 | response.setJson(mapper.writeValueAsString(response)); 47 | return response; 48 | } catch (Exception e) { 49 | logger.error("json error {}", e.getMessage()); 50 | throw new OnenetApiException(e.getMessage()); 51 | }finally { 52 | try { 53 | HttpMethod.httpClient.close(); 54 | } catch (Exception e) { 55 | logger.error("http close error: {}", e.getMessage()); 56 | throw new OnenetApiException(e.getMessage()); 57 | } 58 | } 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/dtu/FindDtuParserList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.dtu; 2 | 3 | import java.io.InputStream; 4 | import java.text.SimpleDateFormat; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import org.apache.commons.io.IOUtils; 9 | import org.apache.http.HttpResponse; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.response.dtu.DtuParserList; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class FindDtuParserList extends AbstractAPI { 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private String name; // 精确匹配名字(可选) 24 | private HttpGetMethod HttpMethod; 25 | /** 26 | * TCP透传查询 27 | * @param name: 名字,精确匹配名字(可选),String 28 | * @param key:masterkey 或者 该设备的设备apikey 29 | */ 30 | public FindDtuParserList(String name, String key) { 31 | this.name = name; 32 | this.method = Method.GET; 33 | this.key = key; 34 | Map headmap = new HashMap(); 35 | Map urlmap = new HashMap(); 36 | HttpMethod = new HttpGetMethod(method); 37 | this.url = Config.getString("test.url") + "/dtu/parser"; 38 | if (name != null) { 39 | urlmap.put("name", name); 40 | } 41 | headmap.put("api-key", key); 42 | HttpMethod.setHeader(headmap); 43 | HttpMethod.setcompleteUrl(url, urlmap); 44 | } 45 | 46 | public BasicResponse executeApi() { 47 | BasicResponse response; 48 | mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd")); 49 | try { 50 | HttpResponse httpResponse = HttpMethod.execute(); 51 | InputStream instreams = httpResponse.getEntity().getContent(); 52 | String str = IOUtils.toString(instreams, "UTF-8"); 53 | response = mapper.readValue(str, BasicResponse.class); 54 | response.setJson(str); 55 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), DtuParserList.class); 56 | response.setData(newData); 57 | return response; 58 | } catch (Exception e) { 59 | logger.error("error: {}" , e.getMessage()); 60 | throw new OnenetApiException(e.getMessage()); 61 | }finally { 62 | try { 63 | HttpMethod.httpClient.close(); 64 | } catch (Exception e) { 65 | logger.error("http close error: {}", e.getMessage()); 66 | throw new OnenetApiException(e.getMessage()); 67 | } 68 | } 69 | 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/dtu/ModifyDtuParser.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.dtu; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 11 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 12 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 13 | import cmcc.iot.onenet.javasdk.http.HttpPutMethod; 14 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 15 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 16 | import cmcc.iot.onenet.javasdk.utils.Config; 17 | 18 | public class ModifyDtuParser extends AbstractAPI { 19 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 20 | private String name; 21 | private String filepath; 22 | private HttpPutMethod HttpMethod; 23 | private Integer id; 24 | 25 | /** 26 | * TCP透传更新 27 | * @param id :parserId ,Integer 28 | * @param name:名字, String 29 | * @param filepath:路径,String 30 | * @param key:masterkey 或者 设备apikey 31 | */ 32 | public ModifyDtuParser(Integer id, String name, String filepath, String key) { 33 | this.name = name; 34 | this.filepath = filepath; 35 | this.key = key; 36 | this.method = Method.PUT; 37 | Map headmap = new HashMap(); 38 | HttpMethod = new HttpPutMethod(method); 39 | headmap.put("api-key", key); 40 | HttpMethod.setHeader(headmap); 41 | if (id == null) { 42 | throw new OnenetApiException("parser id is required "); 43 | } 44 | this.url = Config.getString("test.url") + "/dtu/parser/" + id; 45 | Map fileMap = new HashMap(); 46 | fileMap.put("parser", filepath); 47 | Map stringMap = new HashMap(); 48 | stringMap.put("name", name); 49 | ((HttpPutMethod) HttpMethod).setEntity(stringMap, fileMap); 50 | HttpMethod.setcompleteUrl(url, null); 51 | } 52 | 53 | public BasicResponse executeApi() { 54 | BasicResponse response = null; 55 | try { 56 | HttpResponse httpResponse = HttpMethod.execute(); 57 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 58 | response.setJson(mapper.writeValueAsString(response)); 59 | return response; 60 | } catch (Exception e) { 61 | logger.error("json error {}", e.getMessage()); 62 | throw new OnenetApiException(e.getMessage()); 63 | } finally { 64 | try { 65 | HttpMethod.httpClient.close(); 66 | } catch (Exception e) { 67 | logger.error("http close error: {}", e.getMessage()); 68 | throw new OnenetApiException(e.getMessage()); 69 | } 70 | } 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/key/AddKeyApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.key; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 16 | import cmcc.iot.onenet.javasdk.model.Permissions; 17 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 18 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 19 | import cmcc.iot.onenet.javasdk.response.key.NewKeyResponse; 20 | import cmcc.iot.onenet.javasdk.utils.Config; 21 | 22 | public class AddKeyApi extends AbstractAPI{ 23 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 24 | private String title; 25 | private Listpermissions; 26 | private HttpPostMethod HttpMethod; 27 | /** 28 | * @param title:名称(可选),String 29 | * @param permissions,Listpermissions 30 | * @param key:masterkey 或者 该设备的设备key 31 | */ 32 | public AddKeyApi(String title, List permissions,String key) { 33 | this.title = title; 34 | this.permissions = permissions; 35 | this.key=key; 36 | this.method = Method.POST; 37 | Map headmap = new HashMap(); 38 | HttpMethod= new HttpPostMethod(method); 39 | headmap.put("api-key", key); 40 | HttpMethod.setHeader(headmap); 41 | this.url=Config.getString("test.url")+"/keys"; 42 | Map bodymap = new HashMap(); 43 | if (title != null) { 44 | bodymap.put("title", title); 45 | } 46 | if(permissions!=null){ 47 | bodymap.put("permissions", permissions); 48 | } 49 | String json=null; 50 | ObjectMapper remapper = new ObjectMapper(); 51 | try { 52 | json = remapper.writeValueAsString(bodymap); 53 | } catch (Exception e) { 54 | logger.error("json error {}", e.getMessage()); 55 | throw new OnenetApiException(e.getMessage()); 56 | } 57 | ((HttpPostMethod)HttpMethod).setEntity(json); 58 | HttpMethod.setcompleteUrl(url,null); 59 | } 60 | 61 | public BasicResponse executeApi(){ 62 | BasicResponse response=null; 63 | try { 64 | HttpResponse httpResponse=HttpMethod.execute(); 65 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 66 | response.setJson(mapper.writeValueAsString(response)); 67 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewKeyResponse.class); 68 | response.setData(newData); 69 | return response; 70 | } catch (Exception e) { 71 | e.printStackTrace(); 72 | logger.error("json error {}", e.getMessage()); 73 | throw new OnenetApiException(e.getMessage()); 74 | } 75 | finally { 76 | try { 77 | HttpMethod.httpClient.close(); 78 | } catch (Exception e) { 79 | logger.error("http close error: {}", e.getMessage()); 80 | throw new OnenetApiException(e.getMessage()); 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/key/DeleteKeyApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.key; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpDeleteMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.utils.Config; 18 | 19 | public class DeleteKeyApi extends AbstractAPI{ 20 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 21 | private String keyStr; 22 | private HttpDeleteMethod HttpMethod; 23 | 24 | /** 25 | * @param keyStr:需要删除的apikey,String 26 | * @param key:masterkey(注:只能为master-key) 27 | */ 28 | public DeleteKeyApi(String keyStr, String key) { 29 | this.keyStr = keyStr; 30 | this.key = key; 31 | this.method = Method.DELETE; 32 | Map headmap = new HashMap(); 33 | HttpMethod = new HttpDeleteMethod(method); 34 | headmap.put("api-key", key); 35 | HttpMethod.setHeader(headmap); 36 | this.url = Config.getString("test.url") + "/keys" + "/" + keyStr; 37 | HttpMethod.setcompleteUrl(url,null); 38 | } 39 | 40 | 41 | public BasicResponse executeApi() { 42 | BasicResponse response = null; 43 | try { 44 | HttpResponse httpResponse = HttpMethod.execute(); 45 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 46 | response.setJson(mapper.writeValueAsString(response)); 47 | return response; 48 | } catch (Exception e) { 49 | logger.error("json error {}", e.getMessage()); 50 | throw new OnenetApiException(e.getMessage()); 51 | } 52 | finally { 53 | try { 54 | HttpMethod.httpClient.close(); 55 | } catch (Exception e) { 56 | logger.error("http close error: {}", e.getMessage()); 57 | throw new OnenetApiException(e.getMessage()); 58 | } 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/key/FindKeyList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.key; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.apache.http.HttpResponse; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.response.key.KeyList; 18 | import cmcc.iot.onenet.javasdk.utils.Config; 19 | 20 | public class FindKeyList extends AbstractAPI{ 21 | private String apikey; 22 | private Integer page; 23 | private Integer perpage; 24 | private HttpGetMethod HttpMethod; 25 | private String devId; 26 | private String title; 27 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 28 | /** 29 | * @param title:根据名称查询,可选,字符串(左匹配 30 | * @param apikey:需要查找的apikey,String 31 | * @param page:指定页码,最大页数为10000(可选),Integer 32 | * @param perpage:指定每页输出设备个数,默认30,最多100(可选),Integer 33 | * @param devId:可选,只查看与该设备相关的非master-key,String 34 | * @param key:masterkey(注:只能为master-key) 35 | */ 36 | public FindKeyList(String title,String apikey, Integer page, Integer perpage, String devId,String key) { 37 | this.apikey = apikey; 38 | this.page = page; 39 | this.perpage = perpage; 40 | this.devId = devId; 41 | this.method = Method.GET; 42 | this.key = key; 43 | this.title = title; 44 | Map headmap = new HashMap(); 45 | Map urlmap = new HashMap(); 46 | HttpMethod = new HttpGetMethod(method); 47 | this.url = Config.getString("test.url") + "/keys"; 48 | // url参数 49 | if (apikey != null) { 50 | urlmap.put("key", apikey); 51 | } 52 | if (StringUtils.isNotBlank(title)) { 53 | urlmap.put("title", title); 54 | } 55 | if (page != null) { 56 | urlmap.put("page", page); 57 | } 58 | if (perpage != null) { 59 | urlmap.put("per_page", perpage); 60 | } 61 | if (devId != null) { 62 | urlmap.put("device_id", devId); 63 | } 64 | headmap.put("api-key", key); 65 | HttpMethod.setHeader(headmap); 66 | HttpMethod.setcompleteUrl(url,urlmap); 67 | } 68 | 69 | 70 | public BasicResponse executeApi() { 71 | BasicResponse response; 72 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 73 | try { 74 | HttpResponse httpResponse = HttpMethod.execute(); 75 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 76 | response.setJson(mapper.writeValueAsString(response)); 77 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), KeyList.class); 78 | response.setData(newData); 79 | return response; 80 | } catch (Exception e) { 81 | logger.error("error: {}" , e.getMessage()); 82 | throw new OnenetApiException(e.getMessage()); 83 | }finally { 84 | try { 85 | HttpMethod.httpClient.close(); 86 | } catch (Exception e) { 87 | logger.error("http close error: {}", e.getMessage()); 88 | throw new OnenetApiException(e.getMessage()); 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/key/ModifyKeyApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.key; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpPutMethod; 16 | import cmcc.iot.onenet.javasdk.model.Permissions; 17 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 18 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class ModifyKeyApi extends AbstractAPI{ 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private String title; 24 | private String apikey; 25 | private Listpermissions; 26 | private HttpPutMethod HttpMethod; 27 | /** 28 | * @param title:名称(可选),String 29 | * @param apikey:需要修改的apikey,String 30 | * @param permissions:apikey权限,Listpermissions 31 | * @param key:masterkey(注:只能为master-key) 32 | */ 33 | public ModifyKeyApi(String title, String apikey, List permissions,String key) { 34 | this.title = title; 35 | this.apikey = apikey; 36 | this.permissions = permissions; 37 | this.key=key; 38 | this.method = Method.PUT; 39 | 40 | Map headmap = new HashMap(); 41 | HttpMethod= new HttpPutMethod(method); 42 | headmap.put("api-key", key); 43 | HttpMethod.setHeader(headmap); 44 | this.url=Config.getString("test.url")+"/keys/"+apikey; 45 | Map bodymap = new HashMap(); 46 | if (title != null) { 47 | bodymap.put("title", title); 48 | } 49 | if(permissions!=null){ 50 | bodymap.put("permissions", permissions); 51 | } 52 | String json=null; 53 | try { 54 | json = mapper.writeValueAsString(bodymap); 55 | } catch (Exception e) { 56 | logger.error("json error {}", e.getMessage()); 57 | throw new OnenetApiException(e.getMessage()); 58 | } 59 | ((HttpPutMethod)HttpMethod).setEntity(json); 60 | HttpMethod.setcompleteUrl(url,null); 61 | } 62 | 63 | 64 | public BasicResponse executeApi(){ 65 | ObjectMapper mapper = new ObjectMapper(); 66 | BasicResponse response=null; 67 | try { 68 | HttpResponse httpResponse=HttpMethod.execute(); 69 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 70 | response.setJson(mapper.writeValueAsString(response)); 71 | return response; 72 | } catch (Exception e) { 73 | logger.error("json error {}", e.getMessage()); 74 | throw new OnenetApiException(e.getMessage()); 75 | }finally { 76 | try { 77 | HttpMethod.httpClient.close(); 78 | } catch (Exception e) { 79 | logger.error("http close error: {}", e.getMessage()); 80 | throw new OnenetApiException(e.getMessage()); 81 | } 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/mqtt/CreateMqttTopicApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.mqtt; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.utils.Config; 18 | 19 | public class CreateMqttTopicApi extends AbstractAPI { 20 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 21 | private HttpPostMethod HttpMethod; 22 | private String name; 23 | /** 24 | * @param name:设备订阅的主题(必选),String 25 | * @param key:masterkey 26 | */ 27 | public CreateMqttTopicApi(String name,String key) { 28 | this.name = name; 29 | this.key = key; 30 | this.method = Method.POST; 31 | 32 | Map headmap = new HashMap(); 33 | HttpMethod= new HttpPostMethod(method); 34 | headmap.put("api-key", key); 35 | HttpMethod.setHeader(headmap); 36 | this.url=Config.getString("test.url")+"/mqtt"+"/topic"; 37 | Map bodymap = new HashMap(); 38 | if(name!=null){ 39 | bodymap.put("name", name); 40 | } 41 | String json=null; 42 | ObjectMapper remapper = new ObjectMapper(); 43 | try { 44 | json = remapper.writeValueAsString(bodymap); 45 | } catch (Exception e) { 46 | logger.error("json error {}", e.getMessage()); 47 | throw new OnenetApiException(e.getMessage()); 48 | } 49 | ((HttpPostMethod)HttpMethod).setEntity(json); 50 | HttpMethod.setcompleteUrl(url,null); 51 | } 52 | 53 | 54 | 55 | public BasicResponse executeApi() { 56 | BasicResponse response = null; 57 | try { 58 | HttpResponse httpResponse = HttpMethod.execute(); 59 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 60 | response.setJson(mapper.writeValueAsString(response)); 61 | return response; 62 | } catch (Exception e) { 63 | logger.error("json error {}", e.getMessage()); 64 | throw new OnenetApiException(e.getMessage()); 65 | } 66 | finally { 67 | try { 68 | HttpMethod.httpClient.close(); 69 | } catch (Exception e) { 70 | logger.error("http close error: {}", e.getMessage()); 71 | throw new OnenetApiException(e.getMessage()); 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/mqtt/DeleteUserTopic.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.mqtt; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpDeleteMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.utils.Config; 18 | 19 | public class DeleteUserTopic extends AbstractAPI{ 20 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 21 | private String name; 22 | private HttpDeleteMethod HttpMethod; 23 | /** 24 | * 删除产品的Topic 25 | * @param name:topic名(必选) 26 | * @param key:masterkey 27 | */ 28 | public DeleteUserTopic(String name,String key) { 29 | this.name = name; 30 | this.key = key; 31 | this.method = Method.DELETE; 32 | Map headmap = new HashMap(); 33 | Map urlmap = new HashMap(); 34 | if(name!=null){ 35 | urlmap.put("name", name); 36 | } 37 | HttpMethod = new HttpDeleteMethod(method); 38 | headmap.put("api-key", key); 39 | HttpMethod.setHeader(headmap); 40 | this.url = Config.getString("test.url") + "/mqtt" + "/topic" ; 41 | HttpMethod.setcompleteUrl(url,urlmap); 42 | 43 | } 44 | 45 | public BasicResponse executeApi() { 46 | BasicResponse response = null; 47 | try { 48 | HttpResponse httpResponse = HttpMethod.execute(); 49 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 50 | response.setJson(mapper.writeValueAsString(response)); 51 | return response; 52 | } catch (Exception e) { 53 | logger.error("json error {}", e.getMessage()); 54 | throw new OnenetApiException(e.getMessage()); 55 | }finally { 56 | try { 57 | HttpMethod.httpClient.close(); 58 | } catch (Exception e) { 59 | logger.error("http close error: {}", e.getMessage()); 60 | throw new OnenetApiException(e.getMessage()); 61 | } 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/mqtt/FindTopicDevices.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.mqtt; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.response.mqtt.TopicDeviceList; 18 | import cmcc.iot.onenet.javasdk.utils.Config; 19 | 20 | public class FindTopicDevices extends AbstractAPI{ 21 | private Integer page; 22 | private Integer perPage; 23 | private String topic; 24 | private HttpGetMethod HttpMethod; 25 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 26 | 27 | /** 28 | * @param page 29 | * @param perPage 30 | * @param topic 31 | * @param key 32 | */ 33 | public FindTopicDevices(Integer page, Integer perPage, String topic,String key) { 34 | this.page = page; 35 | this.perPage = perPage; 36 | this.topic = topic; 37 | this.method = Method.GET; 38 | this.key = key; 39 | 40 | Map headmap = new HashMap(); 41 | Map urlmap = new HashMap(); 42 | HttpMethod = new HttpGetMethod(method); 43 | this.url = Config.getString("test.url") +"/mqtt"+"/topic_device"; 44 | if (topic != null) { 45 | urlmap.put("topic", topic); 46 | } 47 | if (perPage != null) { 48 | urlmap.put("per_page", perPage); 49 | } 50 | if (page != null) { 51 | urlmap.put("page", page); 52 | } 53 | headmap.put("api-key", key); 54 | HttpMethod.setHeader(headmap); 55 | HttpMethod.setcompleteUrl(url,urlmap); 56 | } 57 | 58 | public BasicResponse executeApi(){ 59 | BasicResponse response=null; 60 | try { 61 | HttpResponse httpResponse=HttpMethod.execute(); 62 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 63 | response.setJson(mapper.writeValueAsString(response)); 64 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), TopicDeviceList.class); 65 | response.setData(newData); 66 | return response; 67 | 68 | } catch (Exception e) { 69 | logger.error("json error {}", e.getMessage()); 70 | throw new OnenetApiException(e.getMessage()); 71 | } 72 | finally { 73 | try { 74 | HttpMethod.httpClient.close(); 75 | } catch (Exception e) { 76 | logger.error("http close error: {}", e.getMessage()); 77 | throw new OnenetApiException(e.getMessage()); 78 | } 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/mqtt/GetDevicesTopicsApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.mqtt; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.core.type.TypeReference; 12 | import com.fasterxml.jackson.databind.ObjectMapper; 13 | 14 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 15 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 16 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 17 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 18 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class GetDevicesTopicsApi extends AbstractAPI{ 22 | private String devId; 23 | private HttpGetMethod HttpMethod; 24 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 25 | 26 | /** 27 | * 查询设备订阅的Topic列表 28 | * @param devId:设备ID(必选),String 29 | * @param key:masterkey 30 | */ 31 | public GetDevicesTopicsApi(String devId,String key) { 32 | this.devId = devId; 33 | this.key=key; 34 | this.method = Method.GET; 35 | 36 | Map headmap = new HashMap(); 37 | HttpMethod = new HttpGetMethod(method); 38 | this.url = Config.getString("test.url") +"/mqtt"+"/device_topic/"+devId; 39 | headmap.put("api-key", key); 40 | HttpMethod.setHeader(headmap); 41 | HttpMethod.setcompleteUrl(url,null); 42 | } 43 | 44 | 45 | public BasicResponse> executeApi() { 46 | BasicResponse response = null; 47 | try { 48 | HttpResponse httpResponse = HttpMethod.execute(); 49 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 50 | response.setJson(mapper.writeValueAsString(response)); 51 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), new TypeReference>(){}); 52 | response.setData(newData); 53 | return response; 54 | } catch (Exception e) { 55 | logger.error("error: {}" , e.getMessage()); 56 | throw new OnenetApiException(e.getMessage()); 57 | }finally { 58 | try { 59 | HttpMethod.httpClient.close(); 60 | } catch (Exception e) { 61 | logger.error("http close error: {}", e.getMessage()); 62 | throw new OnenetApiException(e.getMessage()); 63 | } 64 | } 65 | 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/mqtt/GetUserTopics.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.mqtt; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.core.type.TypeReference; 12 | import com.fasterxml.jackson.databind.ObjectMapper; 13 | 14 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 15 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 16 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 17 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 18 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class GetUserTopics extends AbstractAPI{ 22 | private HttpGetMethod HttpMethod; 23 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 24 | 25 | /** 26 | * 查询产品Topic 27 | * @param key:masterkey 28 | */ 29 | public GetUserTopics(String key) { 30 | this.key=key; 31 | this.method = Method.GET; 32 | Map headmap = new HashMap(); 33 | HttpMethod = new HttpGetMethod(method); 34 | this.url = Config.getString("test.url") +"/mqtt"+"/topic"; 35 | headmap.put("api-key", key); 36 | HttpMethod.setHeader(headmap); 37 | HttpMethod.setcompleteUrl(url,null); 38 | } 39 | 40 | public BasicResponse> executeApi() { 41 | BasicResponse response = null; 42 | try { 43 | HttpResponse httpResponse = HttpMethod.execute(); 44 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 45 | response.setJson(mapper.writeValueAsString(response)); 46 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), new TypeReference>(){}); 47 | response.setData(newData); 48 | return response; 49 | } catch (Exception e) { 50 | logger.error("json error {}", e.getMessage()); 51 | throw new OnenetApiException(e.getMessage()); 52 | } 53 | finally { 54 | try { 55 | HttpMethod.httpClient.close(); 56 | } catch (Exception e) { 57 | logger.error("http close error: {}", e.getMessage()); 58 | throw new OnenetApiException(e.getMessage()); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/mqtt/SendMqttApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.mqtt; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.utils.Config; 19 | 20 | public class SendMqttApi extends AbstractAPI { 21 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 22 | private String topic; 23 | private Object contents;// 用户自定义数据 24 | private HttpPostMethod HttpMethod; 25 | 26 | /** 27 | * @param topic:设备订阅的主题(必选),String 28 | * @param contents:用户自定义数据:json、string、二进制数据(小于64K) 29 | * @param key:masterkey 30 | */ 31 | public SendMqttApi(String topic, Object contents,String key) { 32 | this.topic = topic; 33 | this.contents = contents; 34 | this.key = key; 35 | this.method = Method.POST; 36 | Map headmap = new HashMap(); 37 | Map urlmap = new HashMap(); 38 | HttpMethod = new HttpPostMethod(method); 39 | headmap.put("api-key", key); 40 | HttpMethod.setHeader(headmap); 41 | this.url = Config.getString("test.url") + "/mqtt"; 42 | if (topic != null) { 43 | urlmap.put("topic", topic); 44 | } 45 | // body参数处理 46 | if (contents instanceof byte[]) { 47 | try { 48 | String s = new String((byte[]) contents, "UTF-8"); 49 | ((HttpPostMethod) HttpMethod).setEntity(s); 50 | } catch (UnsupportedEncodingException e) { 51 | logger.error("bytes[] error {}", e.getMessage()); 52 | throw new OnenetApiException(e.getMessage()); 53 | } 54 | } 55 | if (contents instanceof String) { 56 | ((HttpPostMethod) HttpMethod).setEntity((String) contents); 57 | } 58 | HttpMethod.setcompleteUrl(url,urlmap); 59 | } 60 | 61 | public BasicResponse executeApi() { 62 | BasicResponse response = null; 63 | try { 64 | HttpResponse httpResponse = HttpMethod.execute(); 65 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 66 | response.setJson(mapper.writeValueAsString(response)); 67 | return response; 68 | } catch (Exception e) { 69 | logger.error("json error {}", e.getMessage()); 70 | throw new OnenetApiException(e.getMessage()); 71 | } 72 | finally { 73 | try { 74 | HttpMethod.httpClient.close(); 75 | } catch (Exception e) { 76 | logger.error("http close error: {}", e.getMessage()); 77 | throw new OnenetApiException(e.getMessage()); 78 | } 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/triggers/AddTriggersApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.triggers; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.response.triggers.NewTriggersResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class AddTriggersApi extends AbstractAPI{ 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private String title; 24 | private String dsid; 25 | private List devids; 26 | private Listdsuuids; 27 | private String desturl; 28 | private String type; 29 | private Integer threshold; 30 | private HttpPostMethod HttpMethod; 31 | 32 | 33 | /** 34 | * @param title 35 | * @param dsid 36 | * @param devids 37 | * @param dsuuids 38 | * @param desturl 39 | * @param type 40 | * @param threshold 41 | * @param key 42 | */ 43 | public AddTriggersApi(String title, String dsid, List devids, List dsuuids, String desturl, 44 | String type, Integer threshold,String key) { 45 | super(); 46 | this.title = title; 47 | this.dsid = dsid; 48 | this.devids = devids; 49 | this.dsuuids = dsuuids; 50 | this.desturl = desturl; 51 | this.type = type; 52 | this.threshold = threshold; 53 | this.key=key; 54 | this.method = Method.POST; 55 | Map headmap = new HashMap(); 56 | HttpMethod= new HttpPostMethod(method); 57 | headmap.put("api-key", key); 58 | HttpMethod.setHeader(headmap); 59 | this.url=Config.getString("test.url")+"/triggers"; 60 | // body参数 61 | Map bodymap = new HashMap(); 62 | if (title != null) { 63 | bodymap.put("title", title); 64 | } 65 | if (dsid != null) { 66 | bodymap.put("ds_id", dsid); 67 | } 68 | if (devids != null) { 69 | bodymap.put("dev_ids", devids); 70 | } 71 | if (dsuuids != null) { 72 | bodymap.put("ds_uuids", dsuuids); 73 | } 74 | if (desturl != null) { 75 | bodymap.put("url", desturl); 76 | } 77 | if (type != null) { 78 | bodymap.put("type", type); 79 | } 80 | if (threshold != null) { 81 | bodymap.put("threshold", threshold); 82 | } 83 | String json=null; 84 | ObjectMapper remapper = new ObjectMapper(); 85 | try { 86 | json = remapper.writeValueAsString(bodymap); 87 | } catch (Exception e) { 88 | logger.error("json error {}", e.getMessage()); 89 | throw new OnenetApiException(e.getMessage()); 90 | } 91 | ((HttpPostMethod)HttpMethod).setEntity(json); 92 | HttpMethod.setcompleteUrl(url,null); 93 | } 94 | 95 | 96 | 97 | public BasicResponse executeApi(){ 98 | BasicResponse response=null; 99 | try { 100 | HttpResponse httpResponse=HttpMethod.execute(); 101 | response = mapper.readValue(httpResponse.getEntity().getContent(),BasicResponse.class); 102 | response.setJson(mapper.writeValueAsString(response)); 103 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), NewTriggersResponse.class); 104 | response.setData(newData); 105 | return response; 106 | } catch (Exception e) { 107 | logger.error("json error {}", e.getMessage()); 108 | throw new OnenetApiException(e.getMessage()); 109 | } 110 | finally { 111 | try { 112 | HttpMethod.httpClient.close(); 113 | } catch (Exception e) { 114 | logger.error("http close error: {}", e.getMessage()); 115 | throw new OnenetApiException(e.getMessage()); 116 | } 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/triggers/DeleteTriggersApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.triggers; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.fasterxml.jackson.databind.ObjectMapper; 11 | 12 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 13 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 14 | import cmcc.iot.onenet.javasdk.http.HttpDeleteMethod; 15 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 16 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 17 | import cmcc.iot.onenet.javasdk.utils.Config; 18 | 19 | public class DeleteTriggersApi extends AbstractAPI { 20 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 21 | private String tirggerId; 22 | private HttpDeleteMethod HttpMethod; 23 | 24 | /** 25 | * @param tirggerId 26 | * @param key 27 | */ 28 | public DeleteTriggersApi(String tirggerId,String key) { 29 | this.tirggerId = tirggerId; 30 | this.key=key; 31 | this.method = Method.DELETE; 32 | Map headmap = new HashMap(); 33 | HttpMethod = new HttpDeleteMethod(method); 34 | headmap.put("api-key", key); 35 | HttpMethod.setHeader(headmap); 36 | this.url = Config.getString("test.url") + "/triggers" + "/" + tirggerId; 37 | HttpMethod.setcompleteUrl(url,null); 38 | } 39 | 40 | 41 | public BasicResponse executeApi() { 42 | BasicResponse response = null; 43 | try { 44 | HttpResponse httpResponse = HttpMethod.execute(); 45 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 46 | response.setJson(mapper.writeValueAsString(response)); 47 | return response; 48 | } catch (Exception e) { 49 | logger.error("json error {}", e.getMessage()); 50 | throw new OnenetApiException(e.getMessage()); 51 | } 52 | finally { 53 | try { 54 | HttpMethod.httpClient.close(); 55 | } catch (Exception e) { 56 | logger.error("http close error: {}", e.getMessage()); 57 | throw new OnenetApiException(e.getMessage()); 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/triggers/FindTriggersListApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.triggers; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.response.triggers.TriggersList; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class FindTriggersListApi extends AbstractAPI{ 22 | private String title; 23 | private Integer page; 24 | private Integer perpage; 25 | private HttpGetMethod HttpMethod; 26 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 27 | /** 28 | * @param title:名称(可选),String 29 | * @param page:指定页码,最大页数为10000(可选),Integer 30 | * @param perpage:指定每页输出设备个数,默认30,最多100(可选),Integer 31 | * @param key:masterkey 或者 设备apikey 32 | */ 33 | public FindTriggersListApi(String title, Integer page, Integer perpage, String key) { 34 | this.title = title; 35 | this.page = page; 36 | this.perpage = perpage; 37 | this.method = Method.GET; 38 | this.key = key; 39 | Map headmap = new HashMap(); 40 | Map urlmap = new HashMap(); 41 | HttpMethod = new HttpGetMethod(method); 42 | headmap.put("api-key", key); 43 | HttpMethod.setHeader(headmap); 44 | this.url = Config.getString("test.url") + "/triggers"; 45 | // url参数 46 | if (title != null) { 47 | urlmap.put("title", title); 48 | } 49 | if (page != null) { 50 | urlmap.put("page", page); 51 | } 52 | if (perpage != null) { 53 | urlmap.put("per_page", perpage); 54 | } 55 | headmap.put("api-key", key); 56 | HttpMethod.setHeader(headmap); 57 | HttpMethod.setcompleteUrl(url,urlmap); 58 | } 59 | 60 | public BasicResponse executeApi() { 61 | BasicResponse response; 62 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 63 | try { 64 | HttpResponse httpResponse = HttpMethod.execute(); 65 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 66 | response.setJson(mapper.writeValueAsString(response)); 67 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), TriggersList.class); 68 | response.setData(newData); 69 | return response; 70 | } catch (Exception e) { 71 | logger.error("json error {}", e.getMessage()); 72 | throw new OnenetApiException(e.getMessage()); 73 | } 74 | finally { 75 | try { 76 | HttpMethod.httpClient.close(); 77 | } catch (Exception e) { 78 | logger.error("http close error: {}", e.getMessage()); 79 | throw new OnenetApiException(e.getMessage()); 80 | } 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/triggers/GetTriggersApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.triggers; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpGetMethod; 16 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 17 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 18 | import cmcc.iot.onenet.javasdk.response.triggers.TriggersResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class GetTriggersApi extends AbstractAPI { 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private HttpGetMethod HttpMethod; 24 | private String tirggerId; 25 | 26 | /** 27 | * 查询单个触发器 28 | * @param tirggerId:触发器ID,String 29 | * @param key:masterkey 或者 设备apikey 30 | */ 31 | public GetTriggersApi(String tirggerId,String key) { 32 | this.tirggerId = tirggerId; 33 | this.key=key; 34 | this.method = Method.GET; 35 | this.HttpMethod=new HttpGetMethod(method); 36 | Map headmap = new HashMap(); 37 | headmap.put("api-key", key); 38 | HttpMethod.setHeader(headmap); 39 | this.url = Config.getString("test.url") + "/triggers" + "/" + tirggerId; 40 | HttpMethod.setcompleteUrl(url,null); 41 | } 42 | 43 | public BasicResponse executeApi() { 44 | BasicResponse response; 45 | // ObjectMapper mapper = new ObjectMapper(); 46 | // mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 47 | try { 48 | HttpResponse httpResponse=HttpMethod.execute(); 49 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 50 | response.setJson(mapper.writeValueAsString(response)); 51 | Object newData = mapper.readValue(mapper.writeValueAsString(response.getDataInternal()), TriggersResponse.class); 52 | response.setData(newData); 53 | return response; 54 | } catch (Exception e) { 55 | logger.error("json error {}", e.getMessage()); 56 | throw new OnenetApiException(e.getMessage()); 57 | } 58 | finally { 59 | try { 60 | HttpMethod.httpClient.close(); 61 | } catch (Exception e) { 62 | logger.error("http close error: {}", e.getMessage()); 63 | throw new OnenetApiException(e.getMessage()); 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/api/triggers/ModifyTriggersApi.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.api.triggers; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpResponse; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | import cmcc.iot.onenet.javasdk.api.AbstractAPI; 14 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 15 | import cmcc.iot.onenet.javasdk.http.HttpPostMethod; 16 | import cmcc.iot.onenet.javasdk.http.HttpPutMethod; 17 | import cmcc.iot.onenet.javasdk.request.RequestInfo.Method; 18 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 19 | import cmcc.iot.onenet.javasdk.utils.Config; 20 | 21 | public class ModifyTriggersApi extends AbstractAPI { 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | private String tirggerId; 24 | private String title; 25 | private String dsid; 26 | private List devids; 27 | private Listdsuuids; 28 | private String desturl; 29 | private String type; 30 | private Integer threshold; 31 | private HttpPutMethod HttpMethod; 32 | 33 | /** 34 | * 触发器更新 35 | * @param tirggerId:触发器ID,String 36 | * @param title:设备名(可选),String 37 | * @param dsid 数据流名称(id)(可选),String 38 | * @param devids:设备ID(可选),List 39 | * @param dsuuids:数据流uuid(可选),List 40 | * @param desturl:url,String 41 | * @param type:触发类型,String 42 | * @param threshold:阙值,根据type不同,见以下说明,Integer 43 | * @param key:masterkey 或者 设备apikey 44 | */ 45 | public ModifyTriggersApi(String tirggerId, String title, String dsid, List devids, List dsuuids, 46 | String desturl, String type, Integer threshold,String key) { 47 | super(); 48 | this.tirggerId = tirggerId; 49 | this.title = title; 50 | this.dsid = dsid; 51 | this.devids = devids; 52 | this.dsuuids = dsuuids; 53 | this.desturl = desturl; 54 | this.type = type; 55 | this.threshold = threshold; 56 | this.key = key; 57 | this.method = Method.PUT; 58 | Map headmap = new HashMap(); 59 | HttpMethod= new HttpPutMethod(method); 60 | headmap.put("api-key", key); 61 | HttpMethod.setHeader(headmap); 62 | this.url=Config.getString("test.url")+"/triggers/"+tirggerId; 63 | // body参数 64 | Map bodymap = new HashMap(); 65 | if (title != null) { 66 | bodymap.put("title", title); 67 | } 68 | if (dsid != null) { 69 | bodymap.put("ds_id", dsid); 70 | } 71 | if (devids != null) { 72 | bodymap.put("dev_ids", devids); 73 | } 74 | if (dsuuids != null) { 75 | bodymap.put("ds_uuids", dsuuids); 76 | } 77 | if (desturl != null) { 78 | bodymap.put("url", desturl); 79 | } 80 | if (type != null) { 81 | bodymap.put("type", type); 82 | } 83 | if (threshold != null) { 84 | bodymap.put("threshold", threshold); 85 | } 86 | String json=null; 87 | try { 88 | json = mapper.writeValueAsString(bodymap); 89 | } catch (Exception e) { 90 | 91 | logger.error("json error {}", e.getMessage()); 92 | throw new OnenetApiException(e.getMessage()); 93 | } 94 | ((HttpPutMethod)HttpMethod).setEntity(json); 95 | HttpMethod.setcompleteUrl(url,null); 96 | } 97 | 98 | public BasicResponse executeApi() { 99 | ObjectMapper mapper = new ObjectMapper(); 100 | BasicResponse response = null; 101 | try { 102 | HttpResponse httpResponse = HttpMethod.execute(); 103 | response = mapper.readValue(httpResponse.getEntity().getContent(), BasicResponse.class); 104 | response.setJson(mapper.writeValueAsString(response)); 105 | return response; 106 | } catch (Exception e) { 107 | logger.error("json error {}", e.getMessage()); 108 | throw new OnenetApiException(e.getMessage()); 109 | } 110 | finally { 111 | try { 112 | HttpMethod.httpClient.close(); 113 | } catch (Exception e) { 114 | logger.error("http close error: {}", e.getMessage()); 115 | throw new OnenetApiException(e.getMessage()); 116 | } 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/exception/OnenetApiException.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.exception; 2 | 3 | /** 4 | * Created by Yuzhou on 2017/3/21. 5 | */ 6 | public class OnenetApiException extends RuntimeException { 7 | private String message = null; 8 | public String getMessage() { 9 | return message; 10 | } 11 | public OnenetApiException( String message) { 12 | this.message = message; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/http/BasicHttpMethod.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.http; 2 | 3 | import java.net.URI; 4 | import java.net.URISyntaxException; 5 | import java.util.Map; 6 | import java.util.Set; 7 | import java.util.Map.Entry; 8 | 9 | import org.apache.http.client.methods.HttpGet; 10 | import org.apache.http.client.methods.HttpPost; 11 | import org.apache.http.client.methods.HttpPut; 12 | import org.apache.http.client.methods.HttpDelete; 13 | import org.apache.http.client.methods.HttpRequestBase; 14 | import org.apache.http.impl.client.CloseableHttpClient; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | import com.fasterxml.jackson.databind.ObjectMapper; 19 | 20 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 21 | import cmcc.iot.onenet.javasdk.request.RequestInfo; 22 | 23 | public class BasicHttpMethod implements RequestInfo{ 24 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 25 | public CloseableHttpClient httpClient; 26 | public HttpRequestBase httpRequestBase; 27 | public String url; 28 | public Method method; 29 | boolean upload; 30 | public ObjectMapper mapper = new ObjectMapper(); 31 | public BasicHttpMethod(Method method) { 32 | this.method = method; 33 | switch (method) { 34 | case POST: 35 | httpRequestBase= new HttpPost(); 36 | break; 37 | case PUT: 38 | httpRequestBase= new HttpPut(); 39 | break; 40 | case DELETE: 41 | httpRequestBase= new HttpDelete(); 42 | break; 43 | default: 44 | httpRequestBase= new HttpGet(); 45 | break; 46 | } 47 | } 48 | public HttpRequestBase setHttpRequestBase() { 49 | return null; 50 | } 51 | public void setHttpRequestBase(HttpRequestBase httpRequestBase) { 52 | this.httpRequestBase = httpRequestBase; 53 | } 54 | 55 | public void setcompleteUrl(String url,Map params) { 56 | // TODO Auto-generated method stub 57 | if(params!=null) 58 | { 59 | url+="?"; 60 | Set> entrys=params.entrySet(); 61 | int size=entrys.size(); 62 | int index=0; 63 | for(Entry entry:entrys) 64 | { 65 | url+=entry.getKey()+"="+entry.getValue(); 66 | if(++index stringMap, Map fileMap) { 92 | // TODO Auto-generated method stub 93 | 94 | } 95 | 96 | public void sethttpMethod(Method method) { 97 | // TODO Auto-generated method stub 98 | 99 | } 100 | 101 | public void setHeader(Map params) { 102 | if (params != null) { 103 | Set> entrys = params.entrySet(); 104 | for (Entry entry : entrys) 105 | httpRequestBase.setHeader(entry.getKey(),(String) entry.getValue()); 106 | } 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/http/HttpDeleteMethod.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.http; 2 | 3 | import java.util.Map; 4 | 5 | import org.apache.http.HttpResponse; 6 | import org.apache.http.HttpStatus; 7 | import org.apache.http.impl.client.HttpClients; 8 | import org.apache.http.util.EntityUtils; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 13 | 14 | public class HttpDeleteMethod extends BasicHttpMethod { 15 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 16 | 17 | public HttpDeleteMethod(Method method) { 18 | super(method); 19 | // TODO Auto-generated constructor stub 20 | } 21 | 22 | public void setEntity(String json) { 23 | // TODO Auto-generated method stub 24 | 25 | } 26 | 27 | public void setEntity(Map stringMap, Map fileMap) { 28 | // TODO Auto-generated method stub 29 | 30 | } 31 | 32 | public void sethttpMethod(Method method) { 33 | // TODO Auto-generated method stub 34 | 35 | } 36 | 37 | public HttpResponse execute() throws Exception { 38 | HttpResponse httpResponse = null; 39 | httpClient = HttpClients.createDefault(); 40 | httpResponse = httpClient.execute(httpRequestBase); 41 | int statusCode = httpResponse.getStatusLine().getStatusCode(); 42 | if (statusCode != HttpStatus.SC_OK && statusCode != 221) { 43 | String response = EntityUtils.toString(httpResponse.getEntity()); 44 | logger.error("request failed status:{}, response::{}",statusCode, response); 45 | throw new OnenetApiException("request failed: " + response); 46 | } 47 | return httpResponse; 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/http/HttpGetMethod.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.http; 2 | 3 | import org.apache.http.HttpResponse; 4 | import org.apache.http.HttpStatus; 5 | import org.apache.http.client.methods.HttpGet; 6 | import org.apache.http.impl.client.HttpClients; 7 | import org.apache.http.util.EntityUtils; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 12 | 13 | public class HttpGetMethod extends BasicHttpMethod { 14 | 15 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 16 | HttpGet httpGet; 17 | 18 | public HttpGetMethod(Method method) { 19 | super(method); 20 | 21 | } 22 | 23 | public HttpResponse execute() throws Exception { 24 | HttpResponse httpResponse = null; 25 | httpClient = HttpClients.createDefault(); 26 | 27 | httpResponse = httpClient.execute(httpRequestBase); 28 | int statusCode = httpResponse.getStatusLine().getStatusCode(); 29 | if (statusCode != HttpStatus.SC_OK && statusCode != 221) { 30 | String response = EntityUtils.toString(httpResponse.getEntity()); 31 | logger.error("request failed status:{}, response::{}",statusCode, response); 32 | throw new OnenetApiException("request failed: " + response); 33 | } 34 | 35 | return httpResponse; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/http/HttpPostMethod.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.http; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.UnsupportedEncodingException; 6 | import java.nio.charset.Charset; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.Map.Entry; 10 | import java.util.Set; 11 | 12 | import org.apache.http.HttpEntity; 13 | import org.apache.http.HttpResponse; 14 | import org.apache.http.HttpStatus; 15 | import org.apache.http.client.ClientProtocolException; 16 | import org.apache.http.client.methods.HttpPost; 17 | import org.apache.http.entity.ByteArrayEntity; 18 | import org.apache.http.entity.StringEntity; 19 | import org.apache.http.entity.mime.MultipartEntityBuilder; 20 | import org.apache.http.entity.mime.content.FileBody; 21 | import org.apache.http.entity.mime.content.StringBody; 22 | import org.apache.http.impl.client.HttpClients; 23 | import org.apache.http.util.EntityUtils; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 28 | 29 | public class HttpPostMethod extends BasicHttpMethod { 30 | 31 | public HttpPostMethod(Method method) { 32 | super(method); 33 | } 34 | 35 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 36 | 37 | @Override 38 | public void setEntity(Object json) { 39 | if (json != null) { 40 | if (json instanceof String) { 41 | StringEntity entity = new StringEntity(json.toString(), Charset.forName("UTF-8")); 42 | ((HttpPost) httpRequestBase).setEntity(entity);// 向下转型 43 | } 44 | if (json instanceof byte[]) { 45 | ((HttpPost) httpRequestBase).setEntity(new ByteArrayEntity((byte[]) json)); 46 | } 47 | } 48 | 49 | } 50 | 51 | public void setEntity(Map stringMap, Map fileMap) { 52 | this.upload = true; 53 | Set> stringBodySet = null; 54 | if (stringMap != null) { 55 | Set> stringSet = stringMap.entrySet(); 56 | Map stringEntityMap = new HashMap(); 57 | for (Entry entry : stringSet) { 58 | try { 59 | stringEntityMap.put(entry.getKey(), new StringBody(entry.getValue(), Charset.forName("UTF-8"))); 60 | } catch (UnsupportedEncodingException e) { 61 | logger.error("error:" + e.getMessage()); 62 | throw new OnenetApiException(e.getMessage()); 63 | } 64 | } 65 | stringBodySet = stringEntityMap.entrySet(); 66 | } 67 | Set> fileBodySet = null; 68 | if (fileMap != null) { 69 | Set> fileSet = fileMap.entrySet(); 70 | 71 | Map fileBodyMap = new HashMap(); 72 | 73 | for (Entry entry : fileSet) { 74 | fileBodyMap.put(entry.getKey(), new FileBody(new File(entry.getValue()))); 75 | } 76 | fileBodySet = fileBodyMap.entrySet(); 77 | } 78 | 79 | MultipartEntityBuilder builder = MultipartEntityBuilder.create(); 80 | 81 | if (fileBodySet != null) { 82 | for (Entry entry : fileBodySet) { 83 | builder.addPart(entry.getKey(), entry.getValue()); 84 | } 85 | } 86 | if (stringBodySet != null) { 87 | for (Entry entry : stringBodySet) { 88 | builder.addPart(entry.getKey(), entry.getValue()); 89 | } 90 | } 91 | 92 | HttpEntity reqEntity = builder.build(); 93 | ((HttpPost) httpRequestBase).setEntity(reqEntity); 94 | } 95 | 96 | public HttpResponse execute() throws Exception { 97 | HttpResponse httpResponse = null; 98 | httpClient = HttpClients.createDefault(); 99 | httpResponse = httpClient.execute(httpRequestBase); 100 | int statusCode = httpResponse.getStatusLine().getStatusCode(); 101 | if (statusCode != HttpStatus.SC_OK && statusCode != 221) { 102 | String response =EntityUtils.toString(httpResponse.getEntity()); 103 | logger.error("request failed status:{}, response::{}",statusCode, response); 104 | throw new OnenetApiException("request failed: "+response); 105 | } 106 | 107 | return httpResponse; 108 | 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/http/HttpPutMethod.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.http; 2 | 3 | import java.io.File; 4 | import java.io.UnsupportedEncodingException; 5 | import java.nio.charset.Charset; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.Set; 9 | import java.util.Map.Entry; 10 | 11 | import org.apache.http.HttpEntity; 12 | import org.apache.http.HttpResponse; 13 | import org.apache.http.HttpStatus; 14 | import org.apache.http.client.methods.HttpPut; 15 | import org.apache.http.entity.StringEntity; 16 | import org.apache.http.entity.mime.MultipartEntityBuilder; 17 | import org.apache.http.entity.mime.content.FileBody; 18 | import org.apache.http.entity.mime.content.StringBody; 19 | import org.apache.http.impl.client.HttpClients; 20 | import org.apache.http.util.EntityUtils; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | 24 | import cmcc.iot.onenet.javasdk.exception.OnenetApiException; 25 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 26 | 27 | public class HttpPutMethod extends BasicHttpMethod { 28 | 29 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 30 | 31 | public HttpPutMethod(Method method) { 32 | super(method); 33 | // TODO Auto-generated constructor stub 34 | } 35 | 36 | public void setEntity(String json) { 37 | // TODO Auto-generated method stub 38 | if (json != null) { 39 | StringEntity entity = new StringEntity(json, Charset.forName("UTF-8")); 40 | ((HttpPut) httpRequestBase).setEntity(entity);// 向下转型 41 | } 42 | } 43 | 44 | public void setEntity(Map stringMap, Map fileMap) { 45 | // TODO Auto-generated method stub 46 | this.upload = true; 47 | Set> stringSet = stringMap.entrySet(); 48 | Set> fileSet = fileMap.entrySet(); 49 | Map stringEntityMap = new HashMap(); 50 | Map fileBodyMap = new HashMap(); 51 | for (Entry entry : stringSet) { 52 | try { 53 | stringEntityMap.put(entry.getKey(), new StringBody(entry.getValue(), Charset.forName("UTF-8"))); 54 | } catch (UnsupportedEncodingException e) { 55 | logger.error("error:" + e.getMessage()); 56 | throw new OnenetApiException(e.getMessage()); 57 | } 58 | } 59 | for (Entry entry : fileSet) { 60 | fileBodyMap.put(entry.getKey(), new FileBody(new File(entry.getValue()))); 61 | } 62 | MultipartEntityBuilder builder = MultipartEntityBuilder.create(); 63 | Set> fileBodySet = fileBodyMap.entrySet(); 64 | Set> stringBodySet = stringEntityMap.entrySet(); 65 | for (Entry entry : fileBodySet) { 66 | builder.addPart(entry.getKey(), entry.getValue()); 67 | } 68 | for (Entry entry : stringBodySet) { 69 | builder.addPart(entry.getKey(), entry.getValue()); 70 | } 71 | HttpEntity reqEntity = builder.build(); 72 | ((HttpPut) httpRequestBase).setEntity(reqEntity); 73 | } 74 | 75 | public void sethttpMethod(Method method) { 76 | // TODO Auto-generated method stub 77 | 78 | } 79 | 80 | public HttpResponse execute() throws Exception { 81 | HttpResponse httpResponse = null; 82 | httpClient = HttpClients.createDefault(); 83 | httpResponse = httpClient.execute(httpRequestBase); 84 | int statusCode = httpResponse.getStatusLine().getStatusCode(); 85 | if (statusCode != HttpStatus.SC_OK && statusCode != 221) { 86 | String response = EntityUtils.toString(httpResponse.getEntity()); 87 | logger.error("request failed status:{}, response::{}",statusCode, response); 88 | throw new OnenetApiException("request failed: " + response); 89 | } 90 | return httpResponse; 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/model/Data.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.model; 2 | 3 | public class Data{ 4 | private String at; 5 | private Object value; 6 | public Data(String at, Object value) { 7 | super(); 8 | this.at = at; 9 | this.value = value; 10 | } 11 | public String getAt() { 12 | return at; 13 | } 14 | public void setAt(String at) { 15 | this.at = at; 16 | } 17 | public Object getValue() { 18 | return value; 19 | } 20 | public void setValue(Object value) { 21 | this.value = value; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/model/Datapoints.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.model; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | public class Datapoints { 7 | //必须 8 | public String id; 9 | public Listdatapoints; 10 | public List getDatapoints() { 11 | return datapoints; 12 | } 13 | 14 | public void setDatapoints(List datapoints) { 15 | this.datapoints = datapoints; 16 | } 17 | 18 | public String getId() { 19 | return id; 20 | } 21 | 22 | public void setId(String id) { 23 | this.id = id; 24 | } 25 | 26 | public Datapoints(String id, List datapoints) { 27 | super(); 28 | this.id = id; 29 | this.datapoints = datapoints; 30 | } 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/model/Devices.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.model; 2 | 3 | public class Devices { 4 | 5 | public String dev_id; 6 | 7 | public Devices(String dev_id) { 8 | this.dev_id = dev_id; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/model/Location.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.model; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Location { 7 | private double ele; 8 | private double lat;//纬度 9 | private double lon;//经度 10 | private boolean eleSet; 11 | 12 | public Location(double ele, double lat, double lon, boolean eleSet) { 13 | this.ele = ele; 14 | this.lat = lat; 15 | this.lon = lon; 16 | this.eleSet = eleSet; 17 | } 18 | 19 | public Map toMap() { 20 | Map result = new HashMap(); 21 | if (eleSet) { 22 | result.put("ele", ele); 23 | } 24 | result.put("lon", lon); 25 | result.put("lat", lat); 26 | result.put("ele", ele); 27 | return result; 28 | } 29 | 30 | public Location(double lon,double lat, double ele) { 31 | this.ele = ele; 32 | this.lat = lat; 33 | this.lon = lon; 34 | } 35 | 36 | 37 | 38 | public double getEle() { 39 | return ele; 40 | } 41 | 42 | public double getLat() { 43 | return lat; 44 | } 45 | 46 | public double getLon() { 47 | return lon; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/model/Permissions.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.model; 2 | 3 | import java.util.List; 4 | 5 | public class Permissions { 6 | private Listresources; 7 | private Listaccess_methods; 8 | 9 | public Permissions(List resources, List access_methods) { 10 | this.resources = resources; 11 | this.access_methods = access_methods; 12 | } 13 | public List getResources() { 14 | return resources; 15 | } 16 | public void setResources(List resources) { 17 | this.resources = resources; 18 | } 19 | public List getAccess_methods() { 20 | return access_methods; 21 | } 22 | public void setAccess_methods(List access_methods) { 23 | this.access_methods = access_methods; 24 | } 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/model/key.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.model; 2 | 3 | public class key { 4 | private String title; 5 | private String key; 6 | public String getTitle() { 7 | return title; 8 | } 9 | public void setTitle(String title) { 10 | this.title = title; 11 | } 12 | public String getKey() { 13 | return key; 14 | } 15 | public void setKey(String key) { 16 | this.key = key; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/request/RequestInfo.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.request; 2 | 3 | import java.util.Map; 4 | 5 | 6 | public interface RequestInfo { 7 | //定义一个枚举 8 | public enum Method{ 9 | POST,GET,DELETE,PUT 10 | } 11 | public void setHeader(Map params); 12 | public void setEntity(Object json); 13 | public void setEntity(Map stringMap,Map fileMap); 14 | public void setcompleteUrl(String completeUrl,Map params); 15 | public void sethttpMethod(Method method); 16 | public void setType(boolean upload); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/BasicResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response; 2 | 3 | import com.fasterxml.jackson.annotation.JsonGetter; 4 | import com.fasterxml.jackson.annotation.JsonIgnore; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.annotation.JsonSetter; 7 | 8 | public class BasicResponse { 9 | public int errno; 10 | public String error; 11 | @JsonProperty("data") 12 | public Object dataInternal; 13 | public T data; 14 | @JsonIgnore 15 | public String json; 16 | 17 | public String getJson() { 18 | return json; 19 | } 20 | 21 | public void setJson(String json) { 22 | this.json = json; 23 | } 24 | 25 | public int getErrno() { 26 | return errno; 27 | } 28 | 29 | public void setErrno(int errno) { 30 | this.errno = errno; 31 | } 32 | 33 | public String getError() { 34 | return error; 35 | } 36 | 37 | public void setError(String error) { 38 | this.error = error; 39 | } 40 | 41 | @JsonGetter("data") 42 | public Object getDataInternal() { 43 | return dataInternal; 44 | } 45 | @JsonSetter("data") 46 | public void setDataInternal(Object dataInternal) { 47 | this.dataInternal = dataInternal; 48 | } 49 | 50 | public T getData() { 51 | return data; 52 | } 53 | 54 | public void setData(T data) { 55 | this.data = data; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/bindata/NewBindataResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.bindata; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class NewBindataResponse { 6 | @JsonProperty(value="index") 7 | public String index; 8 | 9 | public String getIndex() { 10 | return index; 11 | } 12 | 13 | public void setIndex(String index) { 14 | this.index = index; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/cmds/CmdsList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.cmds; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | import java.util.List; 6 | 7 | public class CmdsList { 8 | @JsonProperty("cursor") 9 | private String cursor; 10 | @JsonProperty("count") 11 | private Integer count; 12 | 13 | @JsonProperty("items") 14 | private List items; 15 | 16 | public static class CmdsItem{ 17 | @JsonProperty("cmd_uuid") 18 | private String cmdUuid; 19 | @JsonProperty("dev_id") 20 | private Integer devId; 21 | @JsonProperty("expire_time") 22 | private String expireTime; 23 | @JsonProperty("status") 24 | private Integer status; 25 | @JsonProperty("send_time") 26 | private String sendTime; 27 | @JsonProperty("confirm_time") 28 | private String confirmTime; 29 | @JsonProperty("confirm_body") 30 | private String confirm_body; 31 | @JsonProperty("body") 32 | private String body; 33 | 34 | public String getCmdUuid() { 35 | return cmdUuid; 36 | } 37 | 38 | public void setCmdUuid(String cmdUuid) { 39 | this.cmdUuid = cmdUuid; 40 | } 41 | 42 | public Integer getDevId() { 43 | return devId; 44 | } 45 | 46 | public void setDevId(Integer devId) { 47 | this.devId = devId; 48 | } 49 | 50 | public String getExpireTime() { 51 | return expireTime; 52 | } 53 | 54 | public void setExpireTime(String expireTime) { 55 | this.expireTime = expireTime; 56 | } 57 | 58 | public Integer getStatus() { 59 | return status; 60 | } 61 | 62 | public void setStatus(Integer status) { 63 | this.status = status; 64 | } 65 | 66 | public String getSendTime() { 67 | return sendTime; 68 | } 69 | 70 | public void setSendTime(String sendTime) { 71 | this.sendTime = sendTime; 72 | } 73 | 74 | public String getConfirmTime() { 75 | return confirmTime; 76 | } 77 | 78 | public void setConfirmTime(String confirmTime) { 79 | this.confirmTime = confirmTime; 80 | } 81 | 82 | public String getConfirm_body() { 83 | return confirm_body; 84 | } 85 | 86 | public void setConfirm_body(String confirm_body) { 87 | this.confirm_body = confirm_body; 88 | } 89 | 90 | public String getBody() { 91 | return body; 92 | } 93 | 94 | public void setBody(String body) { 95 | this.body = body; 96 | } 97 | } 98 | 99 | public String getCursor() { 100 | return cursor; 101 | } 102 | 103 | public void setCursor(String cursor) { 104 | this.cursor = cursor; 105 | } 106 | 107 | public Integer getCount() { 108 | return count; 109 | } 110 | 111 | public void setCount(Integer count) { 112 | this.count = count; 113 | } 114 | 115 | public List getItems() { 116 | return items; 117 | } 118 | 119 | public void setItems(List items) { 120 | this.items = items; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/cmds/CmdsResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.cmds; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class CmdsResponse { 6 | @JsonProperty("status") 7 | private Integer status; 8 | @JsonProperty("desc") 9 | private String desc; 10 | public Integer getStatus() { 11 | return status; 12 | } 13 | public void setStatus(Integer status) { 14 | this.status = status; 15 | } 16 | public String getDesc() { 17 | return desc; 18 | } 19 | public void setDesc(String desc) { 20 | this.desc = desc; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/cmds/NewCmdsResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.cmds; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class NewCmdsResponse { 6 | @JsonProperty(value = "cmd_uuid") 7 | public String cmduuid; 8 | 9 | public String getCmduuid() { 10 | return cmduuid; 11 | } 12 | 13 | public void setCmduuid(String cmduuid) { 14 | this.cmduuid = cmduuid; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/datapoints/DatapointsList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.datapoints; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.fasterxml.jackson.annotation.JsonCreator; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | 9 | 10 | public class DatapointsList { 11 | @JsonProperty("count") 12 | private String count; 13 | @JsonProperty("cursor") 14 | private String cursor; 15 | 16 | public String getCursor() { 17 | return cursor; 18 | } 19 | public void setCursor(String cursor) { 20 | this.cursor = cursor; 21 | } 22 | public String getCount() { 23 | return count; 24 | } 25 | public void setCount(String count) { 26 | this.count = count; 27 | } 28 | 29 | public ArrayList getDevices() { 30 | return devices; 31 | } 32 | 33 | 34 | 35 | 36 | public void setDevices(ArrayList devices) { 37 | this.devices = devices; 38 | } 39 | 40 | 41 | 42 | 43 | @JsonProperty("datastreams") 44 | private ArrayList devices; 45 | 46 | 47 | 48 | @JsonCreator 49 | public DatapointsList(@JsonProperty("count")String count, @JsonProperty("datastreams")ArrayList devices) { 50 | super(); 51 | this.count = count; 52 | this.devices = devices; 53 | } 54 | 55 | 56 | 57 | 58 | public static class DatastreamsItem{ 59 | @JsonProperty("id") 60 | public String id; 61 | public String getId() { 62 | return id; 63 | } 64 | 65 | 66 | 67 | public void setId(String id) { 68 | this.id = id; 69 | } 70 | 71 | 72 | 73 | public List getDatapoints() { 74 | return datapoints; 75 | } 76 | 77 | 78 | 79 | public void setDatapoints(List datapoints) { 80 | this.datapoints = datapoints; 81 | } 82 | 83 | 84 | 85 | @JsonProperty("datapoints") 86 | public Listdatapoints; 87 | 88 | 89 | @JsonCreator 90 | public DatastreamsItem(@JsonProperty("id")String id, @JsonProperty("datapoints")List datapoints) { 91 | super(); 92 | this.id = id; 93 | this.datapoints = datapoints; 94 | } 95 | 96 | 97 | 98 | public static class DatapointsItem{ 99 | @JsonProperty("at") 100 | private String at; 101 | public String getAt() { 102 | return at; 103 | } 104 | 105 | public void setAt(String at) { 106 | this.at = at; 107 | } 108 | 109 | public Object getValue() { 110 | return value; 111 | } 112 | 113 | public void setValue(Object value) { 114 | this.value = value; 115 | } 116 | 117 | @JsonProperty("value") 118 | private Object value; 119 | 120 | @JsonCreator 121 | public DatapointsItem(@JsonProperty("at")String at, @JsonProperty("value")Object value) { 122 | super(); 123 | this.at = at; 124 | this.value = value; 125 | } 126 | 127 | } 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/datastreams/DatastreamsResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.datastreams; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import com.fasterxml.jackson.annotation.JsonCreator; 7 | import com.fasterxml.jackson.annotation.JsonFormat; 8 | import com.fasterxml.jackson.annotation.JsonProperty; 9 | 10 | public class DatastreamsResponse { 11 | @JsonProperty("id") 12 | private String id; 13 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 14 | @JsonProperty("create_time") 15 | private Date createTime; 16 | @JsonProperty("tags") 17 | private List tags; 18 | @JsonProperty("unit") 19 | private String unit; 20 | @JsonProperty("unit_symbol") 21 | private String unitSymbol; 22 | @JsonProperty("current_value") 23 | private Object currentValue; 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 25 | @JsonProperty("update_at") 26 | private Date updateAt; 27 | @JsonProperty("formula") 28 | private String formula; 29 | @JsonProperty("interval") 30 | private int interval; 31 | @JsonProperty("cmd") 32 | private String cmd; 33 | @JsonProperty("uuid") 34 | private String uuid; 35 | @JsonCreator 36 | public DatastreamsResponse(@JsonProperty("id")String id, @JsonProperty("create_time")Date createTime, @JsonProperty("tags")List tags, @JsonProperty("unit")String unit, @JsonProperty("unit_symbol")String unitSymbol, 37 | @JsonProperty("current_value") Object currentValue,@JsonProperty("update_at")Date updateAt,@JsonProperty("formula")String formula,@JsonProperty("interval")int interval,@JsonProperty("cmd")String cmd,@JsonProperty("uuid")String uuid) { 38 | super(); 39 | this.id = id; 40 | this.createTime = createTime; 41 | this.tags = tags; 42 | this.unit = unit; 43 | this.unitSymbol = unitSymbol; 44 | this.currentValue = currentValue; 45 | this.updateAt = updateAt; 46 | this.formula=formula; 47 | this.interval=interval; 48 | this.cmd=cmd; 49 | this.uuid=uuid; 50 | } 51 | public String getId() { 52 | return id; 53 | } 54 | public void setId(String id) { 55 | this.id = id; 56 | } 57 | public Date getCreateTime() { 58 | return createTime; 59 | } 60 | public void setCreateTime(Date createTime) { 61 | this.createTime = createTime; 62 | } 63 | public List getTags() { 64 | return tags; 65 | } 66 | public void setTags(List tags) { 67 | this.tags = tags; 68 | } 69 | public String getUnit() { 70 | return unit; 71 | } 72 | public void setUnit(String unit) { 73 | this.unit = unit; 74 | } 75 | public String getUnitSymbol() { 76 | return unitSymbol; 77 | } 78 | public void setUnitSymbol(String unitSymbol) { 79 | this.unitSymbol = unitSymbol; 80 | } 81 | public Object getCurrentValue() { 82 | return currentValue; 83 | } 84 | public void setCurrentValue(Object currentValue) { 85 | this.currentValue = currentValue; 86 | } 87 | public Date getUpdateAt() { 88 | return updateAt; 89 | } 90 | public String getFormula() { 91 | return formula; 92 | } 93 | public void setFormula(String formula) { 94 | this.formula = formula; 95 | } 96 | public int getInterval() { 97 | return interval; 98 | } 99 | public void setInterval(int interval) { 100 | this.interval = interval; 101 | } 102 | public String getCmd() { 103 | return cmd; 104 | } 105 | public void setCmd(String cmd) { 106 | this.cmd = cmd; 107 | } 108 | public String getUuid() { 109 | return uuid; 110 | } 111 | public void setUuid(String uuid) { 112 | this.uuid = uuid; 113 | } 114 | public void setUpdateAt(Date updateAt) { 115 | this.updateAt = updateAt; 116 | } 117 | /*public static class CurrentValue{ 118 | @JsonProperty("index") 119 | private String index; 120 | 121 | 122 | public String getIndex() { 123 | return index; 124 | } 125 | 126 | 127 | public void setIndex(String index) { 128 | this.index = index; 129 | } 130 | 131 | 132 | @JsonCreator 133 | public CurrentValue(@JsonProperty("index")String index) { 134 | super(); 135 | this.index = index; 136 | } 137 | }*/ 138 | 139 | } 140 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/datastreams/NewdatastramsResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.datastreams; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class NewdatastramsResponse { 6 | @JsonProperty(value = "ds_uuid") 7 | public String id; 8 | 9 | public String getid() { 10 | return id; 11 | } 12 | 13 | public void setid(String id) { 14 | this.id = id; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/device/DeciceLatestDataPoint.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.device; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | 6 | import com.fasterxml.jackson.annotation.JsonCreator; 7 | import com.fasterxml.jackson.annotation.JsonFormat; 8 | import com.fasterxml.jackson.annotation.JsonProperty; 9 | 10 | public class DeciceLatestDataPoint { 11 | @JsonProperty("total_count") 12 | private int totalcount; 13 | @JsonProperty("devices") 14 | private ArrayList devices; 15 | 16 | @JsonCreator 17 | public DeciceLatestDataPoint(@JsonProperty("total_count") int totalcount, 18 | @JsonProperty("devices") ArrayList devices) { 19 | this.totalcount = totalcount; 20 | this.devices = devices; 21 | } 22 | 23 | public static class DeviceItem { 24 | @JsonProperty("id") 25 | private String id; 26 | @JsonProperty("title") 27 | private String title; 28 | @JsonProperty("datastreams") 29 | private ArrayList datastreams; 30 | 31 | @JsonCreator 32 | public DeviceItem(@JsonProperty("id") String id, @JsonProperty("title") String title, 33 | @JsonProperty("datastreams") ArrayList datastreams) { 34 | super(); 35 | this.id = id; 36 | this.title = title; 37 | this.datastreams = datastreams; 38 | } 39 | 40 | public static class DatastreamsItem 41 | { 42 | @JsonProperty("id") 43 | private String id; 44 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") 45 | @JsonProperty("at") 46 | private Date at; 47 | @JsonProperty("value") 48 | private Object value; 49 | 50 | @JsonCreator 51 | public DatastreamsItem(@JsonProperty("id") String id,@JsonProperty("at") Date at, 52 | @JsonProperty("value") Object value) { 53 | super(); 54 | this.id = id; 55 | this.at = at; 56 | this.value = value; 57 | } 58 | 59 | public String getId() { 60 | return id; 61 | } 62 | 63 | public void setId(String id) { 64 | this.id = id; 65 | } 66 | 67 | public Date getAt() { 68 | return at; 69 | } 70 | 71 | public void setAt(Date at) { 72 | this.at = at; 73 | } 74 | 75 | public Object getValue() { 76 | return value; 77 | } 78 | 79 | public void setValue(Object value) { 80 | this.value = value; 81 | } 82 | 83 | } 84 | 85 | public String getId() { 86 | return id; 87 | } 88 | 89 | public void setId(String id) { 90 | this.id = id; 91 | } 92 | 93 | public String getTitle() { 94 | return title; 95 | } 96 | 97 | public void setTitle(String title) { 98 | this.title = title; 99 | } 100 | 101 | public ArrayList getDatastreams() { 102 | return datastreams; 103 | } 104 | 105 | public void setDatastreams(ArrayList datastreams) { 106 | this.datastreams = datastreams; 107 | } 108 | 109 | } 110 | 111 | public int getTotalcount() { 112 | return totalcount; 113 | } 114 | 115 | public void setTotalcount(int totalcount) { 116 | this.totalcount = totalcount; 117 | } 118 | 119 | public ArrayList getDevices() { 120 | return devices; 121 | } 122 | 123 | public void setDevices(ArrayList devices) { 124 | this.devices = devices; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/device/DeviceList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.device; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import com.fasterxml.jackson.annotation.JsonCreator; 9 | import com.fasterxml.jackson.annotation.JsonFormat; 10 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 11 | import com.fasterxml.jackson.annotation.JsonProperty; 12 | 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | public class DeviceList { 15 | @JsonProperty("total_count") 16 | private int totalcount; 17 | @JsonProperty("per_page") 18 | private int perpage; 19 | @JsonProperty("page") 20 | private int page; 21 | @JsonProperty("devices") 22 | private ArrayList devices; 23 | @JsonCreator 24 | public DeviceList(@JsonProperty("total_count") int totalcount, @JsonProperty("per_page") int perpage, @JsonProperty("page") int page,@JsonProperty("devices") ArrayList devices ) { 25 | this.totalcount = totalcount; 26 | this.perpage = perpage; 27 | this.page = page; 28 | this.devices=devices; 29 | } 30 | // @JsonIgnoreProperties(ignoreUnknown = true) 31 | public static class DeviceItem{ 32 | @JsonProperty("id") 33 | private String id; 34 | @JsonProperty("title") 35 | private String title; 36 | @JsonProperty("protocol") 37 | private String protocol; 38 | @JsonProperty("desc") 39 | private String desc; 40 | @JsonProperty("private") 41 | private Boolean isPrivate; 42 | @JsonProperty("auth_info") 43 | private Object authInfo; 44 | @JsonProperty("online") 45 | private Boolean isonline; 46 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") 47 | @JsonProperty("create_time") 48 | private Date createTime; 49 | @JsonProperty("location") 50 | private Location location; 51 | @JsonProperty("rg_id") 52 | private String rgid; 53 | @JsonProperty("interval") 54 | private Integer interval; 55 | @JsonProperty("tags") 56 | private List tags; 57 | /*** 58 | * 设备最后上线时间 59 | **/ 60 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") 61 | @JsonProperty("last_login") 62 | private Date lastLogin; 63 | 64 | /*** 65 | * rtmp协议设备下通道数量 66 | **/ 67 | @JsonProperty("channel_count") 68 | private Integer channelCount; 69 | 70 | @JsonProperty("other") 71 | private Map other; 72 | 73 | 74 | 75 | @JsonCreator 76 | public DeviceItem(@JsonProperty("id")String id, @JsonProperty("title")String title,@JsonProperty("protocol") String protocol, @JsonProperty("desc")String desc, @JsonProperty("private")Boolean isPrivate, @JsonProperty("auth_info")Object authInfo, 77 | @JsonProperty("online")Boolean isonline, @JsonProperty("create_time")Date createTime,@JsonProperty("location")Location location,@JsonProperty("rg_id")String rgid,@JsonProperty("interval")Integer interval,@JsonProperty("tags")List tags, 78 | @JsonProperty("channel_count") Integer channelCount,@JsonProperty("last_login") Date lastLogin,@JsonProperty("other")Map other) { 79 | super(); 80 | this.id = id; 81 | this.title = title; 82 | this.protocol = protocol; 83 | this.desc = desc; 84 | this.isPrivate = isPrivate; 85 | this.authInfo = authInfo; 86 | this.isonline = isonline; 87 | this.createTime = createTime; 88 | this.location=location; 89 | this.rgid=rgid; 90 | this.interval=interval; 91 | this.tags = tags; 92 | this.lastLogin = lastLogin; 93 | this.channelCount = channelCount; 94 | this.other = other; 95 | } 96 | 97 | public Location getLocation() { 98 | return location; 99 | } 100 | 101 | public void setLocation(Location location) { 102 | this.location = location; 103 | } 104 | 105 | public String getId() { 106 | return id; 107 | } 108 | 109 | public void setId(String id) { 110 | this.id = id; 111 | } 112 | 113 | public String getTitle() { 114 | return title; 115 | } 116 | 117 | public void setTitle(String title) { 118 | this.title = title; 119 | } 120 | 121 | public String getProtocol() { 122 | return protocol; 123 | } 124 | 125 | public void setProtocol(String protocol) { 126 | this.protocol = protocol; 127 | } 128 | 129 | public String getDesc() { 130 | return desc; 131 | } 132 | 133 | public void setDesc(String desc) { 134 | this.desc = desc; 135 | } 136 | 137 | public Boolean getIsPrivate() { 138 | return isPrivate; 139 | } 140 | 141 | public void setIsPrivate(Boolean isPrivate) { 142 | this.isPrivate = isPrivate; 143 | } 144 | 145 | public Object getAuthInfo() { 146 | return authInfo; 147 | } 148 | 149 | public void setAuthInfo(Object authInfo) { 150 | this.authInfo = authInfo; 151 | } 152 | 153 | public Boolean getIsonline() { 154 | return isonline; 155 | } 156 | 157 | public void setIsonline(Boolean isonline) { 158 | this.isonline = isonline; 159 | } 160 | 161 | public Date getCreateTime() { 162 | return createTime; 163 | } 164 | 165 | public void setCreateTime(Date createTime) { 166 | this.createTime = createTime; 167 | } 168 | 169 | public static class Location{ 170 | @JsonProperty("ele") 171 | private double ele; 172 | @JsonProperty("lat") 173 | private double lat;//纬度 174 | @JsonProperty("lon") 175 | private double lon;//经度 176 | 177 | @JsonCreator 178 | public Location(@JsonProperty("ele")double ele, @JsonProperty("lat")double lat, @JsonProperty("lon")double lon) { 179 | this.ele = ele; 180 | this.lat = lat; 181 | this.lon = lon; 182 | } 183 | public double getEle() { 184 | return ele; 185 | } 186 | public void setEle(double ele) { 187 | this.ele = ele; 188 | } 189 | public double getLat() { 190 | return lat; 191 | } 192 | public void setLat(double lat) { 193 | this.lat = lat; 194 | } 195 | public double getLon() { 196 | return lon; 197 | } 198 | public void setLon(double lon) { 199 | this.lon = lon; 200 | } 201 | } 202 | 203 | public String getRgid() { 204 | return rgid; 205 | } 206 | 207 | public void setRgid(String rgid) { 208 | this.rgid = rgid; 209 | } 210 | public Integer getInterval() { 211 | return interval; 212 | } 213 | 214 | public void setInterval(Integer interval) { 215 | this.interval = interval; 216 | } 217 | public List getTags() { 218 | return tags; 219 | } 220 | 221 | public void setTags(List tags) { 222 | this.tags = tags; 223 | } 224 | public Map getOther() { 225 | return other; 226 | } 227 | 228 | public void setOther(Map other) { 229 | this.other = other; 230 | } 231 | } 232 | 233 | public int getTotalcount() { 234 | return totalcount; 235 | } 236 | 237 | public void setTotalcount(int totalcount) { 238 | this.totalcount = totalcount; 239 | } 240 | 241 | public int getPerpage() { 242 | return perpage; 243 | } 244 | 245 | public void setPerpage(int perpage) { 246 | this.perpage = perpage; 247 | } 248 | 249 | public int getPage() { 250 | return page; 251 | } 252 | 253 | public void setPage(int page) { 254 | this.page = page; 255 | } 256 | 257 | public List getDevices() { 258 | return devices; 259 | } 260 | 261 | public void setDevices(ArrayList devices) { 262 | this.devices = devices; 263 | } 264 | 265 | } 266 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/device/DeviceResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.device; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import com.fasterxml.jackson.annotation.JsonCreator; 8 | import com.fasterxml.jackson.annotation.JsonFormat; 9 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 10 | import com.fasterxml.jackson.annotation.JsonProperty; 11 | 12 | @JsonIgnoreProperties(ignoreUnknown = true) 13 | public class DeviceResponse { 14 | @JsonProperty("id") 15 | private String id; 16 | @JsonProperty("title") 17 | private String title; 18 | @JsonProperty("protocol") 19 | private String protocol; 20 | @JsonProperty("desc") 21 | private String desc; 22 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 23 | @JsonProperty("create_time") 24 | private Date createTime; 25 | @JsonProperty("tags") 26 | private List tags; 27 | @JsonProperty("location") 28 | private Location location; 29 | @JsonProperty("private") 30 | private Boolean isPrivate; 31 | private String routeTo; 32 | @JsonProperty("auth_info") 33 | private Object authInfo; 34 | @JsonProperty("other") 35 | private Map other; 36 | @JsonProperty("interval") 37 | private Integer interval; 38 | @JsonProperty("online") 39 | private Boolean isonline; 40 | @JsonProperty("keys") 41 | private List keys; 42 | @JsonProperty("datastreams") 43 | private List dataStreams; 44 | 45 | @JsonCreator 46 | public DeviceResponse(@JsonProperty("id") String id, @JsonProperty("title") String title, 47 | @JsonProperty("protocol") String protocol, @JsonProperty("desc") String desc, 48 | @JsonProperty("create_time") Date createTime, @JsonProperty("tags") List tags, 49 | @JsonProperty("location") Location location, @JsonProperty("private") Boolean isPrivate, 50 | @JsonProperty("auth_info") Object authInfo, @JsonProperty("other") Map other, 51 | @JsonProperty("interval") Integer interval, @JsonProperty("online") Boolean isonline, 52 | @JsonProperty("keys") List keys, @JsonProperty("datastreams") List dataStreams) { 53 | this.id = id; 54 | this.title = title; 55 | this.protocol = protocol; 56 | this.desc = desc; 57 | this.createTime = createTime; 58 | this.tags = tags; 59 | this.location = location; 60 | this.isPrivate = isPrivate; 61 | this.authInfo = authInfo; 62 | this.other = other; 63 | this.interval = interval; 64 | this.isonline = isonline; 65 | this.keys = keys; 66 | this.dataStreams = dataStreams; 67 | } 68 | 69 | public String getId() { 70 | return id; 71 | } 72 | 73 | public void setId(String id) { 74 | this.id = id; 75 | } 76 | 77 | public String getTitle() { 78 | return title; 79 | } 80 | 81 | public void setTitle(String title) { 82 | this.title = title; 83 | } 84 | 85 | public String getProtocol() { 86 | return protocol; 87 | } 88 | 89 | public void setProtocol(String protocol) { 90 | this.protocol = protocol; 91 | } 92 | 93 | public String getDesc() { 94 | return desc; 95 | } 96 | 97 | public void setDesc(String desc) { 98 | this.desc = desc; 99 | } 100 | 101 | public Date getCreateTime() { 102 | return createTime; 103 | } 104 | 105 | public void setCreateTime(Date createTime) { 106 | this.createTime = createTime; 107 | } 108 | 109 | public List getTags() { 110 | return tags; 111 | } 112 | 113 | public void setTags(List tags) { 114 | this.tags = tags; 115 | } 116 | 117 | public Location getLocation() { 118 | return location; 119 | } 120 | 121 | public void setLocation(Location location) { 122 | this.location = location; 123 | } 124 | 125 | public Boolean getIsPrivate() { 126 | return isPrivate; 127 | } 128 | 129 | public void setIsPrivate(Boolean isPrivate) { 130 | this.isPrivate = isPrivate; 131 | } 132 | 133 | public String getRouteTo() { 134 | return routeTo; 135 | } 136 | 137 | public void setRouteTo(String routeTo) { 138 | this.routeTo = routeTo; 139 | } 140 | 141 | public Object getAuthInfo() { 142 | return authInfo; 143 | } 144 | 145 | public void setAuthInfo(Object authInfo) { 146 | this.authInfo = authInfo; 147 | } 148 | 149 | public Map getOther() { 150 | return other; 151 | } 152 | 153 | public void setOther(Map other) { 154 | this.other = other; 155 | } 156 | 157 | public Integer getInterval() { 158 | return interval; 159 | } 160 | 161 | public void setInterval(Integer interval) { 162 | this.interval = interval; 163 | } 164 | 165 | public Boolean getIsonline() { 166 | return isonline; 167 | } 168 | 169 | public void setIsonline(Boolean isonline) { 170 | this.isonline = isonline; 171 | } 172 | 173 | public List getKeys() { 174 | return keys; 175 | } 176 | 177 | public void setKeys(List keys) { 178 | this.keys = keys; 179 | } 180 | 181 | public List getDataStreams() { 182 | return dataStreams; 183 | } 184 | 185 | public void setDataStreams(List dataStreams) { 186 | this.dataStreams = dataStreams; 187 | } 188 | 189 | public static class KeyItems { 190 | @JsonProperty("title") 191 | private String title; 192 | @JsonProperty("key") 193 | private String keystr; 194 | 195 | @JsonCreator 196 | public KeyItems(@JsonProperty("title") String title, @JsonProperty("key") String keystr) { 197 | super(); 198 | this.title = title; 199 | this.keystr = keystr; 200 | } 201 | 202 | } 203 | 204 | @JsonIgnoreProperties(ignoreUnknown = true) 205 | public static class DataStreamItem { 206 | @JsonProperty("id") 207 | private String id; 208 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 209 | @JsonProperty("create_time") 210 | private Date createTime; 211 | @JsonProperty("tags") 212 | private List tags; 213 | @JsonProperty("unit") 214 | private String unit; 215 | @JsonProperty("unit_symbol") 216 | private String unitSymbol; 217 | @JsonProperty("current_value") 218 | private Object currentValue; 219 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 220 | @JsonProperty("update_at") 221 | private Date updateAt; 222 | @JsonProperty("formula") 223 | private String formula; 224 | @JsonProperty("interval") 225 | private int interval; 226 | @JsonProperty("cmd") 227 | private String cmd; 228 | @JsonProperty("uuid") 229 | private String uuid; 230 | 231 | public DataStreamItem(@JsonProperty("id") String id, @JsonProperty("create_time") Date createTime, 232 | @JsonProperty("tags") List tags, @JsonProperty("unit") String unit, 233 | @JsonProperty("unit_symbol") String unitSymbol, @JsonProperty("current_value") Object currentValue, 234 | @JsonProperty("update_at") Date updateAt, @JsonProperty("formula") String formula, 235 | @JsonProperty("interval") int interval, @JsonProperty("cmd") String cmd, 236 | @JsonProperty("uuid") String uuid) { 237 | this.id = id; 238 | this.createTime = createTime; 239 | this.tags = tags; 240 | this.unit = unit; 241 | this.unitSymbol = unitSymbol; 242 | this.currentValue = currentValue; 243 | this.updateAt = updateAt; 244 | this.formula = formula; 245 | this.interval = interval; 246 | this.cmd = cmd; 247 | this.uuid = uuid; 248 | } 249 | 250 | public String getId() { 251 | return id; 252 | } 253 | 254 | public void setId(String id) { 255 | this.id = id; 256 | } 257 | 258 | public Date getCreateTime() { 259 | return createTime; 260 | } 261 | 262 | public void setCreateTime(Date createTime) { 263 | this.createTime = createTime; 264 | } 265 | 266 | public List getTags() { 267 | return tags; 268 | } 269 | 270 | public void setTags(List tags) { 271 | this.tags = tags; 272 | } 273 | 274 | public String getUnit() { 275 | return unit; 276 | } 277 | 278 | public void setUnit(String unit) { 279 | this.unit = unit; 280 | } 281 | 282 | public String getUnitSymbol() { 283 | return unitSymbol; 284 | } 285 | 286 | public void setUnitSymbol(String unitSymbol) { 287 | this.unitSymbol = unitSymbol; 288 | } 289 | 290 | public Object getCurrentValue() { 291 | return currentValue; 292 | } 293 | 294 | public void setCurrentValue(Object currentValue) { 295 | this.currentValue = currentValue; 296 | } 297 | 298 | public Date getUpdateAt() { 299 | return updateAt; 300 | } 301 | 302 | public String getFormula() { 303 | return formula; 304 | } 305 | 306 | public void setFormula(String formula) { 307 | this.formula = formula; 308 | } 309 | 310 | public int getInterval() { 311 | return interval; 312 | } 313 | 314 | public void setInterval(int interval) { 315 | this.interval = interval; 316 | } 317 | 318 | public String getCmd() { 319 | return cmd; 320 | } 321 | 322 | public void setCmd(String cmd) { 323 | this.cmd = cmd; 324 | } 325 | 326 | public String getUuid() { 327 | return uuid; 328 | } 329 | 330 | public void setUuid(String uuid) { 331 | this.uuid = uuid; 332 | } 333 | 334 | public void setUpdateAt(Date updateAt) { 335 | this.updateAt = updateAt; 336 | } 337 | 338 | } 339 | 340 | @JsonIgnoreProperties(ignoreUnknown = true) 341 | public static class Location { 342 | 343 | @JsonProperty("ele") 344 | private double ele; 345 | @JsonProperty("lat") 346 | private double lat;// 纬度 347 | @JsonProperty("lon") 348 | private double lon;// 经度 349 | 350 | public Location(@JsonProperty("ele") double ele, @JsonProperty("lat") double lat, 351 | @JsonProperty("lon") double lon) { 352 | this.ele = ele; 353 | this.lat = lat; 354 | this.lon = lon; 355 | } 356 | 357 | public double getEle() { 358 | return ele; 359 | } 360 | 361 | public void setEle(double ele) { 362 | this.ele = ele; 363 | } 364 | 365 | public double getLat() { 366 | return lat; 367 | } 368 | 369 | public void setLat(double lat) { 370 | this.lat = lat; 371 | } 372 | 373 | public double getLon() { 374 | return lon; 375 | } 376 | 377 | public void setLon(double lon) { 378 | this.lon = lon; 379 | } 380 | 381 | } 382 | } 383 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/device/DevicesStatusList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.device; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.fasterxml.jackson.annotation.JsonCreator; 6 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | public class DevicesStatusList { 11 | @JsonProperty("total_count") 12 | private int totalcount; 13 | @JsonProperty("devices") 14 | private ArrayList devices; 15 | 16 | @JsonCreator 17 | public DevicesStatusList(@JsonProperty("total_count") int totalcount, 18 | @JsonProperty("devices") ArrayList devices) { 19 | this.totalcount = totalcount; 20 | this.devices = devices; 21 | } 22 | @JsonIgnoreProperties(ignoreUnknown = true) 23 | public static class DeviceItem{ 24 | 25 | 26 | @JsonProperty("id") 27 | private String id; 28 | @JsonProperty("title") 29 | private String title; 30 | @JsonProperty("online") 31 | private Boolean isonline; 32 | 33 | @JsonCreator 34 | public DeviceItem(@JsonProperty("id") String id, @JsonProperty("title") String title,@JsonProperty("online") Boolean isonline) { 35 | super(); 36 | this.id = id; 37 | this.title = title; 38 | this.isonline = isonline; 39 | } 40 | public String getId() { 41 | return id; 42 | } 43 | 44 | public void setId(String id) { 45 | this.id = id; 46 | } 47 | 48 | public String getTitle() { 49 | return title; 50 | } 51 | 52 | public void setTitle(String title) { 53 | this.title = title; 54 | } 55 | 56 | public Boolean getIsonline() { 57 | return isonline; 58 | } 59 | 60 | public void setIsonline(Boolean isonline) { 61 | this.isonline = isonline; 62 | } 63 | 64 | } 65 | public ArrayList getDevices() { 66 | return devices; 67 | } 68 | public void setDevices(ArrayList devices) { 69 | this.devices = devices; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/device/KeyRelDeviceList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.device; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * 10 | * @Description api-key关联设备查询接口返回结果实体 11 | * @author luowz 12 | * @date 2019/1/2 19:45 13 | * @version 1.0 14 | * 15 | **/ 16 | @JsonIgnoreProperties(ignoreUnknown = true) 17 | public class KeyRelDeviceList { 18 | 19 | @JsonProperty("total_count") 20 | private int totalcount; 21 | @JsonProperty("per_page") 22 | private int perpage; 23 | @JsonProperty("page") 24 | private int page; 25 | @JsonProperty("devices") 26 | private ArrayList devices; 27 | 28 | @JsonIgnoreProperties(ignoreUnknown = true) 29 | public static class KeyRelDeviceDetail{ 30 | @JsonProperty("create_time") 31 | private String createTime; 32 | @JsonProperty("name") 33 | private String name; 34 | @JsonProperty("id") 35 | private String id; 36 | 37 | @JsonProperty("desc") 38 | private String desc; 39 | @JsonProperty("act_time") 40 | private String actTime; 41 | @JsonProperty("last_ct") 42 | private String lastCt; 43 | 44 | 45 | public String getDesc() { 46 | return desc; 47 | } 48 | 49 | public void setDesc(String desc) { 50 | this.desc = desc; 51 | } 52 | 53 | public String getCreateTime() { 54 | return createTime; 55 | } 56 | 57 | public void setCreateTime(String createTime) { 58 | this.createTime = createTime; 59 | } 60 | 61 | public String getName() { 62 | return name; 63 | } 64 | 65 | public void setName(String name) { 66 | this.name = name; 67 | } 68 | 69 | public String getId() { 70 | return id; 71 | } 72 | 73 | public void setId(String id) { 74 | this.id = id; 75 | } 76 | } 77 | 78 | public int getTotalcount() { 79 | return totalcount; 80 | } 81 | 82 | public void setTotalcount(int totalcount) { 83 | this.totalcount = totalcount; 84 | } 85 | 86 | public int getPerpage() { 87 | return perpage; 88 | } 89 | 90 | public void setPerpage(int perpage) { 91 | this.perpage = perpage; 92 | } 93 | 94 | public int getPage() { 95 | return page; 96 | } 97 | 98 | public void setPage(int page) { 99 | this.page = page; 100 | } 101 | 102 | public ArrayList getDevices() { 103 | return devices; 104 | } 105 | 106 | public void setDevices(ArrayList devices) { 107 | this.devices = devices; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/device/ModifyKeyRelDeviceResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.device; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | 6 | /** 7 | * 8 | * @Description 4.7.6修改apikey关联设备列表接口 的返回结果对象 9 | * @author luowz 10 | * @date 2019/1/2 19:45 11 | * @version 1.0 12 | * 13 | **/ 14 | 15 | @JsonIgnoreProperties(ignoreUnknown = true) 16 | public class ModifyKeyRelDeviceResponse { 17 | @JsonProperty("add") 18 | private Integer add; 19 | @JsonProperty("del") 20 | private Integer del; 21 | public Integer getAdd() { 22 | return add; 23 | } 24 | 25 | public void setAdd(Integer add) { 26 | this.add = add; 27 | } 28 | 29 | public Integer getDel() { 30 | return del; 31 | } 32 | 33 | public void setDel(Integer del) { 34 | this.del = del; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/device/NewDeviceResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.device; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | 6 | @JsonIgnoreProperties(ignoreUnknown = true) 7 | public class NewDeviceResponse { 8 | 9 | @JsonProperty(value="device_id") 10 | private String deviceId; 11 | 12 | 13 | @JsonProperty(value="psk") 14 | private String psk; 15 | 16 | 17 | public String getDeviceId() { 18 | return deviceId; 19 | } 20 | 21 | public void setDeviceId(String DeviceId) { 22 | this.deviceId = DeviceId; 23 | } 24 | 25 | public String getPsk() { 26 | return psk; 27 | } 28 | 29 | public void setPsk(String psk) { 30 | this.psk = psk; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/device/RegDeviceResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.device; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | 6 | @JsonIgnoreProperties(ignoreUnknown = true) 7 | public class RegDeviceResponse { 8 | public String getKey() { 9 | return key; 10 | } 11 | public void setKey(String key) { 12 | this.key = key; 13 | } 14 | public String getDevid() { 15 | return devid; 16 | } 17 | public void setDevid(String devid) { 18 | this.devid = devid; 19 | } 20 | @JsonProperty(value="key") 21 | public String key; 22 | @JsonProperty(value="device_id") 23 | public String devid; 24 | } 25 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/dtu/DtuParserList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.dtu; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | 6 | import com.fasterxml.jackson.annotation.JsonCreator; 7 | import com.fasterxml.jackson.annotation.JsonFormat; 8 | import com.fasterxml.jackson.annotation.JsonProperty; 9 | 10 | public class DtuParserList { 11 | @JsonProperty("parsers") 12 | private ArrayList parsers; 13 | 14 | public static class ParsersItem { 15 | @JsonProperty("id") 16 | private Integer id; 17 | @JsonProperty("name") 18 | private String name; 19 | @JsonProperty("fileName") 20 | private String fileName; 21 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") 22 | @JsonProperty("time") 23 | private Date time; 24 | 25 | @JsonCreator 26 | public ParsersItem(@JsonProperty("id")Integer id, @JsonProperty("name")String name, @JsonProperty("fileName")String fileName 27 | ,@JsonProperty("time")Date time){ 28 | this.id = id; 29 | this.name = name; 30 | this.fileName = fileName; 31 | this.time = time; 32 | } 33 | 34 | public Integer getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Integer id) { 39 | this.id = id; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public String getFileName() { 51 | return fileName; 52 | } 53 | 54 | public void setFileName(String fileName) { 55 | this.fileName = fileName; 56 | } 57 | 58 | public Date getTime() { 59 | return time; 60 | } 61 | 62 | public void setTime(Date time) { 63 | this.time = time; 64 | } 65 | } 66 | 67 | public ArrayList getParsers() { 68 | return parsers; 69 | } 70 | 71 | public void setParsers(ArrayList parsers) { 72 | this.parsers = parsers; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/dtu/NewParserResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.dtu; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class NewParserResponse { 6 | @JsonProperty(value = "id") 7 | public String id; 8 | 9 | public String getId() { 10 | return id; 11 | } 12 | 13 | public void setId(String id) { 14 | this.id = id; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/key/KeyList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.key; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | import com.fasterxml.jackson.annotation.JsonCreator; 8 | import com.fasterxml.jackson.annotation.JsonFormat; 9 | import com.fasterxml.jackson.annotation.JsonProperty; 10 | 11 | public class KeyList { 12 | @JsonProperty("total_count") 13 | public int totalcount; 14 | @JsonProperty("per_page") 15 | public int perpage; 16 | @JsonProperty("page") 17 | public int page; 18 | @JsonProperty("keys") 19 | public ArrayList keys; 20 | 21 | 22 | @JsonCreator 23 | public KeyList(@JsonProperty("total_count")int totalcount,@JsonProperty("per_page") int perpage, @JsonProperty("page")int page, @JsonProperty("keys")ArrayList keys) { 24 | this.totalcount = totalcount; 25 | this.perpage = perpage; 26 | this.page = page; 27 | this.keys = keys; 28 | } 29 | 30 | 31 | 32 | public static class KeysItem{ 33 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 34 | @JsonProperty("create_time") 35 | public Date createTime; 36 | @JsonProperty("title") 37 | public String title; 38 | @JsonProperty("key") 39 | public String key; 40 | @JsonProperty("permissions") 41 | public ArrayList permissions; 42 | 43 | public Date getCreateTime() { 44 | return createTime; 45 | } 46 | 47 | 48 | public void setCreateTime(Date createTime) { 49 | this.createTime = createTime; 50 | } 51 | 52 | 53 | public String getTitle() { 54 | return title; 55 | } 56 | 57 | 58 | public void setTitle(String title) { 59 | this.title = title; 60 | } 61 | 62 | 63 | public String getKey() { 64 | return key; 65 | } 66 | 67 | 68 | public void setKey(String key) { 69 | this.key = key; 70 | } 71 | 72 | 73 | public ArrayList getPermissions() { 74 | return permissions; 75 | } 76 | 77 | 78 | public void setPermissions(ArrayList permissions) { 79 | this.permissions = permissions; 80 | } 81 | 82 | 83 | @JsonCreator 84 | public KeysItem( @JsonProperty("create_time")Date createTime, @JsonProperty("title")String title,@JsonProperty("key") String key,@JsonProperty("permissions") ArrayList permissions) { 85 | this.createTime = createTime; 86 | this.title = title; 87 | this.key = key; 88 | this.permissions = permissions; 89 | } 90 | 91 | 92 | public static class PermissionsItem{ 93 | @JsonProperty("resources") 94 | public Listresources; 95 | public List getResources() { 96 | return resources; 97 | } 98 | 99 | 100 | public void setResources(List resources) { 101 | this.resources = resources; 102 | } 103 | 104 | 105 | public ArrayList getAccessMethods() { 106 | return accessMethods; 107 | } 108 | 109 | 110 | public void setAccessMethods(ArrayList accessMethods) { 111 | this.accessMethods = accessMethods; 112 | } 113 | 114 | 115 | @JsonProperty("access_methods") 116 | public ArrayList accessMethods; 117 | @JsonCreator 118 | public PermissionsItem(@JsonProperty("permissions")List resources,@JsonProperty("access_methods")ArrayList accessMethods) { 119 | this.resources = resources; 120 | this.accessMethods=accessMethods; 121 | } 122 | 123 | 124 | public static class DevicesItem{ 125 | @JsonProperty("dev_id") 126 | public String devid; 127 | 128 | @JsonCreator 129 | public DevicesItem(@JsonProperty("dev_id")String devid) { 130 | this.devid = devid; 131 | } 132 | 133 | 134 | } 135 | } 136 | } 137 | 138 | 139 | 140 | public int getTotalcount() { 141 | return totalcount; 142 | } 143 | 144 | 145 | 146 | public void setTotalcount(int totalcount) { 147 | this.totalcount = totalcount; 148 | } 149 | 150 | 151 | 152 | public int getPerpage() { 153 | return perpage; 154 | } 155 | 156 | 157 | 158 | public void setPerpage(int perpage) { 159 | this.perpage = perpage; 160 | } 161 | 162 | 163 | 164 | public int getPage() { 165 | return page; 166 | } 167 | 168 | 169 | 170 | public void setPage(int page) { 171 | this.page = page; 172 | } 173 | 174 | 175 | 176 | public ArrayList getKeys() { 177 | return keys; 178 | } 179 | 180 | 181 | 182 | public void setKeys(ArrayList keys) { 183 | this.keys = keys; 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/key/NewKeyResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.key; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class NewKeyResponse { 6 | @JsonProperty(value="key") 7 | public String key; 8 | 9 | public String getKey() { 10 | return key; 11 | } 12 | 13 | public void setKey(String key) { 14 | this.key = key; 15 | } 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/mqtt/TopicDeviceList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.mqtt; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.fasterxml.jackson.annotation.JsonCreator; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | public class TopicDeviceList { 9 | @JsonProperty("total_count") 10 | private int totalcount; 11 | @JsonProperty("per_page") 12 | private int perpage; 13 | @JsonProperty("page") 14 | private int page; 15 | @JsonProperty("devices") 16 | private ArrayList devices; 17 | 18 | @JsonCreator 19 | public TopicDeviceList(@JsonProperty("total_count")int totalcount,@JsonProperty("per_page") int perpage, @JsonProperty("page")int page, @JsonProperty("devices") ArrayList devices) { 20 | this.totalcount = totalcount; 21 | this.perpage = perpage; 22 | this.page = page; 23 | this.devices = devices; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/triggers/NewTriggersResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.triggers; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class NewTriggersResponse { 6 | @JsonProperty(value="trigger_id") 7 | public String Tirggerid; 8 | 9 | public String getTirggerid() { 10 | return Tirggerid; 11 | } 12 | 13 | public void setTirggerid(String Tirggerid) { 14 | this.Tirggerid = Tirggerid; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/triggers/TriggerDeviceDetailItem.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.triggers; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | /** 6 | * 7 | * @Description triger绑定的设备列表的设备详情 8 | * @author luowz 9 | * @date 2019/1/2 11:06 10 | * @version 1.0 11 | * 12 | **/ 13 | public class TriggerDeviceDetailItem { 14 | @JsonProperty(value="id") 15 | private String id; 16 | 17 | @JsonProperty(value="title") 18 | private String title; 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getTitle() { 29 | return title; 30 | } 31 | 32 | public void setTitle(String title) { 33 | this.title = title; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/triggers/TriggersList.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.triggers; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import com.fasterxml.jackson.annotation.JsonCreator; 7 | import com.fasterxml.jackson.annotation.JsonFormat; 8 | import com.fasterxml.jackson.annotation.JsonProperty; 9 | 10 | public class TriggersList { 11 | @JsonProperty("total_count") 12 | private int totalcount; 13 | @JsonProperty("per_page") 14 | private int perpage; 15 | @JsonProperty("page") 16 | private int page; 17 | @JsonProperty("triggers") 18 | private Listlist; 19 | @JsonCreator 20 | public TriggersList(@JsonProperty("total_count")int totalcount,@JsonProperty("per_page") int perpage, @JsonProperty("page")int page, @JsonProperty("triggers")List list) { 21 | this.totalcount = totalcount; 22 | this.perpage = perpage; 23 | this.page = page; 24 | this.list = list; 25 | } 26 | public static class TriggersItem{ 27 | @JsonProperty("id") 28 | private String id; 29 | @JsonProperty("title") 30 | private String title; 31 | @JsonProperty("ds_uuids") 32 | private List dsuuids; 33 | @JsonProperty("url") 34 | private String url; 35 | @JsonProperty("type") 36 | private String type; 37 | @JsonProperty("threshold") 38 | private int threshold; 39 | @JsonProperty("invalid") 40 | private boolean invalid; 41 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 42 | @JsonProperty("create_time") 43 | private Date createtime; 44 | @JsonProperty("target_type") 45 | private Date targettype; 46 | 47 | @JsonProperty("dev_ids") 48 | private List devIds; 49 | @JsonProperty("ds_id") 50 | private String dsId; 51 | 52 | public String getId() { 53 | return id; 54 | } 55 | 56 | public void setId(String id) { 57 | this.id = id; 58 | } 59 | 60 | public String getTitle() { 61 | return title; 62 | } 63 | 64 | public void setTitle(String title) { 65 | this.title = title; 66 | } 67 | 68 | public List getDsuuids() { 69 | return dsuuids; 70 | } 71 | 72 | public void setDsuuids(List dsuuids) { 73 | this.dsuuids = dsuuids; 74 | } 75 | 76 | public String getUrl() { 77 | return url; 78 | } 79 | 80 | public void setUrl(String url) { 81 | this.url = url; 82 | } 83 | 84 | public String getType() { 85 | return type; 86 | } 87 | 88 | public void setType(String type) { 89 | this.type = type; 90 | } 91 | 92 | public int getThreshold() { 93 | return threshold; 94 | } 95 | 96 | public void setThreshold(int threshold) { 97 | this.threshold = threshold; 98 | } 99 | 100 | public boolean isInvalid() { 101 | return invalid; 102 | } 103 | 104 | public void setInvalid(boolean invalid) { 105 | this.invalid = invalid; 106 | } 107 | 108 | public Date getCreatetime() { 109 | return createtime; 110 | } 111 | 112 | public void setCreatetime(Date createtime) { 113 | this.createtime = createtime; 114 | } 115 | 116 | public Date getTargettype() { 117 | return targettype; 118 | } 119 | 120 | public void setTargettype(Date targettype) { 121 | this.targettype = targettype; 122 | } 123 | 124 | public List getDevIds() { 125 | return devIds; 126 | } 127 | 128 | public void setDevIds(List devIds) { 129 | this.devIds = devIds; 130 | } 131 | 132 | public String getDsId() { 133 | return dsId; 134 | } 135 | 136 | public void setDsId(String dsId) { 137 | this.dsId = dsId; 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/response/triggers/TriggersResponse.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.response.triggers; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import com.fasterxml.jackson.annotation.JsonFormat; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | 9 | public class TriggersResponse { 10 | @JsonProperty("id") 11 | private String id; 12 | @JsonProperty("title") 13 | private String title; 14 | @JsonProperty("ds_uuids") 15 | private List dsuuids; 16 | @JsonProperty("url") 17 | private String url; 18 | @JsonProperty("type") 19 | private String type; 20 | @JsonProperty("threshold") 21 | private int threshold; 22 | @JsonProperty("invalid") 23 | private boolean invalid; 24 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 25 | @JsonProperty("create_time") 26 | private Date createtime; 27 | @JsonProperty("target_type") 28 | private Date targettype; 29 | @JsonProperty("dev_ids") 30 | private List devIds; 31 | @JsonProperty("dev_details") 32 | private List devDetails; 33 | @JsonProperty("ds_id") 34 | private String dsId; 35 | 36 | 37 | public List getDevIds() { 38 | return devIds; 39 | } 40 | public void setDevIds(List devIds) { 41 | this.devIds = devIds; 42 | } 43 | public Date getTargettype() { 44 | return targettype; 45 | } 46 | public void setTargettype(Date targettype) { 47 | this.targettype = targettype; 48 | } 49 | public Date getCreatetime() { 50 | return createtime; 51 | } 52 | public void setCreatetime(Date createtime) { 53 | this.createtime = createtime; 54 | } 55 | public String getId() { 56 | return id; 57 | } 58 | public void setId(String id) { 59 | this.id = id; 60 | } 61 | public String getTitle() { 62 | return title; 63 | } 64 | public void setTitle(String title) { 65 | this.title = title; 66 | } 67 | public List getDsuuids() { 68 | return dsuuids; 69 | } 70 | public void setDsuuids(List dsuuids) { 71 | this.dsuuids = dsuuids; 72 | } 73 | public String getUrl() { 74 | return url; 75 | } 76 | public void setUrl(String url) { 77 | this.url = url; 78 | } 79 | public String getType() { 80 | return type; 81 | } 82 | public void setType(String type) { 83 | this.type = type; 84 | } 85 | public int getThreshold() { 86 | return threshold; 87 | } 88 | public void setThreshold(int threshold) { 89 | this.threshold = threshold; 90 | } 91 | public boolean isInvalid() { 92 | return invalid; 93 | } 94 | public void setInvalid(boolean invalid) { 95 | this.invalid = invalid; 96 | } 97 | 98 | public List getDevDetails() { 99 | return devDetails; 100 | } 101 | 102 | public void setDevDetails(List devDetails) { 103 | this.devDetails = devDetails; 104 | } 105 | 106 | public String getDsId() { 107 | return dsId; 108 | } 109 | 110 | public void setDsId(String dsId) { 111 | this.dsId = dsId; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/utils/Config.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.utils; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import org.slf4j.LoggerFactory; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | import java.util.Properties; 11 | 12 | public class Config { 13 | private final static Properties properties; 14 | private static org.slf4j.Logger logger = LoggerFactory.getLogger(Config.class); 15 | static { 16 | // Logger.getRootLogger().setLevel(Level.OFF); 17 | InputStream in = Config.class.getClassLoader().getResourceAsStream("config.properties"); 18 | properties = new Properties(); 19 | try { 20 | properties.load(in); 21 | } catch (IOException e) { 22 | logger.error("init config error", e); 23 | } 24 | } 25 | 26 | /** 27 | * 读取以逗号分割的字符串,作为字符串数组返回 28 | * 29 | * @param conf 30 | * @return 31 | */ 32 | public static List getStringList(String conf) { 33 | return Arrays.asList(StringUtils.split(properties.getProperty(conf), ",")); 34 | } 35 | 36 | /** 37 | * 读取字符串 38 | * 39 | * @param conf 40 | * @return 41 | */ 42 | public static String getString(String conf) { 43 | return properties.getProperty(conf); 44 | } 45 | 46 | /** 47 | * 读取整数 48 | * 49 | * @param conf 50 | * @return 51 | */ 52 | public static int getInt(String conf) { 53 | int ret = 0; 54 | try { 55 | ret = Integer.parseInt(getString(conf)); 56 | } catch (NumberFormatException e) { 57 | logger.error("format error", e); 58 | } 59 | return ret; 60 | } 61 | 62 | /** 63 | * 读取布尔值 64 | * 65 | * @param conf 66 | * @return 67 | */ 68 | public static boolean getBoolean(String conf) { 69 | return Boolean.parseBoolean(getString(conf)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /javaSDK/src/main/java/cmcc/iot/onenet/javasdk/utils/OrderConstant.java: -------------------------------------------------------------------------------- 1 | package cmcc.iot.onenet.javasdk.utils;/** 2 | * 3 | * @Description 常量定义 4 | * @author luowz 5 | * @date 2018/12/28 15:50 6 | * @version 1.0 7 | * 8 | **/ 9 | public class OrderConstant { 10 | /*** 11 | * 正序 12 | **/ 13 | public static final String ORDER_ASC = "ASC"; 14 | /*** 15 | * 正序 16 | **/ 17 | public static final String ORDER_DESC = "DESC"; 18 | /*** 19 | * 不指定顺序,默认顺序 20 | **/ 21 | public static final String ORDER_NONE = null; 22 | } 23 | -------------------------------------------------------------------------------- /javaSDK/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | test.url=http://api.heclouds.com 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /javaSDK/src/test/java/com/cmcciot/onenet/api/ApiTest.java: -------------------------------------------------------------------------------- 1 | package com.cmcciot.onenet.api; 2 | 3 | import cmcc.iot.onenet.javasdk.api.dtu.DeleteDtuParser; 4 | import cmcc.iot.onenet.javasdk.response.BasicResponse; 5 | import org.junit.Test; 6 | 7 | 8 | public class ApiTest { 9 | 10 | @Test 11 | public void testDeleteDtuParserApi() { 12 | String key = "m4EubNp9WCeAxjFu4lVw=kn2idE="; 13 | Integer id = 385; 14 | 15 | 16 | /** 17 | * TCP透传查询 18 | * @param name: 名字,精确匹配名字(可选),String 19 | * @param key:masterkey 或者 该设备的设备apikey 20 | */ 21 | DeleteDtuParser api = new DeleteDtuParser(id, key); 22 | BasicResponse response = api.executeApi(); 23 | System.out.println("errno:"+response.errno+" error:"+response.error); 24 | } 25 | 26 | } 27 | 28 | --------------------------------------------------------------------------------