Java Boolean to Hide/Show Controls on Xpages (DocumentCollection: Send Log Email)


	/**
	 * 
	 * Method: SecurityAccessOkay() Created from Copy: 2013.09.10.38.08.PM
	 * Security Access boolean for Xpages Controls (Hide/Show)
	 * Updated: 2013.09.14.1.57.AM, revamped to add Newsletter class
	 */
	// links control, items on form vanish if Security access is N0
	// for viewaccess, updateaccess, addaccess, and deleteaccess in NSF back-end
	public boolean SecurityAccessOkay() {

		// let's add a try catch here, grab errors near the end
		try {

			// BEGIN DEBUG
			System.out.println("BEGIN DEBUG | SecurityAccessOkay started... ");
			Session session = DominoUtils.getCurrentSession(FacesContext
					.getCurrentInstance());  
			//load database via current server found in session
			Database database = (Database) session.getDatabase(session.getServerName(),"docu.nsf");
			
			System.out.println("LoginBeanSQL.java | SecurityAccessOkay Connected to " + database);
			// Find the view in question
			View view = database.getView("SecurityAccessView");
			System.out.println("LoginBeanSQL.java | SecurityAccessOkay Connected to " + view);
			//determine database state for searching
			if (database.isFTIndexed())				
				database.updateFTIndex(false);
		    else 
		    	database.updateFTIndex(true);

			//Collect entries based on search criteria in VIEWACCESS = username101
			DocumentCollection doColl =
			      view.getAllDocumentsByKey(VIEWACCESS, false);
			      System.out.println("LoginBeanSQL.java | DocumentCollection Counts Obtained...");
			      System.out.println("LoginBeanSQL.java | DocumentCollection " + doColl.getCount() + " Account(s) for username101");
				  System.out.println("LoginBeanSQL.java | DocumentCollection completed successfully...");

				  //create new documents with collection results and send email
				  Newsletter news = session.createNewsletter(doColl);
				  //Set Subject items
			      news.setSubjectItemName("Categories");
			      news.setDoSubject(true);

			      //Begin the retrieval of users that match DocumentCollection search
				  Document newDoc = (Document) doColl.getFirstDocument();
				  //loop through until no additional documents from DocumentCollection are found
				   //ensure collection is greater ?
				  //make boolean available to the XP component 'rendered'
				  if (doColl.getCount() > 0) {

					  //prepare email
					  newDoc.appendItemValue("Form", "Memo");
					  newDoc.appendItemValue("Categories", "User Form Access Report");
					  // Sending email
					  System.out.println("BEGIN DEBUG | SecurityAccessOkay sending email... ");
					  newDoc.send(false, "your email address..."); 
					  // Sent email
					  System.out.println("BEGIN DEBUG | SecurityAccessOkay email sent... ");
					  // Boolean true
					  System.out.println("BEGIN DEBUG | SecurityAccessOkay releasing access to controls... ");
				return true;
				  // END DEBUG
				  }

			    } catch(NotesException e) {
			      System.out.println(e.id + " " + e.text);
			      e.printStackTrace();

		} catch (Exception e) {

			e.printStackTrace();
		}

		// message if unsuccessful
		System.out
				.println("LoginBeanSQL.java | DocumentCollection completed, but no records available...");
		System.out
		.println("LoginBeanSQL.java | DocumentCollection, user does not have access to see component...");
		  // Email not sent
		  System.out.println("BEGIN DEBUG | SecurityAccessOkay email not sent... ");
		return false;
	}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...