IDEMPIERE-4304 Saved Query duplicates if use to save after sharing (#81)
* IDEMPIERE-4304 Saved Query duplicates if use to save after sharing * IDEMPIERE-4304 Saved Query duplicates if use to save after sharing - Replaced JDBC call for Query
This commit is contained in:
parent
89faa3ac49
commit
4eac03ba0f
|
@ -38,7 +38,7 @@ public class MUserQuery extends X_AD_UserQuery
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -3606227368868305024L;
|
private static final long serialVersionUID = -5640578235804864422L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all active queries of client for Tab
|
* Get all active queries of client for Tab
|
||||||
|
@ -250,6 +250,26 @@ public class MUserQuery extends X_AD_UserQuery
|
||||||
}
|
}
|
||||||
return retValue;
|
return retValue;
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Specific Tab Query
|
||||||
|
* Private or globall
|
||||||
|
* @param ctx context
|
||||||
|
* @param AD_Tab_ID tab
|
||||||
|
* @param name name
|
||||||
|
* @return query or null
|
||||||
|
*/
|
||||||
|
public static MUserQuery getUserQueryByName(Properties ctx, int AD_Tab_ID, String name)
|
||||||
|
{
|
||||||
|
String sqlWhere = " AD_Client_ID=? AND AD_Tab_ID=? AND UPPER(Name) LIKE ? "
|
||||||
|
+ "AND (AD_User_ID = ? OR AD_User_ID IS NULL) ";
|
||||||
|
|
||||||
|
return new Query(ctx, Table_Name, sqlWhere, null)
|
||||||
|
.setParameters(Env.getAD_Client_ID (ctx), AD_Tab_ID, name.toUpperCase(), Env.getAD_User_ID(ctx))
|
||||||
|
.setOnlyActiveRecords(true)
|
||||||
|
.setOrderBy("Name")
|
||||||
|
.first();
|
||||||
|
} // getUserQueryByName
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger s_log = CLogger.getCLogger (MUserQuery.class);
|
private static CLogger s_log = CLogger.getCLogger (MUserQuery.class);
|
||||||
|
@ -289,5 +309,31 @@ public class MUserQuery extends X_AD_UserQuery
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the current user can save the query privately
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean userCanSave() {
|
||||||
|
if (getAD_Client_ID() != Env.getAD_Client_ID(Env.getCtx()) || //Cannot modify a query from another client (e.g. System)
|
||||||
|
getAD_User_ID() != Env.getAD_User_ID(Env.getCtx()) || //Cannot save a query from a different user
|
||||||
|
get_Value(COLUMNNAME_AD_User_ID) == null) //Cannot save privately (user-specific) an already existing global query
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the current users has permission
|
||||||
|
* to share or modify the query globally
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean userCanShare() {
|
||||||
|
if (!MRole.PREFERENCETYPE_Client.equals(MRole.getDefault().getPreferenceType()) || //Share button only works for roles with preference level = Client
|
||||||
|
getAD_Client_ID() != Env.getAD_Client_ID(Env.getCtx())) //Cannot modify a query from another client (e.g. System)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // MUserQuery
|
} // MUserQuery
|
||||||
|
|
|
@ -1368,6 +1368,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
|
||||||
} else {
|
} else {
|
||||||
cmd_saveSimple(true, shareAllUsers);
|
cmd_saveSimple(true, shareAllUsers);
|
||||||
}
|
}
|
||||||
|
if (shareAllUsers)
|
||||||
|
btnSave.setDisabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Confirm panel actions
|
// Confirm panel actions
|
||||||
|
@ -1477,14 +1479,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MUserQuery uq = userQueries[index-1];
|
MUserQuery uq = userQueries[index-1];
|
||||||
// If global query do not allow other users to save the query
|
btnSave.setDisabled(!uq.userCanSave());
|
||||||
if (uq.getAD_User_ID() != Env.getAD_User_ID(Env.getCtx())) {
|
btnShare.setDisabled(!uq.userCanShare());
|
||||||
if (!MRole.PREFERENCETYPE_Client.equals(MRole.getDefault().getPreferenceType()) ||
|
|
||||||
uq.getAD_Client_ID() != Env.getAD_Client_ID(Env.getCtx())) {
|
|
||||||
btnSave.setDisabled(true);
|
|
||||||
btnShare.setDisabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parseUserQuery(userQueries[index-1]);
|
parseUserQuery(userQueries[index-1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1829,7 +1825,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
|
||||||
code.append( (Object) historyCombo.getSelectedItem().getValue());
|
code.append( (Object) historyCombo.getSelectedItem().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
MUserQuery uq = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID, name);
|
MUserQuery uq = MUserQuery.getUserQueryByName(Env.getCtx(), m_AD_Tab_ID, name);
|
||||||
if (code.length() > 0) { // New or updated
|
if (code.length() > 0) { // New or updated
|
||||||
if (uq == null) // Create a new record
|
if (uq == null) // Create a new record
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue