2 * Copyright © 2017 Orange, Inc. and others. All rights reserved.
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
9 package org.opendaylight.transportpce.servicehandler.validation.checks;
11 import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ServiceEndpoint;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
16 * Class for checking missing info on Tx/Rx for A/Z end.
19 public final class ServicehandlerTxRxCheck {
21 // This is class is public so that these messages can be accessed from Junit (avoid duplications).
22 public static final class LogMessages {
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;
31 // Static blocks are generated once and spare memory.
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";
40 public static String endpointTypeNotSet(ServiceEndpointType endpointType) {
41 return SERVICE + endpointType + " is not set";
44 public static String rateNull(ServiceEndpointType endpointType) {
45 return "Something wrong when accessing " + SERVICE + endpointType + " rate, format or clli";
48 public static String rateNotSet(ServiceEndpointType endpointType) {
49 return SERVICE + endpointType + " rate is not set";
52 public static String formatNotSet(ServiceEndpointType endpointType) {
53 return SERVICE + endpointType + " format is not set";
56 public static String clliNotSet(ServiceEndpointType endpointType) {
57 return SERVICE + endpointType + " clli is not set";
60 private LogMessages() {
65 * Check if a String is not null and not equal to ''.
69 * @return true if String ok false if not
71 public static boolean checkString(String value) {
72 return (value != null && !value.isEmpty());
76 * Check Compliance of Service TxRx info.
77 * @param serviceEnd Service Endpoint
78 * @param endpointType Endpoint type
80 * @return true if String ok false if not
82 public static ComplianceCheckResult check(ServiceEndpoint serviceEnd, ServiceEndpointType endpointType) {
83 if (serviceEnd == null) {
84 return new ComplianceCheckResult(false, LogMessages.endpointTypeNotSet(endpointType));
87 if (serviceEnd.getServiceRate() == null) {
88 String message = "Something wrong when accessing Service " + endpointType + " rate, format or clli";
89 return new ComplianceCheckResult(false, message);
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));
97 if (serviceformat == null) {
98 return new ComplianceCheckResult(false, LogMessages.formatNotSet(endpointType));
100 if (!checkString(clli)) {
101 return new ComplianceCheckResult(false, LogMessages.clliNotSet(endpointType));
103 if (serviceEnd.getTxDirection() == null || serviceEnd.getRxDirection() == null) {
104 return new ComplianceCheckResult(false, LogMessages.TXRXDIR_NOT_SET);
106 return new ComplianceCheckResult(true, "");
109 private ServicehandlerTxRxCheck() {