DatasetLocation.java

/*
 * Copyright 2018 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.dataset;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.genesys.blocks.model.UuidModel;
import org.genesys.util.MCPDUtil;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * The Class DatasetLocation.
 *
 * @author Andrey Lugovskoy.
 */
@Entity
@Table(name="dataset_location")
@Getter
@Setter
@NoArgsConstructor
public class DatasetLocation extends UuidModel {

	/**
	 *
	 */
	private static final long serialVersionUID = -3107167591979299613L;

	/** The dataset. */
	@ManyToOne(cascade = { CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.DETACH }, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(name = "datasetId")
	@JsonIgnore
	private Dataset dataset;

	/** The user-provided country name. */
	private String userCountry;

	/** Country as detected from coordinates. */
	private String mapCountry;

	/** The state province. */
	private String stateProvince;

	/** The verbatim locality. */
	private String verbatimLocality;

	/** The decimal latitude. */
	private Double decimalLatitude;

	/** The decimal longitude. */
	private Double decimalLongitude;

	/** ISO3 country code of the location */
	@Size(max = 3)
	@Column(length = 3)
	private String countryCode;

	/** The start date  */
	@Size(max = 8)
	@Column(length = 8)
	private String startDate;

	/** The end date  */
	@Size(max = 8)
	@Column(length = 8)
	private String endDate;

	/** Description of environment conditions. */
	@Lob
	private String description;

	/**
	 * Sets the start date if startDate is valid McpdDate.
	 *
	 * @param startDate the new start date
	 */
	public void setStartDate(String startDate) {
	    if(MCPDUtil.isMcpdDate(startDate)) {
            this.startDate = startDate;
        }
	}

	/**
	 * Sets the end date if endDate is valid McpdDate.
	 *
	 * @param endDate the new start date
	 */
	public void setEndDate(String endDate) {
	    if(MCPDUtil.isMcpdDate(endDate)) {
            this.endDate = endDate;
        }
	}

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