Line 1... |
Line 1... |
1 |
/*
|
1 |
/*
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 |
*
|
3 |
*
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
9 |
* language governing permissions and limitations under the License.
|
9 |
* language governing permissions and limitations under the License.
|
Line 48... |
Line 48... |
48 |
import javax.crypto.NoSuchPaddingException;
|
48 |
import javax.crypto.NoSuchPaddingException;
|
49 |
import javax.crypto.SecretKey;
|
49 |
import javax.crypto.SecretKey;
|
50 |
import javax.crypto.spec.GCMParameterSpec;
|
50 |
import javax.crypto.spec.GCMParameterSpec;
|
51 |
import javax.crypto.spec.SecretKeySpec;
|
51 |
import javax.crypto.spec.SecretKeySpec;
|
52 |
import javax.swing.JOptionPane;
|
52 |
import javax.swing.JOptionPane;
|
- |
|
53 |
import javax.swing.SwingUtilities;
|
53 |
|
54 |
|
54 |
public class AttachmentUtils {
|
55 |
public class AttachmentUtils {
|
55 |
|
56 |
|
56 |
String generateBase64Key() throws NoSuchAlgorithmException {
|
57 |
String generateBase64Key() throws NoSuchAlgorithmException {
|
57 |
final KeyGenerator generator = KeyGenerator.getInstance("AES");
|
58 |
final KeyGenerator generator = KeyGenerator.getInstance("AES");
|
Line 239... |
Line 240... |
239 |
insert.add(table.getField("NAME"), AttachmentSQLElement.EDM_KEY_METADATA);
|
240 |
insert.add(table.getField("NAME"), AttachmentSQLElement.EDM_KEY_METADATA);
|
240 |
insert.add(table.getField("VALUE"), generateBase64Key());
|
241 |
insert.add(table.getField("VALUE"), generateBase64Key());
|
241 |
table.getDBSystemRoot().getDataSource().execute(insert.asString());
|
242 |
table.getDBSystemRoot().getDataSource().execute(insert.asString());
|
242 |
}
|
243 |
}
|
243 |
|
244 |
|
- |
|
245 |
public void createURL(String url, SQLRowAccessor rowSource, int idParent) throws SQLException {
|
- |
|
246 |
final SQLRowValues rowValsAttachment = new SQLRowValues(rowSource.getTable().getTable("ATTACHMENT"));
|
- |
|
247 |
rowValsAttachment.put("SOURCE_TABLE", rowSource.getTable().getName());
|
- |
|
248 |
rowValsAttachment.put("SOURCE_ID", rowSource.getID());
|
- |
|
249 |
rowValsAttachment.put("ID_PARENT", idParent);
|
- |
|
250 |
rowValsAttachment.put("NAME", url);
|
- |
|
251 |
rowValsAttachment.put("SOURCE_TABLE", rowSource.getTable().getName());
|
- |
|
252 |
rowValsAttachment.put("SOURCE_ID", rowSource.getID());
|
- |
|
253 |
rowValsAttachment.put("MIMETYPE", Attachment.MIMETYPE_URL);
|
- |
|
254 |
rowValsAttachment.put("FILENAME", url);
|
- |
|
255 |
rowValsAttachment.put("FILESIZE", 0);
|
- |
|
256 |
rowValsAttachment.put("STORAGE_PATH", "");
|
- |
|
257 |
rowValsAttachment.put("STORAGE_FILENAME", "");
|
- |
|
258 |
rowValsAttachment.commit();
|
- |
|
259 |
}
|
- |
|
260 |
|
244 |
public File getFile(Attachment attachment) {
|
261 |
public File getFile(Attachment attachment) {
|
245 |
|
262 |
|
246 |
final ComptaPropsConfiguration config = ComptaPropsConfiguration.getInstanceCompta();
|
263 |
final ComptaPropsConfiguration config = ComptaPropsConfiguration.getInstanceCompta();
|
247 |
boolean isOnCloud = config.isOnCloud();
|
264 |
boolean isOnCloud = config.isOnCloud();
|
248 |
|
265 |
|
Line 290... |
Line 307... |
290 |
} catch (IOException e) {
|
307 |
} catch (IOException e) {
|
291 |
ExceptionHandler.handle("Impossible de copier le fichier vers le fichier temporaire de réception", e);
|
308 |
ExceptionHandler.handle("Impossible de copier le fichier vers le fichier temporaire de réception", e);
|
292 |
return null;
|
309 |
return null;
|
293 |
}
|
310 |
}
|
294 |
} else {
|
311 |
} else {
|
- |
|
312 |
if (SwingUtilities.isEventDispatchThread()) {
|
- |
|
313 |
JOptionPane.showMessageDialog(null, "Le fichier n'existe pas sur le serveur!\n" + fileIn.getAbsolutePath(), "Erreur fichier", JOptionPane.ERROR_MESSAGE);
|
- |
|
314 |
} else {
|
- |
|
315 |
SwingUtilities.invokeLater(new Runnable() {
|
- |
|
316 |
|
- |
|
317 |
@Override
|
- |
|
318 |
public void run() {
|
295 |
JOptionPane.showMessageDialog(null, "Le fichier n'existe pas sur le serveur!\n" + fileIn.getAbsolutePath(), "Erreur fichier", JOptionPane.ERROR_MESSAGE);
|
319 |
JOptionPane.showMessageDialog(null, "Le fichier n'existe pas sur le serveur!\n" + fileIn.getAbsolutePath(), "Erreur fichier", JOptionPane.ERROR_MESSAGE);
|
- |
|
320 |
}
|
- |
|
321 |
});
|
- |
|
322 |
}
|
296 |
return null;
|
323 |
return null;
|
297 |
}
|
324 |
}
|
298 |
} catch (IOException e1) {
|
325 |
} catch (IOException e1) {
|
299 |
ExceptionHandler.handle("Impossible de trouver le fichier\n" + storagePathFile + File.pathSeparator + fileName, e1);
|
326 |
ExceptionHandler.handle("Impossible de trouver le fichier\n" + storagePathFile + File.pathSeparator + fileName, e1);
|
300 |
return null;
|
327 |
return null;
|