/** * @AppName: Docu.nsf * Program: SecurityControllerBean.java * Created from Copy: 2013.09.12.4.09.AM * Grab all Documents by ID and fetch specific docs to hide/show controls at will * for users based on permissions * * Updated: 2013.09.13.1.09.AM, added instructions to connect to view documents * Updated: 2013.09.14.12.45.AM, added comments in code */ package com.dokoll.solutions.inc.developement.Utils; import java.util.Enumeration; import java.util.Vector; import javax.faces.context.FacesContext; import lotus.domino.Database; import lotus.domino.Document; import lotus.domino.DocumentCollection; import lotus.domino.Session; import com.ibm.xsp.model.domino.DominoUtils; /** * @author Dököll Solutions, Inc. * @version 2013.09.12.4.09.AM * */ public class SecurityControllerBean { //... Vector<String> vector; //... static String USERID = "username101"; //load to Xpages tabPanel/controls //add to button and other controls 'SecurityControllerBean.DocAccessLookup()' //... public boolean DocAccessLookup() { try { // Grab current session Session session = DominoUtils.getCurrentSession(FacesContext .getCurrentInstance()); //load database via current server found in session Database database = session.getDatabase(session.getServerName(),"docu.nsf"); //run method to grab all documents that match UserID String DocumentIDs(database); //Add results found in following Vector Enumeration<String> eNum = vector.elements(); //Loop through Vector while (eNum.hasMoreElements()) { String id = (String)eNum.nextElement(); //begin selecting all DocumentIDs Document doc = database.getDocumentByID(id); //DEBUG::: System.out.println(doc); System.out.println(doc.getItemValueString("UserID")); //Prepare item to search against String UserID = doc.getItemValueString("UserID"); //fetch occurrences of USERID static value(s) if (UserID.contains(USERID)) { System.out.println("Yo, access Dude! " + UserID.toString()); //turn on controls on Xpages return true; } } } catch(Exception e) { e.printStackTrace(); } //shut off controls on Xpages System.out.println("What's the deal! "); return false; } //grab all docs but fetch criteria set forth static variable USERID public void DocumentIDs(Database database) { try { //get All saved documents and return Strings specified in doc.getItemValueString(...) //... DocumentCollection dc = database.getAllDocuments(); //... vector = new Vector<String>(); //... Document savedDoc = dc.getFirstDocument(); //loop through collection of saved docs in view, matching UserID column while (savedDoc != null) { //Pass documents found to newVector //release vector, keep looping through vector.addElement(savedDoc.getNoteID()); //... savedDoc = dc.getNextDocument(); } } catch(Exception e) { e.printStackTrace(); } } }