2 * Copyright (c) 2018 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.translate.write;
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;
28 * Responsible for validation of DataObjects.
29 * Handles all update operations (create, update, delete).
31 * @param <D> Specific DataObject derived type, that is handled by this writer
32 * @see Writer#validate(InstanceIdentifier, DataObject, DataObject, WriteContext)
35 public interface Validator<D extends DataObject> {
37 * Validates write operation.
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
45 @Nonnull final InstanceIdentifier<D> id,
46 @Nonnull final D dataAfter,
47 @Nonnull final WriteContext writeContext) throws CreateValidationFailedException;
50 * Validates update operation.
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
58 void validateUpdate(InstanceIdentifier<D> id, D dataBefore, D dataAfter, WriteContext writeContext)
59 throws UpdateValidationFailedException;
62 * Validates delete operation.
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
69 void validateDelete(InstanceIdentifier<D> id, D dataBefore, WriteContext writeContext)
70 throws DeleteValidationFailedException;