[SECIOTSRK-370] Return policy as String, drop hash field
authoro.abakumov <alexander.abakumov@gmail.com>
Wed, 2 Aug 2017 08:53:51 +0000 (11:53 +0300)
committerOleksandr Abakumov <o.abakumov@samsung.com>
Mon, 7 Aug 2017 07:59:46 +0000 (10:59 +0300)
servers/dsm/src/main/java/com/samsung/dsm/model/restapi/RestPolicy.java [deleted file]
servers/dsm/src/main/java/com/samsung/dsm/rest/device/DeviceApi.java
servers/dsm/src/main/java/com/samsung/dsm/rest/policy/PolicyApi.java
servers/dsm/src/test/java/com/samsung/dsm/rest/DeviceApiTest.java

diff --git a/servers/dsm/src/main/java/com/samsung/dsm/model/restapi/RestPolicy.java b/servers/dsm/src/main/java/com/samsung/dsm/model/restapi/RestPolicy.java
deleted file mode 100644 (file)
index 9619819..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.samsung.dsm.model.restapi;
-
-/**
- * @author <A HREF="mailto:o.abakumov@samsung.com">Oleksandr Abakumov</A>
- * @version 1.0
- * @since 2017-07-17
- */
-public class RestPolicy implements RestEntity {
-    private String policy;
-
-    private int hash;
-
-    public RestPolicy(String policy, int hash) {
-        this.policy = policy;
-        this.hash = hash;
-    }
-
-    public String getPolicy() {
-        return policy;
-    }
-
-    public int getHash() {
-        return hash;
-    }
-
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-
-        RestPolicy that = (RestPolicy) o;
-
-        if (hash != that.hash) return false;
-        return policy != null ? policy.equals(that.policy) : that.policy == null;
-    }
-
-    @Override
-    public int hashCode() {
-        int result = policy != null ? policy.hashCode() : 0;
-        result = 31 * result + hash;
-        return result;
-    }
-
-    @Override
-    public String toString() {
-        return "RestPolicy{" +
-                "policy='" + policy + '\'' +
-                ", hash=" + hash +
-                '}';
-    }
-}
index 866a39c..7ffcb85 100644 (file)
@@ -14,10 +14,8 @@ import com.samsung.commons.service.DeviceService;
 import com.samsung.commons.service.IotCloudService;
 import com.samsung.dsm.model.restapi.RestAgent;
 import com.samsung.dsm.model.restapi.RestDevice;
-import com.samsung.dsm.model.restapi.RestPolicy;
 import com.samsung.dsm.model.restapi.converter.AgentConverter;
 import com.samsung.dsm.model.restapi.converter.DeviceConverter;
-import com.samsung.dsm.model.restapi.converter.PolicyConverter;
 import com.samsung.dsm.rest.iotcloud.IotCloudAssociatedUserNotExists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
@@ -57,9 +55,6 @@ public class DeviceApi {
     @Autowired
     private AgentConverter agentConverter;
 
-    @Autowired
-    private PolicyConverter policyConverter;
-
     /**
      * Find device by it's UUID
      *
@@ -94,9 +89,9 @@ public class DeviceApi {
      * @throws DeviceNotFoundByUuid (NOT_FOUND) device has't been found by it's UUID
      */
     @RequestMapping(value = "/{deviceUuId}/policy")
-    public ResponseEntity<RestPolicy> findPolicyByUUID(@PathVariable String deviceUuId) {
+    public String findPolicyByUUID(@PathVariable String deviceUuId) {
         Policy policy = ofNullable(deviceService.findByUUID(deviceUuId)).orElseThrow(DeviceNotFoundByUuid::new).getPolicy();
-        return new ResponseEntity<>(policyConverter.convert(policy), OK);
+        return policy.getPolicy();
     }
 
     /**
index 84d6f90..4c8eaaa 100644 (file)
@@ -6,7 +6,6 @@
 package com.samsung.dsm.rest.policy;
 
 import static java.util.Optional.ofNullable;
-import static org.springframework.http.HttpStatus.OK;
 
 import com.samsung.commons.domain.Device;
 import com.samsung.commons.domain.IotCloudUser;
@@ -17,13 +16,10 @@ import com.samsung.commons.service.IotCloudService;
 import com.samsung.commons.service.PolicyService;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.samsung.dsm.model.restapi.RestPolicy;
-import com.samsung.dsm.model.restapi.converter.PolicyConverter;
 import com.samsung.dsm.rest.mq.MQSenderImpl;
 
 /**
@@ -40,9 +36,6 @@ public class PolicyApi {
     private final static Logger log = Logger.getLogger(PolicyApi.class);
     @Autowired
     private PolicyService policyService;
-
-    @Autowired
-    private PolicyConverter policyConverter;
     
     @Autowired
     private DeviceService deviceService;
@@ -62,9 +55,9 @@ public class PolicyApi {
      * @throws PolicyNotFoundByDeviceUuidAndAgentUuid (NOT_FOUND) policy hasn't been found by given device UUID and agent UUID
      */
     @RequestMapping(value = "/device/{deviceUuId}/agent/{agentUuId}")
-    public ResponseEntity<RestPolicy> findByUUID(@PathVariable String deviceUuId, @PathVariable String agentUuId) {
+    public String findByUUID(@PathVariable String deviceUuId, @PathVariable String agentUuId) {
         Policy policy = ofNullable(policyService.findByDeviceUuidAndByAgentUuid(deviceUuId, agentUuId)).orElseThrow(PolicyNotFoundByDeviceUuidAndAgentUuid::new);
-        return new ResponseEntity<>(policyConverter.convert(policy), OK);
+        return policy.getPolicy();
     }
 
     @RequestMapping(value = "/request/{policyId}/device/{deviceId}")
index 4c8c064..37dd6c6 100644 (file)
@@ -143,8 +143,8 @@ public class DeviceApiTest {
     public void findPolicyByUuidOk() throws Exception {
         ResultActions result = mockMvc.perform(get(ROOT_URL + "/device/1234/policy")).andExpect(status().isOk());
         String content = result.andReturn().getResponse().getContentAsString();
-        assertTrue(JsonUtils.equalJson(content,
-                "{\"policy\":\"[\\t{\\t\\t\\\"group\\\": \\\"tv-extension\\\",\\t\\t\\\"policies\\\": [\\t\\t\\t{\\t\\t\\t\\t\\\"name\\\": \\\"usb\\\",\\t\\t\\t\\t\\\"state\\\": 0,\\t\\t\\t\\t\\\"items\\\": []\\t\\t\\t},\\t\\t\\t{\\t\\t\\t\\t\\\"name\\\": \\\"screen-capture\\\",\\t\\t\\t\\t\\\"state\\\": 1,\\t\\t\\t\\t\\\"items\\\": []\\t\\t\\t},\\t\\t\\t{\\t\\t\\t\\t\\\"name\\\": \\\"bluetooth\\\",\\t\\t\\t\\t\\\"state\\\": 1,\\t\\t\\t\\t\\\"items\\\": []\\t\\t\\t},\\t\\t\\t{\\t\\t\\t\\t\\\"name\\\": \\\"iptables\\\",\\t\\t\\t\\t\\\"state\\\": -1,\\t\\t\\t\\t\\\"items\\\": [\\t\\t\\t\\t\\t\\\"127.0.0.0/24|UDP|10-1024\\\",\\t\\t\\t\\t\\t\\\"1.1.1.1|TCP|80,443\\\",\\t\\t\\t\\t\\t\\\"8.8.8.8\\\"\\t\\t\\t\\t]\\t\\t\\t}\\t\\t]\\t}]\",\"hash\":1971641242}"));
+
+        assertEquals("[\t{\t\t\"group\": \"tv-extension\",\t\t\"policies\": [\t\t\t{\t\t\t\t\"name\": \"usb\",\t\t\t\t\"state\": 0,\t\t\t\t\"items\": []\t\t\t},\t\t\t{\t\t\t\t\"name\": \"screen-capture\",\t\t\t\t\"state\": 1,\t\t\t\t\"items\": []\t\t\t},\t\t\t{\t\t\t\t\"name\": \"bluetooth\",\t\t\t\t\"state\": 1,\t\t\t\t\"items\": []\t\t\t},\t\t\t{\t\t\t\t\"name\": \"iptables\",\t\t\t\t\"state\": -1,\t\t\t\t\"items\": [\t\t\t\t\t\"127.0.0.0/24|UDP|10-1024\",\t\t\t\t\t\"1.1.1.1|TCP|80,443\",\t\t\t\t\t\"8.8.8.8\"\t\t\t\t]\t\t\t}\t\t]\t}]",content);
     }
 
     @Test