Skip to content

Commit

Permalink
Merge pull request adempiere#3483 from erpcya/bugfix/#ATT-Bad-reference
Browse files Browse the repository at this point in the history
Fixed error with File Storage for process
  • Loading branch information
e-Evolution committed Jun 29, 2021
2 parents 3c04d6e + 043c607 commit 7789f02
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 7 additions & 6 deletions base/src/org/spin/process/SetupFileStorageSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ public void run(String trxName) {
int attachmentReferenceId = DB.getSQLValue(get_TrxName(), "SELECT AD_AttachmentReference_ID "
+ "FROM AD_AttachmentReference "
+ "WHERE AD_Attachment_ID = ? "
+ "AND FileName = ?", attachmentPair.getKey(), entry.getName());
+ "AND FileName = ? "
+ "AND FileHandler_ID = ?", attachmentPair.getKey(), entry.getName(), getAppSupportId());
if(attachmentReferenceId < 0) {
try {
AttachmentUtil.getInstance(getCtx())
.withData(entry.getData())
.withFileHandlerId(getFileHandlerId())
.withAttachmentId(attachmentPair.getKey())
.withFileName(entry.getName())
.withDescription(Msg.getMsg(getCtx(), "CreatedFromSetupExternalStorage"))
.withFileHandlerId(getFileHandlerId())
.saveAttachment();
addLog(entry.getName() + ": @Ok@");
processed.incrementAndGet();
Expand All @@ -114,7 +115,7 @@ private void migrateImage() {
KeyNamePair [] imageArray = DB.getKeyNamePairs("SELECT AD_Image_ID, Name "
+ "FROM AD_Image "
+ "WHERE AD_Client_ID = ? "
+ "AND NOT EXISTS(SELECT 1 FROM AD_AttachmentReference ar WHERE ar.AD_Image_ID = AD_Image.AD_Image_ID)", false, getAD_Client_ID());
+ "AND NOT EXISTS(SELECT 1 FROM AD_AttachmentReference ar WHERE ar.AD_Image_ID = AD_Image.AD_Image_ID AND ar.FileHandler_ID = ?)", false, getAD_Client_ID(), getAppSupportId());
Arrays.asList(imageArray)
.forEach(imagePair -> {
Trx.run(new TrxRunnable() {
Expand All @@ -123,10 +124,10 @@ public void run(String trxName) {
try {
AttachmentUtil.getInstance(getCtx())
.withData(image.getData())
.withFileHandlerId(getFileHandlerId())
.withImageId(image.getAD_Image_ID())
.withFileName(image.getName())
.withDescription(Msg.getMsg(getCtx(), "CreatedFromSetupExternalStorage"))
.withFileHandlerId(getFileHandlerId())
.saveAttachment();
addLog(image.getName() + ": @Ok@");
processed.incrementAndGet();
Expand All @@ -148,7 +149,7 @@ private void migrateArchive() {
KeyNamePair [] archiveArray = DB.getKeyNamePairs("SELECT AD_Archive_ID, Name "
+ "FROM AD_Archive "
+ "WHERE AD_Client_ID = ? "
+ "AND NOT EXISTS(SELECT 1 FROM AD_AttachmentReference ar WHERE ar.AD_Archive_ID = AD_Archive.AD_Archive_ID)", false, getAD_Client_ID());
+ "AND NOT EXISTS(SELECT 1 FROM AD_AttachmentReference ar WHERE ar.AD_Archive_ID = AD_Archive.AD_Archive_ID AND ar.FileHandler_ID = ?)", false, getAD_Client_ID(), getAppSupportId());
Arrays.asList(archiveArray)
.forEach(archivePair -> {
Trx.run(new TrxRunnable() {
Expand All @@ -158,10 +159,10 @@ public void run(String trxName) {
String fileName = archive.getName() + ".pdf";
AttachmentUtil.getInstance(getCtx())
.withData(archive.getBinaryData())
.withFileHandlerId(getFileHandlerId())
.withArchiveId(archive.getAD_Archive_ID())
.withFileName(fileName)
.withDescription(Msg.getMsg(getCtx(), "CreatedFromSetupExternalStorage"))
.withFileHandlerId(getFileHandlerId())
.saveAttachment();
addLog(fileName + ": @Ok@");
processed.incrementAndGet();
Expand Down
12 changes: 11 additions & 1 deletion base/src/org/spin/util/AttachmentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public static AttachmentUtil getInstance() {
*/
public AttachmentUtil withFileHandlerId(int fileHandlerId) {
this.fileHandlerId = fileHandlerId;
this.fileHandler = null;
return this;
}

Expand Down Expand Up @@ -176,6 +177,8 @@ public AttachmentUtil withData(byte[] data) {
*/
public AttachmentUtil withClientId(int clientId) {
this.clientId = clientId;
this.fileHandlerId = 0;
this.fileHandler = null;
return this;
}

Expand Down Expand Up @@ -289,7 +292,9 @@ public AttachmentUtil clear() {
this.fileName = null;
this.description = null;
this.note = null;
this.transactionName = null;
this.transactionName = null;
this.fileHandlerId = 0;
this.fileHandler = null;
return this;
}

Expand Down Expand Up @@ -340,6 +345,11 @@ public byte[] getAttachment() throws Exception {
* @return
*/
public List<String> getFileNameListFromAttachment() {
try {
getFileHandler();
} catch (Exception e) {
throw new AdempiereException(e);
}
List<MADAttachmentReference> list = MADAttachmentReference.getListByAttachmentId(context, fileHandlerId, attachmentId, transactionName);
List<String> fileNameList = new ArrayList<String>();
if(list != null) {
Expand Down

0 comments on commit 7789f02

Please sign in to comment.