Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements administrative methods 
4
 *  Copyright: 2008 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 * 
8
 *   '$Author: daigle $'
9
 *     '$Date: 2009-08-24 14:34:17 -0700 (Mon, 24 Aug 2009) $'
10
 * '$Revision: 5030 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

    
27
package edu.ucsb.nceas.metacat.util;
28

    
29
import java.util.Vector;
30

    
31
import edu.ucsb.nceas.metacat.properties.PropertyService;
32
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
33
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
34
import edu.ucsb.nceas.utilities.StringUtil;
35

    
36
public class OrganizationUtil {
37

    
38
	/**
39
	 * private constructor - all methods are static so there is no no need to
40
	 * instantiate.
41
	 */
42
	private OrganizationUtil() {}
43

    
44
	/**
45
	 * gets a list of organization names from metacat.properties. Parses the csv
46
	 * string into a vector
47
	 * 
48
	 * @return a Vector of Strings that hold all available organizations
49
	 * 
50
	 * TODO MCD this should be retrieved from ldap instead of metacat.properties
51
	 */
52
	public static Vector<String> getOrganizations() throws MetacatUtilException {
53

    
54
		Vector<String> shortOrgNames = new Vector<String>();
55
		Vector<String> longOrgNames = null;
56
		
57
		longOrgNames = PropertyService.getPropertyNamesByGroup("organization.name");
58

    
59
		for (String longName : longOrgNames) {
60
			shortOrgNames.add(longName.substring(18));
61
		}
62
		return shortOrgNames;
63
	}
64
	
65
	/**
66
	 * gets a list of organization names from metacat.properties. Parses the csv
67
	 * string into a vector
68
	 * 
69
	 * @return a Vector of Strings that hold all available organizations
70
	 */
71
	public static Vector<String> getOrgDNs(String orgName) throws MetacatUtilException {
72

    
73
		String orgBaseList = null;
74
		try {
75
			orgBaseList = PropertyService.getProperty("organization.base." + orgName);
76
		} catch (PropertyNotFoundException pnfe) {
77
			throw new MetacatUtilException("Could not get metacat property: organization.base." 
78
					+ orgName + " : " + pnfe.getMessage());
79
		}
80
		// this will always return a vector (maybe an empty one)
81
		return StringUtil.toVector(orgBaseList, ',');
82
	}
83
	
84

    
85
	/**
86
	 * Reports whether LDAP is fully configured.
87
	 * 
88
	 * @return a boolean that is true if all sections are configured and false
89
	 *         otherwise
90
	 */
91
	public static boolean areOrganizationsConfigured() throws MetacatUtilException {
92
		String orgConfiguredString = PropertyService.UNCONFIGURED;
93
		try {
94
			orgConfiguredString = PropertyService.getProperty("configutil.organizationsConfigured");
95
		} catch (PropertyNotFoundException pnfe) {
96
			throw new MetacatUtilException("Could not determine if organizations are configured: "
97
					+ pnfe.getMessage());
98
		}
99
		return !orgConfiguredString.equals(PropertyService.UNCONFIGURED);
100
	}
101
}
(9-9/14)