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-01-26 10:19:01 -0800 (Mon, 26 Jan 2009) $'
10
 * '$Revision: 4776 $'
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.service.PropertyService;
32
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
33
import edu.ucsb.nceas.utilities.StringUtil;
34

    
35
public class OrganizationUtil {
36

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

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

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

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

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

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