1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.gateway.kernel.database;
22
23 import io.netty.handler.codec.http.HttpResponseStatus;
24 import org.waarp.common.database.DbSession;
25 import org.waarp.common.database.data.AbstractDbData.UpdatedInfo;
26 import org.waarp.common.database.exception.WaarpDatabaseException;
27 import org.waarp.common.logging.WaarpLogger;
28 import org.waarp.common.logging.WaarpLoggerFactory;
29 import org.waarp.gateway.kernel.HttpPage.PageRole;
30 import org.waarp.gateway.kernel.database.data.DbTransferLog;
31 import org.waarp.gateway.kernel.session.HttpSession;
32
33
34
35
36 public final class WaarpActionLogger {
37
38
39
40 private static final WaarpLogger logger =
41 WaarpLoggerFactory.getLogger(WaarpActionLogger.class);
42
43 private WaarpActionLogger() {
44 }
45
46
47
48
49
50
51
52
53 public static void logCreate(final DbSession dbSession, final String message,
54 final HttpSession session) {
55 final String sessionContexte = session.toString();
56 logger.info("{} {}", message, sessionContexte);
57 if (dbSession != null) {
58 final PageRole code = session.getCurrentCommand();
59 boolean isSender = false;
60 switch (code) {
61 case ERROR:
62 case HTML:
63 case MENU:
64 session.setLogid(DbConstantGateway.ILLEGALVALUE);
65 return;
66 case DELETE:
67 case GETDOWNLOAD:
68 isSender = false;
69 break;
70 case POST:
71 case POSTUPLOAD:
72 case PUT:
73 isSender = true;
74 break;
75 default:
76 break;
77 }
78
79 try {
80 final DbTransferLog log =
81 new DbTransferLog(dbSession, session.getAuth().getUser(),
82 session.getAuth().getAccount(),
83 DbConstantGateway.ILLEGALVALUE, isSender,
84 session.getFilename(), code.name(),
85 HttpResponseStatus.OK, message,
86 UpdatedInfo.TOSUBMIT);
87 logger.debug("Create FS: {}", log);
88 session.setLogid(log.getSpecialId());
89 return;
90 } catch (final WaarpDatabaseException e1) {
91
92 }
93 }
94 session.setLogid(DbConstantGateway.ILLEGALVALUE);
95 }
96
97
98
99
100
101
102
103
104
105
106 public static void logAction(final DbSession dbSession,
107 final HttpSession session, final String message,
108 final HttpResponseStatus rcode,
109 final UpdatedInfo info) {
110 final String sessionContexte = session.toString();
111 final long specialId = session.getLogid();
112 logger.info("{} {}", message, sessionContexte);
113 if (dbSession != null && specialId != DbConstantGateway.ILLEGALVALUE) {
114 final PageRole code = session.getCurrentCommand();
115 switch (code) {
116 case DELETE:
117 case GETDOWNLOAD:
118 case POST:
119 case POSTUPLOAD:
120 case PUT:
121 break;
122 case ERROR:
123 case HTML:
124 case MENU:
125 default:
126 return;
127 }
128 try {
129
130 final DbTransferLog log =
131 new DbTransferLog(dbSession, session.getAuth().getUser(),
132 session.getAuth().getAccount(), specialId);
133 log.changeUpdatedInfo(info);
134 log.setInfotransf(message);
135 log.setReplyCodeExecutionStatus(rcode);
136 log.update();
137 logger.debug("Update FS: {}", log);
138 session.setLogid(log.getSpecialId());
139 } catch (final WaarpDatabaseException e) {
140
141 }
142 }
143 }
144
145
146
147
148
149
150
151
152
153 public static void logErrorAction(final DbSession dbSession,
154 final HttpSession session,
155 final String message,
156 final HttpResponseStatus rcode) {
157 final String sessionContexte = session.toString();
158 final long specialId = session.getLogid();
159 logger.error(rcode.code() + ":" + message + ' ' + sessionContexte);
160 if (dbSession != null && specialId != DbConstantGateway.ILLEGALVALUE) {
161 final PageRole code = session.getCurrentCommand();
162 switch (code) {
163 case DELETE:
164 case GETDOWNLOAD:
165 case POST:
166 case POSTUPLOAD:
167 case PUT:
168 break;
169 case ERROR:
170 case HTML:
171 case MENU:
172 default:
173 return;
174 }
175 final UpdatedInfo info = UpdatedInfo.INERROR;
176 try {
177
178 final DbTransferLog log =
179 new DbTransferLog(dbSession, session.getAuth().getUser(),
180 session.getAuth().getAccount(), specialId);
181 log.changeUpdatedInfo(info);
182 log.setInfotransf(message);
183 if (rcode.code() < 400) {
184 log.setReplyCodeExecutionStatus(HttpResponseStatus.BAD_REQUEST);
185 } else {
186 log.setReplyCodeExecutionStatus(rcode);
187 }
188 if (session.getFilename() != null) {
189 log.setFilename(session.getFilename());
190 }
191 log.update();
192 logger.debug("Update FS: {}", log);
193 } catch (final WaarpDatabaseException e) {
194
195 }
196 }
197 }
198 }