+ /**
+ * Get depth.
+ * @return depth: -1 for all descendants, 0 for no descendants, or positive value for fixed level of descendants
+ */
+ public int getDepth() {
+ return depth;
+ }
+
+ /**
+ * get fetch descendants option for given descendant.
+ *
+ * @param fetchDescendantsOptionAsString fetch descendants option string
+ * @return fetch descendants option for given descendant
+ */
+ public static FetchDescendantsOption getFetchDescendantsOption(final String fetchDescendantsOptionAsString) {
+ validateFetchDescendantsOption(fetchDescendantsOptionAsString);
+ if (Strings.isNullOrEmpty(fetchDescendantsOptionAsString)
+ || "0".equals(fetchDescendantsOptionAsString) || "none".equals(fetchDescendantsOptionAsString)) {
+ return FetchDescendantsOption.OMIT_DESCENDANTS;
+ } else if ("-1".equals(fetchDescendantsOptionAsString) || "all".equals(fetchDescendantsOptionAsString)) {
+ return FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
+ } else if ("1".equals(fetchDescendantsOptionAsString) || "direct".equals(fetchDescendantsOptionAsString)) {
+ return FetchDescendantsOption.DIRECT_CHILDREN_ONLY;
+ } else {
+ final Integer depth = Integer.valueOf(fetchDescendantsOptionAsString);
+ return new FetchDescendantsOption(depth);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return optionName;
+ }
+
+ private static void validateFetchDescendantsOption(final String fetchDescendantsOptionAsString) {
+ if (Strings.isNullOrEmpty(fetchDescendantsOptionAsString)) {
+ return;
+ }
+ final Matcher matcher = FETCH_DESCENDANTS_OPTION_PATTERN.matcher(fetchDescendantsOptionAsString);
+ if (!matcher.matches()) {
+ throw new DataValidationException("FetchDescendantsOption validation error.",
+ fetchDescendantsOptionAsString + " is not valid fetch descendants option");
+ }
+ }
+