package gov.nih.nci.cananolab.ui.common;

import gov.nih.nci.cananolab.domain.common.PointOfContact;
import gov.nih.nci.cananolab.dto.common.UserBean;
import gov.nih.nci.cananolab.service.common.impl.PointOfContactServiceLocalImpl;
import gov.nih.nci.cananolab.ui.core.InitSetup;
import gov.nih.nci.cananolab.ui.security.InitSecuritySetup;

import java.util.SortedSet;

import javax.servlet.http.HttpServletRequest;

/**
 * This class sets up information required for organization forms.
 * 
 * @author tanq
 * 
 */
public class InitPOCSetup {
	private PointOfContactServiceLocalImpl pocService = new PointOfContactServiceLocalImpl();

	private InitPOCSetup() {
	}

	public static InitPOCSetup getInstance() {
		return new InitPOCSetup();
	}

	public void setPOCDropdowns(HttpServletRequest request) throws Exception {
		InitSetup.getInstance()
				.getDefaultAndOtherLookupTypes(request, "contactRoles",
						"PointOfContact", "role", "otherRole", true);		
		InitSecuritySetup.getInstance().getAllVisibilityGroups(request);
		UserBean user = (UserBean) request.getSession().getAttribute("user");
		getAllOrganizationNames(request, user);
	}
	
	public SortedSet<String> getAllOrganizationNames(
			HttpServletRequest request, UserBean user) throws Exception {
		SortedSet<String> organizationNames = pocService
				.getAllOrganizationNames(user);
		request.getSession().setAttribute("allOrganizationNames", organizationNames);
		return organizationNames;
	}
}

@@ -94,16 +94,72 @@
 ontact;%0A
+import gov.nih.nci.cananolab.domain.common.Publication;%0A
 import g
@@ -200,16 +200,16 @@
 erBean;%0A
-
 import g
@@ -390,16 +390,45 @@
 Setup;%0A%0A
+import java.util.Collection;%0A
 import j
@@ -1176,16 +1176,16 @@
 user%22);%0A
-
 %09%09getAll
@@ -1223,16 +1223,616 @@
 );%0A%09%7D%0A%09%0A
+%09public void persistPOCDropdowns(HttpServletRequest request,%0A%09%09%09PointOfContact primaryPointOfContact, %0A%09%09%09Collection%3CPointOfContact%3E otherPointOfContactCollection ) throws Exception %7B%0A%09%09%09%0A%09%09InitSetup.getInstance().persistLookup(request, %22PointOfContact%22, %22role%22,%0A%09%09%09%09%22otherRole%22,%0A%09%09%09%09(primaryPointOfContact.getRole()));%0A%09%09if (otherPointOfContactCollection!=null) %7B%0A%09%09%09for (PointOfContact otherPoc: otherPointOfContactCollection) %7B%0A%09%09%09%09InitSetup.getInstance().persistLookup(request, %22PointOfContact%22, %22role%22,%0A%09%09%09%09%09%09%22otherRole%22,%0A%09%09%09%09%09%09(otherPoc.getRole()));%0A%09%09%09%7D%0A%09%09%7D%09%09%0A%09%09setPOCDropdowns(request);%0A%09%7D%0A%09%0A
 %09public 

add persistPOCDropdowns()