Skip to content

Commit

Permalink
IDEMPIERE-5989 Attachments are not accessible after upgrade from Idem…
Browse files Browse the repository at this point in the history
…piere 10 to Idempiere 11 (idempiere#2185)

* IDEMPIERE-5989 Attachments are not accessible after upgrade from Idempiere 10 to Idempiere 11

IDEMPIERE-5567
Fix issue when the window doesn't have the UUID field

* - change for a more robust method (similar approach to other points)
  • Loading branch information
CarlosRuiz-globalqss authored Jan 14, 2024
1 parent cb68340 commit a7ddde5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
12 changes: 8 additions & 4 deletions org.adempiere.base/src/org/compiere/model/GridTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,8 @@ public int getAD_AttachmentID()
if (!canHaveAttachment())
return 0;
String recordUU = m_mTable.getKeyUUID(m_currentRow);
return MAttachment.getID(m_vo.AD_Table_ID, recordUU);
int recordID = m_mTable.getKeyID(m_currentRow);
return MAttachment.getID(m_vo.AD_Table_ID, recordID, recordUU);
} // getAttachmentID

/**
Expand All @@ -2147,7 +2148,8 @@ public int getCM_ChatID()
if (!canHaveAttachment())
return 0;
String recordUU = m_mTable.getKeyUUID(m_currentRow);
return MChat.getID(m_vo.AD_Table_ID, recordUU);
int recordID = m_mTable.getKeyID(m_currentRow);
return MChat.getID(m_vo.AD_Table_ID, recordID, recordUU);
} // getCM_ChatID

/**
Expand All @@ -2167,7 +2169,8 @@ public int getAD_PostIt_ID()
if (!canHaveAttachment())
return 0;
String recordUU = m_mTable.getKeyUUID(m_currentRow);
return MPostIt.getID(m_vo.AD_Table_ID, recordUU);
int recordID = m_mTable.getKeyID(m_currentRow);
return MPostIt.getID(m_vo.AD_Table_ID, recordID, recordUU);
} // getAD_PostIt_ID

/**
Expand All @@ -2178,7 +2181,8 @@ public boolean hasLabel()
if (!canHaveAttachment())
return false;
String recordUU = m_mTable.getKeyUUID(m_currentRow);
return MLabelAssignment.hasAnyAssignment(m_vo.AD_Table_ID, recordUU);
int recordID = m_mTable.getKeyID(m_currentRow);
return MLabelAssignment.hasAnyAssignment(m_vo.AD_Table_ID, recordID, recordUU);
} // hasLabel

/**
Expand Down
9 changes: 6 additions & 3 deletions org.adempiere.base/src/org/compiere/model/MAttachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxNam
*/
public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String Record_UU, String trxName)
{
this (ctx, MAttachment.getID(AD_Table_ID, Record_UU) > 0 ? MAttachment.getID(AD_Table_ID, Record_UU) : 0, trxName);
this (ctx, (MAttachment.getID(AD_Table_ID, Record_ID, Record_UU) > 0 ? MAttachment.getID(AD_Table_ID, Record_ID, Record_UU) : 0), trxName);
if (get_ID() == 0) {
setAD_Table_ID (AD_Table_ID);
setRecord_ID (Record_ID);
Expand Down Expand Up @@ -659,7 +659,7 @@ public boolean updateEntry(int i, byte[] data)
* @param Table_ID
* @param Record_ID
* @return AD_Attachment_ID
* @deprecated Use {@link MAttachment#getID(int, String)} instead
* @deprecated Use {@link MAttachment#getID(int, int, String)} instead
*/
public static int getID(int Table_ID, int Record_ID) {
String sql="SELECT AD_Attachment_ID FROM AD_Attachment WHERE AD_Table_ID=? AND Record_ID=?";
Expand All @@ -671,10 +671,13 @@ public static int getID(int Table_ID, int Record_ID) {
* IDEMPIERE-530
* Get the attachment ID based on table_id and record_uu
* @param Table_ID
* @param Record_ID
* @param Record_UU record UUID
* @return AD_Attachment_ID
*/
public static int getID(int Table_ID, String Record_UU) {
public static int getID(int Table_ID, int Record_ID, String Record_UU) {
if (Util.isEmpty(Record_UU))
return getID(Table_ID, Record_ID);
String sql="SELECT AD_Attachment_ID FROM AD_Attachment WHERE AD_Table_ID=? AND Record_UU=?";
int attachid = DB.getSQLValue(null, sql, Table_ID, Record_UU);
return attachid;
Expand Down
7 changes: 5 additions & 2 deletions org.adempiere.base/src/org/compiere/model/MChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public p getHistory (String ConfidentialType)
* @param Table_ID
* @param Record_ID
* @return CM_Chat_ID
* @deprecated Use {@link MChat#getID(int, String)} instead
* @deprecated Use {@link MChat#getID(int, int, String)} instead
*/
public static int getID(int Table_ID, int Record_ID) {
String sql="SELECT CM_Chat_ID FROM CM_Chat WHERE AD_Table_ID=? AND Record_ID=?";
Expand All @@ -239,9 +239,12 @@ public static int getID(int Table_ID, int Record_ID) {
* Get the chat ID based on table_id and record_uu
* @param Table_ID
* @param Record_UU
* @param Record_ID
* @return CM_Chat_ID
*/
public static int getID(int Table_ID, String Record_UU) {
public static int getID(int Table_ID, int Record_ID, String Record_UU) {
if (Util.isEmpty(Record_UU))
return getID(Table_ID, Record_ID);
String sql="SELECT CM_Chat_ID FROM CM_Chat WHERE AD_Table_ID=? AND Record_UU=?";
int chatID = DB.getSQLValueEx(null, sql, Table_ID, Record_UU);
return chatID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ public static boolean hasAnyAssignment(int Table_ID, int Record_ID) {
/**
* Check if record has any label assigned
* @param Table_ID
* @param Record_ID
* @param Record_UU
* @return true if record has any label assigned
*/
public static boolean hasAnyAssignment(int Table_ID, String Record_UU) {
public static boolean hasAnyAssignment(int Table_ID, int Record_ID, String Record_UU) {
if (Util.isEmpty(Record_UU))
return hasAnyAssignment(Table_ID, Record_ID);
String sql="SELECT COUNT(*) FROM AD_LabelAssignment WHERE AD_Table_ID=? AND Record_UU=?";
int counter = DB.getSQLValueEx(null, sql, Table_ID, Record_UU);
return counter > 0;
Expand Down
7 changes: 5 additions & 2 deletions org.adempiere.base/src/org/compiere/model/MPostIt.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public String getUpdatedString()
* @param Table_ID
* @param Record_ID
* @return AD_PostIt_ID
* @deprecated Use {@link MPostIt#getID(int, String)} instead
* @deprecated Use {@link MPostIt#getID(int, int, String)} instead
*/
@Deprecated
public static int getID(int Table_ID, int Record_ID) {
Expand All @@ -139,10 +139,13 @@ public static int getID(int Table_ID, int Record_ID) {

/**
* @param Table_ID
* @param Record_ID
* @param Record_UU
* @return AD_PostIt_ID
*/
public static int getID(int Table_ID, String Record_UU) {
public static int getID(int Table_ID, int Record_ID, String Record_UU) {
if (Util.isEmpty(Record_UU))
return getID(Table_ID, Record_ID);
String sql="SELECT AD_PostIt_ID FROM AD_PostIt WHERE AD_Table_ID=? AND Record_UU=?";
int postItID = DB.getSQLValueEx(null, sql, Table_ID, Record_UU);
return postItID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ public LabelsPanel(AbstractADWindowContent abstractADWindowContent, int AD_Table
this.abstractADWindowContent = abstractADWindowContent;
this.AD_Table_ID = AD_Table_ID;
this.Record_ID = Record_ID;
this.Record_UU = Record_UU;
if (Record_ID > 0 && Record_UU == null) {
MTable table = MTable.get(AD_Table_ID);
PO po = table.getPO(Record_ID, null);
this.Record_UU = po.get_UUID();
} else {
this.Record_UU = Record_UU;
}
setStyle("padding:0px 5px;");
addEventListener(LabelsSearchController.ON_POST_SELECT_LABELITEM_EVENT, this);
update();
Expand Down

0 comments on commit a7ddde5

Please sign in to comment.