ShortFilter.java

/*
 * Copyright 2019 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.server.model;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.genesys.blocks.model.BasicModel;
import org.hibernate.annotations.Type;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * @author Maxym Borodenko
 */
@Entity
@Table(name = "short_filter"
// TODO Manually create an index on json field! (length limited)
// , indexes = { @Index(name="UK_1my8xep8hi5fv42o3ivu0t41o", columnList =
// "json") }
)
@Cacheable
@Getter
@Setter
@NoArgsConstructor
public class ShortFilter extends BasicModel {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -2244432499719332545L;

	/** 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 canEqual(Object other) {
		return other instanceof ShortFilter;
	}
}