it.cnr.iit.jscontact.tools.dto.Anniversary Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jscontact-tools Show documentation
Show all versions of jscontact-tools Show documentation
Java tools for JSContact building, validation, serialization/deserialization and conversion from vCard 4.0 (RFC6350) and its transliterations, namely xCard (RFC6351) and jCard (RFC7095).
/*
* Copyright (C) 2020 Consiglio Nazionale delle Ricerche
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package it.cnr.iit.jscontact.tools.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import it.cnr.iit.jscontact.tools.dto.annotations.ContainsExtensibleEnum;
import it.cnr.iit.jscontact.tools.dto.deserializers.AnniversaryDateDeserializer;
import it.cnr.iit.jscontact.tools.dto.deserializers.AnniversaryKindDeserializer;
import it.cnr.iit.jscontact.tools.dto.interfaces.HasKind;
import it.cnr.iit.jscontact.tools.dto.interfaces.IdMapValue;
import it.cnr.iit.jscontact.tools.dto.interfaces.IsIANAType;
import it.cnr.iit.jscontact.tools.dto.serializers.AnniversaryDateSerializer;
import lombok.*;
import lombok.experimental.SuperBuilder;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
/**
* Class mapping the Anniversary type as defined in section 2.8.1 of [draft-ietf-calext-jscontact].
*
* @see draft-ietf-calext-jscontact
* @author Mario Loffredo
*/
@JsonPropertyOrder({"@type", "kind", "date", "place"})
@JsonInclude(JsonInclude.Include.NON_NULL)
@SuperBuilder
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class Anniversary extends AbstractJSContactType implements HasKind, IdMapValue, IsIANAType, Serializable {
@Pattern(regexp = "Anniversary", message = "invalid @type value in Anniversary")
@JsonProperty("@type")
@Builder.Default
String _type = "Anniversary";
@NotNull(message = "kind is missing in Anniversary")
@JsonDeserialize(using = AnniversaryKindDeserializer.class)
@ContainsExtensibleEnum(enumClass = AnniversaryEnum.class, getMethod = "getKind")
AnniversaryKind kind;
@NotNull(message = "date is missing in Anniversary")
@NonNull
@JsonSerialize(using = AnniversaryDateSerializer.class)
@JsonDeserialize(using = AnniversaryDateDeserializer.class)
@Valid
AnniversaryDate date;
@Valid
Address place;
/**
* Tests if this anniversary is a birthday. See vCard 4.0 BDAY property as defined in section 6.2.5 of [RFC6350].
*
* @return true if this anniversary is a birthday, false otherwise
* @see RFC6350
*/
@JsonIgnore
public boolean isBirth() { return kind.isBirth(); }
/**
* Tests if this anniversary is a date of death. See vCard 4.0 DEATHDATE property as defined in section 6.2.5 of [RFC6474].
*
* @return true if this anniversary is a date of death, false otherwise
* @see RFC6474
*/
@JsonIgnore
public boolean isDeath() { return kind.isDeath(); }
/**
* Tests if this anniversary is a date of wedding, or equivalent. See vCard 4.0 ANNIVERSARY property as defined in section 6.2.6 of [RFC6350].
*
* @return true if this anniversary is a date of wedding, false otherwise
* @see RFC6350
*/
@JsonIgnore
public boolean isWedding() { return kind.isWedding(); }
/**
* Tests if this is an undefined anniversary specified by the value of the "label" property.
*
* @return true if this is an undefined anniversary, false otherwise
*/
@JsonIgnore
public boolean isOtherAnniversary() { return kind.isExtValue(); }
private static Anniversary anniversary(AnniversaryKind type, AnniversaryDate date, String label) {
return Anniversary.builder().kind(type).date(date).build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy