diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/pom.xml b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/pom.xml index ccdd0c4a80b7..c59eaa15d97a 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/pom.xml +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/pom.xml @@ -32,7 +32,6 @@ XWiki Platform - Live Data - API 0.69 - ${basedir}/src/checkstyle/checkstyle-suppressions.xml Live Data API diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/checkstyle/checkstyle-suppressions.xml b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/checkstyle/checkstyle-suppressions.xml deleted file mode 100644 index d07f1e0cb706..000000000000 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/checkstyle/checkstyle-suppressions.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/InitializableLiveDataElement.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/InitializableLiveDataElement.java new file mode 100644 index 000000000000..26be9692cec8 --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/InitializableLiveDataElement.java @@ -0,0 +1,40 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.xwiki.livedata; + +import org.xwiki.stability.Unstable; + +/** + * Helper interface to represents all live data elements that needs initialization. + * + * @version $Id$ + * @since 16.8.0RC1 + */ +@Unstable +public interface InitializableLiveDataElement +{ + /** + * Prevent {@code null} values where it's possible. + */ + default void initialize() + { + } +} diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataActionDescriptor.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataActionDescriptor.java index 56c8a674a37f..5c07d4e60537 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataActionDescriptor.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataActionDescriptor.java @@ -34,7 +34,7 @@ * @since 13.0 */ @JsonInclude(JsonInclude.Include.NON_NULL) -public class LiveDataActionDescriptor extends BaseDescriptor +public class LiveDataActionDescriptor extends BaseDescriptor implements InitializableLiveDataElement { /** * The action pretty name. @@ -187,9 +187,7 @@ public void setUrlProperty(String urlProperty) this.urlProperty = urlProperty; } - /** - * Prevent {@code null} values where it's possible. - */ + @Override public void initialize() { if (this.icon == null) { diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataConfiguration.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataConfiguration.java index c8ee01e5503a..c7642fd6eda9 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataConfiguration.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataConfiguration.java @@ -30,7 +30,7 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) -public class LiveDataConfiguration +public class LiveDataConfiguration implements InitializableLiveDataElement { private String id; @@ -112,9 +112,7 @@ public void setMeta(LiveDataMeta meta) this.meta = meta; } - /** - * Prevent {@code null} values where it's possible. - */ + @Override public void initialize() { if (this.query == null) { diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataEntryDescriptor.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataEntryDescriptor.java index 7bad92cf69c2..e10413ec07ff 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataEntryDescriptor.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataEntryDescriptor.java @@ -28,7 +28,7 @@ * @since 12.10 */ @JsonInclude(JsonInclude.Include.NON_NULL) -public class LiveDataEntryDescriptor +public class LiveDataEntryDescriptor implements InitializableLiveDataElement { private String idProperty; @@ -49,11 +49,4 @@ public void setIdProperty(String idProperty) { this.idProperty = idProperty; } - - /** - * Prevent {@code null} values where it's possible. - */ - public void initialize() - { - } } diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataLayoutDescriptor.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataLayoutDescriptor.java index 984742750718..ca0c69c168a0 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataLayoutDescriptor.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataLayoutDescriptor.java @@ -31,7 +31,7 @@ * @since 12.10 */ @JsonInclude(JsonInclude.Include.NON_NULL) -public class LiveDataLayoutDescriptor extends BaseDescriptor +public class LiveDataLayoutDescriptor extends BaseDescriptor implements InitializableLiveDataElement { private String name; @@ -90,9 +90,7 @@ public void setIcon(Map icon) this.icon = icon; } - /** - * Prevent {@code null} values where it's possible. - */ + @Override public void initialize() { if (this.icon == null) { diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataMeta.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataMeta.java index a91764329852..d500ba24ed15 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataMeta.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataMeta.java @@ -38,7 +38,7 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) -public class LiveDataMeta +public class LiveDataMeta implements InitializableLiveDataElement { private Collection layouts; @@ -310,53 +310,44 @@ public void setDescription(String description) this.description = description; } - /** - * Prevent {@code null} values where it's possible. - */ - public void initialize() + private Collection initializeAndCleanUpCollection(Collection + collection) { - if (this.layouts == null) { - this.layouts = new ArrayList<>(); - } - this.layouts.stream().filter(Objects::nonNull).forEach(LiveDataLayoutDescriptor::initialize); - - if (this.propertyDescriptors == null) { - this.propertyDescriptors = new ArrayList<>(); + Collection result; + if (collection == null) { + result = new ArrayList<>(); + } else { + result = collection; + result.stream().filter(Objects::nonNull).forEach(A::initialize); } - this.propertyDescriptors.stream().filter(Objects::nonNull).forEach(LiveDataPropertyDescriptor::initialize); + return result; + } - if (this.propertyTypes == null) { - this.propertyTypes = new ArrayList<>(); + private A initialize(A descriptor, A newInstance) + { + A result = descriptor; + if (result == null) { + result = newInstance; } - this.propertyTypes.stream().filter(Objects::nonNull).forEach(LiveDataPropertyDescriptor::initialize); + result.initialize(); + return result; + } - if (this.filters == null) { - this.filters = new ArrayList<>(); - } - this.filters.stream().filter(Objects::nonNull).forEach(FilterDescriptor::initialize); + @Override + public void initialize() + { + this.layouts = initializeAndCleanUpCollection(this.layouts); + this.propertyDescriptors = initializeAndCleanUpCollection(this.propertyDescriptors); + this.propertyTypes = initializeAndCleanUpCollection(this.propertyTypes); + this.filters = initializeAndCleanUpCollection(this.filters); + this.actions = initializeAndCleanUpCollection(this.actions); if (this.displayers == null) { this.displayers = new ArrayList<>(); } - if (this.pagination == null) { - this.pagination = new LiveDataPaginationConfiguration(); - } - this.pagination.initialize(); - - if (this.entryDescriptor == null) { - this.entryDescriptor = new LiveDataEntryDescriptor(); - } - this.entryDescriptor.initialize(); - - if (this.actions == null) { - this.actions = new ArrayList<>(); - } - this.actions.stream().filter(Objects::nonNull).forEach(LiveDataActionDescriptor::initialize); - - if (this.selection == null) { - this.selection = new LiveDataSelectionConfiguration(); - } - this.selection.initialize(); + this.pagination = initialize(this.pagination, new LiveDataPaginationConfiguration()); + this.entryDescriptor = initialize(this.entryDescriptor, new LiveDataEntryDescriptor()); + this.selection = initialize(this.selection, new LiveDataSelectionConfiguration()); } } diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataPaginationConfiguration.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataPaginationConfiguration.java index 8c10ae64ac65..1973a6f8828d 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataPaginationConfiguration.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataPaginationConfiguration.java @@ -33,7 +33,7 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) -public class LiveDataPaginationConfiguration +public class LiveDataPaginationConfiguration implements InitializableLiveDataElement { private Integer maxShownPages; @@ -157,9 +157,7 @@ public void setShowPageSizeDropdown(Boolean showPageSizeDropdown) this.showPageSizeDropdown = showPageSizeDropdown; } - /** - * Prevent {@code null} values where it's possible. - */ + @Override public void initialize() { if (this.maxShownPages == null) { diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataPropertyDescriptor.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataPropertyDescriptor.java index 3c0348906c3e..eeb3122ae3d3 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataPropertyDescriptor.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataPropertyDescriptor.java @@ -39,7 +39,7 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) -public class LiveDataPropertyDescriptor +public class LiveDataPropertyDescriptor implements InitializableLiveDataElement { private static final String NAME_CONSTANT = "name"; @@ -47,7 +47,7 @@ public class LiveDataPropertyDescriptor * Holds the filter configuration. */ @JsonInclude(JsonInclude.Include.NON_NULL) - public static class FilterDescriptor extends BaseDescriptor + public static class FilterDescriptor extends BaseDescriptor implements InitializableLiveDataElement { private String defaultOperator; @@ -123,9 +123,7 @@ public void setDefaultOperator(String defaultOperator) this.defaultOperator = defaultOperator; } - /** - * Prevent {@code null} values where it's possible. - */ + @Override public void initialize() { if (this.operators == null) { @@ -561,9 +559,7 @@ public void setEditable(Boolean editable) this.editable = editable; } - /** - * Prevent {@code null} values where it's possible. - */ + @Override public void initialize() { if (this.visible == null) { diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataQuery.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataQuery.java index d9ad3377bfe8..78664efd1811 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataQuery.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataQuery.java @@ -34,7 +34,7 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) -public class LiveDataQuery +public class LiveDataQuery implements InitializableLiveDataElement { /** * Specifies where to take the data from. Represents the "from" clause. @@ -490,9 +490,7 @@ public void setSort(List sort) this.sort = sort; } - /** - * Prevent {@code null} values where it's possible. - */ + @Override public void initialize() { if (this.properties == null) { diff --git a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataSelectionConfiguration.java b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataSelectionConfiguration.java index e528953f60e2..d73a0bbc2f3f 100644 --- a/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataSelectionConfiguration.java +++ b/xwiki-platform-core/xwiki-platform-livedata/xwiki-platform-livedata-api/src/main/java/org/xwiki/livedata/LiveDataSelectionConfiguration.java @@ -26,7 +26,7 @@ * @since 12.10.1 * @since 13.0 */ -public class LiveDataSelectionConfiguration +public class LiveDataSelectionConfiguration implements InitializableLiveDataElement { /** * Specified whether live data entry selection is enabled. @@ -50,11 +50,4 @@ public void setEnabled(boolean enabled) { this.enabled = enabled; } - - /** - * Prevent {@code null} values where it's possible. - */ - public void initialize() - { - } }