X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fcrud%2Fservice%2FCrudRestService.java;h=5539374de52b12d9c066634ade3089c0c9740f63;hb=ca46bdfcfb109b856c293862f6ed77fe78eb510f;hp=69f2186f2d65f0b0659e10161f0a01337c04d5d5;hpb=58c89ea1f45ffd4a9f812ae1c18e93b636737f55;p=aai%2Fgizmo.git diff --git a/src/main/java/org/onap/crud/service/CrudRestService.java b/src/main/java/org/onap/crud/service/CrudRestService.java index 69f2186..5539374 100644 --- a/src/main/java/org/onap/crud/service/CrudRestService.java +++ b/src/main/java/org/onap/crud/service/CrudRestService.java @@ -1,16 +1,15 @@ /** * ============LICENSE_START======================================================= - * Gizmo + * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * All rights reserved. + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs * ================================================================================ * 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 + * 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, @@ -18,25 +17,9 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.crud.service; -import com.google.gson.JsonElement; - -import org.apache.cxf.jaxrs.ext.PATCH; -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; -import org.onap.aaiauth.auth.Auth; -import org.onap.crud.exception.CrudException; -import org.onap.crud.logging.CrudServiceMsgs; -import org.onap.crud.logging.LoggingUtil; -import org.onap.crud.util.CrudProperties; -import org.onap.crud.util.CrudServiceConstants; -import org.onap.crud.util.CrudServiceUtil; -import org.slf4j.MDC; - import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.HashMap; @@ -60,7 +43,20 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriInfo; +import org.apache.cxf.jaxrs.ext.PATCH; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; +import org.onap.aaiauth.auth.Auth; +import org.onap.crud.exception.CrudException; +import org.onap.crud.logging.CrudServiceMsgs; +import org.onap.crud.logging.LoggingUtil; +import org.onap.crud.util.CrudProperties; +import org.onap.crud.util.CrudServiceConstants; +import org.onap.crud.util.CrudServiceUtil; +import org.slf4j.MDC; +import com.google.gson.JsonElement; +@Path("/services/inventory") public class CrudRestService { private AbstractGraphDataService graphDataService; @@ -76,6 +72,12 @@ public class CrudRestService { this.auth = new Auth(CrudServiceConstants.CRD_AUTH_FILE); } + // For unit testing + public CrudRestService(AbstractGraphDataService graphDataService, Auth auth) throws Exception { + this.graphDataService = graphDataService; + this.auth = auth; + } + public enum Action { POST, GET, PUT, DELETE, PATCH } @@ -96,10 +98,7 @@ public class CrudRestService { logger.debug("Incoming request..." + content); Response response = null; - Map params = new HashMap(); - for (Map.Entry> e : uriInfo.getQueryParameters().entrySet()) { - params.put(e.getKey(), e.getValue().get(0)); - } + Map params = addParams ( uriInfo, false, type, version ); try { if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) { @@ -134,14 +133,7 @@ public class CrudRestService { try { if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) { String propertiesKey = CrudProperties.get(CrudServiceConstants.CRD_COLLECTION_PROPERTIES_KEY); - - Map filter = new HashMap(); - - for (Map.Entry> e : uriInfo.getQueryParameters().entrySet()) { - if (!e.getKey().equals(propertiesKey)) { - filter.put(e.getKey(), e.getValue().get(0)); - } - } + Map filter = addParams ( uriInfo, true, type, version ); HashSet properties; if (uriInfo.getQueryParameters().containsKey(propertiesKey)) { @@ -178,10 +170,7 @@ public class CrudRestService { logger.debug("Incoming request..." + content); Response response = null; - Map params = new HashMap(); - for (Map.Entry> e : uriInfo.getQueryParameters().entrySet()) { - params.put(e.getKey(), e.getValue().get(0)); - } + Map params = addParams ( uriInfo, false, type, version ); try { if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) { @@ -213,12 +202,7 @@ public class CrudRestService { logger.debug("Incoming request..." + content); Response response = null; - - - Map filter = new HashMap(); - for (Map.Entry> e : uriInfo.getQueryParameters().entrySet()) { - filter.put(e.getKey(), e.getValue().get(0)); - } + Map filter = addParams ( uriInfo, true, type, version ); try { if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) { @@ -826,4 +810,23 @@ public class CrudRestService { // uses our transaction id. MDC.clear(); } + + private Map addParams ( UriInfo info, boolean filter, String type, String version ) { + String propertiesKey = CrudProperties.get ( CrudServiceConstants.CRD_COLLECTION_PROPERTIES_KEY ); + Map params = new HashMap (); + params.put ( CrudServiceConstants.CRD_RESERVED_VERSION, version ); + params.put ( CrudServiceConstants.CRD_RESERVED_NODE_TYPE, type ); + if (filter) { + for (Map.Entry> e : info.getQueryParameters ().entrySet ()) { + if (!e.getKey ().equals ( propertiesKey )) { + params.put ( e.getKey (), e.getValue ().get ( 0 ) ); + } + } + } else { + for (Map.Entry> e : info.getQueryParameters ().entrySet ()) { + params.put ( e.getKey (), e.getValue ().get ( 0 ) ); + } + } + return params; + } }