Hello everyone,
I have created a recycle bin component for Java and it functional. As of now I have all recycle bin cabinent so all users can read, write and delete objects. The problem I am having is if a user deletes an object it gets sent to the recycle bin and only that user can see it in the recycle bin. When I log out and log in as an admin the object is not visible in the recycle bin. I have included my recyclebinclass.java and the destroy method from my TBO which calls my softDelete in my SBO
RecycleBin.class
public class RecycleBin extends Component
{
public void onInit(ArgumentList arg)
{
System.out.println("In onInit");
super.onInit(arg);
}
public void onRender() {
IDfCollection resultSet = null;
IDfQuery query = null;
Datagrid datagrid = null;
try
{
datagrid = (Datagrid)getControl("mygrid", Datagrid.class);
} catch (Exception ex) {
System.out.println("Creating a new Datagrid Control");
if (datagrid == null) {
datagrid = (Datagrid)createControl("mygrid", Datagrid.class);
}
}
String[] columnArray = new String[6];
columnArray[0] = "dp_original_object_name";
columnArray[1] = "dp_original_folder_paths";
columnArray[2] = "dp_deleted_date";
columnArray[3] = "dp_original_format";
columnArray[4] = "dp_original_size";
columnArray[5] = "parent_id";
TableResultSet res2 = new TableResultSet(columnArray);
String queryString =
"SELECT r_object_id, parent_id, dp_original_object_name, dp_original_size, DATETOSTRING(dp_deleted_date,'dd-mon-yyyy hh:mi:ss') as dp_deleted_date, dp_original_format FROM dp_recycle_bin_relation WHERE dp_deleting_user = USER ORDER BY dp_deleted_date;";
IDfSession sess = getDocbaseSession();
try
{
IDfCollection col = execQuery(sess, queryString);
while (col.next())
{
String[] rowArray = new String[6];
rowArray[0] = col.getString("dp_original_object_name");
rowArray[2] = col.getString("dp_deleted_date");
rowArray[3] = col.getString("dp_original_format");
rowArray[4] = col.getString("dp_original_size");
rowArray[5] = col.getString("parent_id");
String queryFolderString =
"SELECT dp_original_folder_paths FROM dp_recycle_bin_relation WHERE r_object_id = '" +
col.getId("r_object_id").toString() +
"'";
IDfCollection colFolders = execQuery(sess, queryFolderString);
String folderList = "";
while (colFolders.next()) {
folderList =
folderList +
colFolders.getString("dp_original_folder_paths") +
"<br>";
}
colFolders.close();
rowArray[1] = folderList;
res2.add(rowArray);
}
col.close();
} catch (Exception ex) {
System.out.println("Failed to run query " + queryString);
}
Datagrid grid = (Datagrid)getControl("mygrid", Datagrid.class);
DataProvider provider2 = grid.getDataProvider();
provider2.setResultSet(res2, null);
}
IDfSession getDocbaseSession()
{
IDfSessionManager sessionManager = null;
SessionManagerHttpBinding httpBinding = null;
IDfSession dfSession = null;
try {
sessionManager = SessionManagerHttpBinding.getSessionManager();
String docbase = SessionManagerHttpBinding.getCurrentDocbase();
dfSession = sessionManager.getSession(docbase);
} catch (DfIdentityException dfe) {
System.out.println(
"Error while obtaining Session. Id exception" +
dfe.getMessage());
} catch (DfAuthenticationException ae) {
System.out.println(
"Authentication exception while getting client " +
ae.getMessage());
} catch (DfPrincipalException pe) {
System.out.println("Principal exception " + pe.getMessage());
} catch (DfServiceException se) {
System.out.println("Service exception " + se.getMessage());
}
return dfSession;
}
private IDfCollection execQuery(IDfSession sess, String queryString)
throws DfException
{
IDfCollection col = null;
IDfQuery q = new DfQuery();
q.setDQL(queryString);
col = q.execute(sess, 0);
return col;
}
public void onClickRestoreCheckbox(Control control, ArgumentList args)
{
try
{
IDfClient client = DfClient.getLocalClient();
IDfSessionManager sessManager =
SessionManagerHttpBinding.getSessionManager();
String serviceName = IDpRecycleBinService.class.getName();
IDpRecycleBinService recycleBinRestore =
(IDpRecycleBinService)client.newService(
serviceName,
sessManager);
IDfSession sess = getDfSession();
System.out.println("onClickRestoreCheckbox event handler called");
Datagrid grid = (Datagrid)getControl("mygrid", Datagrid.class);
Iterator iterControls = grid.getContainedControls();
while (iterControls.hasNext()) {
Control ctrl = (Control)iterControls.next();
if ((ctrl instanceof DatagridRow)) {
Iterator iterRow = ctrl.getContainedControls();
boolean isSelected = false;
while (iterRow.hasNext()) {
Object inObj = iterRow.next();
if ((inObj instanceof Checkbox)) {
Checkbox chkBox = (Checkbox)inObj;
isSelected = chkBox.getValue();
}
if ((inObj instanceof Hidden)) {
Hidden hidVal = (Hidden)inObj;
String documentId = hidVal.getValue();
if (isSelected) {
System.out.println(
"onClickRestoreCheckbox calling recycleBinRestore.restore for " +
documentId);
String docbase = sess.getDocbaseName();
recycleBinRestore.restore(docbase, documentId);
}}} } }
catch (DfException e)
{
e.printStackTrace();
}
}
public void onClickDeleteCheckbox(Control control, ArgumentList args)
{
try
{
System.out.println("onClickDeleteCheckbox event handler called");
IDfClient client = DfClient.getLocalClient();
IDfSessionManager sessManager = SessionManagerHttpBinding.getSessionManager();
String docbase = SessionManagerHttpBinding.getCurrentDocbase();
IDfSession dfSession = sessManager.getSession(docbase);
String serviceName = IDpRecycleBinTBO.class.getName();
IDfSession sess = getDfSession();
Datagrid grid = (Datagrid)getControl("mygrid", Datagrid.class);
Iterator iterControls = grid.getContainedControls();
while (iterControls.hasNext()) {
Control ctrl = (Control)iterControls.next();
if ((ctrl instanceof DatagridRow)) {
Iterator iterRow = ctrl.getContainedControls();
boolean isSelected = false;
while (iterRow.hasNext()) {
Object inObj = iterRow.next();
if ((inObj instanceof Checkbox)) {
Checkbox chkBox = (Checkbox)inObj;
isSelected = chkBox.getValue();
}
if ((inObj instanceof Hidden)) {
Hidden hidVal = (Hidden)inObj;
String objectId = hidVal.getValue();
if (isSelected) {
IDfId idObj = new DfId(objectId);
System.out.println(
"onClickDeleteCheckbox to hard delete " +
idObj.getId());
IDpRecycleBinTBO del = (IDpRecycleBinTBO)dfSession.getObject(idObj);
del.hardDestroy();
}}} }} }
catch (DfException e)
{
e.printStackTrace();
}}
public void onClickReturn(Control control, ArgumentList args)
{
System.out.println("onClickReturn event handler called");
setComponentReturn();
}}
Code that destorys the object (doHardDelete is set to false)
protected void doDestroy(boolean force, Object[] extendedArgs) throws DfException {
try {
System.out.println("destroy started\n---------------");
if (doHardDelete) {
// If this was called from the hardDestroy() then just do a regular delete
System.out.println("performing a super.destroy");
super.doDestroy(force, extendedArgs);
} else {
System.out.println("performing a soft delete");
IDfClient client = DfClient.getLocalClient();
IDfSession sess = getSession();
IDfSessionManager sessManager = sess.getSessionManager();
String myService = IDpRecycleBinService.class.getName();
IDpRecycleBinService recycleBinService =
(IDpRecycleBinService) client.newService(
myService, sessManager);
IDfSysObject document = (IDfSysObject) sess.getObject(getObjectId());
System.out.println(
"Object Name to softDelete " + document.getObjectName());
String DpRecycleBinUserName;
String DpRecycleBinACL;
DpRecycleBinUserName = "dp_recycle_bin_user";
DpRecycleBinACL = "dp_recycle_bin_acl";
recycleBinService.softDelete(sess.getDocbaseName(), document, DpRecycleBinUserName, DpRecycleBinACL);
}
System.out.println("\ndestroy finished\n----------------");
} catch (Exception dfsce) {
//throw new DfException();
dfsce.printStackTrace();
}
}
SoftDelete in SBO
public void softDelete(String docbase, IDfSysObject document, String DpRecycleBinUserName,String DpRecycleBinACL) throws DfException {
System.out.println("softDelete started\n------------------");
IDfSession session = null;
try {
System.out.println(
"Object id of document to soft delete: "
+ document.getObjectId());
// Get a, IdfID reference to the object to be soft deleted
//IDfClient localClient = DfClient.getLocalClient();
//String docbase =localClient.getDocbaseNameFromId(document.getObjectId());
session = getSession(docbase);
String newRelationObjectID =
createNewRelationObject(session, document.getObjectId());
System.out.println(
"createNewRelationObject returned : " + newRelationObjectID);
// Pass the session and the IDfID object to the method
softDeleteDocument(session, document.getObjectId(), DpRecycleBinUserName, DpRecycleBinACL);
} finally {
releaseSession(session);
System.out.println("softDelete finished\n-------------------");
}
}
/*
* The first step in the soft-delete is to create a record of the details of the
* document being deleted. This is required for 3 reasons.
*
* 1) It is a record that the document has beeen deleted
* 2) It contains the metadata needed to 'undelete' the object
* 3) It contains information about the deleted document so we can display it in
* the 'Recycle Bin' component.
*
*/
private String createNewRelationObject(IDfSession session,
IDfId documentOID)
throws DfException {
// Get reference to object to be deleted to get current values
IDfSysObject document = (IDfSysObject) session.getObject(documentOID);
// Get the current time/date as IDfTime
IDfClientX x = new DfClientX();
IDfTime currentTime =
x.getTime(
getCurrentDateTime("yy/MM/dd hh:mm:ss"),
"yy/mm/dd hh:mi:ss");
// Set standard properties
IDfRelation sysObj = (IDfRelation) session.newObject("dp_recycle_bin_relation");
sysObj.setRelationName("dp_recycle_bin_relation");
sysObj.setParentId(documentOID);
sysObj.setChildId(sysObj.getId("r_object_id"));
sysObj.setPermanentLink(false);
sysObj.setDescription(
"Item placed in recycle bin by DevProg Recycle Bin Business Object");
// Set custom properties
sysObj.setString("dp_deleting_user", session.getLoginUserName());
sysObj.setString