StringBuffer fieldCriterion, int moduleId, Collection allTabls)
{
String recordOwnerField = "";
String recordOwnerTable = "";
StringBuffer selectQuery = new StringBuffer();
CVDal cvdal = new CVDal(this.dataSource);
try
{
// opporunities are activities, so the owner field can be found there.
if (realTableName.equalsIgnoreCase("opportunity") || realTableName.equalsIgnoreCase("literaturerequest") || realTableName.equalsIgnoreCase("task"))
{
selectQuery.append(", activity");
} //end of if statement (thisRealTable.equalsIgnoreCase(...
// we don't have the owner column for the Vendor, Employee, Glaccount
else if (moduleId == 50 || moduleId == 54 || moduleId == 47){
}//end of if statement (moduleId == 50 || ...
else
{
// get the owner field for the module
String moduleOwnerString = "SELECT primarytable, ownerfield "
+ "FROM module WHERE moduleid = ?";
cvdal.setSqlQueryToNull();
cvdal.setSqlQuery(moduleOwnerString);
cvdal.setInt(1, moduleId);
Collection ownerResults = cvdal.executeQuery();
cvdal.setSqlQueryToNull();
if (ownerResults != null)
{
Iterator ownerIterator = ownerResults.iterator();
if (ownerIterator.hasNext())
{
HashMap ownerHashMap = (HashMap) ownerIterator.next();
recordOwnerField = (String) ownerHashMap.get("ownerfield");
recordOwnerTable = (String) ownerHashMap.get("primarytable");
} //end of if statement (ownerIterator.hasNext())
} //end of if statement (ownerResults != null)
} //end of else statement (thisRealTable.equalsIgnoreCase(...
if ((!allTabls.contains(recordOwnerTable))&&(!recordOwnerTable.equals("")))
{
allTabls.add(recordOwnerTable);
selectQuery.append(", " + recordOwnerTable);
}
// Record Owner
selectQuery.append(" WHERE ");
if (realTableName.equalsIgnoreCase("opportunity"))
{
selectQuery.append("opportunity.activityid = activity.activityid AND ");
selectQuery.append("opportunity.opportunityid = " + primaryKey);
selectQuery.append(" AND activity.owner = " + individualID);
selectQuery.append(" AND ");
} //end of if statement (thisRealTable.equalsIgnoreCase(...
else if (realTableName.equalsIgnoreCase("literaturerequest"))
{
selectQuery.append("literaturerequest.activityid = activity.activityid AND ");
selectQuery.append("activity.owner = " + individualID);
selectQuery.append(" AND ");
} //end of if statement (thisRealTable.equalsIgnoreCase(...
else if (realTableName.equalsIgnoreCase("task"))
{
selectQuery.append("task.activityid = activity.activityid AND ");
selectQuery.append(" activity.owner = " + individualID);
selectQuery.append(" AND ");
} //end of if statement (thisRealTable.equalsIgnoreCase(...
// we don't have the owner column for the Vendor, Employee, Glaccount
else if (moduleId == 50 || moduleId == 54 || moduleId == 47)
{
} //end of if statement (moduleId == 50 || ...
else
{
selectQuery.append(recordOwnerTable + ".");
selectQuery.append(recordOwnerField + " = " + individualID);
selectQuery.append(" AND ");
} //end of else statement (thisRealTable.equalsIgnoreCase(...
selectQuery.append(fieldCriterion);
//End Record Owner
// Public Record
selectQuery.append(" UNION ");
selectQuery.append(initialQuery);
selectQuery.append(", publicrecords WHERE publicrecords.moduleid = ");
selectQuery.append(moduleId);
selectQuery.append(" AND publicrecords.recordid = ");
selectQuery.append(realTableName + "." + primaryKey);
selectQuery.append(" AND ");
selectQuery.append(fieldCriterion);
// End Public Record
// Record Permissions
selectQuery.append(" UNION ");
selectQuery.append(initialQuery);
selectQuery.append(", recordauthorisation WHERE recordauthorisation.recordid = ");
selectQuery.append(realTableName + "." + primaryKey);
selectQuery.append(" AND recordauthorisation.recordtypeid = ");
selectQuery.append(moduleId);
selectQuery.append(" AND recordauthorisation.privilegelevel > 0 AND ");
selectQuery.append("recordauthorisation.privilegelevel < 40 AND ");
selectQuery.append("recordauthorisation.individualid = " + individualID);
selectQuery.append(" AND ");
selectQuery.append(fieldCriterion);
// End Record Permissions
} //end of try block
catch (Exception e)
{
System.out.println("[Exception] AdvancedSearchEJB.getRecordPermissionString: "
+ e.toString());
//e.printStackTrace();
} //end of catch block (Exception)
finally
{
cvdal.setSqlQueryToNull();
cvdal.destroy();
cvdal = null;
} //end of try block
return selectQuery.toString();
} //end of getRecordPermissionString method