|
| 1 | +/* |
| 2 | + * Copyright 2013-2020 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 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. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.cloudfoundry.reactor.client.v3.domains; |
| 18 | + |
| 19 | +import org.cloudfoundry.client.v3.domains.CreateDomainRequest; |
| 20 | +import org.cloudfoundry.client.v3.domains.CreateDomainResponse; |
| 21 | +import org.cloudfoundry.client.v3.domains.DeleteDomainRequest; |
| 22 | +import org.cloudfoundry.client.v3.domains.DomainsV3; |
| 23 | +import org.cloudfoundry.client.v3.domains.GetDomainRequest; |
| 24 | +import org.cloudfoundry.client.v3.domains.GetDomainResponse; |
| 25 | +import org.cloudfoundry.client.v3.domains.ListDomainsRequest; |
| 26 | +import org.cloudfoundry.client.v3.domains.ListDomainsResponse; |
| 27 | +import org.cloudfoundry.client.v3.domains.ShareDomainRequest; |
| 28 | +import org.cloudfoundry.client.v3.domains.ShareDomainResponse; |
| 29 | +import org.cloudfoundry.client.v3.domains.UnshareDomainRequest; |
| 30 | +import org.cloudfoundry.client.v3.domains.UpdateDomainRequest; |
| 31 | +import org.cloudfoundry.client.v3.domains.UpdateDomainResponse; |
| 32 | +import org.cloudfoundry.reactor.ConnectionContext; |
| 33 | +import org.cloudfoundry.reactor.TokenProvider; |
| 34 | +import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations; |
| 35 | +import reactor.core.publisher.Mono; |
| 36 | + |
| 37 | +import java.util.Map; |
| 38 | + |
| 39 | +/** |
| 40 | + * The Reactor-based implementation of {@link DomainsV3} |
| 41 | + */ |
| 42 | +public final class ReactorDomainsV3 extends AbstractClientV3Operations implements DomainsV3 { |
| 43 | + |
| 44 | + /** |
| 45 | + * Creates an instance |
| 46 | + * |
| 47 | + * @param connectionContext the {@link ConnectionContext} to use when communicating with the server |
| 48 | + * @param root the root URI of the server. Typically something like {@code https://api.run.pivotal.io}. |
| 49 | + * @param tokenProvider the {@link TokenProvider} to use when communicating with the server |
| 50 | + * @param requestTags map with custom http headers which will be added to web request |
| 51 | + */ |
| 52 | + public ReactorDomainsV3(ConnectionContext connectionContext, Mono<String> root, TokenProvider tokenProvider, Map<String, String> requestTags) { |
| 53 | + super(connectionContext, root, tokenProvider, requestTags); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public Mono<CreateDomainResponse> create(CreateDomainRequest request) { |
| 58 | + return post(request, CreateDomainResponse.class, builder -> builder.pathSegment("domains")) |
| 59 | + .checkpoint(); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public Mono<String> delete(DeleteDomainRequest request) { |
| 64 | + return delete(request, builder -> builder.pathSegment("domains", request.getDomainId())) |
| 65 | + .checkpoint(); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public Mono<GetDomainResponse> get(GetDomainRequest request) { |
| 70 | + return get(request, GetDomainResponse.class, builder -> builder.pathSegment("domains", request.getDomainId())) |
| 71 | + .checkpoint(); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public Mono<ListDomainsResponse> list(ListDomainsRequest request) { |
| 76 | + return get(request, ListDomainsResponse.class, builder -> builder.pathSegment("domains")) |
| 77 | + .checkpoint(); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public Mono<ShareDomainResponse> share(ShareDomainRequest request) { |
| 82 | + return post(request, ShareDomainResponse.class, builder -> builder.pathSegment("domains", request.getDomainId(), "relationships", "shared_organizations")) |
| 83 | + .checkpoint(); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public Mono<Void> unshare(UnshareDomainRequest request) { |
| 88 | + return delete(request, Void.class, builder -> builder.pathSegment("domains", request.getDomainId(), "relationships", "shared_organizations", request.getOrganizationId())) |
| 89 | + .checkpoint(); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public Mono<UpdateDomainResponse> update(UpdateDomainRequest request) { |
| 94 | + return patch(request, UpdateDomainResponse.class, builder -> builder.pathSegment("domains", request.getDomainId())) |
| 95 | + .checkpoint(); |
| 96 | + } |
| 97 | +} |
0 commit comments