Refactor some small TAPI rpcs
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / impl / rpc / GetServiceInterfacePointDetailsImpl.java
1 /*
2  * Copyright © 2024 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.tapi.impl.rpc;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Map;
12 import org.opendaylight.transportpce.tapi.utils.TapiContext;
13 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointDetails;
14 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointDetailsInput;
15 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointDetailsOutput;
16 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointDetailsOutputBuilder;
17 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.get.service._interface.point.details.output.SipBuilder;
18 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePoint;
19 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePointKey;
20 import org.opendaylight.yangtools.yang.common.ErrorType;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26
27 public class GetServiceInterfacePointDetailsImpl implements GetServiceInterfacePointDetails {
28     private static final Logger LOG = LoggerFactory.getLogger(GetServiceInterfacePointDetailsImpl.class);
29     private final TapiContext tapiContext;
30
31     public GetServiceInterfacePointDetailsImpl(TapiContext tapiContext) {
32         this.tapiContext = tapiContext;
33     }
34
35     @Override
36     public ListenableFuture<RpcResult<GetServiceInterfacePointDetailsOutput>> invoke(
37             GetServiceInterfacePointDetailsInput input) {
38         Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips =
39             this.tapiContext.getTapiContext().getServiceInterfacePoint();
40         if (sips == null || sips.isEmpty()) {
41             return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed()
42                 .withError(ErrorType.RPC, "No sips in datastore")
43                 .buildFuture();
44         }
45         var sipKey = new ServiceInterfacePointKey(input.getUuid());
46         if (!sips.containsKey(sipKey)) {
47             return RpcResultBuilder.<GetServiceInterfacePointDetailsOutput>failed()
48                 .withError(ErrorType.RPC, "Sip doesnt exist in datastore")
49                 .buildFuture();
50         }
51         return RpcResultBuilder
52                 .success(new GetServiceInterfacePointDetailsOutputBuilder()
53                     .setSip(new SipBuilder(sips.get(sipKey)).build())
54                     .build())
55                 .buildFuture();
56     }
57
58 }