1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.http.protocol;
22
23 import org.waarp.common.command.exception.CommandAbstractException;
24 import org.waarp.common.database.exception.WaarpDatabaseException;
25 import org.waarp.common.logging.WaarpLogger;
26 import org.waarp.common.logging.WaarpLoggerFactory;
27 import org.waarp.common.utility.WaarpSystemUtil;
28 import org.waarp.http.protocol.servlet.HttpAuthent;
29 import org.waarp.openr66.context.R66BusinessInterface;
30 import org.waarp.openr66.context.R66FiniteDualStates;
31 import org.waarp.openr66.context.task.exception.OpenR66RunnerErrorException;
32 import org.waarp.openr66.database.data.DbTaskRunner;
33 import org.waarp.openr66.protocol.configuration.Configuration;
34
35 import java.io.File;
36
37
38
39
40 public class HttpDeleteSession extends HttpSessionAbstract {
41 private static final WaarpLogger logger =
42 WaarpLoggerFactory.getLogger(HttpDeleteSession.class);
43 private final String identifier;
44 private final File file;
45
46
47
48
49
50
51
52
53
54 public HttpDeleteSession(final String identifier, final HttpAuthent authent)
55 throws WaarpDatabaseException {
56 super(authent);
57 this.identifier = identifier;
58 final DbTaskRunner runner;
59 if (!WaarpSystemUtil.isJunit()) {
60 checkAuthentR66Business(this, session, authent);
61 runner = getDbTaskRunner(authent.getUserId(), identifier);
62 try {
63 session.getDir().changeDirectory(runner.getRule().getRecvPath());
64 } catch (final CommandAbstractException e) {
65
66 }
67 final String baseDir = runner.getRule().getRecvPath();
68 final String path = session.getDir().getFullPath();
69 final String filepath_in = runner.getFilename();
70 final String finalPath =
71 filepath_in.replace(baseDir, path).replace("//", "/");
72 logger.info("From {} to {} using {} gives {}", baseDir, path, filepath_in,
73 finalPath);
74 file = new File(finalPath);
75 } else {
76 runner = null;
77 file = null;
78 }
79 }
80
81
82
83
84
85
86
87
88
89
90
91 private DbTaskRunner getDbTaskRunner(final String user,
92 final String identifier)
93 throws IllegalArgumentException, WaarpDatabaseException {
94 final long specialId = Long.parseLong(identifier);
95 final String requested = Configuration.configuration.getHostId();
96 DbTaskRunner runner = null;
97
98
99 try {
100 logger.debug("{} {} <-> {}", specialId, user, requested);
101 runner = new DbTaskRunner(specialId, user, requested);
102 } catch (final WaarpDatabaseException e) {
103 logger.debug("{} {} {}", specialId, user, requested);
104 runner = new DbTaskRunner(specialId, requested, user);
105 }
106 runner.setSender(true);
107 try {
108 session.setRunner(runner);
109 } catch (final OpenR66RunnerErrorException e) {
110 logger.debug(e);
111 }
112 session.setReady(true);
113 return runner;
114 }
115
116
117
118
119 public final File getFile() {
120 return file;
121 }
122
123
124
125
126 public final String getIdentifier() {
127 return identifier;
128 }
129
130 @Override
131 public final void error(final Exception e,
132 final R66BusinessInterface business)
133 throws IllegalArgumentException {
134 logger.error(e.getMessage());
135 if (business != null) {
136 business.checkAtError(session);
137 }
138 session.newState(R66FiniteDualStates.ERROR);
139 throw new IllegalArgumentException(e);
140 }
141
142 @Override
143 public String toString() {
144 return "DS: {" + session.toString() + ", " + identifier + ", " +
145 file.getAbsolutePath() + "}";
146 }
147 }