InventoryMaintenancePolicy.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.gringlobal.model;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.genesys.blocks.model.Copyable;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.blocks.util.ClassAclOid;
import org.gringlobal.compatibility.LookupDisplay;
import org.gringlobal.custom.validation.javax.CodeValueField;

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

import org.gringlobal.model.community.CommunityCodeValues;

import static org.gringlobal.model.community.CommunityCodeValues.CODE_VALUE_LENGTH;

/**
 * Auto-generated by:
 * org.apache.openjpa.jdbc.meta.ReverseMappingTool$AnnotatedCodeGenerator
 */
@Entity
@Table(name = "inventory_maint_policy")
@JsonIdentityInfo(scope = InventoryMaintenancePolicy.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@Getter
@Setter
@NoArgsConstructor
public class InventoryMaintenancePolicy extends CooperatorOwnedModel implements AclAwareModel, Copyable<InventoryMaintenancePolicy> {

	private static final long serialVersionUID = -7768305448820478577L;

	// ACL Parent
	@Transient
	public static final ClassAclOid<InventoryMaintenancePolicy> ACL_CLASS_IDENTITY = ClassAclOid.forClass(InventoryMaintenancePolicy.class);

	@ManyToOne(fetch = FetchType.LAZY, cascade = {})
	@JoinColumn(name = "curator_cooperator_id")
	private Cooperator curatorCooperator;

	@Basic
	@Column(name = "distribution_critical_quantity")
	private Double distributionCriticalQuantity;

	@Basic
	@Column(name = "distribution_default_form_code", nullable = false, length = CODE_VALUE_LENGTH)
	@CodeValueField(CommunityCodeValues.GERMPLASM_FORM)
	private String distributionDefaultFormCode;

	@Basic
	@Column(name = "distribution_default_quantity")
	private Double distributionDefaultQuantity;

	@Basic
	@Column(name = "distribution_unit_code", length = CODE_VALUE_LENGTH)
	@CodeValueField(CommunityCodeValues.UNIT_OF_QUANTITY)
	private String distributionUnitCode;

	@Basic
	@Column(name = "form_type_code", nullable = false, length = CODE_VALUE_LENGTH)
	@CodeValueField(CommunityCodeValues.GERMPLASM_FORM)
	private String formTypeCode;

	@Id
	@JsonProperty
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "inventory_maint_policy_id", columnDefinition = "int")
	private Long id;

	@Basic
	@Column(name = "is_auto_deducted", nullable = false, length = 1)
	private String isAutoDeducted;

	@Basic
	@Column(name = "maintenance_name", nullable = false, length = 50)
	@LookupDisplay
	private String maintenanceName;

	@Basic
	@Column
	@Lob
	private String note;

	@Basic
	@Column(name = "quantity_on_hand_unit_code", length = CODE_VALUE_LENGTH)
	@CodeValueField(CommunityCodeValues.UNIT_OF_QUANTITY)
	private String quantityOnHandUnitCode;

	@Basic
	@Column(name = "regeneration_critical_quantity")
	private Double regenerationCriticalQuantity;

	@Basic
	@Column(name = "regeneration_method_code", length = CODE_VALUE_LENGTH)
	@CodeValueField("REGENERATION_METHOD")
	private String regenerationMethodCode;

	@Basic
	@Column(name = "web_availability_note")
	@Lob
	private String webAvailabilityNote;

	@NotNull
	@Column(name = "management_type_code", nullable = false, length = CODE_VALUE_LENGTH)
	@CodeValueField(CommunityCodeValues.MANAGEMENT_TYPE)
	private String managementTypeCode;

	@CodeValueField(CommunityCodeValues.STORAGE_TYPE)
	@Column(name = "storage_type_code", length = CODE_VALUE_LENGTH)
	private String storageTypeCode;

	public InventoryMaintenancePolicy(final Long id) {
		this.id = id;
	}

	@Override
	public void lazyLoad() {
		super.lazyLoad();
		lazyLoad(this.curatorCooperator);
	}
	
	/**
	 * Inventory maintenance policy inherits permissions from the type.
	 */
	@Override
	public AclAwareModel aclParentObject() {
		return ACL_CLASS_IDENTITY;
	}

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