Commit edda758c authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Introduce EmptyModel and EmptyModelFilter

parent ab043cb3
......@@ -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;
......
/*
* 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;
}
......@@ -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 <T> the generic type
* @param <R> the generic type
*/
public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R extends BasicModel> extends SuperModelFilter<T, R> {
/** The id. */
public Set<Long> id;
/**
* Collects list of filter predicates
*
* @param instance the instance of Q-type of <em>R</em>
* @param basicModel the basic model
* @return list of predicates
*/
protected List<Predicate> collectPredicates(final EntityPathBase<R> instance, final QBasicModel basicModel) {
List<Predicate> predicates = super.collectPredicates(instance);
if (CollectionUtils.isNotEmpty(id)) {
predicates.add(basicModel.id.in(id));
}
return predicates;
}
/**
* Id.
*
* @return the sets the
*/
public synchronized Set<Long> id() {
if (id == null) {
id = new HashSet<>();
}
return id;
}
public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R extends BasicModel> extends EmptyModelFilter<T, R> {
}
/*
* 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 <T> the generic type
* @param <R> the generic type
*/
public abstract class EmptyModelFilter<T extends EmptyModelFilter<T, R>, R extends EmptyModel> extends SuperModelFilter<T, R> {
/** The id. */
public Set<Long> id;
/**
* Collects list of filter predicates
*
* @param instance the instance of Q-type of <em>R</em>
* @param basicModel the basic model
* @return list of predicates
*/
protected List<Predicate> collectPredicates(final EntityPathBase<R> instance, final QBasicModel basicModel) {
List<Predicate> predicates = super.collectPredicates(instance);
if (CollectionUtils.isNotEmpty(id)) {
predicates.add(basicModel.id.in(id));
}
return predicates;
}
/**
* Id.
*
* @return the sets the
*/
public synchronized Set<Long> id() {
if (id == null) {
id = new HashSet<>();
}
return id;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment