HONEYCOMB-431: add validation support to Writers
[honeycomb.git] / infra / translate-api / src / main / java / io / fd / honeycomb / translate / write / Validator.java
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.translate.write;
18
19 import com.google.common.annotations.Beta;
20 import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException;
21 import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException;
22 import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException;
23 import javax.annotation.Nonnull;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26
27 /**
28  * Responsible for validation of DataObjects.
29  * Handles all update operations (create, update, delete).
30  *
31  * @param <D> Specific DataObject derived type, that is handled by this writer
32  * @see Writer#validate(InstanceIdentifier, DataObject, DataObject, WriteContext)
33  */
34 @Beta
35 public interface Validator<D extends DataObject> {
36     /**
37      * Validates write operation.
38      *
39      * @param id           Identifier(from root) of data being written
40      * @param dataAfter    New data to be written
41      * @param writeContext Write context that provides information about current state of DataTree.
42      * @throws CreateValidationFailedException if write validation failed
43      */
44     void validateWrite(
45         @Nonnull final InstanceIdentifier<D> id,
46         @Nonnull final D dataAfter,
47         @Nonnull final WriteContext writeContext) throws CreateValidationFailedException;
48
49     /**
50      * Validates update operation.
51      *
52      * @param id           Identifier(from root) of data being updated
53      * @param dataBefore   Old data
54      * @param dataAfter    New, updated data
55      * @param writeContext Write context that provides information about current state of DataTree.
56      * @throws UpdateValidationFailedException if update validation failed
57      */
58     void validateUpdate(InstanceIdentifier<D> id, D dataBefore, D dataAfter, WriteContext writeContext)
59         throws UpdateValidationFailedException;
60
61     /**
62      * Validates delete operation.
63      *
64      * @param id           Identifier(from root) of data being written
65      * @param dataBefore   Old data being deleted
66      * @param writeContext Write context that provides information about current state of DataTree.
67      * @throws DeleteValidationFailedException if delete validation failed
68      */
69     void validateDelete(InstanceIdentifier<D> id, D dataBefore, WriteContext writeContext)
70         throws DeleteValidationFailedException;
71 }