IDEMPIERE-5567 Support of UUID as Key (FHCA-4195) (#2013)

* IDEMPIERE-5567 Support of UUID as Key (FHCA-4195)

- Fix for MAttachment.get
- discovered while testing rest endpoing api/v1/models/testuu/{uuid}/attachments/zip

* - remove the deprecated message
- use UU just when there is no ID
This commit is contained in:
Carlos Ruiz 2023-09-19 16:24:09 +02:00 committed by GitHub
parent 7e5a1d89ee
commit 7c486df524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 13 deletions

View File

@ -25,6 +25,7 @@ import java.nio.file.Path;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -58,7 +59,7 @@ public class MAttachment extends X_AD_Attachment
/** /**
* *
*/ */
private static final long serialVersionUID = 1447398065894212273L; private static final long serialVersionUID = 5615231734722570658L;
/** /**
* *
@ -69,7 +70,7 @@ public class MAttachment extends X_AD_Attachment
*/ */
public static MAttachment get (Properties ctx, int AD_Table_ID, int Record_ID) public static MAttachment get (Properties ctx, int AD_Table_ID, int Record_ID)
{ {
return get(ctx, AD_Table_ID, Record_ID, (String)null); return get(ctx, AD_Table_ID, Record_ID, (String)null, (String)null);
} }
/** /**
@ -82,15 +83,41 @@ public class MAttachment extends X_AD_Attachment
*/ */
public static MAttachment get (Properties ctx, int AD_Table_ID, int Record_ID, String trxName) public static MAttachment get (Properties ctx, int AD_Table_ID, int Record_ID, String trxName)
{ {
final String whereClause = I_AD_Attachment.COLUMNNAME_AD_Table_ID+"=? AND "+I_AD_Attachment.COLUMNNAME_Record_ID+"=?"; return get(ctx, AD_Table_ID, Record_ID, (String)null, trxName);
MAttachment retValue = new Query(ctx,I_AD_Attachment.Table_Name,whereClause, trxName) } // get
.setParameters(AD_Table_ID, Record_ID)
/**
* Get Attachment (if there are more than one attachment it gets the first in no specific order)
* @param ctx context
* @param AD_Table_ID table
* @param Record_ID record
* @param Record_UU record UUID
* @param trxName
* @return attachment or null
*/
public static MAttachment get (Properties ctx, int AD_Table_ID, int Record_ID, String Record_UU, String trxName)
{
StringBuilder whereClause = new StringBuilder("AD_Table_ID=?");
List<Object> params = new ArrayList<Object>();
params.add(AD_Table_ID);
if (Record_ID > 0) {
whereClause.append(" AND Record_ID=?");
params.add(Record_ID);
} else if (!Util.isEmpty(Record_UU)) {
whereClause.append(" AND Record_UU=?");
params.add(Record_UU);
}
if (params.size() == 1) {
s_log.warning("Wrong call, no Record_ID neither Record_UU for AD_Table_ID=" + AD_Table_ID + " TrxName=" + trxName);
return null;
}
MAttachment retValue = new Query(ctx, Table_Name, whereClause.toString(), trxName)
.setParameters(params)
.first(); .first();
return retValue; return retValue;
} // get } // get
/** Static Logger */ /** Static Logger */
@SuppressWarnings("unused")
private static CLogger s_log = CLogger.getCLogger (MAttachment.class); private static CLogger s_log = CLogger.getCLogger (MAttachment.class);
private MStorageProvider provider; private MStorageProvider provider;

View File

@ -5029,7 +5029,7 @@ public abstract class PO
public MAttachment getAttachment (boolean requery) public MAttachment getAttachment (boolean requery)
{ {
if (m_attachment == null || requery) if (m_attachment == null || requery)
m_attachment = MAttachment.get (getCtx(), p_info.getAD_Table_ID(), get_ID()); m_attachment = MAttachment.get (getCtx(), p_info.getAD_Table_ID(), get_ID(), get_UUID(), null);
return m_attachment; return m_attachment;
} // getAttachment } // getAttachment

View File

@ -700,7 +700,7 @@ public class MPrintTableFormat extends X_AD_PrintTableFormat implements Immutabl
// //
if(isImageIsAttached()) if(isImageIsAttached())
{ {
MAttachment attachment = MAttachment.get(getCtx(), Table_ID, get_ID()); MAttachment attachment = MAttachment.get(getCtx(), Table_ID, get_ID(), get_UUID(), null);
if (attachment == null) if (attachment == null)
{ {
log.log(Level.WARNING, "No Attachment - ID=" + get_ID()); log.log(Level.WARNING, "No Attachment - ID=" + get_ID());

View File

@ -273,8 +273,7 @@ public class ImageElement extends PrintElement
*/ */
private void loadAttachment(int AD_PrintFormatItem_ID) private void loadAttachment(int AD_PrintFormatItem_ID)
{ {
MAttachment attachment = MAttachment.get(Env.getCtx(), MAttachment attachment = MAttachment.get(Env.getCtx(), MPrintFormatItem.Table_ID, AD_PrintFormatItem_ID, null, null);
MPrintFormatItem.Table_ID, AD_PrintFormatItem_ID);
if (attachment == null) if (attachment == null)
{ {
log.log(Level.WARNING, "No Attachment - AD_PrintFormatItem_ID=" + AD_PrintFormatItem_ID); log.log(Level.WARNING, "No Attachment - AD_PrintFormatItem_ID=" + AD_PrintFormatItem_ID);

View File

@ -1154,7 +1154,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
{ {
int record_ID = adTabbox.getSelectedGridTab().getRecord_ID(); int record_ID = adTabbox.getSelectedGridTab().getRecord_ID();
String recordUU = adTabbox.getSelectedGridTab().getRecord_UU(); String recordUU = adTabbox.getSelectedGridTab().getRecord_UU();
if (logger.isLoggable(Level.INFO)) logger.info("Record_ID=" + record_ID); if (logger.isLoggable(Level.INFO)) logger.info("Record_ID=" + record_ID + ", Record_UU=" + recordUU);
if (record_ID== -1 && Util.isEmpty(recordUU)) // No Key if (record_ID== -1 && Util.isEmpty(recordUU)) // No Key
{ {

View File

@ -953,7 +953,7 @@ public class WEMailDialog extends Window implements EventListener<Event>, ValueC
MMailText mt = (MMailText) MUser.get(Env.getCtx()).getR_DefaultMailText(); MMailText mt = (MMailText) MUser.get(Env.getCtx()).getR_DefaultMailText();
if (mt.get_ID() > 0) { if (mt.get_ID() > 0) {
mt.setPO(MUser.get(Env.getCtx())); mt.setPO(MUser.get(Env.getCtx()));
MAttachment attachment = MAttachment.get(Env.getCtx(), MMailText.Table_ID, mt.get_ID()); MAttachment attachment = MAttachment.get(Env.getCtx(), MMailText.Table_ID, mt.get_ID(), null, null);
if (attachment != null) { if (attachment != null) {
MAttachmentEntry[] entries = attachment.getEntries(); MAttachmentEntry[] entries = attachment.getEntries();
for (MAttachmentEntry entry : entries) { for (MAttachmentEntry entry : entries) {