[jboss-user] [JBoss Seam] - Re: Activation of SFSB and removal of it by Seam question

asookazian do-not-reply at jboss.com
Wed Nov 28 13:02:36 EST 2007


package com.cox.beans.session;
  | 
  | import java.util.ArrayList;
  | import java.util.Calendar;
  | import java.util.GregorianCalendar;
  | import java.util.List;
  | 
  | import javax.annotation.PostConstruct;
  | import javax.annotation.PreDestroy;
  | import javax.ejb.PostActivate;
  | import javax.ejb.PrePassivate;
  | import javax.ejb.Remove;
  | import javax.ejb.Stateful;
  | import javax.ejb.TransactionAttribute;
  | import javax.ejb.TransactionAttributeType;
  | import javax.faces.model.SelectItem;
  | import javax.persistence.EntityManager;
  | import javax.persistence.PersistenceContext;
  | 
  | import org.jboss.seam.annotations.Destroy;
  | import org.jboss.seam.annotations.Factory;
  | import org.jboss.seam.annotations.In;
  | import org.jboss.seam.annotations.Logger;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Out;
  | import org.jboss.seam.annotations.datamodel.DataModel;
  | import org.jboss.seam.annotations.datamodel.DataModelSelectionIndex;
  | import org.jboss.seam.log.Log;
  | 
  | import com.cox.beans.entity.TblSecurityAuditNote;
  | import com.cox.beans.entity.TblSecurityAuditWorking;
  | import com.cox.beans.entity.User;
  | 
  | 
  | 
  | @Stateful
  | //@Restrict("#{identity.loggedIn}")
  | //@Scope(ScopeType.SESSION)
  | @Name("securityAuditAction")
  | public class SecurityAuditAction implements SecurityAuditLocal {
  | 	
  | 	@Logger 
  | 	private Log log;
  | 			
  | 	//using EXTENDED for PersistenceContextType was causing premature update transaction commit to DB when clicking 'no' on radio button...
  | 	@PersistenceContext(unitName="boIcomsSecurityAudit")
  | 	private EntityManager em;
  | 		
  | 	@In(required=false) @Out
  | 	private User user;
  | 		
  | 	@In(required=false)
  | 	private TblSecurityAuditNote myNotes[][];
  | 	
  | 	@In(create=true)
  | 	private NoteLocal noteAction;
  | 	
  | 	private List<SelectItem> myRadioButtonList;
  | 	
  | 	@DataModel(value="myAuditList")
  | 	private List myAuditList;
  | 			
  | 	private Object[] myAuditListSelection;
  | 	
  | 	private final int auditNotStarted = 0;
  | 	private final int auditWaitingICOMS = 1;
  | 	private final int auditComplete = 2;
  | 			
  | 	@DataModelSelectionIndex(value="myAuditList")
  | 	//this is the row number of the underlying collection
  | 	private int currentRowNum;	
  | 		
  | 	//adding empty constructor callback lifecycle methods for debugging purposes (interceptor will output when they get called)
  | 	
  | 	public SecurityAuditAction() {}
  | 	
  | 	@PostConstruct
  | 	public void postConstruct() {
  | 		log.info("in postConstruct");
  | 	}
  | 	
  | 	@PostActivate
  | 	public void postActivate() {
  | 		log.info("in postActivate");
  | 	}
  | 	
  | 	@PrePassivate
  | 	public void prePassivate() {
  | 		log.info("in prePassivate");
  | 		
  | 	}
  | 	
  | 	@PreDestroy
  | 	public void preDestroy() {
  | 		log.info("in preDestroy");
  | 		
  | 	}
  | 	
  | 	private Object[] getMyAuditListSelection() {
  | 		return (Object[])myAuditList.get(currentRowNum);
  | 	}
  | 			
  | 	//@Begin
  |     @Factory("myAuditList")
  |     public void findAuditList()
  |     {
  |     	
  |     	log.info("in getAuditList(): user.getUserId() = " + user.getUserId() + " user.getBillingId() = " + user.getBillingId());   	
  |     	    		
  |     	int employeeId = 900050881; //using btkach id for now;
  |     	
  |     	String networkId = noteAction.getNetworkId()==null?"":noteAction.getNetworkId();
  |     	    		    		    		    		    		
  | 		//List myList = em.createQuery("from User u where u.networkId = :networkId").setParameter("networkId", networkId).getResultList(); 
  | 		//User newUser = (User)myList.get(0);
  | 		
  | 		//employeeId = newUser.getEmployeeId().intValue();
  | 		    		    		
  | 		myAuditList = em.createQuery("SELECT gem, tsaw "+
  | 				"FROM TblSecurityAuditWorking tsaw, "+					
  | 				"GlobalEmployeeMaster gem "+
  | 				"WHERE tsaw.id.siteId = gem.id.siteId "+
  | 				"AND tsaw.id.employeeNumber = gem.id.employeeNumber "+					
  | 				"AND tsaw.reportToId = :employeeId " +
  | 				"ORDER BY tsaw.id.employeeNumber ASC")
  | 				.setParameter("employeeId", employeeId)
  | 				.getResultList();    	
  | 		
  |     	    	
  |     	//call method in NoteAction so facelet can render radio buttons appropriately...
  |     	noteAction.setRenderRadioButtons(myAuditList);
  |     	    	
  |     	log.info("in find(): myAuditList.size() = " + myAuditList.size());
  |     	
  |     }
  |     
  |     public List<SelectItem> getSecurityAuditRadioButtons() {
  | 		myRadioButtonList = new ArrayList<SelectItem>();
  | 		myRadioButtonList.add(new SelectItem("true", "Yes", "Yes it is"));
  | 		myRadioButtonList.add(new SelectItem("false", "No", "No it isn't"));
  | 		return myRadioButtonList;
  | 	}
  |         
  |     public String getHeader() {    	
  |     	return "Please enter your note for the associate";		
  | 	}
  |     
  |     //@End
  |     @TransactionAttribute(TransactionAttributeType.REQUIRED)  //REQUIRED is default, but added for clarity
  |     public void submit() {
  |     	
  |     	Object[] myAuditListSelection = getMyAuditListSelection();
  |     	
  |     	TblSecurityAuditWorking tsaw = (TblSecurityAuditWorking)myAuditListSelection[1];
  |     	    	
  |     	/*ResourceLoader resourceLoader = ResourceLoader.instance();
  |     	
  |     	String[] bundleNames = resourceLoader.getBundleNames();
  |     	
  |     	ResourceBundle resourceBundle = resourceLoader.loadBundle("resources/securityAudit");
  |     	*/
  |     	
  |     	    	
  |     	//determine what status to assign to each row/employee based on answers to radio buttons...
  |     	
  |     	Boolean icomsAccountApproved = tsaw.getIcomsAccountApproved()==null?false:tsaw.getIcomsAccountApproved();    	
  |     	Boolean adjustmentLimitApproved = tsaw.getAdjustmentLimitApproved()==null?false:tsaw.getAdjustmentLimitApproved();    	
  |     	Boolean securityLevelApproved = tsaw.getSecurityLevelApproved()==null?false:tsaw.getSecurityLevelApproved();
  |     	    	    	    	
  |     	if ( icomsAccountApproved && adjustmentLimitApproved && securityLevelApproved ) {
  |     		//green
  |     		tsaw.setAuditProgress(auditComplete);
  |     	}
  |     	else if ( !icomsAccountApproved && !adjustmentLimitApproved && !securityLevelApproved ) {
  |     		//red
  |     		tsaw.setAuditProgress(auditNotStarted);
  |     	}
  |     	else {
  |     		//yellow    		
  |     		tsaw.setAuditProgress(auditWaitingICOMS);
  |     	}
  |     	
  |     	
  |     	// TO DO: determine if quarter and year are pre-populated or not from snapshot (i.e. do we need to do the setter methods here or not for update?)
  |     	//determine quarter and year...
  |     	Calendar cal = new GregorianCalendar();
  |     	
  |     	tsaw.setAuditYear(cal.get(Calendar.YEAR));
  |                 
  |         int month = cal.get(Calendar.MONTH);           // 0=Jan, 1=Feb, ...       
  |         
  |         if (month <= 2)
  |         	tsaw.setAuditQuarter(1);
  |         else if (month >= 3 && month <= 5)
  |         	tsaw.setAuditQuarter(2);
  |         else if (month >= 6 && month <= 8)
  |         	tsaw.setAuditQuarter(3);
  |         else
  |         	tsaw.setAuditQuarter(4);
  |             	
  |     	em.merge(tsaw);
  |     	    	    	
  |     	//check to see if there are any notes for each radio button for this employee/row
  |     	//then update/insert accordingly
  |     	
  |     	//TO DO: move the hard-coding 3 for # of updateable columns in dataTable to resource bundle
  |     	
  |     	// TO DO: noteAction.submit() was moved to action listener attribute in modalPanels...
  |     	//call submit to ensure new note is added to array
  |     	//noteAction.submit();
  |     	    	
  |     	for (int i = 0; i < 3; i++) {
  |     		TblSecurityAuditNote note = myNotes[currentRowNum];
  |     		if (note != null) {
  |     			log.info("myNotes["+currentRowNum+"]["+i+"]: noteText = " + note.getNoteText());    			
  |     			em.persist(note);
  |     		}
  |     	}
  |     	
  |     	em.flush();
  |  
  |     }
  |         
  |     
  |     
  | 	@Remove @Destroy
  | 	public void destroy() {
  | 		
  | 	}
  | 
  | 		
  | 	 
  | 
  | }

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4108634#4108634

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4108634



More information about the jboss-user mailing list