All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.erudika.para.core.Address Maven / Gradle / Ivy

There is a newer version: 1.50.3
Show newest version
/*
 * Copyright 2013-2017 Erudika. https://erudika.com
 *
 * 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.
 *
 * For issues and patches go to: https://github.com/erudika
 */
package com.erudika.para.core;

import com.erudika.para.core.utils.CoreUtils;
import com.erudika.para.core.utils.ParaObjectUtils;
import com.erudika.para.annotations.Locked;
import com.erudika.para.annotations.Stored;
import com.erudika.para.utils.Config;
import com.erudika.para.utils.Pager;
import com.erudika.para.utils.Utils;
import java.util.List;
import java.util.Objects;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotBlank;

/**
 * This class represents an address. It enables location based search queries.
 * It can be attached to any object by creating a {@link Linker} between the two.
 * @author Alex Bogdanovski [[email protected]]
 * @see Linker
 */
public class Address implements ParaObject {
	private static final long serialVersionUID = 1L;

	@Stored @Locked private String id;
	@Stored @Locked private Long timestamp;
	@Stored @Locked private String type;
	@Stored @Locked private String appid;
	@Stored @Locked private String parentid;
	@Stored @Locked private String creatorid;
	@Stored private Long updated;
	@Stored private String name;
	@Stored private List tags;
	@Stored private Integer votes;
	@Stored private Boolean stored;
	@Stored private Boolean indexed;
	@Stored private Boolean cached;

	@Stored @NotBlank @Size(min = 3, max = 255) private String address;
	@Stored @NotBlank @Size(min = 2, max = 255) private String country;
	@Stored @Size(min = 0, max = 255) private String city;
	@Stored @NotBlank private String latlng;
	@Stored private String phone;

	/**
	 * No-args constructor.
	 * Same as {@code Address(null)}
	 */
	public Address() {
		this(null);
	}

	/**
	 * Default constructor.
	 * @param id the id
	 */
	public Address(String id) {
		setId(id);
		setName(getName());
	}

	/**
	 * The name of the city. Optional.
	 * @return the city
	 */
	public String getCity() {
		return city;
	}

	/**
	 * Sets the city.
	 * @param city city name
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * The Latitude and Longitude points of this address. Must not be null or empty.
	 * @return "lat,lng" as a string
	 */
	public String getLatlng() {
		return latlng;
	}

	/**
	 * Sets the coordinates in the form "LAT,LNG".
	 * @param latlng the coords
	 */
	public void setLatlng(String latlng) {
		this.latlng = latlng;
	}

	/**
	 * The phone number. Multiple phones separated by comma are allowed.
	 * @return the phone number
	 */
	public String getPhone() {
		return phone;
	}

	/**
	 * Sets a new phone number.
	 * @param phone the number as a string
	 */
	public void setPhone(String phone) {
		this.phone = phone;
	}

	/**
	 * The country in which the address is located. Must not be null or empty.
	 * @return the full country name
	 */
	public String getCountry() {
		return country;
	}

	/**
	 * Sets a new country name.
	 * @param country the name of the country
	 */
	public void setCountry(String country) {
		this.country = country;
	}

	/**
	 * The street address and other address info.
	 * @return the street address
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * Sets new street address. Must not be null or empty.
	 * @param address the address info
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	////////////////////////////////////////////////////////

	@Override
	public final String getId() {
		return id;
	}

	@Override
	public final void setId(String id) {
		this.id = id;
	}

	@Override
	public final String getType() {
		type = (type == null) ? Utils.type(this.getClass()) : type;
		return type;
	}

	@Override
	public final void setType(String type) {
		this.type = type;
	}

	@Override
	public String getAppid() {
		appid = (appid == null) ? Config.APP_NAME_NS : appid;
		return appid;
	}

	@Override
	public void setAppid(String appid) {
		this.appid = appid;
	}

	@Override
	public String getObjectURI() {
		return CoreUtils.getInstance().getObjectURI(this);
	}

	@Override
	public List getTags() {
		return tags;
	}

	@Override
	public Boolean getStored() {
		if (stored == null) {
			stored = true;
		}
		return stored;
	}

	@Override
	public void setStored(Boolean stored) {
		this.stored = stored;
	}

	@Override
	public Boolean getIndexed() {
		if (indexed == null) {
			indexed = true;
		}
		return indexed;
	}

	@Override
	public void setIndexed(Boolean indexed) {
		this.indexed = indexed;
	}

	@Override
	public Boolean getCached() {
		if (cached == null) {
			cached = true;
		}
		return cached;
	}

	@Override
	public void setCached(Boolean cached) {
		this.cached = cached;
	}

	@Override
	public void setTags(List tags) {
		this.tags = tags;
	}

	@Override
	public Long getTimestamp() {
		return (timestamp != null && timestamp != 0) ? timestamp : null;
	}

	@Override
	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	@Override
	public String getCreatorid() {
		return creatorid;
	}

	@Override
	public void setCreatorid(String creatorid) {
		this.creatorid = creatorid;
	}

	@Override
	public final String getName() {
		return CoreUtils.getInstance().getName(name, id);
	}

	@Override
	public final void setName(String name) {
		this.name = (name == null || !name.isEmpty()) ? name : this.name;
	}

	@Override
	public String getPlural() {
		return Utils.singularToPlural(getType());
	}

	@Override
	public String getParentid() {
		return parentid;
	}

	@Override
	public void setParentid(String parentid) {
		this.parentid = parentid;
	}

	@Override
	public Long getUpdated() {
		return (updated != null && updated != 0) ? updated : null;
	}

	@Override
	public void setUpdated(Long updated) {
		this.updated = updated;
	}

	@Override
	public String create() {
		return CoreUtils.getInstance().getDao().create(getAppid(), this);
	}

	@Override
	public void update() {
		CoreUtils.getInstance().getDao().update(getAppid(), this);
	}

	@Override
	public void delete() {
		CoreUtils.getInstance().getDao().delete(getAppid(), this);
	}

	@Override
	public boolean exists() {
		return CoreUtils.getInstance().getDao().read(getAppid(), getId()) != null;
	}

	@Override
	public boolean voteUp(String userid) {
		return CoreUtils.getInstance().vote(this, userid, VoteValue.UP);
	}

	@Override
	public boolean voteDown(String userid) {
		return CoreUtils.getInstance().vote(this, userid, VoteValue.DOWN);
	}

	@Override
	public Integer getVotes() {
		return (votes == null) ? 0 : votes;
	}

	@Override
	public void setVotes(Integer votes) {
		this.votes = votes;
	}

	@Override
	public Long countLinks(String type2) {
		return CoreUtils.getInstance().countLinks(this, type2);
	}

	@Override
	public List getLinks(String type2, Pager... pager) {
		return CoreUtils.getInstance().getLinks(this, type2, pager);
	}

	@Override
	public 

List

getLinkedObjects(String type, Pager... pager) { return CoreUtils.getInstance().getLinkedObjects(this, type, pager); } @Override public

List

findLinkedObjects(String type, String field, String query, Pager... pager) { return CoreUtils.getInstance().findLinkedObjects(this, type, field, query, pager); } @Override public boolean isLinked(String type2, String id2) { return CoreUtils.getInstance().isLinked(this, type2, id2); } @Override public boolean isLinked(ParaObject toObj) { return CoreUtils.getInstance().isLinked(this, toObj); } @Override public String link(String id2) { return CoreUtils.getInstance().link(this, id2); } @Override public void unlink(String type, String id2) { CoreUtils.getInstance().unlink(this, type, id2); } @Override public void unlinkAll() { CoreUtils.getInstance().unlinkAll(this); } @Override public Long countChildren(String type) { return CoreUtils.getInstance().countChildren(this, type); } @Override public

List

getChildren(String type, Pager... pager) { return CoreUtils.getInstance().getChildren(this, type, pager); } @Override public

List

getChildren(String type, String field, String term, Pager... pager) { return CoreUtils.getInstance().getChildren(this, type, field, term, pager); } @Override public

List

findChildren(String type, String query, Pager... pager) { return CoreUtils.getInstance().findChildren(this, type, query, pager); } @Override public void deleteChildren(String type) { CoreUtils.getInstance().deleteChildren(this, type); } @Override public int hashCode() { int hash = 7; hash = 67 * hash + Objects.hashCode(this.id) + Objects.hashCode(this.name); return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final ParaObject other = (ParaObject) obj; if (!Objects.equals(this.id, other.getId())) { return false; } return true; } @Override public String toString() { return ParaObjectUtils.toJSON(this); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy