Use version 13.1.0 of openroadm-service models
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / validation / checks / ServicehandlerTxRxCheck.java
1 /*
2  * Copyright © 2017 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
9 package org.opendaylight.transportpce.servicehandler.validation.checks;
10
11 import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ServiceEndpoint;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
14
15 /**
16  * Class for checking missing info on Tx/Rx for A/Z end.
17  *
18  */
19 public final class ServicehandlerTxRxCheck {
20
21     // This is class is public so that these messages can be accessed from Junit (avoid duplications).
22     public static final class LogMessages {
23
24         private static final String SERVICE = "Service ";
25         public static final String TXRXDIR_NOT_SET;
26         public static final String TXDIR_PORT_NOT_SET;
27         public static final String TXDIR_LGX_NOT_SET;
28         public static final String RXDIR_PORT_NOT_SET;
29         public static final String RXDIR_LGX_NOT_SET;
30
31         // Static blocks are generated once and spare memory.
32         static {
33             TXRXDIR_NOT_SET = "Service TxDirection or RxDirection is not correctly set";
34             TXDIR_PORT_NOT_SET = "Service TxDirection Port is not correctly set";
35             TXDIR_LGX_NOT_SET = "Service TxDirection Lgx is not correctly set";
36             RXDIR_PORT_NOT_SET = "Service RxDirection Port is not correctly set";
37             RXDIR_LGX_NOT_SET = "Service RxDirection Lgx is not correctly set";
38         }
39
40         public static String endpointTypeNotSet(ServiceEndpointType endpointType) {
41             return SERVICE + endpointType + " is not set";
42         }
43
44         public static String rateNull(ServiceEndpointType endpointType) {
45             return "Something wrong when accessing " + SERVICE + endpointType + " rate, format or clli";
46         }
47
48         public static String rateNotSet(ServiceEndpointType endpointType) {
49             return SERVICE + endpointType + " rate is not set";
50         }
51
52         public static String formatNotSet(ServiceEndpointType endpointType) {
53             return SERVICE + endpointType + " format is not set";
54         }
55
56         public static String clliNotSet(ServiceEndpointType endpointType) {
57             return SERVICE + endpointType + " clli is not set";
58         }
59
60         private LogMessages() {
61         }
62     }
63
64     /**
65      * Check if a String is not null and not equal to ''.
66      *
67      * @param value
68      *            String value
69      * @return true if String ok false if not
70      */
71     public static boolean checkString(String value) {
72         return (value != null && !value.isEmpty());
73     }
74
75     /**
76      * Check Compliance of Service TxRx info.
77      * @param serviceEnd Service Endpoint
78      * @param endpointType Endpoint type
79      *
80      * @return true if String ok false if not
81      */
82     public static ComplianceCheckResult check(ServiceEndpoint serviceEnd, ServiceEndpointType endpointType) {
83         if (serviceEnd == null) {
84             return new ComplianceCheckResult(false, LogMessages.endpointTypeNotSet(endpointType));
85         }
86
87         if (serviceEnd.getServiceRate() == null) {
88             String message = "Something wrong when accessing Service " + endpointType + " rate, format or clli";
89             return new ComplianceCheckResult(false, message);
90         }
91         Long serviceRate = serviceEnd.getServiceRate().toJava();
92         ServiceFormat serviceformat = serviceEnd.getServiceFormat();
93         String clli = serviceEnd.getClli();
94         if (serviceRate <= 0) {
95             return new ComplianceCheckResult(false, LogMessages.rateNotSet(endpointType));
96         }
97         if (serviceformat == null) {
98             return new ComplianceCheckResult(false, LogMessages.formatNotSet(endpointType));
99         }
100         if (!checkString(clli)) {
101             return new ComplianceCheckResult(false, LogMessages.clliNotSet(endpointType));
102         }
103         if (serviceEnd.getTxDirection() == null || serviceEnd.getRxDirection() == null) {
104             return new ComplianceCheckResult(false, LogMessages.TXRXDIR_NOT_SET);
105         }
106         return new ComplianceCheckResult(true, "");
107     }
108
109     private ServicehandlerTxRxCheck() {
110     }
111
112 }