View Javadoc
1   /*
2    * Copyright 2019 the original author or authors.
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 org.bremersee.dccon.repository;
18  
19  import java.util.Optional;
20  import java.util.stream.Stream;
21  import javax.validation.constraints.NotNull;
22  import org.bremersee.dccon.model.DnsZone;
23  import org.springframework.validation.annotation.Validated;
24  
25  /**
26   * The dns zone repository.
27   *
28   * @author Christian Bremer
29   */
30  @Validated
31  public interface DnsZoneRepository {
32  
33    /**
34     * Determines whether the given zone is a reverse zone.
35     *
36     * @param dnsZoneName the dns zone name
37     * @return the boolean
38     */
39    boolean isDnsReverseZone(final String dnsZoneName);
40  
41    /**
42     * Find all dns zones.
43     *
44     * @return the dns zones
45     */
46    Stream<DnsZone> findAll();
47  
48    /**
49     * Find dns reverse zones stream.
50     *
51     * @return the stream
52     */
53    default Stream<DnsZone> findDnsReverseZones() {
54      return findAll().filter(dnsZone -> isDnsReverseZone(dnsZone.getName()));
55    }
56  
57    /**
58     * Find non dns reverse zones stream.
59     *
60     * @return the stream
61     */
62    default Stream<DnsZone> findNonDnsReverseZones() {
63      return findAll().filter(dnsZone -> !isDnsReverseZone(dnsZone.getName()));
64    }
65  
66    /**
67     * Check whether dns zone exists or not.
68     *
69     * @param zoneName the zone name
70     * @return {@code true} if the dns zone exists, otherwise {@code false}
71     */
72    boolean exists(@NotNull String zoneName);
73  
74    /**
75     * Find dns zone.
76     *
77     * @param zoneName the zone name
78     * @return the dns zone
79     */
80    Optional<DnsZone> findOne(@NotNull String zoneName);
81  
82    /**
83     * Save dns zone.
84     *
85     * @param zoneName the zone name
86     * @return the dns zone
87     */
88    DnsZone save(@NotNull String zoneName);
89  
90    /**
91     * Delete dns zone.
92     *
93     * @param zoneName the zone name
94     * @return {@code true} is the repository was deleted, otherwise {@code false}
95     */
96    boolean delete(@NotNull String zoneName);
97  
98  
99  }