AccessionList.java

/**
 * Copyright 2015 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.genesys;

import java.util.Set;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.security.model.AclAwareModel;
import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

@Entity
@Table(name = "accession_list")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid", scope = AccessionList.class)
@Getter
@Setter
@NoArgsConstructor
public class AccessionList extends AuditedVersionedModel implements AclAwareModel {
	private static final long serialVersionUID = 991886970995006680L;

	@Field(type = FieldType.Keyword)
	@Column(name = "uuid", unique = true, nullable = false, updatable = false)
	@Type(type = "uuid-binary")
	protected UUID uuid;

	@ManyToMany(cascade = {}, fetch = FetchType.LAZY)
	@JoinTable(name = "accession_listitem", joinColumns = @JoinColumn(name = "listid"), inverseJoinColumns = @JoinColumn(name = "acceid"))
	private Set<AccessionId> accessionIds;

	@Column(name = "title", nullable = false)
	private String title;

	@Column(name = "description", nullable = true)
	private String description;

	@Column
	private boolean shared;

	@PrePersist
	protected void pre() {
		if (uuid == null) {
			uuid = UUID.randomUUID();
		}
	}

	public boolean isShared() {
		return shared;
	}

	public boolean getShared() {
		return shared;
	}

	@Override
	public boolean canEqual(Object other) {
		return other instanceof AccessionList;
	}
}