aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/main/java/org/onap/nbi/apis/hub/HubResource.java17
-rwxr-xr-xsrc/main/java/org/onap/nbi/apis/hub/model/Subscriber.java2
-rw-r--r--src/main/java/org/onap/nbi/apis/hub/service/EventFactory.java10
-rwxr-xr-xsrc/main/java/org/onap/nbi/apis/hub/service/NotifierService.java6
-rw-r--r--src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java2
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ResourceModel.java8
-rw-r--r--src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java19
7 files changed, 45 insertions, 19 deletions
diff --git a/src/main/java/org/onap/nbi/apis/hub/HubResource.java b/src/main/java/org/onap/nbi/apis/hub/HubResource.java
index bd98820..9ef5235 100755
--- a/src/main/java/org/onap/nbi/apis/hub/HubResource.java
+++ b/src/main/java/org/onap/nbi/apis/hub/HubResource.java
@@ -44,6 +44,10 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+import java.net.URI;
+import java.util.List;
+import java.util.stream.Collectors;
+
@RestController
@RequestMapping("/hub")
@EnableScheduling
@@ -66,7 +70,10 @@ public class HubResource extends ResourceManagement {
Subscriber subscriber = subscriptionService.createSubscription(subscription);
- URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(subscriber.getId())
+ URI location = ServletUriComponentsBuilder
+ .fromCurrentRequest()
+ .path("/{id}")
+ .buildAndExpand(subscriber.getId())
.toUri();
return ResponseEntity.created(location).build();
@@ -75,7 +82,7 @@ public class HubResource extends ResourceManagement {
@GetMapping(value = "/{subscriptionId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Subscription> getSubscription(@PathVariable String subscriptionId) {
- Subscriber subscriber = subscriptionService.findSubscriptionById(subscriptionId);
+ Subscriber subscriber = subscriptionService.findSubscriptionById(subscriptionId);
if (subscriber == null) {
return ResponseEntity.notFound().build();
}
@@ -92,9 +99,9 @@ public class HubResource extends ResourceManagement {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", String.valueOf(totalCount));
headers.add("X-Result-Count", String.valueOf(subscribers.size()));
-
- List<Subscription> subscriptions =
- subscribers.stream().map(Subscription::createFromSubscriber).collect(Collectors.toList());
+ List<Subscription> subscriptions = subscribers.stream()
+ .map(Subscription::createFromSubscriber)
+ .collect(Collectors.toList());
return this.findResponse(subscriptions, filter, headers);
diff --git a/src/main/java/org/onap/nbi/apis/hub/model/Subscriber.java b/src/main/java/org/onap/nbi/apis/hub/model/Subscriber.java
index df0cffd..ab2b05f 100755
--- a/src/main/java/org/onap/nbi/apis/hub/model/Subscriber.java
+++ b/src/main/java/org/onap/nbi/apis/hub/model/Subscriber.java
@@ -56,7 +56,7 @@ public class Subscriber implements Resource {
return query;
}
- public static Subscriber createFromRequest(Subscription request) {
+ public static Subscriber createFromSubscription(Subscription request) {
Subscriber sub = new Subscriber();
sub.setCallback(request.getCallback());
diff --git a/src/main/java/org/onap/nbi/apis/hub/service/EventFactory.java b/src/main/java/org/onap/nbi/apis/hub/service/EventFactory.java
index b2a017c..3e04b84 100644
--- a/src/main/java/org/onap/nbi/apis/hub/service/EventFactory.java
+++ b/src/main/java/org/onap/nbi/apis/hub/service/EventFactory.java
@@ -59,13 +59,15 @@ public class EventFactory {
*/
private static Object filterServiceOrder(final ServiceOrder serviceOrder) {
- Object filteredServiceOrder;
+ Object filteredServiceOrder = null;
- JsonRepresentation jsonRepresentation = new JsonRepresentation();
- jsonRepresentation.add("id").add("href").add("externalId").add("state").add("orderDate").add
+ if (serviceOrder != null) {
+ JsonRepresentation jsonRepresentation = new JsonRepresentation();
+ jsonRepresentation.add("id").add("href").add("externalId").add("state").add("orderDate").add
("completionDateTime").add("orderItem");
- filteredServiceOrder = JacksonFilter.createNode(serviceOrder, jsonRepresentation);
+ filteredServiceOrder = JacksonFilter.createNode(serviceOrder, jsonRepresentation);
+ }
return filteredServiceOrder;
}
diff --git a/src/main/java/org/onap/nbi/apis/hub/service/NotifierService.java b/src/main/java/org/onap/nbi/apis/hub/service/NotifierService.java
index 2bfbca1..4f7a549 100755
--- a/src/main/java/org/onap/nbi/apis/hub/service/NotifierService.java
+++ b/src/main/java/org/onap/nbi/apis/hub/service/NotifierService.java
@@ -19,6 +19,7 @@ import org.onap.nbi.apis.hub.model.Event;
import org.onap.nbi.apis.hub.model.Subscriber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
@@ -31,9 +32,12 @@ import javax.validation.Valid;
public class NotifierService {
private final Logger logger = LoggerFactory.getLogger(NotifierService.class);
+ @Autowired
+ RestTemplate restTemplate;
+
@Async
public void run(Subscriber subscriber, @Valid Event event) {
- ResponseEntity<String> re = new RestTemplate().postForEntity(subscriber.getCallback(), event, String.class);
+ ResponseEntity<String> re = restTemplate.postForEntity(subscriber.getCallback(), event, String.class);
if (re.getStatusCode() == HttpStatus.OK) logger.debug("FAILED");
}
}
diff --git a/src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java b/src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java
index cf9ab66..09826bc 100644
--- a/src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java
+++ b/src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java
@@ -32,7 +32,7 @@ public class SubscriptionService {
}
public Subscriber createSubscription(Subscription subscription){
- Subscriber sub = Subscriber.createFromRequest(subscription);
+ Subscriber sub = Subscriber.createFromSubscription(subscription);
return subscriberRepository.save(sub);
}
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ResourceModel.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ResourceModel.java
index 0aabb63..9faef49 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ResourceModel.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ResourceModel.java
@@ -23,7 +23,7 @@ public class ResourceModel {
private String resourceUuid;
- //private String resourceCustomizationUuid;
+ private String resourceCustomizationUuid;
private ParametersModel parameters;
@@ -32,7 +32,7 @@ public class ResourceModel {
setResourceName((String)info.get("name"));
setResourceInvariantUuid((String)info.get("resourceInvariantUUID"));
setResourceUuid((String)info.get("id"));
- //setResourceCustomizationUuid((String)info.get("modelCustomizationId"));
+ setResourceCustomizationUuid((String)info.get("modelCustomizationId"));
}
public String getResourceName() {
@@ -59,7 +59,6 @@ public class ResourceModel {
this.resourceUuid = resourceUuid;
}
- /*
public String getResourceCustomizationUuid() {
return resourceCustomizationUuid;
}
@@ -67,7 +66,7 @@ public class ResourceModel {
public void setResourceCustomizationUuid(String resourceCustomizationUuid) {
this.resourceCustomizationUuid = resourceCustomizationUuid;
}
- */
+
public ParametersModel getParameters() {
return parameters;
}
@@ -82,6 +81,7 @@ public class ResourceModel {
"resourceName='" + resourceName + '\'' +
", resourceInvariantUuid='" + resourceInvariantUuid + '\'' +
", resourceUuid='" + resourceUuid + '\'' +
+ ", resourceCustomizationUuid='" + resourceCustomizationUuid + '\'' +
", parameters='" + parameters + '}';
}
}
diff --git a/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java b/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java
index 486c4ef..f2b72f8 100644
--- a/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java
+++ b/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java
@@ -15,14 +15,19 @@
*/
package org.onap.nbi.apis.assertions;
+import org.onap.nbi.apis.hub.model.Event;
+import org.onap.nbi.apis.hub.model.EventType;
import org.onap.nbi.apis.hub.model.Subscription;
+import java.util.Date;
+import java.util.UUID;
+
public class HubAssertions {
public static Subscription createServiceOrderCreationSubscription(){
Subscription subscription = new Subscription();
subscription.setId("id");
- subscription.setCallback("http://localhost:8090");
+ subscription.setCallback("http://localhost:8080/test");
subscription.setQuery("eventType = ServiceOrderCreationNotification");
return subscription;
}
@@ -30,7 +35,7 @@ public class HubAssertions {
public static Subscription createServiceOrderStateChangeSubscription(){
Subscription subscription = new Subscription();
subscription.setId("id");
- subscription.setCallback("http://localhost:8090");
+ subscription.setCallback("http://localhost/test");
subscription.setQuery("eventType = ServiceOrderStateChangeNotification");
return subscription;
}
@@ -38,8 +43,16 @@ public class HubAssertions {
public static Subscription createServiceOrderItemStateChangeSubscription(){
Subscription subscription = new Subscription();
subscription.setId("id");
- subscription.setCallback("http://localhost:8090");
+ subscription.setCallback("http://localhost/test");
subscription.setQuery("eventType = ServiceOrderItemStateChangeNotification");
return subscription;
}
+
+ public static Event createFakeEvent() {
+ Event event = new Event();
+ event.setEventId(UUID.randomUUID().toString());
+ event.setEventDate(new Date());
+ event.setEventType(EventType.SERVICE_ORDER_CREATION.value());
+ return event;
+ }
}