2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.policy.gui.editors.apex.rest.handling.plugin.upload;
22 import javax.ws.rs.client.Client;
23 import javax.ws.rs.client.ClientBuilder;
24 import javax.ws.rs.client.Entity;
25 import javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27 import org.onap.policy.common.parameters.ParameterService;
28 import org.onap.policy.gui.editors.apex.rest.UploadPluginConfigParameters;
31 * Client for the Policy Model upload endpoint.
33 public class UploadPluginClient {
35 private final Client client;
36 private final UploadPluginConfigParameters uploadConfigParam;
39 * Create a upload plugin client.
41 public UploadPluginClient() {
42 this(ClientBuilder.newClient(), ParameterService.get(UploadPluginConfigParameters.GROUP_NAME));
46 * Create a upload plugin client.
47 * @param client the http client
48 * @param uploadConfigParam the upload configuration parameters
50 UploadPluginClient(final Client client,
51 final UploadPluginConfigParameters uploadConfigParam) {
53 this.uploadConfigParam = uploadConfigParam;
57 * Uploads the policy to the configured endpoint.
59 * @param uploadPolicyRequestDto the policy DTO to upload
60 * @return the request response
62 public Response upload(final UploadPolicyRequestDto uploadPolicyRequestDto) {
64 .target(uploadConfigParam.getUrl())
65 .request(MediaType.APPLICATION_JSON)
66 .post(Entity.entity(uploadPolicyRequestDto, MediaType.APPLICATION_JSON));