diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-10-22 11:52:17 +0200 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-10-23 08:23:11 +0200 |
commit | ecdcbe8aba5e468693a7f22970064c335881d3b9 (patch) | |
tree | 2c7e4813f3e830c6e85fdfa0b0539efd48ab34e5 | |
parent | ecd6201899fc1f6d0e72bb4951538a3f491a3b1b (diff) |
Introduce ResourcesService
- move controller logic into ResourcesService [0]
[0] http-related classes and fields will be removed from this service,
once changes in the HttpEntry class are done
Issue-ID: AAI-4028
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: I88f7c2a2336f4843cab5814670e60b7119a03faa
7 files changed, 609 insertions, 461 deletions
diff --git a/aai-resources/src/main/java/org/onap/aai/rest/ResourcesController.java b/aai-resources/src/main/java/org/onap/aai/rest/ResourcesController.java index f8d1df8..ade12db 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/ResourcesController.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/ResourcesController.java @@ -22,9 +22,8 @@ package org.onap.aai.rest; import io.micrometer.core.annotation.Timed; +import lombok.RequiredArgsConstructor; -import java.io.UnsupportedEncodingException; -import java.net.URI; import java.security.Principal; import java.util.*; import java.util.stream.Collectors; @@ -35,37 +34,25 @@ import javax.ws.rs.core.*; import javax.ws.rs.core.Response.Status; import org.apache.commons.lang3.ObjectUtils; -import org.javatuples.Pair; import org.keycloak.adapters.springsecurity.account.SimpleKeycloakAccount; import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; import org.onap.aai.concurrent.AaiCallable; -import org.onap.aai.config.SpringContextAware; -import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Introspector; -import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.sideeffect.OwnerCheck; import org.onap.aai.query.builder.Pageable; -import org.onap.aai.parsers.query.QueryParser; -import org.onap.aai.query.builder.QueryOptions; -import org.onap.aai.rest.db.DBRequest; -import org.onap.aai.rest.db.HttpEntry; -import org.onap.aai.rest.exceptions.AAIInvalidXMLNamespace; -import org.onap.aai.rest.util.ValidateEncoding; import org.onap.aai.restcore.HttpMethod; import org.onap.aai.restcore.RESTAPI; -import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.service.ResourcesService; import org.onap.aai.util.AAIConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; @Timed @Controller +@RequiredArgsConstructor @Path("{version: v[1-9][0-9]*|latest}") public class ResourcesController extends RESTAPI { - private static final Logger logger = LoggerFactory.getLogger(ResourcesController.class.getName()); + private final ResourcesService resourcesService; @PUT @Path("/{uri: .+}") @@ -76,7 +63,7 @@ public class ResourcesController extends RESTAPI { @Context HttpServletRequest req) { Set<String> roles = getRoles(req.getUserPrincipal(), req.getMethod()); MediaType mediaType = headers.getMediaType(); - return this.handleWrites(mediaType, HttpMethod.PUT, content, versionParam, uri, headers, info, roles); + return resourcesService.handleWrites(mediaType, HttpMethod.PUT, content, versionParam, uri, headers, info, roles); } @PUT @@ -87,60 +74,7 @@ public class ResourcesController extends RESTAPI { @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) { - String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); - String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); - MediaType inputMediaType = headers.getMediaType(); - Response response; - Loader loader; - TransactionalGraphEngine dbEngine = null; - boolean success = true; - - try { - validateRequest(info); - SchemaVersion version = new SchemaVersion(versionParam); - - HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); - traversalUriHttpEntry.setHttpEntryProperties(version); - loader = traversalUriHttpEntry.getLoader(); - dbEngine = traversalUriHttpEntry.getDbEngine(); - - URI uriObject = UriBuilder.fromPath(uri).build(); - this.validateURI(uriObject); - - QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); - - Introspector wrappedEntity = loader.unmarshal("relationship", content, - org.onap.aai.restcore.MediaType.getEnum(this.getInputMediaType(inputMediaType))); - - DBRequest request = new DBRequest.Builder(HttpMethod.PUT_EDGE, uriObject, uriQuery, wrappedEntity, headers, - info, transId).build(); - List<DBRequest> requests = new ArrayList<>(); - requests.add(request); - Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = - traversalUriHttpEntry.process(requests, sourceOfTruth); - - response = responsesTuple.getValue1().get(0).getValue1(); - success = responsesTuple.getValue0(); - - } catch (AAIException e) { - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.PUT, e); - success = false; - } catch (Exception e) { - AAIException aaiException = new AAIException("AAI_4000", e); - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.PUT, aaiException); - success = false; - } finally { - if (dbEngine != null) { - if (success) { - dbEngine.commit(); - } else { - dbEngine.rollback(); - } - } - - } - - return response; + return resourcesService.updateRelationship(content, versionParam, uri, headers, info); } @PATCH @@ -152,7 +86,7 @@ public class ResourcesController extends RESTAPI { @Context HttpServletRequest req) { Set<String> roles = getRoles(req.getUserPrincipal(), req.getMethod()); MediaType mediaType = MediaType.APPLICATION_JSON_TYPE; - return this.handleWrites(mediaType, HttpMethod.MERGE_PATCH, content, versionParam, uri, headers, info, roles); + return resourcesService.handleWrites(mediaType, HttpMethod.MERGE_PATCH, content, versionParam, uri, headers, info, roles); } @@ -197,164 +131,20 @@ public class ResourcesController extends RESTAPI { AAIConstants.AAI_CRUD_TIMEOUT_LIMIT, headers, info, HttpMethod.GET, new AaiCallable<Response>() { @Override public Response process() { - return getLegacy(versionParam, uri, depthParam, cleanUp, headers, info, req, + return resourcesService.getLegacy(versionParam, uri, depthParam, cleanUp, headers, info, req, new HashSet<String>(), pageable, roles); } }); } - /** - * This method exists as a workaround for filtering out undesired query params while routing between REST consumers - */ - public Response getLegacy(String versionParam, String uri, String depthParam, String cleanUp, - HttpHeaders headers, UriInfo info, HttpServletRequest req, Set<String> removeQueryParams, - Pageable pageable, Set<String> roles) { - String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); - String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); - Response response; - TransactionalGraphEngine dbEngine = null; - Loader loader; - - try { - validateRequest(info); - SchemaVersion version = new SchemaVersion(versionParam); - - final HttpEntry traversalUriHttpEntry = - SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); - String serverBase = req.getRequestURL().toString().replaceAll("/(v[0-9]+|latest)/.*", "/"); - traversalUriHttpEntry.setHttpEntryProperties(version, serverBase); - dbEngine = traversalUriHttpEntry.getDbEngine(); - loader = traversalUriHttpEntry.getLoader(); - MultivaluedMap<String, String> params = info.getQueryParameters(); - - params = removeNonFilterableParams(params); - - uri = uri.split("\\?")[0]; - - URI uriObject = UriBuilder.fromPath(uri).build(); - - QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject, params); - - String objType = ""; - if (!uriQuery.getContainerType().equals("")) { - objType = uriQuery.getContainerType(); - } else { - objType = uriQuery.getResultType(); - } - Introspector obj = loader.introspectorFromName(objType); - DBRequest request = - new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, headers, info, transId).build(); - List<DBRequest> requests = Collections.singletonList(request); - - Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = null; - if (hasValidPaginationParams(pageable)) { - responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth, roles, true, new QueryOptions(pageable)); - } else { - responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth, roles); - } - - response = responsesTuple.getValue1().get(0).getValue1(); - - } catch (AAIException e) { - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, e); - } catch (Exception e) { - AAIException ex = new AAIException("AAI_4000", e); - - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, ex); - } finally { - if (dbEngine != null) { - if (cleanUp.equals("true")) { - dbEngine.commit(); - } else { - dbEngine.rollback(); - } - } - } - - return response; - } - - private boolean hasValidPaginationParams(Pageable pageable) { - return pageable.getPage() >= 0 && pageable.getPageSize() > 0; - } - - private MultivaluedMap<String, String> removeNonFilterableParams(MultivaluedMap<String, String> params) { - - String[] toRemove = - {"depth", "cleanup", "nodes-only", "format", "resultIndex", "resultSize", "includeTotalCount", "skip-related-to"}; - Set<String> toRemoveSet = Arrays.stream(toRemove).collect(Collectors.toSet()); - - MultivaluedMap<String, String> cleanedParams = new MultivaluedHashMap<>(); - params.keySet().forEach(k -> { - if (!toRemoveSet.contains(k)) { - cleanedParams.addAll(k, params.get(k)); - } - }); - - return cleanedParams; - } - @DELETE @Path("/{uri: .+}") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response delete(@PathParam("version") String versionParam, @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, @Context UriInfo info, @QueryParam("resource-version") String resourceVersion, @Context HttpServletRequest req) { - Set<String> roles = getRoles(req.getUserPrincipal(), req.getMethod()); - String outputMediaType = getMediaType(headers.getAcceptableMediaTypes()); - String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); - String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); - - TransactionalGraphEngine dbEngine = null; - Response response; - - boolean success = true; - - try { - - validateRequest(info); - SchemaVersion version = new SchemaVersion(versionParam); - - HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); - traversalUriHttpEntry.setHttpEntryProperties(version); - dbEngine = traversalUriHttpEntry.getDbEngine(); - Loader loader = traversalUriHttpEntry.getLoader(); - - URI uriObject = UriBuilder.fromPath(uri).build(); - - QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); - String objType = uriQuery.getResultType(); - Introspector obj = loader.introspectorFromName(objType); - - DBRequest request = - new DBRequest.Builder(HttpMethod.DELETE, uriObject, uriQuery, obj, headers, info, transId).build(); - List<DBRequest> requests = new ArrayList<>(); - requests.add(request); - Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = - traversalUriHttpEntry.process(requests, sourceOfTruth, roles); - - response = responsesTuple.getValue1().get(0).getValue1(); - success = responsesTuple.getValue0(); - - } catch (AAIException e) { - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.DELETE, e); - success = false; - } catch (Exception e) { - AAIException ex = new AAIException("AAI_4000", e); - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.DELETE, ex); - success = false; - } finally { - if (dbEngine != null) { - if (success) { - dbEngine.commit(); - } else { - dbEngine.rollback(); - } - } - } - - return response; + return resourcesService.delete(versionParam, uri, headers, info, req, roles); } /** @@ -376,62 +166,7 @@ public class ResourcesController extends RESTAPI { @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) { - MediaType inputMediaType = headers.getMediaType(); - String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); - String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); - Loader loader; - TransactionalGraphEngine dbEngine = null; - Response response; - - boolean success = true; - - try { - this.validateRequest(info); - SchemaVersion version = new SchemaVersion(versionParam); - - HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); - traversalUriHttpEntry.setHttpEntryProperties(version); - loader = traversalUriHttpEntry.getLoader(); - dbEngine = traversalUriHttpEntry.getDbEngine(); - - if (content.equals("")) { - throw new AAIException("AAI_3102", "You must supply a relationship"); - } - URI uriObject = UriBuilder.fromPath(uri).build(); - this.validateURI(uriObject); - - QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); - - Introspector wrappedEntity = loader.unmarshal("relationship", content, - org.onap.aai.restcore.MediaType.getEnum(this.getInputMediaType(inputMediaType))); - - DBRequest request = new DBRequest.Builder(HttpMethod.DELETE_EDGE, uriObject, uriQuery, wrappedEntity, - headers, info, transId).build(); - List<DBRequest> requests = new ArrayList<>(); - requests.add(request); - Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = - traversalUriHttpEntry.process(requests, sourceOfTruth); - - response = responsesTuple.getValue1().get(0).getValue1(); - success = responsesTuple.getValue0(); - } catch (AAIException e) { - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.DELETE, e); - success = false; - } catch (Exception e) { - AAIException ex = new AAIException("AAI_4000", e); - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.DELETE, ex); - success = false; - } finally { - if (dbEngine != null) { - if (success) { - dbEngine.commit(); - } else { - dbEngine.rollback(); - } - } - } - - return response; + return resourcesService.deleteRelationship(content, versionParam, uri, headers, info); } @GET @@ -455,187 +190,11 @@ public class ResourcesController extends RESTAPI { AAIConstants.AAI_CRUD_TIMEOUT_LIMIT, headers, info, HttpMethod.GET, new AaiCallable<Response>() { @Override public Response process() { - return getRelationshipList(versionParam, req, uri, cleanUp, headers, info, pageable); + return resourcesService.getRelationshipList(versionParam, req, uri, cleanUp, headers, info, pageable); } }); } - public Response getRelationshipList(String versionParam, HttpServletRequest req, String uri, String cleanUp, - HttpHeaders headers, UriInfo info, Pageable pageable) { - String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); - String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); - Response response = null; - TransactionalGraphEngine dbEngine = null; - Loader loader = null; - - try { - validateRequest(info); - SchemaVersion version = new SchemaVersion(versionParam); - - final HttpEntry traversalUriHttpEntry = - SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); - String serverBase = req.getRequestURL().toString().replaceAll("/(v[0-9]+|latest)/.*", "/"); - traversalUriHttpEntry.setHttpEntryProperties(version, serverBase); - dbEngine = traversalUriHttpEntry.getDbEngine(); - loader = traversalUriHttpEntry.getLoader(); - MultivaluedMap<String, String> params = info.getQueryParameters(); - - params = removeNonFilterableParams(params); - - uri = uri.split("\\?")[0]; - - URI uriObject = UriBuilder.fromPath(uri).build(); - - QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject, params); - - String objType = ""; - if (!uriQuery.getContainerType().equals("")) { - objType = uriQuery.getContainerType(); - } else { - objType = uriQuery.getResultType(); - } - Introspector obj = loader.introspectorFromName(objType); - DBRequest request = - new DBRequest.Builder(HttpMethod.GET_RELATIONSHIP, uriObject, uriQuery, obj, headers, info, transId) - .build(); - List<DBRequest> requests = new ArrayList<>(); - requests.add(request); - - Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = null; - if (hasValidPaginationParams(pageable)) { - responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth, Collections.emptySet(), true, new QueryOptions(pageable)); - } else { - responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth); - } - response = responsesTuple.getValue1().get(0).getValue1(); - } catch (AAIException e) { - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET_RELATIONSHIP, e); - } catch (Exception e) { - AAIException ex = new AAIException("AAI_4000", e); - - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET_RELATIONSHIP, ex); - } finally { - if (dbEngine != null) { - if (cleanUp.equals("true")) { - dbEngine.commit(); - } else { - dbEngine.rollback(); - } - } - } - return response; - } - - private void validateRequest(UriInfo info) throws AAIException, UnsupportedEncodingException { - - if (!ValidateEncoding.getInstance().validate(info)) { - throw new AAIException("AAI_3008", "uri=" + getPath(info)); - } - } - - private String getPath(UriInfo info) { - String path = info.getPath(false); - MultivaluedMap<String, String> map = info.getQueryParameters(false); - String params = "?"; - List<String> parmList = new ArrayList<>(); - for (String key : map.keySet()) { - for (String value : map.get(key)) { - parmList.add(key + "=" + value); - } - } - String queryParams = String.join("&", parmList); - if (!map.isEmpty()) { - path += params + queryParams; - } - - return path; - - } - - private Response handleWrites(MediaType mediaType, HttpMethod method, String content, String versionParam, - String uri, HttpHeaders headers, UriInfo info, Set<String> roles) { - - Response response; - TransactionalGraphEngine dbEngine = null; - Loader loader; - SchemaVersion version; - String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); - String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); - boolean success = true; - - try { - validateRequest(info); - - version = new SchemaVersion(versionParam); - - HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); - traversalUriHttpEntry.setHttpEntryProperties(version); - loader = traversalUriHttpEntry.getLoader(); - dbEngine = traversalUriHttpEntry.getDbEngine(); - URI uriObject = UriBuilder.fromPath(uri).build(); - this.validateURI(uriObject); - QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); - String objName = uriQuery.getResultType(); - if (content.length() == 0) { - if (mediaType.toString().contains(MediaType.APPLICATION_JSON)) { - content = "{}"; - } else { - content = "<empty/>"; - } - } - Introspector obj = loader.unmarshal(objName, content, - org.onap.aai.restcore.MediaType.getEnum(this.getInputMediaType(mediaType))); - if (obj == null) { - throw new AAIException("AAI_3000", "object could not be unmarshalled:" + content); - } - - if (mediaType.toString().contains(MediaType.APPLICATION_XML) && !content.equals("<empty/>") - && isEmptyObject(obj)) { - throw new AAIInvalidXMLNamespace(content); - } - - this.validateIntrospector(obj, loader, uriObject, method); - - DBRequest request = new DBRequest.Builder(method, uriObject, uriQuery, obj, headers, info, transId) - .rawRequestContent(content).build(); - List<DBRequest> requests = new ArrayList<>(); - requests.add(request); - Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = - traversalUriHttpEntry.process(requests, sourceOfTruth, roles); - - response = responsesTuple.getValue1().get(0).getValue1(); - success = responsesTuple.getValue0(); - } catch (AAIException e) { - response = consumerExceptionResponseGenerator(headers, info, method, e); - success = false; - } catch (Exception e) { - AAIException ex = new AAIException("AAI_4000", e); - response = consumerExceptionResponseGenerator(headers, info, method, ex); - success = false; - } finally { - if (dbEngine != null) { - if (success) { - dbEngine.commit(); - } else { - dbEngine.rollback(); - } - } - } - - return response; - } - - private void validateURI(URI uri) throws AAIException { - if (hasRelatedTo(uri)) { - throw new AAIException("AAI_3010"); - } - } - - private boolean hasRelatedTo(URI uri) { - - return uri.toString().contains("/" + RestTokens.COUSIN + "/"); - } - protected boolean isEmptyObject(Introspector obj) { return "{}".equals(obj.marshal(false)); } @@ -643,11 +202,11 @@ public class ResourcesController extends RESTAPI { private Set<String> getRoles(Principal userPrincipal, String method) { KeycloakAuthenticationToken token = (KeycloakAuthenticationToken) userPrincipal; if (ObjectUtils.isEmpty(token)) { - return Collections.EMPTY_SET; + return Collections.emptySet(); } SimpleKeycloakAccount account = (SimpleKeycloakAccount) token.getDetails(); if (ObjectUtils.isEmpty(account)) { - return Collections.EMPTY_SET; + return Collections.emptySet(); } // When the request is not a GET, we need to exclude ReadOnly access roles if (isNotGetRequest(method)) { diff --git a/aai-resources/src/main/java/org/onap/aai/service/ResourcesService.java b/aai-resources/src/main/java/org/onap/aai/service/ResourcesService.java new file mode 100644 index 0000000..da326a0 --- /dev/null +++ b/aai-resources/src/main/java/org/onap/aai/service/ResourcesService.java @@ -0,0 +1,585 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2024 Deutsche Telekom. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.service; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import org.javatuples.Pair; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.introspection.Introspector; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.tools.CreateUUID; +import org.onap.aai.introspection.tools.DefaultFields; +import org.onap.aai.introspection.tools.InjectKeysFromURI; +import org.onap.aai.introspection.tools.IntrospectorValidator; +import org.onap.aai.introspection.tools.Issue; +import org.onap.aai.introspection.tools.RemoveNonVisibleProperty; +import org.onap.aai.logging.ErrorLogHelper; +import org.onap.aai.parsers.query.QueryParser; +import org.onap.aai.query.builder.Pageable; +import org.onap.aai.query.builder.QueryOptions; +import org.onap.aai.rest.RestTokens; +import org.onap.aai.rest.db.DBRequest; +import org.onap.aai.rest.db.HttpEntry; +import org.onap.aai.rest.exceptions.AAIInvalidXMLNamespace; +import org.onap.aai.rest.util.ValidateEncoding; +import org.onap.aai.restcore.HttpMethod; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.onap.aai.setup.SchemaVersion; +import org.springframework.stereotype.Service; + +@Service +public class ResourcesService { + + /** + * This method exists as a workaround for filtering out undesired query params + * while routing between REST consumers + */ + public Response getLegacy(String versionParam, String uri, String depthParam, String cleanUp, + HttpHeaders headers, UriInfo info, HttpServletRequest req, Set<String> removeQueryParams, + Pageable pageable, Set<String> roles) { + String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); + String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); + Response response; + TransactionalGraphEngine dbEngine = null; + Loader loader; + + try { + validateRequest(info); + SchemaVersion version = new SchemaVersion(versionParam); + + final HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); + String serverBase = req.getRequestURL().toString().replaceAll("/(v[0-9]+|latest)/.*", "/"); + traversalUriHttpEntry.setHttpEntryProperties(version, serverBase); + dbEngine = traversalUriHttpEntry.getDbEngine(); + loader = traversalUriHttpEntry.getLoader(); + MultivaluedMap<String, String> params = info.getQueryParameters(); + + params = removeNonFilterableParams(params); + + uri = uri.split("\\?")[0]; + + URI uriObject = UriBuilder.fromPath(uri).build(); + + QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject, params); + + String objType = ""; + if (!uriQuery.getContainerType().equals("")) { + objType = uriQuery.getContainerType(); + } else { + objType = uriQuery.getResultType(); + } + Introspector obj = loader.introspectorFromName(objType); + DBRequest request = new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, headers, info, transId) + .build(); + List<DBRequest> requests = Collections.singletonList(request); + + Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = null; + if (hasValidPaginationParams(pageable)) { + responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth, roles, true, + new QueryOptions(pageable)); + } else { + responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth, roles); + } + + response = responsesTuple.getValue1().get(0).getValue1(); + + } catch (AAIException e) { + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, e); + } catch (Exception e) { + AAIException ex = new AAIException("AAI_4000", e); + + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, ex); + } finally { + if (dbEngine != null) { + if (cleanUp.equals("true")) { + dbEngine.commit(); + } else { + dbEngine.rollback(); + } + } + } + + return response; + } + + public Response updateRelationship(String content, String versionParam, String uri, HttpHeaders headers, + UriInfo info) { + String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); + String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); + MediaType inputMediaType = headers.getMediaType(); + Response response; + Loader loader; + TransactionalGraphEngine dbEngine = null; + boolean success = true; + + try { + validateRequest(info); + SchemaVersion version = new SchemaVersion(versionParam); + + HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); + traversalUriHttpEntry.setHttpEntryProperties(version); + loader = traversalUriHttpEntry.getLoader(); + dbEngine = traversalUriHttpEntry.getDbEngine(); + + URI uriObject = UriBuilder.fromPath(uri).build(); + validateURI(uriObject); + + QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); + + Introspector wrappedEntity = loader.unmarshal("relationship", content, + org.onap.aai.restcore.MediaType.getEnum(this.getInputMediaType(inputMediaType))); + + DBRequest request = new DBRequest.Builder(HttpMethod.PUT_EDGE, uriObject, uriQuery, wrappedEntity, headers, + info, transId).build(); + List<DBRequest> requests = new ArrayList<>(); + requests.add(request); + Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth); + + response = responsesTuple.getValue1().get(0).getValue1(); + success = responsesTuple.getValue0(); + + } catch (AAIException e) { + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.PUT, e); + success = false; + } catch (Exception e) { + AAIException aaiException = new AAIException("AAI_4000", e); + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.PUT, aaiException); + success = false; + } finally { + if (dbEngine != null) { + if (success) { + dbEngine.commit(); + } else { + dbEngine.rollback(); + } + } + + } + + return response; + } + + public Response handleWrites(MediaType mediaType, HttpMethod method, String content, String versionParam, + String uri, HttpHeaders headers, UriInfo info, Set<String> roles) { + + Response response; + TransactionalGraphEngine dbEngine = null; + Loader loader; + SchemaVersion version; + String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); + String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); + boolean success = true; + + try { + validateRequest(info); + + version = new SchemaVersion(versionParam); + + HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); + traversalUriHttpEntry.setHttpEntryProperties(version); + loader = traversalUriHttpEntry.getLoader(); + dbEngine = traversalUriHttpEntry.getDbEngine(); + URI uriObject = UriBuilder.fromPath(uri).build(); + this.validateURI(uriObject); + QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); + String objName = uriQuery.getResultType(); + if (content.length() == 0) { + if (mediaType.toString().contains(MediaType.APPLICATION_JSON)) { + content = "{}"; + } else { + content = "<empty/>"; + } + } + Introspector obj = loader.unmarshal(objName, content, + org.onap.aai.restcore.MediaType.getEnum(this.getInputMediaType(mediaType))); + if (obj == null) { + throw new AAIException("AAI_3000", "object could not be unmarshalled:" + content); + } + + if (mediaType.toString().contains(MediaType.APPLICATION_XML) && !content.equals("<empty/>") + && isEmptyObject(obj)) { + throw new AAIInvalidXMLNamespace(content); + } + + validateIntrospector(obj, loader, uriObject, method); + + DBRequest request = new DBRequest.Builder(method, uriObject, uriQuery, obj, headers, info, transId) + .rawRequestContent(content).build(); + List<DBRequest> requests = new ArrayList<>(); + requests.add(request); + Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth, + roles); + + response = responsesTuple.getValue1().get(0).getValue1(); + success = responsesTuple.getValue0(); + } catch (AAIException e) { + response = consumerExceptionResponseGenerator(headers, info, method, e); + success = false; + } catch (Exception e) { + AAIException ex = new AAIException("AAI_4000", e); + response = consumerExceptionResponseGenerator(headers, info, method, ex); + success = false; + } finally { + if (dbEngine != null) { + if (success) { + dbEngine.commit(); + } else { + dbEngine.rollback(); + } + } + } + + return response; + } + + public Response deleteRelationship(String content, String versionParam, String uri, HttpHeaders headers, + UriInfo info) { + MediaType inputMediaType = headers.getMediaType(); + String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); + String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); + Loader loader; + TransactionalGraphEngine dbEngine = null; + Response response; + + boolean success = true; + + try { + this.validateRequest(info); + SchemaVersion version = new SchemaVersion(versionParam); + + HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); + traversalUriHttpEntry.setHttpEntryProperties(version); + loader = traversalUriHttpEntry.getLoader(); + dbEngine = traversalUriHttpEntry.getDbEngine(); + + if (content.equals("")) { + throw new AAIException("AAI_3102", "You must supply a relationship"); + } + URI uriObject = UriBuilder.fromPath(uri).build(); + this.validateURI(uriObject); + + QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); + + Introspector wrappedEntity = loader.unmarshal("relationship", content, + org.onap.aai.restcore.MediaType.getEnum(this.getInputMediaType(inputMediaType))); + + DBRequest request = new DBRequest.Builder(HttpMethod.DELETE_EDGE, uriObject, uriQuery, wrappedEntity, + headers, info, transId).build(); + List<DBRequest> requests = new ArrayList<>(); + requests.add(request); + Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth); + + response = responsesTuple.getValue1().get(0).getValue1(); + success = responsesTuple.getValue0(); + } catch (AAIException e) { + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.DELETE, e); + success = false; + } catch (Exception e) { + AAIException ex = new AAIException("AAI_4000", e); + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.DELETE, ex); + success = false; + } finally { + if (dbEngine != null) { + if (success) { + dbEngine.commit(); + } else { + dbEngine.rollback(); + } + } + } + + return response; + } + + public Response getRelationshipList(String versionParam, HttpServletRequest req, String uri, String cleanUp, + HttpHeaders headers, UriInfo info, Pageable pageable) { + String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); + String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); + Response response = null; + TransactionalGraphEngine dbEngine = null; + Loader loader = null; + + try { + validateRequest(info); + SchemaVersion version = new SchemaVersion(versionParam); + + final HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); + String serverBase = req.getRequestURL().toString().replaceAll("/(v[0-9]+|latest)/.*", "/"); + traversalUriHttpEntry.setHttpEntryProperties(version, serverBase); + dbEngine = traversalUriHttpEntry.getDbEngine(); + loader = traversalUriHttpEntry.getLoader(); + MultivaluedMap<String, String> params = info.getQueryParameters(); + + params = removeNonFilterableParams(params); + + uri = uri.split("\\?")[0]; + + URI uriObject = UriBuilder.fromPath(uri).build(); + + QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject, params); + + String objType = ""; + if (!uriQuery.getContainerType().equals("")) { + objType = uriQuery.getContainerType(); + } else { + objType = uriQuery.getResultType(); + } + Introspector obj = loader.introspectorFromName(objType); + DBRequest request = new DBRequest.Builder(HttpMethod.GET_RELATIONSHIP, uriObject, uriQuery, obj, headers, info, + transId) + .build(); + List<DBRequest> requests = new ArrayList<>(); + requests.add(request); + + Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = null; + if (hasValidPaginationParams(pageable)) { + responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth, Collections.emptySet(), true, + new QueryOptions(pageable)); + } else { + responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth); + } + response = responsesTuple.getValue1().get(0).getValue1(); + } catch (AAIException e) { + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET_RELATIONSHIP, e); + } catch (Exception e) { + AAIException ex = new AAIException("AAI_4000", e); + + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET_RELATIONSHIP, ex); + } finally { + if (dbEngine != null) { + if (cleanUp.equals("true")) { + dbEngine.commit(); + } else { + dbEngine.rollback(); + } + } + } + return response; + } + + public Response delete(String versionParam, String uri, HttpHeaders headers, UriInfo info, + HttpServletRequest req, Set<String> roles) { + + String outputMediaType = getMediaType(headers.getAcceptableMediaTypes()); + String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); + String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); + + TransactionalGraphEngine dbEngine = null; + Response response; + + boolean success = true; + + try { + + validateRequest(info); + SchemaVersion version = new SchemaVersion(versionParam); + + HttpEntry traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); + traversalUriHttpEntry.setHttpEntryProperties(version); + dbEngine = traversalUriHttpEntry.getDbEngine(); + Loader loader = traversalUriHttpEntry.getLoader(); + + URI uriObject = UriBuilder.fromPath(uri).build(); + + QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); + String objType = uriQuery.getResultType(); + Introspector obj = loader.introspectorFromName(objType); + + DBRequest request = new DBRequest.Builder(HttpMethod.DELETE, uriObject, uriQuery, obj, headers, info, transId) + .build(); + List<DBRequest> requests = new ArrayList<>(); + requests.add(request); + Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalUriHttpEntry.process(requests, sourceOfTruth, + roles); + + response = responsesTuple.getValue1().get(0).getValue1(); + success = responsesTuple.getValue0(); + + } catch (AAIException e) { + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.DELETE, e); + success = false; + } catch (Exception e) { + AAIException ex = new AAIException("AAI_4000", e); + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.DELETE, ex); + success = false; + } finally { + if (dbEngine != null) { + if (success) { + dbEngine.commit(); + } else { + dbEngine.rollback(); + } + } + } + + return response; + } + + private String getMediaType(List<MediaType> mediaTypeList) { + String mediaType = "application/json"; + Iterator<MediaType> mediaTypes = mediaTypeList.iterator(); + + while(mediaTypes.hasNext()) { + if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaTypes.next())) { + mediaType = "application/xml"; + } + } + + return mediaType; + } + + private boolean hasValidPaginationParams(Pageable pageable) { + return pageable.getPage() >= 0 && pageable.getPageSize() > 0; + } + + private MultivaluedMap<String, String> removeNonFilterableParams(MultivaluedMap<String, String> params) { + + String[] toRemove = { "depth", "cleanup", "nodes-only", "format", "resultIndex", "resultSize", "includeTotalCount", + "skip-related-to" }; + Set<String> toRemoveSet = Arrays.stream(toRemove).collect(Collectors.toSet()); + + MultivaluedMap<String, String> cleanedParams = new MultivaluedHashMap<>(); + params.keySet().forEach(k -> { + if (!toRemoveSet.contains(k)) { + cleanedParams.addAll(k, params.get(k)); + } + }); + + return cleanedParams; + } + + private void validateURI(URI uri) throws AAIException { + if (hasRelatedTo(uri)) { + throw new AAIException("AAI_3010"); + } + } + + private boolean hasRelatedTo(URI uri) { + + return uri.toString().contains("/" + RestTokens.COUSIN + "/"); + } + + private void validateRequest(UriInfo info) throws AAIException, UnsupportedEncodingException { + + if (!ValidateEncoding.getInstance().validate(info)) { + throw new AAIException("AAI_3008", "uri=" + getPath(info)); + } + } + + private void validateIntrospector(Introspector obj, Loader loader, URI uri, HttpMethod method) + throws AAIException, UnsupportedEncodingException { + int maximumDepth = AAIProperties.MAXIMUM_DEPTH; + boolean validateRequired = true; + if (method.equals(HttpMethod.MERGE_PATCH)) { + validateRequired = false; + maximumDepth = 0; + } + + IntrospectorValidator validator = (new IntrospectorValidator.Builder()).validateRequired(validateRequired) + .restrictDepth(maximumDepth).addResolver(new RemoveNonVisibleProperty()).addResolver(new CreateUUID()) + .addResolver(new DefaultFields()).addResolver(new InjectKeysFromURI(loader, uri)).build(); + boolean result = validator.validate(obj); + if (!result) { + result = validator.resolveIssues(); + } + + String errors; + if (!result) { + List<String> messages = new ArrayList<>(); + Iterator<Issue> issues = validator.getIssues().iterator(); + + while (issues.hasNext()) { + Issue issue = (Issue) issues.next(); + if (!issue.isResolved()) { + messages.add(issue.getDetail()); + } + } + + errors = String.join(",", messages); + throw new AAIException("AAI_3000", errors); + } else { + String objURI = obj.getURI(); + errors = "/" + uri.getRawPath(); + if (!errors.endsWith(objURI)) { + throw new AAIException("AAI_3000", "uri and payload keys don't match"); + } + } + } + + private String getPath(UriInfo info) { + String path = info.getPath(false); + MultivaluedMap<String, String> map = info.getQueryParameters(false); + String params = "?"; + List<String> parmList = new ArrayList<>(); + for (String key : map.keySet()) { + for (String value : map.get(key)) { + parmList.add(key + "=" + value); + } + } + String queryParams = String.join("&", parmList); + if (!map.isEmpty()) { + path += params + queryParams; + } + + return path; + } + + protected String getInputMediaType(MediaType mediaType) { + String type = mediaType.getType(); + return type + "/" + mediaType.getSubtype(); + } + + private Response consumerExceptionResponseGenerator(HttpHeaders headers, UriInfo info, HttpMethod templateAction, + AAIException e) { + ArrayList<String> templateVars = new ArrayList<>(); + templateVars.add(templateAction.toString()); + templateVars.add(info.getPath()); + templateVars.addAll(e.getTemplateVars()); + ErrorLogHelper.logException(e); + return Response.status(e.getErrorObject().getHTTPResponseCode()) + .entity(ErrorLogHelper.getRESTAPIErrorResponseWithLogging(headers.getAcceptableMediaTypes(), e, templateVars)) + .build(); + } + + protected boolean isEmptyObject(Introspector obj) { + return "{}".equals(obj.marshal(false)); + } + +} diff --git a/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessConsumerTest.java index 772ee70..4bab61d 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessConsumerTest.java @@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils; import org.json.JSONException; import org.junit.jupiter.api.Test; import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.service.ResourcesService; import org.skyscreamer.jsonassert.JSONAssert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -117,7 +118,7 @@ public class BulkProcessConsumerTest extends BulkProcessorTestAbstraction { @Test public void testBulkDeletePserverAndComplexRelationship() throws IOException, JSONException { - resourcesController = new ResourcesController(); + resourcesController = new ResourcesController(new ResourcesService()); String pserverData = getPayload("payloads/relationship/pserver-bugfix.json"); String complexData = getPayload("payloads/relationship/complex-bugfix.json"); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ExampleConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ExampleConsumerTest.java index 67d7bc5..fbdfd5b 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ExampleConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ExampleConsumerTest.java @@ -71,7 +71,7 @@ public class ExampleConsumerTest extends AAISetup { private List<MediaType> outputMediaTypes; - private static final Logger logger = LoggerFactory.getLogger(ResourcesController.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(ResourcesControllerTest.class.getName()); @BeforeEach public void setup() { diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ResourcesControllerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ResourcesControllerTest.java index 74ee9e4..3b729e7 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ResourcesControllerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ResourcesControllerTest.java @@ -67,6 +67,7 @@ import org.onap.aai.dbmap.AAIGraph; import org.onap.aai.entities.PServer; import org.onap.aai.entities.PServerListResponse; import org.onap.aai.exceptions.AAIException; +import org.onap.aai.service.ResourcesService; import org.onap.aai.setup.SchemaVersions; import org.onap.aai.util.AAIConfig; import org.onap.aai.util.AAIConstants; @@ -117,7 +118,7 @@ public class ResourcesControllerTest { } logger.info("Starting the setup for the integration tests of Rest Endpoints"); - resourcesController = new ResourcesController(); + resourcesController = new ResourcesController(new ResourcesService()); httpHeaders = Mockito.mock(HttpHeaders.class); uriInfo = Mockito.mock(UriInfo.class); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/URLFromVertexIdConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/URLFromVertexIdConsumerTest.java index 98f2f93..c29a186 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/URLFromVertexIdConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/URLFromVertexIdConsumerTest.java @@ -47,6 +47,7 @@ import org.mockito.Mockito; import org.onap.aai.AAISetup; import org.onap.aai.dbmap.AAIGraph; import org.onap.aai.exceptions.AAIException; +import org.onap.aai.service.ResourcesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.mock.web.MockHttpServletRequest; @@ -77,7 +78,7 @@ public class URLFromVertexIdConsumerTest extends AAISetup { private List<MediaType> outputMediaTypes; - private static final Logger logger = LoggerFactory.getLogger(ResourcesController.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(ResourcesControllerTest.class.getName()); @BeforeEach public void setup() { @@ -87,7 +88,7 @@ public class URLFromVertexIdConsumerTest extends AAISetup { logger.info("Starting the setup for the integration tests of Rest Endpoints"); urlFromVertexIdConsumer = new URLFromVertexIdConsumer(); - resourcesController = new ResourcesController(); + resourcesController = new ResourcesController(new ResourcesService()); httpHeaders = Mockito.mock(HttpHeaders.class); uriInfo = Mockito.mock(UriInfo.class); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/VertexIdConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/VertexIdConsumerTest.java index 7710c0f..c7a9bdd 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/VertexIdConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/VertexIdConsumerTest.java @@ -47,6 +47,7 @@ import org.mockito.Mockito; import org.onap.aai.AAISetup; import org.onap.aai.dbmap.AAIGraph; import org.onap.aai.exceptions.AAIException; +import org.onap.aai.service.ResourcesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.mock.web.MockHttpServletRequest; @@ -77,7 +78,7 @@ public class VertexIdConsumerTest extends AAISetup { private List<MediaType> outputMediaTypes; - private static final Logger logger = LoggerFactory.getLogger(ResourcesController.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(ResourcesControllerTest.class.getName()); @BeforeEach public void setup() { @@ -87,7 +88,7 @@ public class VertexIdConsumerTest extends AAISetup { logger.info("Starting the setup for the integration tests of Rest Endpoints"); vertexIdConsumer = new VertexIdConsumer(); - resourcesController = new ResourcesController(); + resourcesController = new ResourcesController(new ResourcesService()); httpHeaders = Mockito.mock(HttpHeaders.class); uriInfo = Mockito.mock(UriInfo.class); |