Skip to content

Commit

Permalink
Added resourceUrls in ResourceManagerTaskInfoResponse
Browse files Browse the repository at this point in the history
jfdlf
  • Loading branch information
vthglyk committed May 21, 2018
1 parent 4a69974 commit 9dbd081
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import eu.h2020.symbiote.core.internal.CoreQueryRequest;
import org.springframework.data.annotation.PersistenceConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;


public class ResourceManagerTaskInfoResponse extends ResourceManagerTaskInfoRequest {

private List<String> resourceIds;

private Map<String, String> resourceUrls;

private List<QueryResourceResult> resourceDescriptions;

private ResourceManagerTaskInfoResponseStatus status;
Expand Down Expand Up @@ -60,12 +60,14 @@ public ResourceManagerTaskInfoResponse(String taskId,
String enablerLogicName,
SparqlQueryRequest sparqlQueryRequest,
List<String> resourceIds,
Map<String, String> resourceUrls,
List<QueryResourceResult> resourceDescriptions,
ResourceManagerTaskInfoResponseStatus status,
String message) {
super(taskId, minNoResources, coreQueryRequest, queryInterval, allowCaching, cachingInterval,
informPlatformProxy, enablerLogicName, sparqlQueryRequest);
setResourceIds(new ArrayList<>(resourceIds));
setResourceUrls(new HashMap<>(resourceUrls));
setResourceDescriptions(new ArrayList<>(resourceDescriptions));
setStatus(status);
setMessage(message);
Expand Down Expand Up @@ -109,29 +111,43 @@ public ResourceManagerTaskInfoResponse(@JsonProperty("taskId") String taskId,
@JsonProperty("enablerLogicName") String enablerLogicName,
@JsonProperty("sparqlQueryRequest") SparqlQueryRequest sparqlQueryRequest,
@JsonProperty("resourceIds") List<String> resourceIds,
@JsonProperty("resourceUrls") Map<String, String> resourceUrls,
@JsonProperty("resourceDescriptions") List<QueryResourceResult> resourceDescriptions,
@JsonProperty("status") ResourceManagerTaskInfoResponseStatus status,
@JsonProperty("message") String message) {
super(taskId, minNoResources, maxNoResources, coreQueryRequest, queryInterval, allowCaching, cachingInterval,
informPlatformProxy, enablerLogicName, sparqlQueryRequest);
setResourceIds(new ArrayList<>(resourceIds));
setResourceUrls(new HashMap<>(resourceUrls));
setResourceDescriptions(new ArrayList<>(resourceDescriptions));
setStatus(status);
setMessage(message);
}


/**
*
* @param resourceManagerTaskInfoRequest the input request
*/
public ResourceManagerTaskInfoResponse(ResourceManagerTaskInfoRequest resourceManagerTaskInfoRequest) {
super(resourceManagerTaskInfoRequest);
setStatus(ResourceManagerTaskInfoResponseStatus.UNKNOWN);
setResourceIds(new ArrayList<>());
setResourceUrls(new HashMap<>());
setResourceDescriptions(new ArrayList<>());
setMessage("");
}

/**
* Copy constructor
*
* @param resourceManagerTaskInfoResponse the input response
*/
public ResourceManagerTaskInfoResponse(ResourceManagerTaskInfoResponse resourceManagerTaskInfoResponse) {
this((ResourceManagerTaskInfoRequest) resourceManagerTaskInfoResponse);
setStatus(resourceManagerTaskInfoResponse.getStatus());
setResourceIds(new ArrayList<>(resourceManagerTaskInfoResponse.getResourceIds()));
setResourceUrls(new HashMap<>(resourceManagerTaskInfoResponse.getResourceUrls()));
setResourceDescriptions(new ArrayList<>(resourceManagerTaskInfoResponse.getResourceDescriptions()));
setMessage(resourceManagerTaskInfoResponse.getMessage());
}
Expand All @@ -143,6 +159,9 @@ public void setResourceIds(List<String> resourceIds) {
this.resourceIds = resourceIds;
}

public Map<String, String> getResourceUrls() { return resourceUrls; }
public void setResourceUrls(Map<String, String> resourceUrls) { this.resourceUrls = resourceUrls; }

public List<QueryResourceResult> getResourceDescriptions() { return resourceDescriptions; }
public void setResourceDescriptions(List<QueryResourceResult> resourceDescriptions) {
this.resourceDescriptions = resourceDescriptions.stream().
Expand All @@ -161,23 +180,17 @@ public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ResourceManagerTaskInfoResponse)) return false;
if (!super.equals(o)) return false;

ResourceManagerTaskInfoResponse that = (ResourceManagerTaskInfoResponse) o;

if (getResourceIds() != null ? !getResourceIds().equals(that.getResourceIds()) : that.getResourceIds() != null)
return false;
if (getResourceDescriptions() != null ? !getResourceDescriptions().equals(that.getResourceDescriptions()) : that.getResourceDescriptions() != null)
return false;
if (getStatus() != that.getStatus()) return false;
return getMessage() != null ? getMessage().equals(that.getMessage()) : that.getMessage() == null;
return Objects.equals(resourceIds, that.resourceIds) &&
Objects.equals(resourceUrls, that.resourceUrls) &&
Objects.equals(resourceDescriptions, that.resourceDescriptions) &&
status == that.status &&
Objects.equals(message, that.message);
}

@Override
public int hashCode() {
int result = getResourceIds() != null ? getResourceIds().hashCode() : 0;
result = 31 * result + (getResourceDescriptions() != null ? getResourceDescriptions().hashCode() : 0);
result = 31 * result + (getStatus() != null ? getStatus().hashCode() : 0);
result = 31 * result + (getMessage() != null ? getMessage().hashCode() : 0);
return result;

return Objects.hash(resourceIds, resourceUrls, resourceDescriptions, status, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

/**
* Created by vasgl on 7/27/2017.
Expand Down Expand Up @@ -108,8 +111,8 @@ public void constructorTest2() {
ResourceManagerTaskInfoResponse response1 = new ResourceManagerTaskInfoResponse(
"1", 5, 10, coreQueryRequest,
"P0-0-0T0:0:0.01", true, "P0-0-0T0:0:0.01", true,
"enablerLogic", new SparqlQueryRequest(), new ArrayList<>(), new ArrayList<>(),
ResourceManagerTaskInfoResponseStatus.SUCCESS, "success");
"enablerLogic", new SparqlQueryRequest(), new ArrayList<>(), new HashMap<>(),
new ArrayList<>(), ResourceManagerTaskInfoResponseStatus.SUCCESS, "success");

ResourceManagerTaskInfoResponse response2 = new ResourceManagerTaskInfoResponse(response1);

Expand Down Expand Up @@ -165,6 +168,10 @@ public void testEquals() {
resourceIds.add("1");
resourceIds.add("2");

HashMap<String, String> resourceUrls = new HashMap<>();
resourceUrls.put("1", "1.com");
resourceUrls.put("2", "2.com");

ArrayList<QueryResourceResult> resourceDescriptions = new ArrayList<>();
QueryResourceResult result1 = new QueryResourceResult();
result1.setId("1");
Expand All @@ -178,95 +185,101 @@ public void testEquals() {

ResourceManagerTaskInfoResponse response1 = new ResourceManagerTaskInfoResponse("1", 2, 10,
coreQueryRequest,"P0-0-0T0:0:0.06", true, "P0-0-0T0:0:1",
true, "TestEnablerLogic", sparqlQueryRequest, resourceIds, resourceDescriptions,
ResourceManagerTaskInfoResponseStatus.SUCCESS, "success");
true, "TestEnablerLogic", sparqlQueryRequest, resourceIds, resourceUrls,
resourceDescriptions, ResourceManagerTaskInfoResponseStatus.SUCCESS, "success");
response1.setMaxNoResources(6);

ResourceManagerTaskInfoResponse response2 = new ResourceManagerTaskInfoResponse(response1);
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.setTaskId("2");
assertEquals("1", response1.getTaskId());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.setTaskId(response1.getTaskId());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.setMinNoResources(5);
assertEquals(2, (int) response1.getMinNoResources());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.setMinNoResources(response1.getMinNoResources());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.getCoreQueryRequest().setLocation_name("Athens");
assertEquals("Zurich", response1.getCoreQueryRequest().getLocation_name());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.getCoreQueryRequest().setLocation_name("Zurich");
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.setQueryInterval("P0-0-0T0:0:0.07");
assertEquals(60, (long) new IntervalFormatter(response1.getQueryInterval()).getMillis());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.setQueryInterval(response1.getQueryInterval());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.setAllowCaching(false);
assertEquals(true, response1.getAllowCaching());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.setAllowCaching(response1.getAllowCaching());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.setCachingInterval("P0-0-0T0:0:0.07");
assertEquals(1000, (long) new IntervalFormatter(response1.getCachingInterval()).getMillis());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.setCachingInterval(response1.getCachingInterval());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.setInformPlatformProxy(false);
assertEquals(true, response1.getInformPlatformProxy());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.setInformPlatformProxy(response1.getInformPlatformProxy());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.setEnablerLogicName("Test");
assertEquals("TestEnablerLogic", response1.getEnablerLogicName());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.setEnablerLogicName(response1.getEnablerLogicName());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.getSparqlQueryRequest().setSparqlQuery("response2");
assertEquals("response1", response1.getSparqlQueryRequest().getSparqlQuery());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.getSparqlQueryRequest().setSparqlQuery(response1.getSparqlQueryRequest().getSparqlQuery());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.getSparqlQueryRequest().setOutputFormat(SparqlQueryOutputFormat.CSV);
assertEquals(SparqlQueryOutputFormat.COUNT, response1.getSparqlQueryRequest().getOutputFormat());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.getSparqlQueryRequest().setOutputFormat(response1.getSparqlQueryRequest().getOutputFormat());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.getResourceIds().set(0, "3");
assertEquals(2, response1.getResourceIds().size());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.getResourceIds().set(0, "1");
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.getResourceUrls().put("1", "1.eu");
assertEquals(2, response1.getResourceUrls().size());
assertNotEquals(response1, response2);
response2.getResourceUrls().put("1", "1.com");
assertEquals(response1, response2);

response2.getResourceDescriptions().get(0).setId("3");
assertEquals(2, response1.getResourceIds().size());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.getResourceDescriptions().get(0).setId("1");
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.setStatus(ResourceManagerTaskInfoResponseStatus.FAILED);
assertEquals(ResourceManagerTaskInfoResponseStatus.SUCCESS, response1.getStatus());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.setStatus(response1.getStatus());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);

response2.setMessage("failed");
assertEquals("success", response1.getMessage());
assertEquals(false, response1.equals(response2));
assertNotEquals(response1, response2);
response2.setMessage(response1.getMessage());
assertEquals(true, response1.equals(response2));
assertEquals(response1, response2);
}
}

0 comments on commit 9dbd081

Please sign in to comment.