|
| 1 | +/* |
| 2 | + * Copyright 2022 Conductor Authors. |
| 3 | + * <p> |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 5 | + * the License. You may obtain a copy of the License at |
| 6 | + * <p> |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * <p> |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 10 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | +package io.orkes.conductor.client.http; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +import com.netflix.conductor.client.http.ConductorClient; |
| 18 | +import com.netflix.conductor.client.http.ConductorClientRequest; |
| 19 | +import com.netflix.conductor.client.http.ConductorClientRequest.Method; |
| 20 | +import com.netflix.conductor.client.http.ConductorClientResponse; |
| 21 | +import com.netflix.conductor.common.metadata.SchemaDef; |
| 22 | + |
| 23 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 24 | + |
| 25 | +class SchemaResource { |
| 26 | + |
| 27 | + private final ConductorClient client; |
| 28 | + |
| 29 | + SchemaResource(ConductorClient client) { |
| 30 | + this.client = client; |
| 31 | + } |
| 32 | + |
| 33 | + void saveSchemas(List<SchemaDef> schemaDefs) { |
| 34 | + ConductorClientRequest request = ConductorClientRequest.builder() |
| 35 | + .method(Method.POST) |
| 36 | + .path("/schema") |
| 37 | + .body(schemaDefs) |
| 38 | + .build(); |
| 39 | + client.execute(request); |
| 40 | + } |
| 41 | + |
| 42 | + List<SchemaDef> getAllSchemas(Boolean shortFormat) { |
| 43 | + ConductorClientRequest request = ConductorClientRequest.builder() |
| 44 | + .method(Method.GET) |
| 45 | + .path("/schema") |
| 46 | + .addQueryParam("short", shortFormat) |
| 47 | + .build(); |
| 48 | + ConductorClientResponse<List<SchemaDef>> resp = client.execute(request, new TypeReference<>() {}); |
| 49 | + return resp.getData(); |
| 50 | + } |
| 51 | + |
| 52 | + SchemaDef getSchema(String name) { |
| 53 | + ConductorClientRequest request = ConductorClientRequest.builder() |
| 54 | + .method(Method.GET) |
| 55 | + .path("/schema/{name}") |
| 56 | + .addPathParam("name", name) |
| 57 | + .build(); |
| 58 | + ConductorClientResponse<SchemaDef> resp = client.execute(request, new TypeReference<>() {}); |
| 59 | + return resp.getData(); |
| 60 | + } |
| 61 | + |
| 62 | + SchemaDef getSchema(String name, int version) { |
| 63 | + ConductorClientRequest request = ConductorClientRequest.builder() |
| 64 | + .method(Method.GET) |
| 65 | + .path("/schema/{name}/{version}") |
| 66 | + .addPathParam("name", name) |
| 67 | + .addPathParam("version", version) |
| 68 | + .build(); |
| 69 | + ConductorClientResponse<SchemaDef> resp = client.execute(request, new TypeReference<>() {}); |
| 70 | + return resp.getData(); |
| 71 | + } |
| 72 | + |
| 73 | + void deleteSchema(String name) { |
| 74 | + ConductorClientRequest request = ConductorClientRequest.builder() |
| 75 | + .method(Method.DELETE) |
| 76 | + .path("/schema/{name}") |
| 77 | + .addPathParam("name", name) |
| 78 | + .build(); |
| 79 | + client.execute(request); |
| 80 | + } |
| 81 | + |
| 82 | + void deleteSchema(String name, int version) { |
| 83 | + ConductorClientRequest request = ConductorClientRequest.builder() |
| 84 | + .method(Method.DELETE) |
| 85 | + .path("/schema/{name}/{version}") |
| 86 | + .addPathParam("name", name) |
| 87 | + .addPathParam("version", version) |
| 88 | + .build(); |
| 89 | + client.execute(request); |
| 90 | + } |
| 91 | +} |
0 commit comments