IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part / Peer review
This commit is contained in:
parent
16cf4aee67
commit
d03f0b79ad
|
@ -168,3 +168,110 @@ UPDATE AD_Ref_Table SET IsValueDisplayed='Y', AD_Display=200961,Updated=TO_DATE(
|
|||
UPDATE AD_Ref_Table SET IsValueDisplayed='N',Updated=TO_DATE('2012-11-30 17:34:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Reference_ID=200023
|
||||
;
|
||||
|
||||
INSERT INTO ad_storageprovider
|
||||
(ad_client_id,
|
||||
ad_org_id,
|
||||
ad_storageprovider_id,
|
||||
ad_storageprovider_uu,
|
||||
created,
|
||||
createdby,
|
||||
folder,
|
||||
isactive,
|
||||
method,
|
||||
name,
|
||||
password,
|
||||
updated,
|
||||
updatedby,
|
||||
url,
|
||||
username)
|
||||
SELECT
|
||||
ad_client_id,
|
||||
0,
|
||||
nextidfunc(200033,'N'),
|
||||
generate_uuid(),
|
||||
sysdate,
|
||||
100,
|
||||
coalesce(windowsarchivepath, unixarchivepath),
|
||||
'Y',
|
||||
'FileSystem',
|
||||
'Folder',
|
||||
null,
|
||||
sysdate,
|
||||
100,
|
||||
null,
|
||||
null
|
||||
FROM ad_client
|
||||
WHERE storearchiveonfilesystem='Y' AND (windowsarchivepath is not null or unixarchivepath is not null)
|
||||
;
|
||||
|
||||
UPDATE ad_clientinfo
|
||||
SET storagearchive_id = (SELECT ad_storageprovider_id FROM ad_storageprovider JOIN ad_client ON ad_client.ad_client_id=ad_storageprovider.ad_client_id
|
||||
WHERE ad_storageprovider.ad_client_id=ad_clientinfo.ad_client_id
|
||||
AND coalesce(ad_client.windowsarchivepath, ad_client.unixarchivepath)=ad_storageprovider.folder)
|
||||
WHERE ad_clientinfo.ad_client_id IN
|
||||
(SELECT ad_client_id FROM ad_client WHERE storearchiveonfilesystem='Y' AND (windowsarchivepath is not null or unixarchivepath is not null))
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:49:08 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Column SET IsActive='N',Updated=TO_DATE('2012-12-05 18:49:08','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=50215
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:49:14 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Column SET IsActive='N',Updated=TO_DATE('2012-12-05 18:49:14','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=50216
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:49:18 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Column SET IsActive='N',Updated=TO_DATE('2012-12-05 18:49:18','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=50214
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:55:57 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Field SET IsCentrallyMaintained='N', Name='Attachment Store',Updated=TO_DATE('2012-12-05 18:55:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=200948
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:55:57 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Field_Trl SET IsTranslated='N' WHERE AD_Field_ID=200948
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Element SET Name='Archive Store', PrintName='Archive Store',Updated=TO_DATE('2012-12-05 18:56:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Element_ID=200257
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Element_Trl SET IsTranslated='N' WHERE AD_Element_ID=200257
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Column SET ColumnName='StorageArchive_ID', Name='Archive Store', Description=NULL, Help=NULL WHERE AD_Element_ID=200257
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Process_Para SET ColumnName='StorageArchive_ID', Name='Archive Store', Description=NULL, Help=NULL, AD_Element_ID=200257 WHERE UPPER(ColumnName)='STORAGEARCHIVE_ID' AND IsCentrallyMaintained='Y' AND AD_Element_ID IS NULL
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Process_Para SET ColumnName='StorageArchive_ID', Name='Archive Store', Description=NULL, Help=NULL WHERE AD_Element_ID=200257 AND IsCentrallyMaintained='Y'
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Field SET Name='Archive Store', Description=NULL, Help=NULL WHERE AD_Column_ID IN (SELECT AD_Column_ID FROM AD_Column WHERE AD_Element_ID=200257) AND IsCentrallyMaintained='Y'
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_PrintFormatItem pi SET PrintName='Archive Store', Name='Archive Store' WHERE IsCentrallyMaintained='Y' AND EXISTS (SELECT * FROM AD_Column c WHERE c.AD_Column_ID=pi.AD_Column_ID AND c.AD_Element_ID=200257)
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201212051000_IDEMPIERE_390.sql') FROM dual
|
||||
;
|
||||
|
||||
|
|
|
@ -168,3 +168,110 @@ UPDATE AD_Ref_Table SET IsValueDisplayed='Y', AD_Display=200961,Updated=TO_TIMES
|
|||
UPDATE AD_Ref_Table SET IsValueDisplayed='N',Updated=TO_TIMESTAMP('2012-11-30 17:34:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Reference_ID=200023
|
||||
;
|
||||
|
||||
INSERT INTO ad_storageprovider
|
||||
(ad_client_id,
|
||||
ad_org_id,
|
||||
ad_storageprovider_id,
|
||||
ad_storageprovider_uu,
|
||||
created,
|
||||
createdby,
|
||||
folder,
|
||||
isactive,
|
||||
method,
|
||||
name,
|
||||
password,
|
||||
updated,
|
||||
updatedby,
|
||||
url,
|
||||
username)
|
||||
SELECT
|
||||
ad_client_id,
|
||||
0,
|
||||
nextidfunc(200033,'N'),
|
||||
generate_uuid(),
|
||||
now(),
|
||||
100,
|
||||
coalesce(windowsarchivepath, unixarchivepath),
|
||||
'Y',
|
||||
'FileSystem',
|
||||
'Folder',
|
||||
null,
|
||||
now(),
|
||||
100,
|
||||
null,
|
||||
null
|
||||
FROM ad_client
|
||||
WHERE storearchiveonfilesystem='Y' AND (windowsarchivepath is not null or unixarchivepath is not null)
|
||||
;
|
||||
|
||||
UPDATE ad_clientinfo
|
||||
SET storagearchive_id = (SELECT ad_storageprovider_id FROM ad_storageprovider JOIN ad_client ON ad_client.ad_client_id=ad_storageprovider.ad_client_id
|
||||
WHERE ad_storageprovider.ad_client_id=ad_clientinfo.ad_client_id
|
||||
AND coalesce(ad_client.windowsarchivepath, ad_client.unixarchivepath)=ad_storageprovider.folder)
|
||||
WHERE ad_clientinfo.ad_client_id IN
|
||||
(SELECT ad_client_id FROM ad_client WHERE storearchiveonfilesystem='Y' AND (windowsarchivepath is not null or unixarchivepath is not null))
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:49:08 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Column SET IsActive='N',Updated=TO_TIMESTAMP('2012-12-05 18:49:08','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=50215
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:49:14 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Column SET IsActive='N',Updated=TO_TIMESTAMP('2012-12-05 18:49:14','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=50216
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:49:18 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Column SET IsActive='N',Updated=TO_TIMESTAMP('2012-12-05 18:49:18','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=50214
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:55:57 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Field SET IsCentrallyMaintained='N', Name='Attachment Store',Updated=TO_TIMESTAMP('2012-12-05 18:55:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=200948
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:55:57 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Field_Trl SET IsTranslated='N' WHERE AD_Field_ID=200948
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Element SET Name='Archive Store', PrintName='Archive Store',Updated=TO_TIMESTAMP('2012-12-05 18:56:36','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Element_ID=200257
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Element_Trl SET IsTranslated='N' WHERE AD_Element_ID=200257
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Column SET ColumnName='StorageArchive_ID', Name='Archive Store', Description=NULL, Help=NULL WHERE AD_Element_ID=200257
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Process_Para SET ColumnName='StorageArchive_ID', Name='Archive Store', Description=NULL, Help=NULL, AD_Element_ID=200257 WHERE UPPER(ColumnName)='STORAGEARCHIVE_ID' AND IsCentrallyMaintained='Y' AND AD_Element_ID IS NULL
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Process_Para SET ColumnName='StorageArchive_ID', Name='Archive Store', Description=NULL, Help=NULL WHERE AD_Element_ID=200257 AND IsCentrallyMaintained='Y'
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_Field SET Name='Archive Store', Description=NULL, Help=NULL WHERE AD_Column_ID IN (SELECT AD_Column_ID FROM AD_Column WHERE AD_Element_ID=200257) AND IsCentrallyMaintained='Y'
|
||||
;
|
||||
|
||||
-- Dec 5, 2012 6:56:36 PM COT
|
||||
-- IDEMPIERE-390 Attachments/archives on load balancer scenario / Implement archive part
|
||||
UPDATE AD_PrintFormatItem SET PrintName='Archive Store', Name='Archive Store' WHERE IsCentrallyMaintained='Y' AND EXISTS (SELECT * FROM AD_Column c WHERE c.AD_Column_ID=AD_PrintFormatItem.AD_Column_ID AND c.AD_Element_ID=200257)
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201212051000_IDEMPIERE_390.sql') FROM dual
|
||||
;
|
||||
|
||||
|
|
|
@ -291,6 +291,6 @@ Import-Package: com.sun.mail.auth;version="1.4.5",
|
|||
Eclipse-BuddyPolicy: registered
|
||||
Eclipse-ExtensibleAPI: true
|
||||
Bundle-Activator: org.adempiere.base.BaseActivator
|
||||
Service-Component: OSGI-INF/eventmanager.xml, OSGI-INF/dslocator.xml, OSGI-INF/extensionlocator.xml, OSGI-INF/serverbean.xml, OSGI-INF/statusbean.xml, OSGI-INF/defaultmodelfactory.xml, OSGI-INF/defaultdocfactory.xml, OSGI-INF/attachmentfile.xml, OSGI-INF/attachmentDB.xml,OSGI-INF/archiveDB.xml,OSGI-INF/archivefile.xml
|
||||
Service-Component: OSGI-INF/eventmanager.xml, OSGI-INF/dslocator.xml, OSGI-INF/extensionlocator.xml, OSGI-INF/serverbean.xml, OSGI-INF/statusbean.xml, OSGI-INF/defaultmodelfactory.xml, OSGI-INF/defaultdocfactory.xml, OSGI-INF/attachmentfile.xml, OSGI-INF/attachmentdb.xml,OSGI-INF/archivedb.xml,OSGI-INF/archivefile.xml
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Require-Bundle: org.eclipse.equinox.app;bundle-version="1.3.1"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.adempiere.base.archive.store.archiveDB">
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.adempiere.base.archive.store.archivedb">
|
||||
<implementation class="org.compiere.model.ArchiveDB"/>
|
||||
<property name="storage" type="String" value="DB"/>
|
||||
<service>
|
||||
<provide interface="org.compiere.model.IArchiveStore"/>
|
||||
</service>
|
||||
<property name="method" type="String" value="DB"/>
|
||||
</scr:component>
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.adempiere.base.archive.store.archivefile">
|
||||
<implementation class="org.compiere.model.ArchiveFileSystem"/>
|
||||
<property name="storage" type="String" value="FileSystem"/>
|
||||
<service>
|
||||
<provide interface="org.compiere.model.IArchiveStore"/>
|
||||
</service>
|
||||
<property name="method" type="String" value="FileSystem"/>
|
||||
</scr:component>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.adempiere.base.attachment.store.attachmentDB">
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.adempiere.base.attachment.store.attachmentdb">
|
||||
<implementation class="org.compiere.model.AttachmentDBSystem"/>
|
||||
<service>
|
||||
<provide interface="org.compiere.model.IAttachmentStore"/>
|
|
@ -38,13 +38,10 @@ public class ArchiveDB implements IArchiveStore {
|
|||
@Override
|
||||
public byte[] loadLOBData(MArchive archive, MStorageProvider prov) {
|
||||
byte[] deflatedData = archive.getByteData();
|
||||
archive.m_deflated = null;
|
||||
archive.m_inflated = null;
|
||||
if (deflatedData == null)
|
||||
return null;
|
||||
//
|
||||
log.fine("ZipSize=" + deflatedData.length);
|
||||
archive.m_deflated = new Integer(deflatedData.length);
|
||||
if (deflatedData.length == 0)
|
||||
return null;
|
||||
|
||||
|
@ -67,7 +64,6 @@ public class ArchiveDB implements IArchiveStore {
|
|||
log.fine("Size=" + inflatedData.length + " - zip=" + entry.getCompressedSize()
|
||||
+ "(" + entry.getSize() + ") "
|
||||
+ (entry.getCompressedSize() * 100 / entry.getSize()) + "%");
|
||||
archive.m_inflated = new Integer(inflatedData.length);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "", e);
|
||||
|
@ -83,7 +79,6 @@ public class ArchiveDB implements IArchiveStore {
|
|||
public void save(MArchive archive, MStorageProvider prov,byte[] inflatedData) {
|
||||
if (inflatedData == null || inflatedData.length == 0)
|
||||
throw new IllegalArgumentException("InflatedData is NULL");
|
||||
archive.m_inflated = new Integer(inflatedData.length);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(out);
|
||||
zip.setMethod(ZipOutputStream.DEFLATED);
|
||||
|
@ -105,11 +100,9 @@ public class ArchiveDB implements IArchiveStore {
|
|||
zip.close();
|
||||
deflatedData = out.toByteArray();
|
||||
log.fine("Length=" + inflatedData.length);
|
||||
archive.m_deflated = new Integer(deflatedData.length);
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "saveLOBData", e);
|
||||
deflatedData = null;
|
||||
archive.m_deflated = null;
|
||||
}
|
||||
archive.setByteData(deflatedData);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import javax.xml.transform.TransformerFactory;
|
|||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Util;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -58,12 +59,11 @@ public class ArchiveFileSystem implements IArchiveStore {
|
|||
*/
|
||||
@Override
|
||||
public byte[] loadLOBData(MArchive archive, MStorageProvider prov) {
|
||||
if ("".equals(archive.m_archivePathRoot)) {
|
||||
String archivePathRoot = getArchivePathRoot(prov);
|
||||
if ("".equals(archivePathRoot)) {
|
||||
throw new IllegalArgumentException("no attachmentPath defined");
|
||||
}
|
||||
byte[] data = archive.getByteData();
|
||||
archive.m_deflated = null;
|
||||
archive.m_inflated = null;
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class ArchiveFileSystem implements IArchiveStore {
|
|||
String filePath = fileNode.getNodeValue();
|
||||
log.fine("filePath: " + filePath);
|
||||
if(filePath!=null){
|
||||
filePath = filePath.replaceFirst(ARCHIVE_FOLDER_PLACEHOLDER, archive.m_archivePathRoot.replaceAll("\\\\","\\\\\\\\"));
|
||||
filePath = filePath.replaceFirst(ARCHIVE_FOLDER_PLACEHOLDER, archivePathRoot.replaceAll("\\\\","\\\\\\\\"));
|
||||
//just to be shure...
|
||||
String replaceSeparator = File.separator;
|
||||
if(!replaceSeparator.equals("/")){
|
||||
|
@ -145,7 +145,8 @@ public class ArchiveFileSystem implements IArchiveStore {
|
|||
*/
|
||||
@Override
|
||||
public void save(MArchive archive, MStorageProvider prov,byte[] inflatedData) {
|
||||
if ("".equals(archive.m_archivePathRoot)) {
|
||||
String archivePathRoot = getArchivePathRoot(prov);
|
||||
if ("".equals(archivePathRoot)) {
|
||||
throw new IllegalArgumentException("no attachmentPath defined");
|
||||
}
|
||||
if (inflatedData == null || inflatedData.length == 0) {
|
||||
|
@ -162,7 +163,7 @@ public class ArchiveFileSystem implements IArchiveStore {
|
|||
BufferedOutputStream out = null;
|
||||
try {
|
||||
// create destination folder
|
||||
StringBuilder msgfile = new StringBuilder().append(archive.m_archivePathRoot).append(File.separator)
|
||||
StringBuilder msgfile = new StringBuilder().append(archivePathRoot).append(File.separator)
|
||||
.append(archive.getArchivePathSnippet());
|
||||
final File destFolder = new File(msgfile.toString());
|
||||
if (!destFolder.exists()) {
|
||||
|
@ -171,7 +172,7 @@ public class ArchiveFileSystem implements IArchiveStore {
|
|||
}
|
||||
}
|
||||
// write to pdf
|
||||
msgfile = new StringBuilder().append(archive.m_archivePathRoot).append(File.separator)
|
||||
msgfile = new StringBuilder().append(archivePathRoot).append(File.separator)
|
||||
.append(archive.getArchivePathSnippet()).append(archive.get_ID()).append(".pdf");
|
||||
final File destFile = new File(msgfile.toString());
|
||||
|
||||
|
@ -201,7 +202,6 @@ public class ArchiveFileSystem implements IArchiveStore {
|
|||
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "saveLOBData", e);
|
||||
archive.m_deflated = null;
|
||||
archive.setByteData(null);
|
||||
} finally {
|
||||
if(out != null){
|
||||
|
@ -213,4 +213,17 @@ public class ArchiveFileSystem implements IArchiveStore {
|
|||
|
||||
}
|
||||
|
||||
private String getArchivePathRoot(MStorageProvider prov) {
|
||||
String archivePathRoot = prov.getFolder();
|
||||
if (archivePathRoot == null)
|
||||
archivePathRoot = "";
|
||||
if (Util.isEmpty(archivePathRoot)) {
|
||||
log.severe("no archivePath defined");
|
||||
} else if (!archivePathRoot.endsWith(File.separator)){
|
||||
archivePathRoot = archivePathRoot + File.separator;
|
||||
log.fine(archivePathRoot);
|
||||
}
|
||||
return archivePathRoot;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import javax.xml.transform.dom.DOMSource;
|
|||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Util;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
|
@ -50,24 +51,9 @@ public class AttachmentFileSystem implements IAttachmentStore {
|
|||
|
||||
private final CLogger log = CLogger.getCLogger(getClass());
|
||||
|
||||
public String m_attachmentPathRoot;
|
||||
|
||||
@Override
|
||||
public boolean save(MAttachment attach,MStorageProvider prov) {
|
||||
|
||||
/*if(File.separatorChar == '\\'){
|
||||
m_attachmentPathRoot = prov.getWi;
|
||||
} else {
|
||||
m_attachmentPathRoot = prov.getUnixAttachmentPath();
|
||||
}*/
|
||||
m_attachmentPathRoot=prov.getFolder();
|
||||
if("".equals(m_attachmentPathRoot)){
|
||||
log.severe("no attachmentPath defined");
|
||||
} else if (!m_attachmentPathRoot.endsWith(File.separator)){
|
||||
m_attachmentPathRoot = m_attachmentPathRoot + File.separator;
|
||||
log.fine(m_attachmentPathRoot);
|
||||
}
|
||||
|
||||
String attachmentPathRoot = getAttachmentPathRoot(prov);
|
||||
if (attach.m_items == null || attach.m_items.size() == 0) {
|
||||
attach.setBinaryData(null);
|
||||
return true;
|
||||
|
@ -85,21 +71,21 @@ public class AttachmentFileSystem implements IAttachmentStore {
|
|||
File entryFile = attach.m_items.get(i).getFile();
|
||||
final String path = entryFile.getAbsolutePath();
|
||||
// if local file - copy to central attachment folder
|
||||
log.fine(path + " - " + attach.m_attachmentPathRoot);
|
||||
if (!path.startsWith(attach.m_attachmentPathRoot)) {
|
||||
log.fine(path + " - " + attachmentPathRoot);
|
||||
if (!path.startsWith(attachmentPathRoot)) {
|
||||
log.fine("move file: " + path);
|
||||
FileChannel in = null;
|
||||
FileChannel out = null;
|
||||
try {
|
||||
//create destination folder
|
||||
StringBuilder msgfile = new StringBuilder().append(attach.m_attachmentPathRoot).append(File.separator).append(getAttachmentPathSnippet(attach));
|
||||
StringBuilder msgfile = new StringBuilder().append(attachmentPathRoot).append(File.separator).append(getAttachmentPathSnippet(attach));
|
||||
final File destFolder = new File(msgfile.toString());
|
||||
if(!destFolder.exists()){
|
||||
if(!destFolder.mkdirs()){
|
||||
log.warning("unable to create folder: " + destFolder.getPath());
|
||||
}
|
||||
}
|
||||
msgfile = new StringBuilder().append(attach.m_attachmentPathRoot).append(File.separator)
|
||||
msgfile = new StringBuilder().append(attachmentPathRoot).append(File.separator)
|
||||
.append(getAttachmentPathSnippet(attach)).append(File.separator).append(entryFile.getName());
|
||||
final File destFile = new File(msgfile.toString());
|
||||
in = new FileInputStream(entryFile).getChannel();
|
||||
|
@ -117,7 +103,7 @@ public class AttachmentFileSystem implements IAttachmentStore {
|
|||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.severe("unable to copy file " + entryFile.getAbsolutePath() + " to "
|
||||
+ attach.m_attachmentPathRoot + File.separator +
|
||||
+ attachmentPathRoot + File.separator +
|
||||
getAttachmentPathSnippet(attach) + File.separator + entryFile.getName());
|
||||
} finally {
|
||||
if (in != null && in.isOpen()) {
|
||||
|
@ -132,7 +118,7 @@ public class AttachmentFileSystem implements IAttachmentStore {
|
|||
//entry.setAttribute("name", m_items.get(i).getName());
|
||||
entry.setAttribute("name", attach.getEntryName(i));
|
||||
String filePathToStore = entryFile.getAbsolutePath();
|
||||
filePathToStore = filePathToStore.replaceFirst(attach.m_attachmentPathRoot.replaceAll("\\\\","\\\\\\\\"), attach.ATTACHMENT_FOLDER_PLACEHOLDER);
|
||||
filePathToStore = filePathToStore.replaceFirst(attachmentPathRoot.replaceAll("\\\\","\\\\\\\\"), attach.ATTACHMENT_FOLDER_PLACEHOLDER);
|
||||
log.fine(filePathToStore);
|
||||
entry.setAttribute("file", filePathToStore);
|
||||
root.appendChild(entry);
|
||||
|
@ -158,7 +144,8 @@ public class AttachmentFileSystem implements IAttachmentStore {
|
|||
|
||||
@Override
|
||||
public boolean loadLOBData(MAttachment attach,MStorageProvider prov) {
|
||||
if("".equals(attach.m_attachmentPathRoot)){
|
||||
String attachmentPathRoot = getAttachmentPathRoot(prov);
|
||||
if (Util.isEmpty(attachmentPathRoot)) {
|
||||
log.severe("no attachmentPath defined");
|
||||
return false;
|
||||
}
|
||||
|
@ -192,7 +179,7 @@ public class AttachmentFileSystem implements IAttachmentStore {
|
|||
String filePath = fileNode.getNodeValue();
|
||||
log.fine("filePath: " + filePath);
|
||||
if(filePath!=null){
|
||||
filePath = filePath.replaceFirst(attach.ATTACHMENT_FOLDER_PLACEHOLDER, attach.m_attachmentPathRoot.replaceAll("\\\\","\\\\\\\\"));
|
||||
filePath = filePath.replaceFirst(attach.ATTACHMENT_FOLDER_PLACEHOLDER, attachmentPathRoot.replaceAll("\\\\","\\\\\\\\"));
|
||||
//just to be shure...
|
||||
String replaceSeparator = File.separator;
|
||||
if(!replaceSeparator.equals("/")){
|
||||
|
@ -271,7 +258,8 @@ public class AttachmentFileSystem implements IAttachmentStore {
|
|||
}
|
||||
}
|
||||
}
|
||||
final File folder = new File(m_attachmentPathRoot + getAttachmentPathSnippet(attach));
|
||||
String attachmentPathRoot = getAttachmentPathRoot(prov);
|
||||
final File folder = new File(attachmentPathRoot + getAttachmentPathSnippet(attach));
|
||||
if (folder.exists()) {
|
||||
if (!folder.delete()) {
|
||||
log.warning("unable to delete " + folder.getAbsolutePath());
|
||||
|
@ -295,5 +283,18 @@ public class AttachmentFileSystem implements IAttachmentStore {
|
|||
log.config("Index=" + index + " - NewSize=" + attach.m_items.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private String getAttachmentPathRoot(MStorageProvider prov) {
|
||||
String attachmentPathRoot = prov.getFolder();
|
||||
if (attachmentPathRoot == null)
|
||||
attachmentPathRoot = "";
|
||||
if (Util.isEmpty(attachmentPathRoot)) {
|
||||
log.severe("no attachmentPath defined");
|
||||
} else if (!attachmentPathRoot.endsWith(File.separator)){
|
||||
attachmentPathRoot = attachmentPathRoot + File.separator;
|
||||
log.fine(attachmentPathRoot);
|
||||
}
|
||||
return attachmentPathRoot;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -399,24 +399,6 @@ public interface I_AD_Client
|
|||
*/
|
||||
public int getSMTPPort();
|
||||
|
||||
/** Column name StoreArchiveOnFileSystem */
|
||||
public static final String COLUMNNAME_StoreArchiveOnFileSystem = "StoreArchiveOnFileSystem";
|
||||
|
||||
/** Set Store Archive On File System */
|
||||
public void setStoreArchiveOnFileSystem (boolean StoreArchiveOnFileSystem);
|
||||
|
||||
/** Get Store Archive On File System */
|
||||
public boolean isStoreArchiveOnFileSystem();
|
||||
|
||||
/** Column name UnixArchivePath */
|
||||
public static final String COLUMNNAME_UnixArchivePath = "UnixArchivePath";
|
||||
|
||||
/** Set Unix Archive Path */
|
||||
public void setUnixArchivePath (String UnixArchivePath);
|
||||
|
||||
/** Get Unix Archive Path */
|
||||
public String getUnixArchivePath();
|
||||
|
||||
/** Column name Updated */
|
||||
public static final String COLUMNNAME_Updated = "Updated";
|
||||
|
||||
|
@ -445,13 +427,4 @@ public interface I_AD_Client
|
|||
* Search key for the record in the format required - must be unique
|
||||
*/
|
||||
public String getValue();
|
||||
|
||||
/** Column name WindowsArchivePath */
|
||||
public static final String COLUMNNAME_WindowsArchivePath = "WindowsArchivePath";
|
||||
|
||||
/** Set Windows Archive Path */
|
||||
public void setWindowsArchivePath (String WindowsArchivePath);
|
||||
|
||||
/** Get Windows Archive Path */
|
||||
public String getWindowsArchivePath();
|
||||
}
|
||||
|
|
|
@ -16,44 +16,18 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Archive Model
|
||||
|
@ -65,7 +39,7 @@ public class MArchive extends X_AD_Archive {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3476918478008050158L;
|
||||
private static final long serialVersionUID = 3217541537768473865L;
|
||||
|
||||
/**
|
||||
* Get Archives
|
||||
|
@ -116,10 +90,6 @@ public class MArchive extends X_AD_Archive {
|
|||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger(MArchive.class);
|
||||
|
||||
public Integer m_inflated = null;
|
||||
|
||||
public Integer m_deflated = null;
|
||||
|
||||
/***************************************************************************
|
||||
* Standard Constructor
|
||||
*
|
||||
|
@ -169,21 +139,8 @@ public class MArchive extends X_AD_Archive {
|
|||
setAD_Table_ID(info.getAD_Table_ID());
|
||||
setRecord_ID(info.getRecord_ID());
|
||||
setC_BPartner_ID(info.getC_BPartner_ID());
|
||||
initArchiveStoreDetails(ctx, trxName);
|
||||
} // MArchive
|
||||
|
||||
/** is this client using the file system for archive */
|
||||
private boolean isStoreArchiveOnFileSystem = false;
|
||||
|
||||
/** archive (root) path - if file system is used */
|
||||
public String m_archivePathRoot = "";
|
||||
|
||||
/**
|
||||
* string replaces the archive root in stored xml file to allow the
|
||||
* changing of the attachment root.
|
||||
*/
|
||||
private final String ARCHIVE_FOLDER_PLACEHOLDER = "%ARCHIVE_FOLDER%";
|
||||
|
||||
public MStorageProvider provider;
|
||||
/**
|
||||
* Get the isStoreArchiveOnFileSystem and archivePath for the client.
|
||||
|
@ -192,37 +149,8 @@ public class MArchive extends X_AD_Archive {
|
|||
* @param trxName
|
||||
*/
|
||||
private void initArchiveStoreDetails(Properties ctx, String trxName) {
|
||||
|
||||
MClientInfo clientInfo = MClientInfo.get(ctx);
|
||||
|
||||
provider=new MStorageProvider(ctx, clientInfo.getStorageArchive_ID(), trxName);
|
||||
|
||||
m_archivePathRoot=provider.getFolder();
|
||||
|
||||
if(m_archivePathRoot == null){
|
||||
log.severe("no attachmentPath defined");
|
||||
} else if (!m_archivePathRoot.endsWith(File.separator)) {
|
||||
log.warning("archive path doesn't end with " + File.separator);
|
||||
m_archivePathRoot = m_archivePathRoot + File.separator;
|
||||
log.fine(m_archivePathRoot);
|
||||
}
|
||||
|
||||
/*final MClient client = new MClient(ctx, this.getAD_Client_ID(), trxName);
|
||||
isStoreArchiveOnFileSystem = client.isStoreArchiveOnFileSystem();
|
||||
if (isStoreArchiveOnFileSystem) {
|
||||
if (File.separatorChar == '\\') {
|
||||
m_archivePathRoot = client.getWindowsArchivePath();
|
||||
} else {
|
||||
m_archivePathRoot = client.getUnixArchivePath();
|
||||
}
|
||||
if ("".equals(m_archivePathRoot)) {
|
||||
log.severe("no archivePath defined");
|
||||
} else if (!m_archivePathRoot.endsWith(File.separator)) {
|
||||
log.warning("archive path doesn't end with " + File.separator);
|
||||
m_archivePathRoot = m_archivePathRoot + File.separator;
|
||||
log.fine(m_archivePathRoot);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,10 +161,6 @@ public class MArchive extends X_AD_Archive {
|
|||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("MArchive[");
|
||||
sb.append(get_ID()).append(",Name=").append(getName());
|
||||
if (m_inflated != null)
|
||||
sb.append(",Inflated=").append(m_inflated);
|
||||
if (m_deflated != null)
|
||||
sb.append(",Deflated=").append(m_deflated);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
@ -248,136 +172,6 @@ public class MArchive extends X_AD_Archive {
|
|||
return prov.loadLOBData(this,provider);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return attachment data
|
||||
*/
|
||||
private byte[] getBinaryDataFromFileSystem() {
|
||||
if ("".equals(m_archivePathRoot)) {
|
||||
throw new IllegalArgumentException("no attachmentPath defined");
|
||||
}
|
||||
byte[] data = super.getBinaryData();
|
||||
m_deflated = null;
|
||||
m_inflated = null;
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
try {
|
||||
final DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
final Document document = builder.parse(new ByteArrayInputStream(data));
|
||||
final NodeList entries = document.getElementsByTagName("entry");
|
||||
if(entries.getLength()!=1){
|
||||
log.severe("no archive entry found");
|
||||
}
|
||||
final Node entryNode = entries.item(0);
|
||||
final NamedNodeMap attributes = entryNode.getAttributes();
|
||||
final Node fileNode = attributes.getNamedItem("file");
|
||||
if(fileNode==null ){
|
||||
log.severe("no filename for entry");
|
||||
return null;
|
||||
}
|
||||
String filePath = fileNode.getNodeValue();
|
||||
log.fine("filePath: " + filePath);
|
||||
if(filePath!=null){
|
||||
filePath = filePath.replaceFirst(ARCHIVE_FOLDER_PLACEHOLDER, m_archivePathRoot.replaceAll("\\\\","\\\\\\\\"));
|
||||
//just to be shure...
|
||||
String replaceSeparator = File.separator;
|
||||
if(!replaceSeparator.equals("/")){
|
||||
replaceSeparator = "\\\\";
|
||||
}
|
||||
filePath = filePath.replaceAll("/", replaceSeparator);
|
||||
filePath = filePath.replaceAll("\\\\", replaceSeparator);
|
||||
}
|
||||
log.fine("filePath: " + filePath);
|
||||
final File file = new File(filePath);
|
||||
if (file.exists()) {
|
||||
// read files into byte[]
|
||||
final byte[] dataEntry = new byte[(int) file.length()];
|
||||
try {
|
||||
final FileInputStream fileInputStream = new FileInputStream(file);
|
||||
fileInputStream.read(dataEntry);
|
||||
fileInputStream.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
log.severe("File Not Found.");
|
||||
e.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
log.severe("Error Reading The File.");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
return dataEntry;
|
||||
} else {
|
||||
log.severe("file not found: " + file.getAbsolutePath());
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (SAXException sxe) {
|
||||
// Error generated during parsing)
|
||||
Exception x = sxe;
|
||||
if (sxe.getException() != null)
|
||||
x = sxe.getException();
|
||||
x.printStackTrace();
|
||||
log.severe(x.getMessage());
|
||||
|
||||
} catch (ParserConfigurationException pce) {
|
||||
// Parser with specified options can't be built
|
||||
pce.printStackTrace();
|
||||
log.severe(pce.getMessage());
|
||||
|
||||
} catch (IOException ioe) {
|
||||
// I/O error
|
||||
ioe.printStackTrace();
|
||||
log.severe(ioe.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Binary Data. (inflate)
|
||||
*
|
||||
* @return inflated data
|
||||
*/
|
||||
private byte[] getBinaryDataFromDB() {
|
||||
byte[] deflatedData = super.getBinaryData();
|
||||
m_deflated = null;
|
||||
m_inflated = null;
|
||||
if (deflatedData == null)
|
||||
return null;
|
||||
//
|
||||
log.fine("ZipSize=" + deflatedData.length);
|
||||
m_deflated = new Integer(deflatedData.length);
|
||||
if (deflatedData.length == 0)
|
||||
return null;
|
||||
|
||||
byte[] inflatedData = null;
|
||||
try {
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(deflatedData);
|
||||
ZipInputStream zip = new ZipInputStream(in);
|
||||
ZipEntry entry = zip.getNextEntry();
|
||||
if (entry != null) // just one entry
|
||||
{
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[2048];
|
||||
int length = zip.read(buffer);
|
||||
while (length != -1) {
|
||||
out.write(buffer, 0, length);
|
||||
length = zip.read(buffer);
|
||||
}
|
||||
//
|
||||
inflatedData = out.toByteArray();
|
||||
log.fine("Size=" + inflatedData.length + " - zip=" + entry.getCompressedSize()
|
||||
+ "(" + entry.getSize() + ") "
|
||||
+ (entry.getCompressedSize() * 100 / entry.getSize()) + "%");
|
||||
m_inflated = new Integer(inflatedData.length);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "", e);
|
||||
inflatedData = null;
|
||||
}
|
||||
return inflatedData;
|
||||
} // getBinaryData
|
||||
|
||||
/**
|
||||
* Get Data as Input Stream
|
||||
|
@ -401,130 +195,8 @@ public class MArchive extends X_AD_Archive {
|
|||
IArchiveStore prov = provider.getArchiveStore();
|
||||
if (prov != null)
|
||||
prov.save(this,provider,inflatedData);
|
||||
|
||||
|
||||
|
||||
/*if (isStoreArchiveOnFileSystem) {
|
||||
saveBinaryDataIntoFileSystem(inflatedData);
|
||||
} else {
|
||||
saveBinaryDataIntoDB(inflatedData);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Save to file system. If the MArchive is not saved yet (id==0) it will
|
||||
* first save the MArchive object because it uses the id as filename.
|
||||
* @param inflatedData
|
||||
*/
|
||||
private void saveBinaryDataIntoFileSystem(byte[] inflatedData) {
|
||||
if ("".equals(m_archivePathRoot)) {
|
||||
throw new IllegalArgumentException("no attachmentPath defined");
|
||||
}
|
||||
if (inflatedData == null || inflatedData.length == 0) {
|
||||
throw new IllegalArgumentException("InflatedData is NULL");
|
||||
}
|
||||
if(this.get_ID()==0){
|
||||
//set binary data otherwise save will fail
|
||||
super.setBinaryData(new byte[]{'0'});
|
||||
if(!this.save()) {
|
||||
throw new IllegalArgumentException("unable to save MArchive");
|
||||
}
|
||||
}
|
||||
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
BufferedOutputStream out = null;
|
||||
try {
|
||||
// create destination folder
|
||||
StringBuilder msgfile = new StringBuilder().append(m_archivePathRoot).append(File.separator)
|
||||
.append(getArchivePathSnippet());
|
||||
final File destFolder = new File(msgfile.toString());
|
||||
if (!destFolder.exists()) {
|
||||
if (!destFolder.mkdirs()) {
|
||||
log.warning("unable to create folder: " + destFolder.getPath());
|
||||
}
|
||||
}
|
||||
// write to pdf
|
||||
msgfile = new StringBuilder().append(m_archivePathRoot).append(File.separator)
|
||||
.append(getArchivePathSnippet()).append(this.get_ID()).append(".pdf");
|
||||
final File destFile = new File(msgfile.toString());
|
||||
|
||||
out = new BufferedOutputStream(new FileOutputStream(destFile));
|
||||
out.write(inflatedData);
|
||||
out.flush();
|
||||
|
||||
//create xml entry
|
||||
final DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
final Document document = builder.newDocument();
|
||||
final Element root = document.createElement("archive");
|
||||
document.appendChild(root);
|
||||
document.setXmlStandalone(true);
|
||||
final Element entry = document.createElement("entry");
|
||||
StringBuilder msgsat = new StringBuilder(ARCHIVE_FOLDER_PLACEHOLDER).append(getArchivePathSnippet()).append(this.get_ID()).append(".pdf");
|
||||
entry.setAttribute("file", msgsat.toString());
|
||||
root.appendChild(entry);
|
||||
final Source source = new DOMSource(document);
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
final Result result = new StreamResult(bos);
|
||||
final Transformer xformer = TransformerFactory.newInstance().newTransformer();
|
||||
xformer.transform(source, result);
|
||||
final byte[] xmlData = bos.toByteArray();
|
||||
log.fine(bos.toString());
|
||||
//store xml in db
|
||||
super.setBinaryData(xmlData);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "saveLOBData", e);
|
||||
m_deflated = null;
|
||||
super.setBinaryData(null);
|
||||
} finally {
|
||||
if(out != null){
|
||||
try {
|
||||
out.close();
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Binary Data to database.
|
||||
*
|
||||
* @param inflatedData
|
||||
* inflated data
|
||||
*/
|
||||
private void saveBinaryDataIntoDB(byte[] inflatedData) {
|
||||
if (inflatedData == null || inflatedData.length == 0)
|
||||
throw new IllegalArgumentException("InflatedData is NULL");
|
||||
m_inflated = new Integer(inflatedData.length);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(out);
|
||||
zip.setMethod(ZipOutputStream.DEFLATED);
|
||||
zip.setLevel(Deflater.BEST_COMPRESSION);
|
||||
zip.setComment("adempiere");
|
||||
//
|
||||
byte[] deflatedData = null;
|
||||
try {
|
||||
ZipEntry entry = new ZipEntry("AdempiereArchive");
|
||||
entry.setTime(System.currentTimeMillis());
|
||||
entry.setMethod(ZipEntry.DEFLATED);
|
||||
zip.putNextEntry(entry);
|
||||
zip.write(inflatedData, 0, inflatedData.length);
|
||||
zip.closeEntry();
|
||||
log.fine(entry.getCompressedSize() + " (" + entry.getSize() + ") "
|
||||
+ (entry.getCompressedSize() * 100 / entry.getSize()) + "%");
|
||||
//
|
||||
// zip.finish();
|
||||
zip.close();
|
||||
deflatedData = out.toByteArray();
|
||||
log.fine("Length=" + inflatedData.length);
|
||||
m_deflated = new Integer(deflatedData.length);
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "saveLOBData", e);
|
||||
deflatedData = null;
|
||||
m_deflated = null;
|
||||
}
|
||||
super.setBinaryData(deflatedData);
|
||||
} // setBinaryData
|
||||
|
||||
/**
|
||||
* Get Created By (User) Name
|
||||
*
|
||||
|
@ -579,24 +251,6 @@ public class MArchive extends X_AD_Archive {
|
|||
return path.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
*
|
||||
* @param newRecord
|
||||
* new
|
||||
* @return true if can be saved
|
||||
*/
|
||||
/*protected boolean beforeSave(boolean newRecord) {
|
||||
// Binary Data is Mandatory
|
||||
byte[] data = super.getBinaryData();
|
||||
if (data == null || data.length == 0)
|
||||
return false;
|
||||
//
|
||||
log.fine(toString());
|
||||
return true;
|
||||
} // beforeSave*/
|
||||
|
||||
|
||||
public byte[] getByteData(){
|
||||
return super.getBinaryData();
|
||||
}
|
||||
|
@ -605,4 +259,21 @@ public class MArchive extends X_AD_Archive {
|
|||
super.setBinaryData(BinaryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
*
|
||||
* @param newRecord
|
||||
* new
|
||||
* @return true if can be saved
|
||||
*/
|
||||
protected boolean beforeSave(boolean newRecord) {
|
||||
// Binary Data is Mandatory
|
||||
byte[] data = super.getBinaryData();
|
||||
if (data == null || data.length == 0)
|
||||
return false;
|
||||
//
|
||||
log.fine(toString());
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
} // MArchive
|
||||
|
|
|
@ -47,7 +47,7 @@ public class MAttachment extends X_AD_Attachment
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4443388991706555942L;
|
||||
private static final long serialVersionUID = -8013716602070647299L;
|
||||
|
||||
/**
|
||||
* Get Attachment (if there are more than one attachment it gets the first in no specific order)
|
||||
|
@ -68,7 +68,7 @@ public class MAttachment extends X_AD_Attachment
|
|||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MAttachment.class);
|
||||
|
||||
public MStorageProvider provider;
|
||||
private MStorageProvider provider;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -124,9 +124,6 @@ public class MAttachment extends X_AD_Attachment
|
|||
/** List of Entry Data */
|
||||
public ArrayList<MAttachmentEntry> m_items = null;
|
||||
|
||||
/** attachment (root) path - if file system is used */
|
||||
public String m_attachmentPathRoot = "";
|
||||
|
||||
/** string replaces the attachment root in stored xml file
|
||||
* to allow the changing of the attachment root. */
|
||||
public final String ATTACHMENT_FOLDER_PLACEHOLDER = "%ATTACHMENT_FOLDER%";
|
||||
|
@ -138,33 +135,8 @@ public class MAttachment extends X_AD_Attachment
|
|||
*/
|
||||
private void initAttachmentStoreDetails(Properties ctx, String trxName)
|
||||
{
|
||||
|
||||
MClientInfo clientInfo = MClientInfo.get(ctx);
|
||||
|
||||
provider=new MStorageProvider(ctx, clientInfo.getAD_StorageProvider_ID(), trxName);
|
||||
|
||||
m_attachmentPathRoot=provider.getFolder();
|
||||
|
||||
if(m_attachmentPathRoot == null){
|
||||
log.severe("no attachmentPath defined");
|
||||
}
|
||||
|
||||
/* final MClient client = new MClient(ctx, this.getAD_Client_ID(), trxName);
|
||||
isStoreAttachmentsOnFileSystem = client.isStoreAttachmentsOnFileSystem();
|
||||
if(isStoreAttachmentsOnFileSystem){
|
||||
if(File.separatorChar == '\\'){
|
||||
m_attachmentPathRoot = client.getWindowsAttachmentPath();
|
||||
} else {
|
||||
m_attachmentPathRoot = client.getUnixAttachmentPath();
|
||||
}
|
||||
if("".equals(m_attachmentPathRoot)){
|
||||
log.severe("no attachmentPath defined");
|
||||
} else if (!m_attachmentPathRoot.endsWith(File.separator)){
|
||||
log.warning("attachment path doesn't end with " + File.separator);
|
||||
m_attachmentPathRoot = m_attachmentPathRoot + File.separator;
|
||||
log.fine(m_attachmentPathRoot);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.compiere.model;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.adempiere.base.Service;
|
||||
|
@ -27,16 +26,14 @@ public class MStorageProvider extends X_AD_StorageProvider {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1317908636350952835L;
|
||||
private static final long serialVersionUID = -5889682671195395536L;
|
||||
|
||||
public MStorageProvider(Properties ctx, int AD_StorageProvider_ID,
|
||||
String trxName) {
|
||||
public MStorageProvider(Properties ctx, int AD_StorageProvider_ID, String trxName) {
|
||||
super(ctx, AD_StorageProvider_ID, trxName);
|
||||
}
|
||||
|
||||
public MStorageProvider(Properties ctx, ResultSet rs, String trxName) {
|
||||
super(ctx, rs, trxName);
|
||||
|
||||
}
|
||||
|
||||
public IAttachmentStore getAttachmentStore() {
|
||||
|
@ -46,32 +43,23 @@ public class MStorageProvider extends X_AD_StorageProvider {
|
|||
method = "DB";
|
||||
query.put("method", method);
|
||||
IAttachmentStore store = Service.locator().locate(IAttachmentStore.class, query).getService();
|
||||
if(store == null){
|
||||
log.saveError("Error", "No storage provider found");
|
||||
|
||||
if (store == null){
|
||||
log.saveError("Error", "No attachment storage provider found");
|
||||
}
|
||||
return store;
|
||||
}
|
||||
|
||||
public IArchiveStore getArchiveStore(){
|
||||
|
||||
public IArchiveStore getArchiveStore() {
|
||||
ServiceQuery query=new ServiceQuery();
|
||||
String method = this.getMethod();
|
||||
if (method == null)
|
||||
method = "DB";
|
||||
query.put("storage", method);
|
||||
query.put("method", method);
|
||||
IArchiveStore store = Service.locator().locate(IArchiveStore.class, query).getService();
|
||||
|
||||
if(store == null){
|
||||
log.saveError("Error", "No storage provider found");
|
||||
|
||||
if (store == null){
|
||||
log.saveError("Error", "No archive storage provider found");
|
||||
}
|
||||
return store;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public class X_AD_Client extends PO implements I_AD_Client, I_Persistent
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 20121127L;
|
||||
private static final long serialVersionUID = 20121205L;
|
||||
|
||||
/** Standard Constructor */
|
||||
public X_AD_Client (Properties ctx, int AD_Client_ID, String trxName)
|
||||
|
@ -55,7 +55,6 @@ public class X_AD_Client extends PO implements I_AD_Client, I_Persistent
|
|||
setMMPolicy (null);
|
||||
// F
|
||||
setName (null);
|
||||
setStoreArchiveOnFileSystem (false);
|
||||
setValue (null);
|
||||
} */
|
||||
}
|
||||
|
@ -590,41 +589,6 @@ public class X_AD_Client extends PO implements I_AD_Client, I_Persistent
|
|||
return ii.intValue();
|
||||
}
|
||||
|
||||
/** Set Store Archive On File System.
|
||||
@param StoreArchiveOnFileSystem Store Archive On File System */
|
||||
public void setStoreArchiveOnFileSystem (boolean StoreArchiveOnFileSystem)
|
||||
{
|
||||
set_Value (COLUMNNAME_StoreArchiveOnFileSystem, Boolean.valueOf(StoreArchiveOnFileSystem));
|
||||
}
|
||||
|
||||
/** Get Store Archive On File System.
|
||||
@return Store Archive On File System */
|
||||
public boolean isStoreArchiveOnFileSystem ()
|
||||
{
|
||||
Object oo = get_Value(COLUMNNAME_StoreArchiveOnFileSystem);
|
||||
if (oo != null)
|
||||
{
|
||||
if (oo instanceof Boolean)
|
||||
return ((Boolean)oo).booleanValue();
|
||||
return "Y".equals(oo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Set Unix Archive Path.
|
||||
@param UnixArchivePath Unix Archive Path */
|
||||
public void setUnixArchivePath (String UnixArchivePath)
|
||||
{
|
||||
set_Value (COLUMNNAME_UnixArchivePath, UnixArchivePath);
|
||||
}
|
||||
|
||||
/** Get Unix Archive Path.
|
||||
@return Unix Archive Path */
|
||||
public String getUnixArchivePath ()
|
||||
{
|
||||
return (String)get_Value(COLUMNNAME_UnixArchivePath);
|
||||
}
|
||||
|
||||
/** Set Search Key.
|
||||
@param Value
|
||||
Search key for the record in the format required - must be unique
|
||||
|
@ -641,18 +605,4 @@ public class X_AD_Client extends PO implements I_AD_Client, I_Persistent
|
|||
{
|
||||
return (String)get_Value(COLUMNNAME_Value);
|
||||
}
|
||||
|
||||
/** Set Windows Archive Path.
|
||||
@param WindowsArchivePath Windows Archive Path */
|
||||
public void setWindowsArchivePath (String WindowsArchivePath)
|
||||
{
|
||||
set_Value (COLUMNNAME_WindowsArchivePath, WindowsArchivePath);
|
||||
}
|
||||
|
||||
/** Get Windows Archive Path.
|
||||
@return Windows Archive Path */
|
||||
public String getWindowsArchivePath ()
|
||||
{
|
||||
return (String)get_Value(COLUMNNAME_WindowsArchivePath);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue