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.rev190531.ServiceEndpoint;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.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 TXDIR_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_NOT_SET;
29 public static final String RXDIR_PORT_NOT_SET;
30 public static final String RXDIR_LGX_NOT_SET;
32 // Static blocks are generated once and spare memory.
34 TXDIR_NOT_SET = "Service TxDirection is not correctly set";
35 RXDIR_NOT_SET = "Service RxDirection is not correctly set";
36 TXDIR_PORT_NOT_SET = "Service TxDirection Port is not correctly set";
37 TXDIR_LGX_NOT_SET = "Service TxDirection Lgx is not correctly set";
38 RXDIR_PORT_NOT_SET = "Service RxDirection Port is not correctly set";
39 RXDIR_LGX_NOT_SET = "Service RxDirection Lgx is not correctly set";
42 public static String endpointTypeNotSet(ServiceEndpointType endpointType) {
43 return SERVICE + endpointType + " is not set";
46 public static String rateNull(ServiceEndpointType endpointType) {
47 return "Something wrong when accessing " + SERVICE + endpointType + " rate, format or clli";
50 public static String rateNotSet(ServiceEndpointType endpointType) {
51 return SERVICE + endpointType + " rate is not set";
54 public static String formatNotSet(ServiceEndpointType endpointType) {
55 return SERVICE + endpointType + " format is not set";
58 public static String clliNotSet(ServiceEndpointType endpointType) {
59 return SERVICE + endpointType + " clli is not set";
62 private LogMessages() {
67 * Check if a String is not null and not equal to ''.
71 * @return true if String ok false if not
73 public static boolean checkString(String value) {
74 return (value != null && !value.isEmpty());
79 * Check Compliance of Service TxRx info.
80 * @param serviceEnd Service Endpoint
81 * @param endpointType Endpoint type
83 * @return true if String ok false if not
85 public static ComplianceCheckResult check(ServiceEndpoint serviceEnd, ServiceEndpointType endpointType) {
86 if (serviceEnd == null) {
87 return new ComplianceCheckResult(false, LogMessages.endpointTypeNotSet(endpointType));
90 if (serviceEnd.getServiceRate() == null) {
91 String message = "Something wrong when accessing Service " + endpointType + " rate, format or clli";
92 return new ComplianceCheckResult(false, message);
94 Long serviceRate = serviceEnd.getServiceRate().toJava();
95 ServiceFormat serviceformat = serviceEnd.getServiceFormat();
96 String clli = serviceEnd.getClli();
97 if (serviceRate <= 0) {
98 return new ComplianceCheckResult(false, LogMessages.rateNotSet(endpointType));
100 if (serviceformat == null) {
101 return new ComplianceCheckResult(false, LogMessages.formatNotSet(endpointType));
103 if (!checkString(clli)) {
104 return new ComplianceCheckResult(false, LogMessages.clliNotSet(endpointType));
107 return new ComplianceCheckResult(true, "");
110 private ServicehandlerTxRxCheck() {