001/*
002 * Stallion Core: A Modern Web Framework
003 *
004 * Copyright (C) 2015 - 2016 Stallion Software LLC.
005 *
006 * This program is free software: you can redistribute it and/or modify it under the terms of the
007 * GNU General Public License as published by the Free Software Foundation, either version 2 of
008 * the License, or (at your option) any later version. This program is distributed in the hope that
009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
011 * License for more details. You should have received a copy of the GNU General Public License
012 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
013 *
014 *
015 *
016 */
017
018package io.stallion.services;
019
020import com.fasterxml.jackson.annotation.JsonIgnore;
021import com.fasterxml.jackson.annotation.JsonProperty;
022import com.fasterxml.jackson.core.type.TypeReference;
023import io.stallion.dataAccess.ModelBase;
024import io.stallion.utils.json.JSON;
025
026import javax.persistence.Column;
027import javax.persistence.Table;
028import java.time.ZonedDateTime;
029import java.util.HashMap;
030
031
032@Table(name="stallion_temp_tokens")
033public class TempToken extends ModelBase {
034    private String customKey = "";
035    private ZonedDateTime expiresAt;
036    private String token = "";
037    private String userType = "";
038    private String targetKey = "";
039    private HashMap<String, Object> data = new HashMap<>();
040    private ZonedDateTime usedAt;
041    private ZonedDateTime createdAt;
042
043    @Column
044    public String getCustomKey() {
045        return customKey;
046    }
047
048    public void setCustomKey(String customKey) {
049        this.customKey = customKey;
050    }
051
052    @Column
053    public ZonedDateTime getExpiresAt() {
054        return expiresAt;
055    }
056
057    public void setExpiresAt(ZonedDateTime expiresAt) {
058        this.expiresAt = expiresAt;
059    }
060
061    @Column
062    public String getToken() {
063        return token;
064    }
065
066    public void setToken(String token) {
067        this.token = token;
068    }
069
070    @JsonIgnore
071    public String getData() throws Exception {
072        return JSON.stringify(data);
073    }
074
075    @JsonIgnore
076    public void setData(String data) throws Exception {
077        this.data = (HashMap<String, Object>)JSON.parse(data, new TypeReference<HashMap<String, Object>>(){});
078    }
079
080
081    @JsonProperty
082    public HashMap<String, Object> getDataObj() {
083        return data;
084    }
085
086    @JsonProperty
087    public void setDataObj(HashMap<String, Object> data) {
088        this.data = data;
089    }
090
091    @Column
092    public ZonedDateTime getUsedAt() {
093        return usedAt;
094    }
095
096    public void setUsedAt(ZonedDateTime usedAt) {
097        this.usedAt = usedAt;
098    }
099
100    @Column
101    public ZonedDateTime getCreatedAt() {
102        return createdAt;
103    }
104
105    public void setCreatedAt(ZonedDateTime createdAt) {
106        this.createdAt = createdAt;
107    }
108
109    @Column
110    public String getUserType() {
111        return userType;
112    }
113
114    public void setUserType(String userType) {
115        this.userType = userType;
116    }
117
118    @Column
119    public String getTargetKey() {
120        return targetKey;
121    }
122
123    public void setTargetKey(String targetKey) {
124        this.targetKey = targetKey;
125    }
126}