1 /**
2 * Copyright 2024 Bloomreach B.V. (<a href="https://www.bloomreach.com">https://www.bloomreach.com</a>)
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 * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>
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 package org.onehippo.forge.exdocpicker.api;
17
18 import java.io.Serializable;
19 import java.util.Collections;
20 import java.util.Iterator;
21 import java.util.List;
22
23 /**
24 * The implementation of this interface is responsible for providing children and parent items to render a tree
25 * list view instead of a flat list view from the searched external data items by {@link ExternalDocumentSearchService}
26 * method implementations.
27 * @param <T> Domain specific external document POJO type which must be serializable.
28 */
29 public interface ExternalDocumentTreeService<T extends Serializable> {
30
31 /**
32 * Returns true if the {@code doc} has children.
33 * @param doc document
34 * @return true if the {@code doc} has children
35 */
36 default boolean hasChildren(T doc) {
37 return false;
38 }
39
40 /**
41 * Returns an iterator of the children of the {@code doc}.
42 * @param doc document
43 * @return an iterator of the children of the {@code doc}
44 */
45 default Iterator<T> getChildren(T doc) {
46 List<T> emptyList = Collections.emptyList();
47 return emptyList.iterator();
48 }
49
50 /**
51 * Returns the parent document of the {@code doc} if any, or null if there's no parent.
52 * @param doc document
53 * @return the parent document of the {@code doc} if any, or null if there's no parent
54 */
55 default T getParent(T doc) {
56 return null;
57 }
58
59 }