Refactor SH CatalogDataUtil
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / validation / CatalogValidation.java
1 /*
2  * Copyright © 2023 Fujitsu Network Communications, 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
9 package org.opendaylight.transportpce.servicehandler.validation;
10
11 import org.opendaylight.transportpce.common.OperationResult;
12 import org.opendaylight.transportpce.servicehandler.CatalogInput;
13 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
14 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerComplianceCheck;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.RpcActions;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.sdnc.request.header.SdncRequestHeader;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.add.openroadm.operational.modes.to.catalog.input.OperationalModeInfo;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public final class CatalogValidation {
22
23     private CatalogValidation() {
24     }
25
26     private static final Logger LOG = LoggerFactory.getLogger(CatalogValidation.class);
27
28     public static OperationResult validateORCatalogRequest(CatalogInput input, RpcActions rpcActions) {
29         /*
30          * -OR request header and operational mode info compliance are verified.
31          */
32         LOG.debug("checking OR Catalog Compliance ...");
33         SdncRequestHeader sdncRequestHeader = input.getSdncRequestHeader();
34         OperationalModeInfo operationalModeInfo = input.getOperationalModeInfo();
35         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.checkORCatalog(
36                 sdncRequestHeader, operationalModeInfo, rpcActions, true);
37         if (!serviceHandlerCheckResult.hasPassed()) {
38             return OperationResult.failed(serviceHandlerCheckResult.getMessage());
39         }
40         LOG.debug("Catalog OR request compliant !");
41         return OperationResult.ok("Validation successful.");
42     }
43
44     public static OperationResult validateSpecificCatalogRequest(CatalogInput input, RpcActions rpcActions) {
45         /*
46          * -Specific request header and operational mode info compliance are verified.
47          */
48         LOG.debug("checking specific Catalog Compliance ...");
49         SdncRequestHeader sdncRequestHeader = input.getSdncRequestHeader();
50         org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210
51                 .add.specific.operational.modes.to.catalog.input.OperationalModeInfo operationalModeInfoSpecific
52             = input.getOperationalModeInfoSpecific();
53         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.checkSpecificCatalog(
54                 sdncRequestHeader, operationalModeInfoSpecific, rpcActions, true);
55         if (!serviceHandlerCheckResult.hasPassed()) {
56             return OperationResult.failed(serviceHandlerCheckResult.getMessage());
57         }
58         LOG.debug("Catalog specific request compliant !");
59         return OperationResult.ok("Validation successful.");
60     }
61 }