001/* 002 * Copyright 2020 Global Biodiversity Information Facility (GBIF) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.gbif.api.model.registry; 017 018import io.swagger.v3.oas.annotations.media.Schema; 019 020import org.gbif.api.vocabulary.EndpointType; 021 022import java.io.Serializable; 023import java.net.URI; 024import java.util.ArrayList; 025import java.util.Date; 026import java.util.List; 027import java.util.Objects; 028import java.util.StringJoiner; 029 030import javax.annotation.Nullable; 031import javax.validation.constraints.Min; 032import javax.validation.constraints.NotNull; 033import javax.validation.constraints.Null; 034import javax.validation.constraints.Size; 035 036public class Endpoint implements MachineTaggable, Serializable, LenientEquals<Endpoint> { 037 038 @Schema( 039 description = "Identifier for the endpoint", 040 accessMode = Schema.AccessMode.READ_ONLY 041 ) 042 private Integer key; 043 044 private EndpointType type; 045 046 private URI url; 047 048 private String description; 049 050 @Schema( 051 description = "The GBIF username of the creator of the endpoint", 052 accessMode = Schema.AccessMode.READ_ONLY 053 ) 054 private String createdBy; 055 056 @Schema( 057 description = "The GBIF username of the last user to modify the endpoint", 058 accessMode = Schema.AccessMode.READ_ONLY 059 ) 060 private String modifiedBy; 061 062 @Schema( 063 description = "Timestamp of when the endpoint was created", 064 accessMode = Schema.AccessMode.READ_ONLY 065 ) 066 private Date created; 067 068 @Schema( 069 description = "Timestamp of when the endpoint was last modified", 070 accessMode = Schema.AccessMode.READ_ONLY 071 ) 072 private Date modified; 073 074 @Schema( 075 description = "Machine tags applied to the endpoint", 076 required = false 077 ) 078 private List<MachineTag> machineTags = new ArrayList<>(); 079 080 @Null(groups = PrePersist.class) 081 @NotNull(groups = PostPersist.class) 082 @Min(1) 083 public Integer getKey() { 084 return key; 085 } 086 087 public void setKey(Integer key) { 088 this.key = key; 089 } 090 091 @NotNull 092 public EndpointType getType() { 093 return type; 094 } 095 096 public void setType(EndpointType type) { 097 this.type = type; 098 } 099 100 @Nullable 101 public URI getUrl() { 102 return url; 103 } 104 105 public void setUrl(URI url) { 106 this.url = url; 107 } 108 109 @Nullable 110 public String getDescription() { 111 return description; 112 } 113 114 public void setDescription(String description) { 115 this.description = description; 116 } 117 118 @Size(min = 3) 119 public String getCreatedBy() { 120 return createdBy; 121 } 122 123 public void setCreatedBy(String createdBy) { 124 this.createdBy = createdBy; 125 } 126 127 @Size(min = 3) 128 public String getModifiedBy() { 129 return modifiedBy; 130 } 131 132 public void setModifiedBy(String modifiedBy) { 133 this.modifiedBy = modifiedBy; 134 } 135 136 @Null(groups = PrePersist.class) 137 @NotNull(groups = PostPersist.class) 138 public Date getCreated() { 139 return created; 140 } 141 142 public void setCreated(Date created) { 143 this.created = created; 144 } 145 146 @Null(groups = PrePersist.class) 147 @NotNull(groups = PostPersist.class) 148 public Date getModified() { 149 return modified; 150 } 151 152 public void setModified(Date modified) { 153 this.modified = modified; 154 } 155 156 @Override 157 public List<MachineTag> getMachineTags() { 158 return machineTags; 159 } 160 161 @Override 162 public void setMachineTags(List<MachineTag> machineTags) { 163 this.machineTags = machineTags; 164 } 165 166 @Override 167 public void addMachineTag(MachineTag machineTag) { 168 machineTags.add(machineTag); 169 } 170 171 @Override 172 public boolean equals(Object o) { 173 if (this == o) { 174 return true; 175 } 176 if (o == null || getClass() != o.getClass()) { 177 return false; 178 } 179 Endpoint endpoint = (Endpoint) o; 180 return Objects.equals(key, endpoint.key) 181 && type == endpoint.type 182 && Objects.equals(url, endpoint.url) 183 && Objects.equals(description, endpoint.description) 184 && Objects.equals(createdBy, endpoint.createdBy) 185 && Objects.equals(modifiedBy, endpoint.modifiedBy) 186 && Objects.equals(created, endpoint.created) 187 && Objects.equals(modified, endpoint.modified) 188 && Objects.equals(machineTags, endpoint.machineTags); 189 } 190 191 @Override 192 public int hashCode() { 193 return Objects.hash( 194 key, type, url, description, createdBy, modifiedBy, created, modified, machineTags); 195 } 196 197 @Override 198 public String toString() { 199 return new StringJoiner(", ", Endpoint.class.getSimpleName() + "[", "]") 200 .add("key=" + key) 201 .add("type=" + type) 202 .add("url=" + url) 203 .add("description='" + description + "'") 204 .add("createdBy='" + createdBy + "'") 205 .add("modifiedBy='" + modifiedBy + "'") 206 .add("created=" + created) 207 .add("modified=" + modified) 208 .add("machineTags=" + machineTags) 209 .toString(); 210 } 211 212 /** 213 * Does not include server controlled values, or nested properties. 214 */ 215 @Override 216 public boolean lenientEquals(Endpoint other) { 217 if (this == other) { 218 return true; 219 } else { 220 return Objects.equals(this.type, other.type) 221 && Objects.equals(this.url, other.url) 222 && Objects.equals(this.description, other.description); 223 } 224 } 225}