Refactor SH CatalogValidation
[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.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public final class CatalogValidation {
20
21     private CatalogValidation() {
22     }
23
24     private static final Logger LOG = LoggerFactory.getLogger(CatalogValidation.class);
25
26     public static OperationResult validateORCatalogRequest(CatalogInput input, RpcActions rpcActions) {
27         /*
28          * -OR request header and operational mode info compliance are verified.
29          */
30         LOG.debug("checking OR Catalog Compliance ...");
31         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.checkORCatalog(
32                 input.getSdncRequestHeader(), input.getOperationalModeInfo(), rpcActions, true);
33         if (!serviceHandlerCheckResult.hasPassed()) {
34             return OperationResult.failed(serviceHandlerCheckResult.getMessage());
35         }
36         LOG.debug("Catalog OR request compliant !");
37         return OperationResult.ok("Validation successful.");
38     }
39
40     public static OperationResult validateSpecificCatalogRequest(CatalogInput input, RpcActions rpcActions) {
41         /*
42          * -Specific request header and operational mode info compliance are verified.
43          */
44         LOG.debug("checking specific Catalog Compliance ...");
45         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.checkSpecificCatalog(
46                 input.getSdncRequestHeader(), input.getOperationalModeInfoSpecific(), rpcActions, true);
47         if (!serviceHandlerCheckResult.hasPassed()) {
48             return OperationResult.failed(serviceHandlerCheckResult.getMessage());
49         }
50         LOG.debug("Catalog specific request compliant !");
51         return OperationResult.ok("Validation successful.");
52     }
53 }