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 @ 3182

History | View | Annotate | Download (3.94 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.VCSGisUtils;
30
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
31
import org.slf4j.Logger;
32
import org.slf4j.LoggerFactory;
33

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

    
40
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractRequestHelper.class);
41

    
42
    private final VCSGisRepository repository;
43
    private final String requestName;
44
    private final String code;
45

    
46
    private int lastErrorCode;
47
    private String lastErrorMessage;
48
    private boolean enableStatus;
49

    
50
    private String authenticationToken;
51
    private String userCode;
52

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

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

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

    
80
    @Override
81
    public VCSGisRepository getRepository() {
82
        return repository;
83
    }
84

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

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

    
128
    public boolean isEnabledStatus() {
129
        return this.enableStatus;
130
    }
131
    
132

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

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

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

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