<commit_before>package edu.iu.grid.oim.view.divrep.form;

import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.TreeSet;

import org.apache.log4j.Logger;

import com.divrep.DivRep;
import com.divrep.DivRepEvent;
import com.divrep.DivRepEventListener;
import com.divrep.common.DivRepButton;
import com.divrep.common.DivRepCheckBox;
import com.divrep.common.DivRepForm;
import com.divrep.common.DivRepFormElement;
import com.divrep.common.DivRepSelectBox;
import com.divrep.common.DivRepStaticContent;
import com.divrep.common.DivRepTextArea;
import com.divrep.common.DivRepTextBox;
import com.divrep.validator.DivRepUniqueValidator;
import com.divrep.validator.DivRepUrlValidator;

import edu.iu.grid.oim.lib.Authorization;
import edu.iu.grid.oim.lib.Footprints;
import edu.iu.grid.oim.lib.AuthorizationException;
import edu.iu.grid.oim.model.UserContext;
import edu.iu.grid.oim.model.UserContext.MessageType;
import edu.iu.grid.oim.model.db.ContactTypeModel;
import edu.iu.grid.oim.model.db.ContactModel;
import edu.iu.grid.oim.model.db.FieldOfScienceModel;
import edu.iu.grid.oim.model.db.VOReportContactModel;
import edu.iu.grid.oim.model.db.VOReportNameModel;
import edu.iu.grid.oim.model.db.VOReportNameFqanModel;
import edu.iu.grid.oim.model.db.SCModel;
import edu.iu.grid.oim.model.db.VOContactModel;
import edu.iu.grid.oim.model.db.VOFieldOfScienceModel;
import edu.iu.grid.oim.model.db.VOModel;
import edu.iu.grid.oim.model.db.record.ContactTypeRecord;
import edu.iu.grid.oim.model.db.record.ContactRecord;
import edu.iu.grid.oim.model.db.record.FieldOfScienceRecord;

import edu.iu.grid.oim.model.db.record.VOReportContactRecord;
import edu.iu.grid.oim.model.db.record.VOReportNameRecord;
import edu.iu.grid.oim.model.db.record.VOReportNameFqanRecord;
import edu.iu.grid.oim.model.db.record.SCRecord;
import edu.iu.grid.oim.model.db.record.VOContactRecord;
import edu.iu.grid.oim.model.db.record.VOFieldOfScienceRecord;
import edu.iu.grid.oim.model.db.record.VORecord;
import edu.iu.grid.oim.view.ToolTip;
import edu.iu.grid.oim.view.divrep.AUPConfirmation;
import edu.iu.grid.oim.view.divrep.Confirmation;
import edu.iu.grid.oim.view.divrep.ContactEditor;
import edu.iu.grid.oim.view.divrep.VOReportNames;
import edu.iu.grid.oim.view.divrep.ContactEditor.Rank;
import edu.iu.grid.oim.view.divrep.FieldOfScience;

public class VOFormDE extends DivRepForm 
{
    static Logger log = Logger.getLogger(VOFormDE.class); 
   
    private UserContext context;
	private Authorization auth;
	private Integer id;
	
	private DivRepTextBox name;
	private DivRepTextBox long_name;
	private DivRepTextArea description;
	private DivRepTextArea community;
	private DivRepSelectBox sc_id;
	private DivRepCheckBox active;
	private DivRepCheckBox disable;
	private DivRepCheckBox child_vo;
	private DivRepSelectBox parent_vo;

	private Confirmation confirmation;
	private DivRepTextArea comment;

	static public ArrayList<ContactTypeRecord.Info> ContactTypes;
	static {
		ContactTypes = new ArrayList<ContactTypeRecord.Info>();
		ContactTypes.add(new ContactTypeRecord.Info(1, "A contact who has registered this virtual organization"));
		ContactTypes.add(new ContactTypeRecord.Info(6, "Contacts who decides on what virtual organizations are allowed to run on VO-owned resources, who are users of this virtual organization, etc"));
		ContactTypes.add(new ContactTypeRecord.Info(3, "Contacts for ticketing and assorted issues. This is typically a user/application support person or a help desk"));
		ContactTypes.add(new ContactTypeRecord.Info(2, "Security notifications sent out by the OSG security team are sent to primary and secondary virtual organization security contacts"));
		ContactTypes.add(new ContactTypeRecord.Info(5, "Contacts who do not fall under any of the above types but would like to be able to edit this virtual organization can be added as miscellaneous contact"));
		ContactTypes.add(new ContactTypeRecord.Info(11, "RA (Registration Authority) agent who can approve certificate requests."));
	}
	
	private HashMap<Integer, ContactEditor> contact_editors = new HashMap();

	// Moving fields related to only VOs that do actual research, apart 
	//  from providing services on their facility to a separate area that
	//  that can be hidden -agopu 2010-05-31
	private DivRepCheckBox science_vo;
	private ScienceVOInfo science_vo_info;
	
	private DivRepTextArea app_description;
	private VOReportNames vo_report_name_div;
	
	private FieldOfScience field_of_science_de;
	
	private URLs urls;
	private DivRepTextBox primary_url; // Moved out of URLs class to enable direct property manipulation
	private DivRepTextBox aup_url;
	private DivRepTextBox membership_services_url;
	private DivRepTextBox purpose_url;
	private DivRepTextBox support_url;	

	class ScienceVOInfo extends DivRepFormElement
	{
		protected void onEvent(DivRepEvent e) {
			// TODO Auto-generated method stub
			
		}	
		
		ScienceVOInfo(DivRep _parent, VORecord rec) {
			super(_parent);

			//new DivRepStaticContent(this, "<div class=\"indent\">");
			//new DivRepStaticContent(this, "<h3>More Extended Descriptions including URLs</h3>");

			app_description = new DivRepTextArea(this);
			app_description.setLabel("Enter an Application Description");
			app_description.setValue(rec.app_description);
			app_description.setSampleValue("CDF Analysis jobs will be run");

			urls = new URLs(this, rec);

			// Fields of Science
			try {
				ArrayList<Integer> selected = new ArrayList<Integer>();
				//select currently selected field of science
				VOFieldOfScienceModel vofsmodel = new VOFieldOfScienceModel(context);
				for(VOFieldOfScienceRecord fsrec : vofsmodel.getByVOID(rec.id)) {
					selected.add(fsrec.field_of_science_id);
				}
				field_of_science_de = new FieldOfScience(this, context, selected);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			// Handle reporting names
			new DivRepStaticContent(this, "<h3>Reporting Names for your VO</h3>");
			new DivRepStaticContent(this, "<p>This section allows you to define report names for this VO. These report names are used by the Gratia Accounting software to organize periodic usage accounting reports. You need to define at least one report name -- for example, one with the same name as the VO (short) name and no FQANs. Large VOs with several sub-groups can define different report names, and also one or more FQAN per report name. Contact <EMAIL> if you have any questions about VO report names.</p>");
			ContactModel cmodel = new ContactModel (context);
			VOReportNameModel vorepname_model = new VOReportNameModel(context);
			VOReportNameFqanModel vorepnamefqan_model = new VOReportNameFqanModel(context);

			ArrayList<VOReportNameRecord> vorepname_records;
			try {
				vorepname_records = vorepname_model.getAll();
				vo_report_name_div = new VOReportNames(this, vorepname_records, cmodel);
				if(id != null) {
					for(VOReportNameRecord vorepname_rec : vorepname_model.getAllByVOID(id)) {
						VOReportContactModel vorcmodel = new VOReportContactModel(context);<commit_msg>(patched) fixed the null rec.id issue for vo science list<commit_after>package edu.iu.grid.oim.view.divrep.form;

import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.TreeSet;

import org.apache.log4j.Logger;

import com.divrep.DivRep;
import com.divrep.DivRepEvent;
import com.divrep.DivRepEventListener;
import com.divrep.common.DivRepButton;
import com.divrep.common.DivRepCheckBox;
import com.divrep.common.DivRepForm;
import com.divrep.common.DivRepFormElement;
import com.divrep.common.DivRepSelectBox;
import com.divrep.common.DivRepStaticContent;
import com.divrep.common.DivRepTextArea;
import com.divrep.common.DivRepTextBox;
import com.divrep.validator.DivRepUniqueValidator;
import com.divrep.validator.DivRepUrlValidator;

import edu.iu.grid.oim.lib.Authorization;
import edu.iu.grid.oim.lib.Footprints;
import edu.iu.grid.oim.lib.AuthorizationException;
import edu.iu.grid.oim.model.UserContext;
import edu.iu.grid.oim.model.UserContext.MessageType;
import edu.iu.grid.oim.model.db.ContactTypeModel;
import edu.iu.grid.oim.model.db.ContactModel;
import edu.iu.grid.oim.model.db.FieldOfScienceModel;
import edu.iu.grid.oim.model.db.VOReportContactModel;
import edu.iu.grid.oim.model.db.VOReportNameModel;
import edu.iu.grid.oim.model.db.VOReportNameFqanModel;
import edu.iu.grid.oim.model.db.SCModel;
import edu.iu.grid.oim.model.db.VOContactModel;
import edu.iu.grid.oim.model.db.VOFieldOfScienceModel;
import edu.iu.grid.oim.model.db.VOModel;
import edu.iu.grid.oim.model.db.record.ContactTypeRecord;
import edu.iu.grid.oim.model.db.record.ContactRecord;
import edu.iu.grid.oim.model.db.record.FieldOfScienceRecord;

import edu.iu.grid.oim.model.db.record.VOReportContactRecord;
import edu.iu.grid.oim.model.db.record.VOReportNameRecord;
import edu.iu.grid.oim.model.db.record.VOReportNameFqanRecord;
import edu.iu.grid.oim.model.db.record.SCRecord;
import edu.iu.grid.oim.model.db.record.VOContactRecord;
import edu.iu.grid.oim.model.db.record.VOFieldOfScienceRecord;
import edu.iu.grid.oim.model.db.record.VORecord;
import edu.iu.grid.oim.view.ToolTip;
import edu.iu.grid.oim.view.divrep.AUPConfirmation;
import edu.iu.grid.oim.view.divrep.Confirmation;
import edu.iu.grid.oim.view.divrep.ContactEditor;
import edu.iu.grid.oim.view.divrep.VOReportNames;
import edu.iu.grid.oim.view.divrep.ContactEditor.Rank;
import edu.iu.grid.oim.view.divrep.FieldOfScience;

public class VOFormDE extends DivRepForm 
{
    static Logger log = Logger.getLogger(VOFormDE.class); 
   
    private UserContext context;
	private Authorization auth;
	private Integer id;
	
	private DivRepTextBox name;
	private DivRepTextBox long_name;
	private DivRepTextArea description;
	private DivRepTextArea community;
	private DivRepSelectBox sc_id;
	private DivRepCheckBox active;
	private DivRepCheckBox disable;
	private DivRepCheckBox child_vo;
	private DivRepSelectBox parent_vo;

	private Confirmation confirmation;
	private DivRepTextArea comment;

	static public ArrayList<ContactTypeRecord.Info> ContactTypes;
	static {
		ContactTypes = new ArrayList<ContactTypeRecord.Info>();
		ContactTypes.add(new ContactTypeRecord.Info(1, "A contact who has registered this virtual organization"));
		ContactTypes.add(new ContactTypeRecord.Info(6, "Contacts who decides on what virtual organizations are allowed to run on VO-owned resources, who are users of this virtual organization, etc"));
		ContactTypes.add(new ContactTypeRecord.Info(3, "Contacts for ticketing and assorted issues. This is typically a user/application support person or a help desk"));
		ContactTypes.add(new ContactTypeRecord.Info(2, "Security notifications sent out by the OSG security team are sent to primary and secondary virtual organization security contacts"));
		ContactTypes.add(new ContactTypeRecord.Info(5, "Contacts who do not fall under any of the above types but would like to be able to edit this virtual organization can be added as miscellaneous contact"));
		ContactTypes.add(new ContactTypeRecord.Info(11, "RA (Registration Authority) agent who can approve certificate requests."));
	}
	
	private HashMap<Integer, ContactEditor> contact_editors = new HashMap();

	// Moving fields related to only VOs that do actual research, apart 
	//  from providing services on their facility to a separate area that
	//  that can be hidden -agopu 2010-05-31
	private DivRepCheckBox science_vo;
	private ScienceVOInfo science_vo_info;
	
	private DivRepTextArea app_description;
	private VOReportNames vo_report_name_div;
	
	private FieldOfScience field_of_science_de;
	
	private URLs urls;
	private DivRepTextBox primary_url; // Moved out of URLs class to enable direct property manipulation
	private DivRepTextBox aup_url;
	private DivRepTextBox membership_services_url;
	private DivRepTextBox purpose_url;
	private DivRepTextBox support_url;	

	class ScienceVOInfo extends DivRepFormElement
	{
		protected void onEvent(DivRepEvent e) {
			// TODO Auto-generated method stub
			
		}	
		
		ScienceVOInfo(DivRep _parent, VORecord rec) {
			super(_parent);

			//new DivRepStaticContent(this, "<div class=\"indent\">");
			//new DivRepStaticContent(this, "<h3>More Extended Descriptions including URLs</h3>");

			app_description = new DivRepTextArea(this);
			app_description.setLabel("Enter an Application Description");
			app_description.setValue(rec.app_description);
			app_description.setSampleValue("CDF Analysis jobs will be run");

			urls = new URLs(this, rec);

			// Fields of Science
			try {
				ArrayList<Integer> selected = new ArrayList<Integer>();
				//select currently selected field of science
				if(rec.id != null) {
					VOFieldOfScienceModel vofsmodel = new VOFieldOfScienceModel(context);
					for(VOFieldOfScienceRecord fsrec : vofsmodel.getByVOID(rec.id)) {
						selected.add(fsrec.field_of_science_id);
					}
				}
				field_of_science_de = new FieldOfScience(this, context, selected);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			// Handle reporting names
			new DivRepStaticContent(this, "<h3>Reporting Names for your VO</h3>");
			new DivRepStaticContent(this, "<p>This section allows you to define report names for this VO. These report names are used by the Gratia Accounting software to organize periodic usage accounting reports. You need to define at least one report name -- for example, one with the same name as the VO (short) name and no FQANs. Large VOs with several sub-groups can define different report names, and also one or more FQAN per report name. Contact <EMAIL> if you have any questions about VO report names.</p>");
			ContactModel cmodel = new ContactModel (context);
			VOReportNameModel vorepname_model = new VOReportNameModel(context);
			VOReportNameFqanModel vorepnamefqan_model = new VOReportNameFqanModel(context);

			ArrayList<VOReportNameRecord> vorepname_records;
			try {
				vorepname_records = vorepname_model.getAll();
				vo_report_name_div = new VOReportNames(this, vorepname_records, cmodel);
				if(id != null) {
					for(VOReportNameRecord vorepname_rec : vorepname_model.getAllByVOID(id)) {
						VOReportContactModel vorcmodel = new VOReportContactModel(context);
{'fraction_non_alphanumeric': 0.08962360816995696, 'fraction_numerical': 0.0027324270783523463, 'mean_word_length': 5.179822710004221, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4247387', 'n_tokens_mistral': 4934, 'n_tokens_neox': 4603, 'n_words': 1148}