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; 017 018import java.util.StringJoiner; 019import java.util.UUID; 020 021/** 022 * Encapsulate a challenge code. 023 */ 024public class ChallengeCode { 025 026 private Integer key; 027 private UUID code; 028 // additional data (may be an email address or something) 029 private String data; 030 031 public static ChallengeCode newRandom() { 032 ChallengeCode challengeCode = new ChallengeCode(); 033 challengeCode.setCode(UUID.randomUUID()); 034 return challengeCode; 035 } 036 037 public static ChallengeCode newRandom(String data) { 038 ChallengeCode challengeCode = newRandom(); 039 challengeCode.setData(data); 040 return challengeCode; 041 } 042 043 public Integer getKey() { 044 return key; 045 } 046 047 public void setKey(Integer key) { 048 this.key = key; 049 } 050 051 public UUID getCode() { 052 return code; 053 } 054 055 public void setCode(UUID code) { 056 this.code = code; 057 } 058 059 public String getData() { 060 return data; 061 } 062 063 public void setData(String data) { 064 this.data = data; 065 } 066 067 @Override 068 public String toString() { 069 return new StringJoiner(", ", ChallengeCode.class.getSimpleName() + "[", "]") 070 .add("key=" + key) 071 .add("code=" + code) 072 .add("data='" + data + "'") 073 .toString(); 074 } 075}