Bump upstream dependencies to Ca
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / impl / rpc / GetServiceInterfacePointListImpl.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.HashMap;
12 import java.util.Map;
13 import org.opendaylight.transportpce.tapi.utils.TapiContext;
14 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointList;
15 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointListInput;
16 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointListOutput;
17 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.GetServiceInterfacePointListOutputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.get.service._interface.point.list.output.Sip;
19 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.get.service._interface.point.list.output.SipBuilder;
20 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.get.service._interface.point.list.output.SipKey;
21 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePoint;
22 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePointKey;
23 import org.opendaylight.yangtools.yang.common.ErrorType;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30 public class GetServiceInterfacePointListImpl implements GetServiceInterfacePointList {
31     private static final Logger LOG = LoggerFactory.getLogger(GetServiceInterfacePointListImpl.class);
32     private final TapiContext tapiContext;
33
34     public GetServiceInterfacePointListImpl(TapiContext tapiContext) {
35         this.tapiContext = tapiContext;
36     }
37
38     @Override
39     public ListenableFuture<RpcResult<GetServiceInterfacePointListOutput>> invoke(
40             GetServiceInterfacePointListInput input) {
41         Map<ServiceInterfacePointKey, ServiceInterfacePoint> sips =
42                 this.tapiContext.getTapiContext().getServiceInterfacePoint();
43         if (sips == null || sips.isEmpty()) {
44             return RpcResultBuilder.<GetServiceInterfacePointListOutput>failed()
45                 .withError(ErrorType.RPC, "No sips in datastore")
46                 .buildFuture();
47         }
48         Map<SipKey, Sip> outSipMap = new HashMap<>();
49         for (ServiceInterfacePoint sip : sips.values()) {
50             Sip si = new SipBuilder(sip).build();
51             outSipMap.put(si.key(), si);
52         }
53         return RpcResultBuilder
54             .success(new GetServiceInterfacePointListOutputBuilder().setSip(outSipMap).build())
55             .buildFuture();
56     }
57
58 }