Statistics
| Revision:

gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.lib / org.gvsig.vcsgis.lib.impl / src / main / java / org / gvsig / vcsgis / lib / requests / AbstractRequestHelper.java @ 3315

History | View | Annotate | Download (4.05 KB)

1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22

    
23
package org.gvsig.vcsgis.lib.requests;
24

    
25
import java.sql.Timestamp;
26
import java.time.LocalDateTime;
27
import java.time.ZoneOffset;
28
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK;
29
import org.gvsig.vcsgis.lib.VCSGisUser;
30
import org.gvsig.vcsgis.lib.VCSGisUtils;
31
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
32
import org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable;
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35

    
36
/**
37
 *
38
 * @author gvSIG Team
39
 */
40
public abstract class AbstractRequestHelper implements RequestHelper {
41

    
42
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractRequestHelper.class);
43

    
44
    private final VCSGisRepository repository;
45
    private final String requestName;
46
    private final String code;
47

    
48
    private int lastErrorCode;
49
    private String lastErrorMessage;
50
    private boolean enableStatus;
51

    
52
    private String authenticationToken;
53
    private String userCode;
54

    
55
    public AbstractRequestHelper(VCSGisRepository repository, String requestName) {
56
        this.repository = repository;
57
        this.requestName = requestName;
58
        this.code = this.repository.createUniqueCode();
59
        enableStatus = true;
60
    }
61
    
62
    @Override
63
    public String getCode() {
64
        return this.code;
65
    }
66

    
67
    @Override
68
    public String getRequestName() {
69
        return this.requestName;
70
    }
71
    
72
    @Override
73
    public int getLastErrorCode() {
74
        return this.lastErrorCode;
75
    }
76

    
77
    @Override
78
    public String getLastErrorMessage() {
79
        return this.lastErrorMessage;
80
    }
81

    
82
    @Override
83
    public VCSGisRepository getRepository() {
84
        return repository;
85
    }
86

    
87
    @Override
88
    public int error(int code) {
89
        return error(code, null);
90
    }
91
    
92
    @Override
93
    public int error(int code, String message) {
94
        this.lastErrorCode = code;
95
        if( message==null ) {
96
            this.lastErrorMessage = VCSGisUtils.getErrorMessage(code);        
97
        } else {
98
            this.lastErrorMessage = message;
99
        }
100
        if( LOGGER.isDebugEnabled() ) {
101
            if( this.lastErrorCode != ERR_OK ) {
102
                try {
103
                    throw new Exception();
104
                } catch(Exception ex) {
105
                    LOGGER.warn("Error code "+this.lastErrorCode+", "+this.lastErrorMessage, ex);
106
                }
107
            }
108
        }
109
        return code;
110
    }
111
  
112
    @Override
113
    public void dispose() {
114
    }
115
    
116
    public Timestamp now() {
117
        return Timestamp.from(LocalDateTime.now().toInstant(ZoneOffset.UTC));
118
    }
119
    
120
    @Override
121
    public int execute() {
122
        return error(ERR_OK);
123
    }
124

    
125
    @Override
126
    public void setEnabledStatus(boolean enable) {
127
        this.enableStatus = enable;
128
    }
129

    
130
    public boolean isEnabledStatus() {
131
        return this.enableStatus;
132
    }
133
    
134

    
135
    @Override
136
    public String getAuthenticationToken() {
137
        return this.authenticationToken;
138
    }
139

    
140
    @Override
141
    public void setAuthenticationToken(String token) {
142
        this.authenticationToken = token;
143
    }
144

    
145
    @Override
146
    public String getUserCode() {
147
        return this.userCode;
148
    }
149

    
150
    @Override
151
    public void setUserCode(String userCode) {
152
        this.userCode = userCode;
153
    }
154
    
155
}