001: /**********************************************************************************
002: * $URL$
003: * $Id$
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.facade.authz.standalone;
021:
022: import java.util.ArrayList;
023: import java.util.Date;
024: import java.util.HashMap;
025: import java.util.List;
026: import java.util.ResourceBundle;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.springframework.dao.DataAccessException;
031: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
032:
033: import org.sakaiproject.tool.assessment.data.dao.authz.AuthorizationData;
034: import org.sakaiproject.tool.assessment.facade.AgentFacade;
035: import org.sakaiproject.tool.assessment.facade.AuthzQueriesFacadeAPI;
036:
037: /**
038: * <p>Description: Facade for AuthZ queries, standalone version.
039: * <p>Sakai Project Copyright (c) 2005</p>
040: * <p> </p>
041: * @author Rachel Gollub <rgollub@stanford.edu>
042: * @author Ed Smiley <esmiley@stanford.edu>
043: */
044: public class AuthzQueriesFacade extends HibernateDaoSupport implements
045: AuthzQueriesFacadeAPI {
046: private static Log log = LogFactory
047: .getLog(AuthzQueriesFacade.class);
048:
049: // stores sql strings
050: private static ResourceBundle res = ResourceBundle
051: .getBundle("org.sakaiproject.tool.assessment.facade.authz.resource.AuthzResource");
052:
053: public boolean hasPrivilege(String functionName) {
054: return true;
055: }
056:
057: /**
058: * Is the agent {agentId} authorized to do {function} to {qualifier}?
059: * @param agentId the agent id.
060: * @param functionId the function to be performed.
061: * @param qualifierId the target of the function.
062: * @return true if authorized (always in standalone)
063: */
064: public boolean isAuthorized(String agentId, String function,
065: String qualifier) {
066: return true;
067: }
068:
069: /**
070: * Create an authorization record for {agentId} authorized to do {function}
071: * to {qualifier}
072: * @param agentId the agent id.
073: * @param functionId the function to be performed.
074: * @param qualifierId the target of the function.
075: * @return the authorization data
076: */
077: public AuthorizationData createAuthorization(String agentId,
078: String functionId, String qualifierId) {
079: AuthorizationData a = new AuthorizationData(agentId,
080: functionId, qualifierId, new Date(), new Date(),
081: AgentFacade.getAgentString(), new Date(), Boolean.TRUE);
082: getHibernateTemplate().save(a);
083: return a;
084: }
085:
086: /**
087: * Remove authorization from qualifier (target).
088: * @param qualifierId the target.
089: */
090: public void removeAuthorizationByQualifier(String qualifierId,
091: boolean isPublishedAssessment) {
092: String query = res.getString("select_authdata_q_id")
093: + qualifierId + "'";
094: String clause = "";
095: if (isPublishedAssessment) {
096: clause = " and (a.functionId='OWN_PUBLISHED_ASSESSMENT'"
097: + " or a.functionId='TAKE_PUBLISHED_ASSESSMENT'"
098: + " or a.functionId='VIEW_PUBLISHED_ASSESSMENT_FEEDBACK'"
099: + " or a.functionId='GRADE_PUBLISHED_ASSESSMENT'"
100: + " or a.functionId='VIEW_PUBLISHED_ASSESSMENT')";
101: } else {
102: clause = " and a.functionId='EDIT_ASSESSMENT'";
103: }
104:
105: List l = getHibernateTemplate().find(query + clause);
106: getHibernateTemplate().deleteAll(l);
107: }
108:
109: /** This returns a HashMap containing
110: * (String a.qualiferId, AuthorizationData a)
111: * agentId is a site for now but can be a user
112: *
113: * @param agentId the agent id
114: * @return HashMap containing qualiferId, AuthorizationData
115: */
116: public HashMap getAuthorizationToViewAssessments(String agentId) {
117: HashMap h = new HashMap();
118: List l = getAuthorizationByAgentAndFunction(agentId, res
119: .getString("VIEW_PUB"));
120: for (int i = 0; i < l.size(); i++) {
121: AuthorizationData a = (AuthorizationData) l.get(i);
122: h.put(a.getQualifierId(), a);
123: }
124: return h;
125: }
126:
127: /**
128: * This returns a HashMap containing authorization data.
129: * @param agentId is a site for now but can be a user
130: * @param functionId the function to be performed.
131: * @return HashMap containing (String a.qualiferId, AuthorizationData a)
132: */
133: public List getAuthorizationByAgentAndFunction(String agentId,
134: String functionId) {
135: try {
136: String query = res.getString("select_authdata_a_id")
137: + agentId + res.getString("and_f_id") + functionId
138: + "'";
139:
140: List list = getHibernateTemplate().find(query);
141: return list;
142: } catch (DataAccessException ex) {
143: log.warn("getAuthorizationByAgentAndFunction " + ex);
144: return new ArrayList();//empty
145: }
146: }
147:
148: /**
149: * Get authorization list by qualifier and function.
150: * @param functionId the function to be performed.
151: * @param qualifierId the target of the function.
152: * @return the list of authorizations.
153: */
154: public List getAuthorizationByFunctionAndQualifier(
155: String functionId, String qualifierId) {
156: try {
157: String query = res.getString("select_authdata_f_id")
158: + functionId + res.getString("and_q_id")
159: + qualifierId + "'";
160:
161: List list = getHibernateTemplate().find(query);
162: //System.out.println("list="+list);
163: return list;
164: } catch (DataAccessException ex) {
165: log.warn("getAuthorizationByAgentAndFunction " + ex);
166: return new ArrayList();//empty
167: }
168: }
169:
170: /**
171: * Check if member of site.
172: * @param siteId the site id
173: * @return true if a member.
174: */
175: public boolean checkMembership(String siteId) {
176: return true;
177: }
178:
179: ///////////////////////////////////////////////////////////////////////////////
180: // The following methods are not implemented in the standalone version of
181: // AuthzQueriesFacade. Currently they are not used in the standalone context,
182: // so they are left throwing UnsupportedOperationExceptions.
183: //
184: // If required for standalone context at some point in the future, you'll
185: // need to implement these, and also should add them to AuthzQueriesFacadeAPI.
186: //
187: ///////////////////////////////////////////////////////////////////////////////
188:
189: /**
190: * UNIMPLEMENTED.
191: * Check the agent {agentId} authorized to do {function} to {qualifier}?
192: * @todo If required for standalone context at some point in the future,
193: * you'll need to implement this
194: * org.sakaiproject.tool.assessment.integration.helper.ifc.AuthzHelper method
195: * @param agentId the agent id.
196: * @param functionId the function to be performed.
197: * @param qualifierId the target of the function.
198: * @return --throw UnsupportedOperationException
199: */
200: public boolean checkAuthorization(String agentId,
201: String functionId, String qualifierId) {
202: throw new java.lang.UnsupportedOperationException(
203: "Method checkAuthorization() not yet implemented for standalone context.");
204: }
205:
206: /**
207: * UNIMPLEMENTED.
208: * Warning. Oddly named method. Just following the convention.
209: * Actually using select from ...AuthorizationData...
210: * @todo If required for standalone context at some point in the future,
211: * you'll need to implement this
212: * org.sakaiproject.tool.assessment.integration.helper.ifc.AuthzHelper method
213: * @param agentId the agent id.
214: * @param functionId the function to be performed.
215: * @return --throw UnsupportedOperationException
216: */
217: public ArrayList getAssessments(String agentId, String functionId) {
218: throw new java.lang.UnsupportedOperationException(
219: "Method getAssessments() not yet implemented for standalone context.");
220: }
221:
222: /**
223: * UNIMPLEMENTED.
224: *
225: * @todo If required for standalone context at some point in the future,
226: * you'll need to implement this org.sakaiproject.tool.assessment.integration.helper.ifc.AuthzHelper method
227: * @param agentId the agent id.
228: * @param functionId the function to be performed.
229: * @return --throw UnsupportedOperationException
230: */
231: public ArrayList getAssessmentsByAgentAndFunction(String agentId,
232: String functionId) {
233: throw new java.lang.UnsupportedOperationException(
234: "Method getAssessmentsByAgentAndFunction() not yet implemented for standalone context.");
235: }
236:
237: }
|