ShortFilter.java
/*
* 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.gringlobal.model;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.genesys.blocks.model.EmptyModel;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author Maxym Borodenko
* @author Matija Obreza
*/
@Entity
@Table(name = "short_filter"
// TODO Manually create an index on json field! (length limited)
)
@Cacheable
@Getter
@Setter
@NoArgsConstructor
public class ShortFilter extends EmptyModel {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -8275242276785470980L;
/** The id. */
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Long id;
/** The generated short name. */
@Column(length = 50, unique = true, nullable = false)
private String code;
/** The applied JSON filters. */
@Column(nullable = false)
@Lob
@Type(type = "org.hibernate.type.TextType")
private String json;
/**
* The new code to use for an old filter.
*
* Filters with {@link #redirect} == null are using the current shortCode syntax.
*/
@JsonIgnore
@Column(length = 50, nullable = true, name = "redir")
private String redirect;
/**
* Instantiates a new ShortFilter.
*
* @param code the short name
* @param json the json filters
*/
public ShortFilter(final String code, final String json) {
this.code = code;
this.json = json;
}
// @Override
// public boolean equals(final Object o) {
// if (this == o)
// return true;
// if (!(o instanceof ShortFilter))
// return false;
// final ShortFilter that = (ShortFilter) o;
// return Objects.equals(id, that.id) && Objects.equals(code, that.code) && Objects.equals(json, that.json);
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(id, code, json);
// }
@Override
public boolean canEqual(Object other) {
return other instanceof ShortFilter;
}
}