Added response data to operational datastore, refactored data validation
[packetcable.git] / packetcable-policy-server / src / main / java / org / opendaylight / controller / packetcable / provider / validation / impl / validators / qos / GateValidator.java
1 /*
2  * Copyright (c) 2015 CableLabs 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.controller.packetcable.provider.validation.impl.validators.qos;
10
11 import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
12 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.AbstractValidator;
13 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.ClassifierValidator;
14 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.ExtClassifierValidator;
15 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.Ipv6ClassifierValidator;
16 import org.opendaylight.yang.gen.v1.urn.packetcable.rev151026.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
17
18 /**
19  * @author rvail
20  */
21 public class GateValidator extends AbstractValidator<Gate> {
22
23     private static final String GATE_ID = "gate.gateId";
24     private static final String GATE_SPEC = "gate.gate-spec";
25     private static final String TRAFFIC_PROFILE = "gate.traffic-profile";
26
27 //    private final GateSpecValidatator gateSpecValidatator = new GateSpecValidatator();
28     private final TrafficProfileValidator trafficProfileValidator = new TrafficProfileValidator();
29     private final ClassifierValidator classifierValidator = new ClassifierValidator();
30     private final ExtClassifierValidator extClassifierValidator = new ExtClassifierValidator();
31     private final Ipv6ClassifierValidator ipv6ClassifierValidator = new Ipv6ClassifierValidator();
32
33     @Override
34     public void validate(final Gate gate, final Extent extent) throws ValidationException {
35         if (gate == null) {
36             throw new ValidationException("gate must exist");
37         }
38
39         mustExist(gate.getGateId(), GATE_ID);
40
41         // all leafs in GateSpec are optional
42         // mustExist(gate.getGateSpec(), GATE_SPEC);
43
44         mustExist(gate.getTrafficProfile(), TRAFFIC_PROFILE);
45         if (extent == Extent.NODE_AND_SUBTREE) {
46 //            validateChild(gateSpecValidatator, gate.getGateSpec());
47             validateChild(trafficProfileValidator, gate.getTrafficProfile());
48         }
49
50         // Classifiers
51
52         if (gate.getClassifier() != null) {
53
54             // classifer is not null, ext and ipv6 must be null
55
56             if (gate.getExtClassifier() != null || gate.getIpv6Classifier() != null) {
57                 getErrorMessages().add("Only one type of classifier is allowed");
58             }
59             else if (extent == Extent.NODE_AND_SUBTREE) {
60                 validateChild(classifierValidator, gate.getClassifier());
61             }
62
63         }
64         else if (gate.getExtClassifier() != null) {
65
66             // classifer is null; ext is not null and ipv6 must be null
67
68             if (gate.getIpv6Classifier() != null) {
69                 getErrorMessages().add("Only one type of classifier is allowed");
70             }
71             else if (extent == Extent.NODE_AND_SUBTREE) {
72                 validateChild(extClassifierValidator, gate.getExtClassifier());
73             }
74
75         }
76         else if (gate.getIpv6Classifier() != null) {
77
78             // classifer and ext are null; ipv6 is not
79             if (extent == Extent.NODE_AND_SUBTREE) {
80                 validateChild(ipv6ClassifierValidator, gate.getIpv6Classifier());
81             }
82
83         }
84         else {
85             getErrorMessages().add("a classifer is required");
86         }
87
88         throwErrorsIfNeeded();
89     }
90 }