diff --git a/core/src/main/java/org/genesys/blocks/model/BasicModel.java b/core/src/main/java/org/genesys/blocks/model/BasicModel.java index dfd6ce08f8c5689150f967271353397509d5334d..3193015bccc084cd041a17fbd13ac8d384863587 100644 --- a/core/src/main/java/org/genesys/blocks/model/BasicModel.java +++ b/core/src/main/java/org/genesys/blocks/model/BasicModel.java @@ -15,8 +15,6 @@ */ package org.genesys.blocks.model; -import java.io.Serializable; - import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -24,18 +22,14 @@ import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.persistence.Transient; -import org.genesys.blocks.util.JsonClassNameWriter; - import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonView; -import com.fasterxml.jackson.databind.annotation.JsonAppend; /** * The Class BasicModel. */ @MappedSuperclass -@JsonAppend(props = { @JsonAppend.Prop(name = "_class", value = JsonClassNameWriter.class, type = String.class) }) -public class BasicModel implements EntityId, Serializable { +public class BasicModel extends EmptyModel { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 2709998920148999956L; diff --git a/core/src/main/java/org/genesys/blocks/model/EmptyModel.java b/core/src/main/java/org/genesys/blocks/model/EmptyModel.java new file mode 100644 index 0000000000000000000000000000000000000000..0e248723541b22741dc6d3348af6b34cc53d2f18 --- /dev/null +++ b/core/src/main/java/org/genesys/blocks/model/EmptyModel.java @@ -0,0 +1,36 @@ +/* + * Copyright 2020 Global Crop Diversity Trust + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.genesys.blocks.model; + +import java.io.Serializable; + +import javax.persistence.MappedSuperclass; + +import org.genesys.blocks.util.JsonClassNameWriter; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; +import com.fasterxml.jackson.databind.annotation.JsonAppend; + +@MappedSuperclass +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") +@JsonAppend(props = { @JsonAppend.Prop(name = "_class", value = JsonClassNameWriter.class, type = String.class) }) +public abstract class EmptyModel implements EntityId, Serializable { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 5934941826741972456L; + +} diff --git a/core/src/main/java/org/genesys/blocks/model/filters/BasicModelFilter.java b/core/src/main/java/org/genesys/blocks/model/filters/BasicModelFilter.java index c2d848094bd2ddc5cc6f59a9ca81644b6cb6e300..988e87b4a2120f618b4eea7af5ccad53f4f83d9a 100644 --- a/core/src/main/java/org/genesys/blocks/model/filters/BasicModelFilter.java +++ b/core/src/main/java/org/genesys/blocks/model/filters/BasicModelFilter.java @@ -15,16 +15,7 @@ */ package org.genesys.blocks.model.filters; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.commons.collections4.CollectionUtils; import org.genesys.blocks.model.BasicModel; -import org.genesys.blocks.model.QBasicModel; - -import com.querydsl.core.types.Predicate; -import com.querydsl.core.types.dsl.EntityPathBase; /** * {@link BasicModel} match by sample filters. @@ -32,36 +23,6 @@ import com.querydsl.core.types.dsl.EntityPathBase; * @param the generic type * @param the generic type */ -public abstract class BasicModelFilter, R extends BasicModel> extends SuperModelFilter { - - /** The id. */ - public Set id; - - /** - * Collects list of filter predicates - * - * @param instance the instance of Q-type of R - * @param basicModel the basic model - * @return list of predicates - */ - protected List collectPredicates(final EntityPathBase instance, final QBasicModel basicModel) { - List predicates = super.collectPredicates(instance); - if (CollectionUtils.isNotEmpty(id)) { - predicates.add(basicModel.id.in(id)); - } - return predicates; - } - - /** - * Id. - * - * @return the sets the - */ - public synchronized Set id() { - if (id == null) { - id = new HashSet<>(); - } - return id; - } +public abstract class BasicModelFilter, R extends BasicModel> extends EmptyModelFilter { } diff --git a/core/src/main/java/org/genesys/blocks/model/filters/EmptyModelFilter.java b/core/src/main/java/org/genesys/blocks/model/filters/EmptyModelFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..1cb6e5ed122570c8902bbef850dd4d0db53a8947 --- /dev/null +++ b/core/src/main/java/org/genesys/blocks/model/filters/EmptyModelFilter.java @@ -0,0 +1,68 @@ +/* + * Copyright 2020 Global Crop Diversity Trust + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.genesys.blocks.model.filters; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.commons.collections4.CollectionUtils; +import org.genesys.blocks.model.BasicModel; +import org.genesys.blocks.model.EmptyModel; +import org.genesys.blocks.model.QBasicModel; + +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.dsl.EntityPathBase; + +/** + * {@link BasicModel} match by sample filters. + * + * @param the generic type + * @param the generic type + */ +public abstract class EmptyModelFilter, R extends EmptyModel> extends SuperModelFilter { + + /** The id. */ + public Set id; + + /** + * Collects list of filter predicates + * + * @param instance the instance of Q-type of R + * @param basicModel the basic model + * @return list of predicates + */ + protected List collectPredicates(final EntityPathBase instance, final QBasicModel basicModel) { + List predicates = super.collectPredicates(instance); + if (CollectionUtils.isNotEmpty(id)) { + predicates.add(basicModel.id.in(id)); + } + return predicates; + } + + /** + * Id. + * + * @return the sets the + */ + public synchronized Set id() { + if (id == null) { + id = new HashSet<>(); + } + return id; + } + +}