AppResource.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 java.util.Optional;

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

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.genesys.blocks.model.Copyable;

/**
 * Auto-generated by:
 * org.apache.openjpa.jdbc.meta.ReverseMappingTool$AnnotatedCodeGenerator
 */
@Entity
@Table(name = "app_resource")
@JsonIdentityInfo(scope = AppResource.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@Getter
@Setter
@NoArgsConstructor
public class AppResource extends CooperatorOwnedModel implements Copyable<AppResource> {
	private static final long serialVersionUID = 7069933268442363330L;

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

	@Basic
	@NotNull
	@Size(max = 100)
	@Column(name = "app_name", nullable = false, length = 100)
	private String appName;

	@Basic
	@NotNull
	@Size(max = 100)
	@Column(name = "app_resource_name", nullable = false, length = 100)
	private String appResourceName;

	@Basic
	@Column
	@Lob
	private String description;

	@Basic
	@NotNull
	@Column(name = "display_member", nullable = false)
	@Lob
	private String displayMember;

	@Basic
	@NotNull
	@Size(max = 100)
	@Column(name = "form_name", nullable = false, length = 100)
	private String formName;

	@Basic
	@Size(max = 2000)
	@Column(length = 2000)
	private String properties;

	@Basic
	@Column(name = "sort_order")
	private Integer sortOrder;

	@NotNull
	@ManyToOne(fetch = FetchType.LAZY, cascade = {})
	@JoinColumn(name = "sys_lang_id", nullable = false)
	private SysLang sysLang;

	@Basic
	@Size(max = 2000)
	@Column(name = "value_member", length = 2000)
	private String valueMember;

	public AppResource(Optional<AppResource> defaultTranslation, SysLang sysLang) {
		if (defaultTranslation.isPresent()) {
			this.appName = defaultTranslation.get().appName;
			this.appResourceName = defaultTranslation.get().appResourceName;
			this.description = defaultTranslation.get().description;
			this.displayMember = defaultTranslation.get().displayMember;
			this.formName = defaultTranslation.get().formName;
			this.properties = defaultTranslation.get().properties;
			this.sortOrder = defaultTranslation.get().sortOrder;
			this.valueMember = defaultTranslation.get().valueMember;
		}
		this.sysLang = sysLang;
	}

	public AppResource(final Long id) {
		this.id = id;
	}
	
	@Override
	public void lazyLoad() {
		super.lazyLoad();
		lazyLoad(this.sysLang);
	}

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