From 9dc24ae6efc0d070ae446b87c6268bb3cd353034 Mon Sep 17 00:00:00 2001 From: NicolasLaplaud Date: Tue, 17 Jul 2018 10:32:42 +0200 Subject: HUB Resource - Adding DELETE, GET, FIND operations on subscriptions Change-Id: If0c326ffc6a3d0ec456e5258a04b3110bb8df583 Issue-ID: EXTAPI-96 Signed-off-by: NicolasLaplaud --- src/main/java/org/onap/nbi/Application.java | 8 -- src/main/java/org/onap/nbi/apis/hub/HubConfig.java | 29 ----- .../java/org/onap/nbi/apis/hub/HubResource.java | 67 ++++++++-- .../java/org/onap/nbi/apis/hub/model/Event.java | 2 +- .../org/onap/nbi/apis/hub/model/Subscriber.java | 3 +- .../org/onap/nbi/apis/hub/model/Subscription.java | 36 ++++-- .../hub/service/CriteriaBuilderServiceOrder.java | 8 +- .../nbi/apis/hub/service/SubscriptionService.java | 47 +++++++ .../serviceorder/MultiCriteriaRequestBuilder.java | 121 ------------------ .../apis/serviceorder/ServiceOrderResource.java | 1 + .../nbi/commons/MultiCriteriaRequestBuilder.java | 136 +++++++++++++++++++++ .../java/org/onap/nbi/configuration/HubConfig.java | 29 +++++ 12 files changed, 297 insertions(+), 190 deletions(-) delete mode 100644 src/main/java/org/onap/nbi/apis/hub/HubConfig.java create mode 100644 src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java delete mode 100644 src/main/java/org/onap/nbi/apis/serviceorder/MultiCriteriaRequestBuilder.java create mode 100644 src/main/java/org/onap/nbi/commons/MultiCriteriaRequestBuilder.java create mode 100644 src/main/java/org/onap/nbi/configuration/HubConfig.java diff --git a/src/main/java/org/onap/nbi/Application.java b/src/main/java/org/onap/nbi/Application.java index e9fcc2d..05588b4 100644 --- a/src/main/java/org/onap/nbi/Application.java +++ b/src/main/java/org/onap/nbi/Application.java @@ -15,11 +15,8 @@ */ package org.onap.nbi; -import org.onap.nbi.apis.hub.service.CriteriaBuilder; -import org.onap.nbi.apis.hub.service.CriteriaBuilderServiceOrder; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; import org.springframework.scheduling.annotation.EnableAsync; @SpringBootApplication @@ -30,9 +27,4 @@ public class Application { SpringApplication.run(Application.class, args); } - @Bean - CriteriaBuilder criteriaBuilder() { - return new CriteriaBuilderServiceOrder(); - } - } diff --git a/src/main/java/org/onap/nbi/apis/hub/HubConfig.java b/src/main/java/org/onap/nbi/apis/hub/HubConfig.java deleted file mode 100644 index 693e628..0000000 --- a/src/main/java/org/onap/nbi/apis/hub/HubConfig.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2018 Orange - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.nbi.apis.hub; - -import org.onap.nbi.apis.hub.service.CriteriaBuilder; -import org.onap.nbi.apis.hub.service.CriteriaBuilderServiceOrder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class HubConfig { - @Bean - CriteriaBuilder criteriaBuilder() { - return new CriteriaBuilderServiceOrder(); - } -} 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 54e9001..811dd51 100755 --- a/src/main/java/org/onap/nbi/apis/hub/HubResource.java +++ b/src/main/java/org/onap/nbi/apis/hub/HubResource.java @@ -17,44 +17,87 @@ package org.onap.nbi.apis.hub; import org.onap.nbi.apis.hub.model.Subscriber; import org.onap.nbi.apis.hub.model.Subscription; -import org.onap.nbi.apis.hub.repository.SubscriberRepository; +import org.onap.nbi.apis.hub.service.SubscriptionService; +import org.onap.nbi.commons.JsonRepresentation; +import org.onap.nbi.commons.MultiCriteriaRequestBuilder; +import org.onap.nbi.commons.ResourceManagement; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import java.net.URI; +import java.util.List; @RestController @RequestMapping("/hub") @EnableScheduling -public class HubResource { +public class HubResource extends ResourceManagement { Logger logger = LoggerFactory.getLogger(HubResource.class); @Autowired - SubscriberRepository subscriberRepository; + MongoTemplate mongoTemplate; + + @Autowired + SubscriptionService subscriptionService; + + @Autowired + MultiCriteriaRequestBuilder multiCriteriaRequestBuilder; @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity createEventSubscription(@RequestBody Subscription subscription) { - logger.debug("Received subscription request: {}", subscription); + logger.debug("POST request for subscription : {}", subscription); - Subscriber sub = Subscriber.createFromRequest(subscription); - sub = subscriberRepository.save(sub); + Subscriber subscriber = subscriptionService.createSubscription(subscription); URI location = ServletUriComponentsBuilder .fromCurrentRequest() - .path("{id}") - .buildAndExpand(sub.getId()) + .path("/{id}") + .buildAndExpand(subscriber.getId()) .toUri(); return ResponseEntity.created(location).build(); } + + @GetMapping(value = "/{subscriptionId}", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity getSubscription(@PathVariable String subscriptionId) { + + Subscriber subscriber = subscriptionService.findSubscriptionById(subscriptionId); + if (subscriber == null) { + return ResponseEntity.notFound().build(); + } + return ResponseEntity.ok(Subscription.createFromSubscriber(subscriber)); + } + + @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity findSubscribers(@RequestParam MultiValueMap params) { + + Query query = multiCriteriaRequestBuilder.buildRequest(params); + List subscribers = mongoTemplate.find(query, Subscriber.class); + JsonRepresentation filter = new JsonRepresentation(params); + long totalCount = subscriptionService.countSubscription(); + HttpHeaders headers = new HttpHeaders(); + headers.add("X-Total-Count", String.valueOf(totalCount)); + headers.add("X-Result-Count", String.valueOf(subscribers.size())); + + return this.findResponse(subscribers, filter, headers); + + } + + @DeleteMapping("/{subscriptionId}") + @ResponseStatus(HttpStatus.NO_CONTENT) + public void deleteSubscription(@PathVariable String subscriptionId) { + logger.debug("DELETE request for subscription id #{}", subscriptionId); + subscriptionService.deleteSubscription(subscriptionId); + } } diff --git a/src/main/java/org/onap/nbi/apis/hub/model/Event.java b/src/main/java/org/onap/nbi/apis/hub/model/Event.java index e68d322..4c8ae79 100755 --- a/src/main/java/org/onap/nbi/apis/hub/model/Event.java +++ b/src/main/java/org/onap/nbi/apis/hub/model/Event.java @@ -27,7 +27,7 @@ public class Event { private LocalDateTime eventDate; @NotNull - private String eventType; + private String eventType = "string"; @NotNull private JsonNode event; 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 a18833e..afb9472 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 @@ -15,6 +15,7 @@ */ package org.onap.nbi.apis.hub.model; +import org.onap.nbi.commons.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.annotation.Id; @@ -26,7 +27,7 @@ import java.util.stream.Stream; @Document -public class Subscriber { +public class Subscriber implements Resource { private static final Logger logger = LoggerFactory.getLogger(Subscriber.class); @Id diff --git a/src/main/java/org/onap/nbi/apis/hub/model/Subscription.java b/src/main/java/org/onap/nbi/apis/hub/model/Subscription.java index 70b50b4..53f33ab 100755 --- a/src/main/java/org/onap/nbi/apis/hub/model/Subscription.java +++ b/src/main/java/org/onap/nbi/apis/hub/model/Subscription.java @@ -15,11 +15,13 @@ */ package org.onap.nbi.apis.hub.model; -import java.util.Objects; +import java.util.stream.Collectors; public class Subscription { + private String id; + private String callback; private String query; @@ -28,11 +30,20 @@ public class Subscription { } - public Subscription(String callback, String query) { + public Subscription(String id, String callback, String query) { + this.id = id; this.callback = callback; this.query = query; } + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + public String getCallback() { return callback; } @@ -49,18 +60,17 @@ public class Subscription { this.query = query; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Subscription that = (Subscription) o; - return Objects.equals(callback, that.callback) && - Objects.equals(query, that.query); - } + public static Subscription createFromSubscriber(Subscriber subscriber) { + Subscription sub = new Subscription(); + sub.setId(subscriber.getId()); + sub.setCallback(subscriber.getCallback()); - @Override - public int hashCode() { + String query = subscriber.getQuery().entrySet() + .stream() + .map(entry -> entry.getKey()+ "=" + String.join(" ",entry.getValue())) + .collect(Collectors.joining()); - return Objects.hash(callback, query); + sub.setQuery(query); + return sub; } } diff --git a/src/main/java/org/onap/nbi/apis/hub/service/CriteriaBuilderServiceOrder.java b/src/main/java/org/onap/nbi/apis/hub/service/CriteriaBuilderServiceOrder.java index 31f0839..4a780a5 100755 --- a/src/main/java/org/onap/nbi/apis/hub/service/CriteriaBuilderServiceOrder.java +++ b/src/main/java/org/onap/nbi/apis/hub/service/CriteriaBuilderServiceOrder.java @@ -34,10 +34,9 @@ public class CriteriaBuilderServiceOrder implements CriteriaBuilder { if (stateNode.isValueNode()) return base.orOperator( Criteria.where("query.serviceOrder__state").exists(false), - Criteria.where("query.serviceOrder__state").in(event.getEvent().path("state").textValue()) + Criteria.where("query.serviceOrder__state").in(stateNode.textValue()) ); - else - return base.and("query.serviceOrder__state").exists(false); + break; case "ServiceOrderItemStateChangeNotification": Object[] states = getStates(event); @@ -46,8 +45,7 @@ public class CriteriaBuilderServiceOrder implements CriteriaBuilder { Criteria.where("query.serviceOrder__serviceOrderItem__state").exists(false), Criteria.where("query.serviceOrder__serviceOrderItem__state").in(states) ); - else - return base.and("query.serviceOrder__serviceOrderItem__state").exists(false); + break; } return base; 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 new file mode 100644 index 0000000..65eaea3 --- /dev/null +++ b/src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2018 Orange + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.nbi.apis.hub.service; + +import org.onap.nbi.apis.hub.model.Subscriber; +import org.onap.nbi.apis.hub.model.Subscription; +import org.onap.nbi.apis.hub.repository.SubscriberRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class SubscriptionService { + + @Autowired + SubscriberRepository subscriberRepository; + + public Subscriber findSubscriptionById(String subscriptionId){ + return subscriberRepository.findOne(subscriptionId); + } + + public Subscriber createSubscription(Subscription subscription){ + Subscriber sub = Subscriber.createFromRequest(subscription); + return subscriberRepository.save(sub); + } + + public void deleteSubscription(String subscriptionId){ + subscriberRepository.delete(subscriptionId); + } + + public long countSubscription(){ + return subscriberRepository.count(); + } + +} diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/MultiCriteriaRequestBuilder.java b/src/main/java/org/onap/nbi/apis/serviceorder/MultiCriteriaRequestBuilder.java deleted file mode 100644 index 7ea2fd4..0000000 --- a/src/main/java/org/onap/nbi/apis/serviceorder/MultiCriteriaRequestBuilder.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Copyright (c) 2018 Orange - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.nbi.apis.serviceorder; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import org.onap.nbi.apis.serviceorder.model.StateType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; -import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; -import org.springframework.util.MultiValueMap; - -@Service -public class MultiCriteriaRequestBuilder { - - private static final Logger LOGGER = LoggerFactory.getLogger(ServiceOrderResource.class); - - - public Query buildRequest(MultiValueMap params) { - Query query = new Query(); - - List externalIds = params.get("externalId"); - if (!CollectionUtils.isEmpty(externalIds)) { - String externalId = externalIds.get(0); - LOGGER.debug("add criterion externalId {}", externalId); - query.addCriteria(Criteria.where("externalId").is(externalId)); - - } - List states = params.get("state"); - if (!CollectionUtils.isEmpty(states)) { - String state = states.get(0); - LOGGER.debug("add criterion state {}", state); - query.addCriteria(Criteria.where("state").is(StateType.fromValue(state))); - - } - List descriptions = params.get("description"); - if (!CollectionUtils.isEmpty(descriptions)) { - String description = descriptions.get(0); - LOGGER.debug("add criterion description {}", description); - query.addCriteria(Criteria.where("description").is(description)); - - } - - handleDate(params, query); - - handleOffsetAndLimit(params, query); - - return query; - } - - private void handleDate(MultiValueMap params, Query query) { - List orderDateLts = params.get("orderDate.lt"); - List orderDateGts = params.get("orderDate.gt"); - if (!CollectionUtils.isEmpty(orderDateLts) || !CollectionUtils.isEmpty(orderDateGts)) { - Criteria orderDateCriteria = Criteria.where("orderDate"); - - if (!CollectionUtils.isEmpty(orderDateLts)) { - String orderDateLt = orderDateLts.get(0); - LOGGER.debug("add criterion orderDate.lt {}", orderDateLt); - orderDateCriteria.lt(convertDate(orderDateLt)); - } - if (!CollectionUtils.isEmpty(orderDateGts)) { - String orderDateGt = orderDateGts.get(0); - LOGGER.debug("add criterion orderDate.gt {}", orderDateGt); - orderDateCriteria.gt(convertDate(orderDateGt)); - } - query.addCriteria(orderDateCriteria); - } - } - - private void handleOffsetAndLimit(MultiValueMap params, Query query) { - List offsets = params.get("offset"); - List limits = params.get("limit"); - if (!CollectionUtils.isEmpty(offsets) && !CollectionUtils.isEmpty(limits)) { - String offsetString = offsets.get(0); - String limitString = limits.get(0); - int offset = Integer.parseInt(offsetString); - int limit = Integer.parseInt(limitString); - final Pageable pageableRequest = new PageRequest(offset, limit); - query.with(pageableRequest); - } else if (!CollectionUtils.isEmpty(limits)) { - String limitString = limits.get(0); - int limit = Integer.parseInt(limitString); - final Pageable pageableRequest = new PageRequest(0, limit); - query.with(pageableRequest); - } - } - - private Date convertDate(String dateString) { - String dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; - SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); - try { - return formatter.parse(dateString); - } catch (ParseException e) { - LOGGER.error("unable to convert date " + dateString + ", the pattern is " + dateFormat + " ; " + e); - } - return null; - - } - -} diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java index d439306..be28f1a 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java @@ -24,6 +24,7 @@ import org.onap.nbi.apis.serviceorder.workflow.CreateAAICustomerManager; import org.onap.nbi.apis.serviceorder.workflow.CreateAAIServiceTypeManager; import org.onap.nbi.apis.serviceorder.workflow.SOTaskManager; import org.onap.nbi.commons.JsonRepresentation; +import org.onap.nbi.commons.MultiCriteriaRequestBuilder; import org.onap.nbi.commons.ResourceManagement; import org.onap.nbi.exceptions.ValidationException; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/org/onap/nbi/commons/MultiCriteriaRequestBuilder.java b/src/main/java/org/onap/nbi/commons/MultiCriteriaRequestBuilder.java new file mode 100644 index 0000000..968f1dd --- /dev/null +++ b/src/main/java/org/onap/nbi/commons/MultiCriteriaRequestBuilder.java @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2018 Orange + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.nbi.commons; + +import org.onap.nbi.apis.serviceorder.model.StateType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.MultiValueMap; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +@Service +public class MultiCriteriaRequestBuilder { + + private static final Logger LOGGER = LoggerFactory.getLogger(MultiCriteriaRequestBuilder.class); + + + public Query buildRequest(MultiValueMap params) { + Query query = new Query(); + + List externalIds = params.get("externalId"); + if (!CollectionUtils.isEmpty(externalIds)) { + String externalId = externalIds.get(0); + LOGGER.debug("add criterion externalId {}", externalId); + query.addCriteria(Criteria.where("externalId").is(externalId)); + + } + List states = params.get("state"); + if (!CollectionUtils.isEmpty(states)) { + String state = states.get(0); + LOGGER.debug("add criterion state {}", state); + query.addCriteria(Criteria.where("state").is(StateType.fromValue(state))); + + } + List descriptions = params.get("description"); + if (!CollectionUtils.isEmpty(descriptions)) { + String description = descriptions.get(0); + LOGGER.debug("add criterion description {}", description); + query.addCriteria(Criteria.where("description").is(description)); + + } + List eventTypes = params.get("query.eventType"); + if (!CollectionUtils.isEmpty(eventTypes)) { + Object[] eventType = new String[]{eventTypes.get(0)}; + LOGGER.debug("add criterion query.eventType {}", eventType); + query.addCriteria(Criteria.where("query.eventType").in(eventType)); + + } + List callbacks = params.get("callback"); + if (!CollectionUtils.isEmpty(callbacks)) { + String callback = callbacks.get(0); + LOGGER.debug("add criterion callback {}", callback); + query.addCriteria(Criteria.where("callback").is(callback)); + + } + + handleDate(params, query); + + handleOffsetAndLimit(params, query); + + return query; + } + + private void handleDate(MultiValueMap params, Query query) { + List orderDateLts = params.get("orderDate.lt"); + List orderDateGts = params.get("orderDate.gt"); + if (!CollectionUtils.isEmpty(orderDateLts) || !CollectionUtils.isEmpty(orderDateGts)) { + Criteria orderDateCriteria = Criteria.where("orderDate"); + + if (!CollectionUtils.isEmpty(orderDateLts)) { + String orderDateLt = orderDateLts.get(0); + LOGGER.debug("add criterion orderDate.lt {}", orderDateLt); + orderDateCriteria.lt(convertDate(orderDateLt)); + } + if (!CollectionUtils.isEmpty(orderDateGts)) { + String orderDateGt = orderDateGts.get(0); + LOGGER.debug("add criterion orderDate.gt {}", orderDateGt); + orderDateCriteria.gt(convertDate(orderDateGt)); + } + query.addCriteria(orderDateCriteria); + } + } + + private void handleOffsetAndLimit(MultiValueMap params, Query query) { + List offsets = params.get("offset"); + List limits = params.get("limit"); + if (!CollectionUtils.isEmpty(offsets) && !CollectionUtils.isEmpty(limits)) { + String offsetString = offsets.get(0); + String limitString = limits.get(0); + int offset = Integer.parseInt(offsetString); + int limit = Integer.parseInt(limitString); + final Pageable pageableRequest = new PageRequest(offset, limit); + query.with(pageableRequest); + } else if (!CollectionUtils.isEmpty(limits)) { + String limitString = limits.get(0); + int limit = Integer.parseInt(limitString); + final Pageable pageableRequest = new PageRequest(0, limit); + query.with(pageableRequest); + } + } + + private Date convertDate(String dateString) { + String dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); + try { + return formatter.parse(dateString); + } catch (ParseException e) { + LOGGER.error("unable to convert date " + dateString + ", the pattern is " + dateFormat + " ; " + e); + } + return null; + + } + +} diff --git a/src/main/java/org/onap/nbi/configuration/HubConfig.java b/src/main/java/org/onap/nbi/configuration/HubConfig.java new file mode 100644 index 0000000..9d86dd6 --- /dev/null +++ b/src/main/java/org/onap/nbi/configuration/HubConfig.java @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2018 Orange + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.nbi.configuration; + +import org.onap.nbi.apis.hub.service.CriteriaBuilder; +import org.onap.nbi.apis.hub.service.CriteriaBuilderServiceOrder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class HubConfig { + @Bean + CriteriaBuilder criteriaBuilder() { + return new CriteriaBuilderServiceOrder(); + } +} -- cgit 1.2.3-korg