Bump upstream dependencies to Ca
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / impl / AddSpecificOperationalModesToCatalogImpl.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.servicehandler.impl;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.transportpce.common.OperationResult;
12 import org.opendaylight.transportpce.common.ResponseCodes;
13 import org.opendaylight.transportpce.servicehandler.CatalogInput;
14 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
15 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperations;
16 import org.opendaylight.transportpce.servicehandler.catalog.CatalogMapper;
17 import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl.LogMessages;
18 import org.opendaylight.transportpce.servicehandler.validation.CatalogValidation;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.RpcActions;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.operational.mode.catalog.rev230526.operational.mode.catalog.SpecificOperationalModes;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalog;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalogInput;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalogOutput;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28
29 public class AddSpecificOperationalModesToCatalogImpl implements AddSpecificOperationalModesToCatalog {
30     private static final Logger LOG = LoggerFactory.getLogger(AddSpecificOperationalModesToCatalogImpl.class);
31     private static final String ADD_SPECIFIC_TO_CATALOG_MSG = "addSpecificToCatalog: {}";
32
33     private CatalogDataStoreOperations catalogDataStoreOperations;
34
35     public AddSpecificOperationalModesToCatalogImpl(CatalogDataStoreOperations catalogDataStoreOperations) {
36         this.catalogDataStoreOperations = catalogDataStoreOperations;
37     }
38
39     /**
40      * Implementation of the RPC to set specific operational modes in the catalog of the controller.
41      * Semantics of the RPC is such that the information in the input replaces the full content
42      * of the specific operational modes catalog in the config data store. Incremental changes to the
43      * catalog, if required, must be done via individual PUT/POST/DELETE RESTconf APIs.
44      *
45      * @param input AddSpecificOperationalModesToCatalogInput to be added to Catalog
46      * @return Result of the request
47      */
48     @Override
49     public ListenableFuture<RpcResult<AddSpecificOperationalModesToCatalogOutput>> invoke(
50             AddSpecificOperationalModesToCatalogInput input) {
51         LOG.info("RPC addSpecificOperationalModesToCatalog in progress");
52         LOG.debug(" Input openSpecificRoadm {}", input);
53         // Validation
54         OperationResult validationResult = CatalogValidation.validateSpecificCatalogRequest(
55                 new CatalogInput(input), RpcActions.FillCatalogWithSpecificOperationalModes);
56         if (! validationResult.isSuccess()) {
57             LOG.warn(ADD_SPECIFIC_TO_CATALOG_MSG, LogMessages.ABORT_SPECIFIC_TO_CATALOG_FAILED);
58             return ModelMappingUtils.addSpecificOpenroadmServiceReply(
59                     input, ResponseCodes.FINAL_ACK_YES,
60                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
61         }
62         LOG.info(" Request System Id {} " ,input.getSdncRequestHeader().getRequestSystemId());
63         LOG.info(" Rpc Action {} " ,input.getSdncRequestHeader().getRpcAction());
64
65         SpecificOperationalModes objToSave = CatalogMapper.createSpecificModesToSave(input);
66         catalogDataStoreOperations.addSpecificOperationalModesToCatalog(objToSave);
67         LOG.info("RPC addSpecificOperationalModesToCatalog Completed");
68         return ModelMappingUtils.addSpecificOpenroadmServiceReply(input, ResponseCodes.FINAL_ACK_YES,
69                 validationResult.getResultMessage(), ResponseCodes.RESPONSE_OK);
70     }
71
72 }