001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.service.impl;
017:
018: import java.util.ArrayList;
019: import java.util.HashMap;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.kuali.core.KualiModule;
024: import org.kuali.core.authorization.AuthorizationType;
025: import org.kuali.core.bo.user.KualiModuleUser;
026: import org.kuali.core.bo.user.UniversalUser;
027: import org.kuali.core.exceptions.UserNotFoundException;
028: import org.kuali.core.service.KualiModuleService;
029:
030: public class KualiModuleServiceImpl implements KualiModuleService {
031:
032: private List<KualiModule> installedModules = new ArrayList<KualiModule>();;
033:
034: public List<KualiModule> getInstalledModules() {
035: return installedModules;
036: }
037:
038: public Map<String, KualiModuleUser> getModuleUsers(
039: UniversalUser user) {
040: Map<String, KualiModuleUser> moduleUsers = new HashMap<String, KualiModuleUser>();
041: for (KualiModule module : installedModules) {
042: try {
043: moduleUsers.put(module.getModuleId(), module
044: .getModuleUserService().getModuleUser(user));
045: } catch (UserNotFoundException e) {
046: // if the user does not exist, create an empty one and set as inactive
047: }
048: }
049: return moduleUsers;
050: }
051:
052: public List<KualiModuleUser> getModuleUserList(UniversalUser user) {
053: List<KualiModuleUser> moduleUsers = new ArrayList<KualiModuleUser>();
054: for (KualiModule module : installedModules) {
055: try {
056: moduleUsers.add(module.getModuleUserService()
057: .getModuleUser(user));
058: } catch (UserNotFoundException e) {
059: // ignore, if the user does not exist, skip it
060: }
061: }
062: return moduleUsers;
063: }
064:
065: public KualiModule getModule(String moduleId) {
066: for (KualiModule module : installedModules) {
067: if (module.getModuleId().equals(moduleId)) {
068: return module;
069: }
070: }
071: return null;
072: }
073:
074: /**
075: * @see org.kuali.core.service.KualiModuleService#getModuleByCode(java.lang.String)
076: */
077: public KualiModule getModuleByCode(String moduleCode) {
078: for (KualiModule module : installedModules) {
079: if (module.getModuleCode().equals(moduleCode)) {
080: return module;
081: }
082: }
083: return null;
084: }
085:
086: public boolean isModuleInstalled(String moduleId) {
087: for (KualiModule module : installedModules) {
088: if (module.getModuleId().equals(moduleId)) {
089: return true;
090: }
091: }
092: return false;
093: }
094:
095: public KualiModule getResponsibleModule(Class boClass) {
096: for (KualiModule module : installedModules) {
097: if (module.getModuleAuthorizer() != null) {
098: if (module.getModuleAuthorizer().isResponsibleFor(
099: boClass)) {
100: return module;
101: }
102: }
103: }
104: return null;
105: }
106:
107: public void setInstalledModules(List<KualiModule> installedModules) {
108: this .installedModules = installedModules;
109: }
110:
111: public boolean isAuthorized(UniversalUser user,
112: AuthorizationType authType) {
113: if (user != null && authType != null) {
114: KualiModule module = getResponsibleModule(authType
115: .getTargetObjectClass());
116: if (module != null) {
117: if (module.getModuleAuthorizer() != null) {
118: if (!module.getModuleAuthorizer().isAuthorized(
119: user, authType)) {
120: return false;
121: }
122: }
123: }
124: }
125: return true;
126: }
127:
128: public List<String> getDataDictionaryPackages() {
129: List<String> packages = new ArrayList<String>();
130: for (KualiModule module : installedModules) {
131: if (module.getDataDictionaryPackages() != null) {
132: packages.addAll(module.getDataDictionaryPackages());
133: }
134: }
135: return packages;
136: }
137: }
|