-/*-\r
- * ============LICENSE_START=======================================================\r
- * SDC\r
- * ================================================================================\r
- * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.openecomp.sdc.be.servlets;\r
-\r
-import java.io.IOException;\r
-import java.util.Set;\r
-import java.util.stream.Collectors;\r
-import javax.inject.Inject;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.ws.rs.Consumes;\r
-import javax.ws.rs.POST;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.core.Context;\r
-import javax.ws.rs.core.MediaType;\r
-import javax.ws.rs.core.Response;\r
-import org.apache.commons.lang3.tuple.ImmutablePair;\r
-import org.onap.sdc.gab.model.GABQuery;\r
-import org.onap.sdc.gab.model.GABQuery.GABQueryType;\r
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;\r
-import org.openecomp.sdc.be.components.impl.GenericArtifactBrowserBusinessLogic;\r
-import org.openecomp.sdc.be.impl.ComponentsUtils;\r
-import org.openecomp.sdc.be.info.GenericArtifactQueryInfo;\r
-import org.openecomp.sdc.be.user.UserBusinessLogic;\r
-import org.openecomp.sdc.common.log.wrappers.Logger;\r
-import org.openecomp.sdc.exception.ResponseFormat;\r
-import org.owasp.esapi.ESAPI;\r
-import org.springframework.stereotype.Controller;\r
-import com.jcabi.aspects.Loggable;\r
-import fj.data.Either;\r
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;\r
-import io.swagger.v3.oas.annotations.Operation;\r
-import io.swagger.v3.oas.annotations.Parameter;\r
-import io.swagger.v3.oas.annotations.info.Info;\r
-import io.swagger.v3.oas.annotations.media.ArraySchema;\r
-import io.swagger.v3.oas.annotations.media.Content;\r
-import io.swagger.v3.oas.annotations.media.Schema;\r
-import io.swagger.v3.oas.annotations.responses.ApiResponse;\r
-import io.swagger.v3.oas.annotations.responses.ApiResponses;\r
-\r
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)\r
-@Path("/v1/catalog/gab")\r
-@Consumes(MediaType.APPLICATION_JSON)\r
-@Produces(MediaType.APPLICATION_JSON)\r
-@OpenAPIDefinition(info = @Info(title = "Generic Artifact Browser"))\r
-@Controller\r
-public class GenericArtifactBrowserServlet extends BeGenericServlet {\r
-\r
- private static final Logger LOGGER = Logger.getLogger(GenericArtifactBrowserServlet.class);\r
- private final GenericArtifactBrowserBusinessLogic gabLogic;\r
- private final ArtifactsBusinessLogic artifactsBusinessLogic;\r
-\r
- @Inject\r
- public GenericArtifactBrowserServlet(UserBusinessLogic userBusinessLogic,\r
- ComponentsUtils componentsUtils,\r
- ArtifactsBusinessLogic artifactsBusinessLogic,\r
- GenericArtifactBrowserBusinessLogic gabLogic) {\r
- super(userBusinessLogic, componentsUtils);\r
- this.artifactsBusinessLogic = artifactsBusinessLogic;\r
- this.gabLogic = gabLogic;\r
- }\r
-\r
- @POST\r
- @Path("/searchFor")\r
- @Operation(description = "Search json paths inside the yaml", method = "POST", summary = "Returns found entries of json paths",responses = @ApiResponse(\r
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
- @ApiResponses(value = {\r
- @ApiResponse(responseCode = "200", description = "Returned yaml entries"),\r
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})\r
- public Response searchFor(\r
- @Parameter(description = "Generic Artifact search model", required = true) GenericArtifactQueryInfo query,\r
- @Context final HttpServletRequest request) {\r
- try {\r
- Either<ImmutablePair<String, byte[]>, ResponseFormat> immutablePairResponseFormatEither = artifactsBusinessLogic\r
- .downloadArtifact(ESAPI.encoder().canonicalize(query.getParentId()), ESAPI.encoder().canonicalize(query.getArtifactUniqueId()));\r
- if (immutablePairResponseFormatEither.isLeft()){\r
- GABQuery gabQuery = prepareGabQuery(query, immutablePairResponseFormatEither);\r
- return buildOkResponse(gabLogic.searchFor(gabQuery));\r
- }else{\r
- throw new IOException(immutablePairResponseFormatEither.right().value().getFormattedMessage());\r
- }\r
- } catch (IOException e) {\r
- LOGGER.error("Cannot search for a given queries in the yaml file", e);\r
- return buildGeneralErrorResponse();\r
- }\r
- }\r
-\r
- private GABQuery prepareGabQuery(GenericArtifactQueryInfo query,\r
- Either<ImmutablePair<String, byte[]>, ResponseFormat> immutablePairResponseFormatEither) {\r
- byte[] content = immutablePairResponseFormatEither.left().value().getRight();\r
- Set<String> queryFields = query.getFields().stream().map(ESAPI.encoder()::canonicalize).collect(Collectors.toSet());\r
- return new GABQuery(queryFields, new String(content), GABQueryType.CONTENT);\r
- }\r
-}\r
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. 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.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.onap.sdc.gab.model.GABQuery;
+import org.onap.sdc.gab.model.GABQuery.GABQueryType;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GenericArtifactBrowserBusinessLogic;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.info.GenericArtifactQueryInfo;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.owasp.esapi.ESAPI;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog/gab")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@OpenAPIDefinition(info = @Info(title = "Generic Artifact Browser"))
+@Controller
+public class GenericArtifactBrowserServlet extends BeGenericServlet {
+
+ private static final Logger LOGGER = Logger.getLogger(GenericArtifactBrowserServlet.class);
+ private final GenericArtifactBrowserBusinessLogic gabLogic;
+ private final ArtifactsBusinessLogic artifactsBusinessLogic;
+
+ @Inject
+ public GenericArtifactBrowserServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ ArtifactsBusinessLogic artifactsBusinessLogic,
+ GenericArtifactBrowserBusinessLogic gabLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.artifactsBusinessLogic = artifactsBusinessLogic;
+ this.gabLogic = gabLogic;
+ }
+
+ @POST
+ @Path("/searchFor")
+ @Operation(description = "Search json paths inside the yaml", method = "POST", summary = "Returns found entries of json paths",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Returned yaml entries"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ public Response searchFor(
+ @Parameter(description = "Generic Artifact search model", required = true) GenericArtifactQueryInfo query,
+ @Context final HttpServletRequest request) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ImmutablePair<String, byte[]> immutablePairResponseFormatEither = getArtifactBL(context)
+ .downloadArtifact(ESAPI.encoder().canonicalize(query.getParentId()), ESAPI.encoder().canonicalize(query.getArtifactUniqueId()));
+ GABQuery gabQuery = prepareGabQuery(query, immutablePairResponseFormatEither);
+ return buildOkResponse(getGenericArtifactBrowserBL(context).searchFor(gabQuery));
+ } catch (IOException e) {
+ LOGGER.error("Cannot search for a given queries in the yaml file", e);
+ return buildGeneralErrorResponse();
+ }
+ }
+
+ private GABQuery prepareGabQuery(GenericArtifactQueryInfo query,
+ ImmutablePair<String, byte[]> immutablePairResponseFormatEither) {
+ byte[] content = immutablePairResponseFormatEither.getRight();
+ Set<String> queryFields = query.getFields().stream().map(ESAPI.encoder()::canonicalize).collect(Collectors.toSet());
+ return new GABQuery(queryFields, new String(content), GABQueryType.CONTENT);
+ }
+
+}