001: /**********************************************************************************
002: * $URL$
003: * $Id$
004: ***********************************************************************************
005: *
006: * Copyright (c) 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.shared.impl.assessment;
021:
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemDataIfc;
029: import org.sakaiproject.tool.assessment.facade.ItemFacade;
030: import org.sakaiproject.tool.assessment.services.ItemService;
031: import org.sakaiproject.tool.assessment.services.assessment.AssessmentServiceException;
032: import org.sakaiproject.tool.assessment.shared.api.assessment.ItemServiceAPI;
033:
034: /**
035: * AssessmentServiceImpl implements a shared interface to get/set item
036: * information.
037: * @author Ed Smiley <esmiley@stanford.edu>
038: */
039: // Our API just uses our internal service. If we want, we can always replace
040: // this internal service and use its implementation as our own.
041: // Note that ItemFacade implements ItemDataIfc.
042: public class ItemServiceImpl implements ItemServiceAPI {
043:
044: private static Log log = LogFactory.getLog(ItemServiceImpl.class);
045:
046: /**
047: * Get a particular item.
048: *
049: * @param itemId the item id
050: * @param agentId the agent id
051: * @return the item data interface
052: */
053: public ItemDataIfc getItem(Long itemId, String agentId) {
054: ItemFacade item = null;
055: try {
056: ItemService service = new ItemService();
057: item = service.getItem(itemId, agentId);
058: } catch (Exception e) {
059: throw new AssessmentServiceException(e);
060: }
061:
062: return item;
063: }
064:
065: /**
066: * Delete a item.
067: *
068: * @param itemId the item id
069: * @param agentId the agent id
070: */
071: public void deleteItem(Long itemId, String agentId) {
072: try {
073: ItemService service = new ItemService();
074: service.deleteItem(itemId, agentId);
075: } catch (Exception e) {
076: throw new AssessmentServiceException(e);
077: }
078: }
079:
080: /**
081: * Delete itemtextset for an item, used for modify
082: *
083: * @param itemId the item id
084: * @param agentId the agent id
085: */
086: public void deleteItemContent(Long itemId, String agentId) {
087: try {
088: ItemService service = new ItemService();
089: service.deleteItemContent(itemId, agentId);
090: } catch (Exception e) {
091: throw new AssessmentServiceException(e);
092: }
093: }
094:
095: /**
096: * Delete metadata for an item, used for modify.
097: * param: itemid, label, agentId
098: *
099: * @param itemId the item id
100: * @param label the metadata label
101: * @param agentId the agent id
102: */
103: public void deleteItemMetaData(Long itemId, String label,
104: String agentId) {
105: try {
106: ItemService service = new ItemService();
107: service.deleteItemMetaData(itemId, label, agentId);
108: } catch (Exception e) {
109: throw new AssessmentServiceException(e);
110: }
111: }
112:
113: /**
114: * Add metadata for an item, used for modify
115: * param: itemid, label, value, agentId
116: *
117: * @param itemId the item id
118: * @param label the metadata label
119: * @param value the value for the label
120: * @param agentId the agent id
121: */
122: public void addItemMetaData(Long itemId, String label,
123: String value, String agentId) {
124: try {
125: ItemService service = new ItemService();
126: service.addItemMetaData(itemId, label, value, agentId);
127: } catch (Exception e) {
128: throw new AssessmentServiceException(e);
129: }
130: }
131:
132: /**
133: * Save item.
134: * @param item interface
135: * @return item interface
136: */
137: public ItemDataIfc saveItem(ItemDataIfc item) {
138: try {
139: String itemId = item.getItemIdString();
140: ItemService service = new ItemService();
141: item = service.saveItem(service.getItem(itemId));
142: } catch (Exception e) {
143: throw new AssessmentServiceException(e);
144: }
145:
146: return item;
147: }
148:
149: /**
150: * Get item.
151: * @param itemId the item id
152: * @return item interface
153: */
154: public ItemDataIfc getItem(String itemId) {
155: ItemFacade item = null;
156: try {
157: ItemService service = new ItemService();
158: item = service.getItem(itemId);
159: } catch (Exception e) {
160: throw new AssessmentServiceException(e);
161: }
162:
163: return item;
164: }
165:
166: /**
167: * Search for items.
168: * @param keyword the keyword to search by.
169: * @return Map of ItemDataIfcs with item id strings as keys.
170: */
171:
172: public Map getItemsByKeyword(String keyword) {
173: Map itemKeywordMap = new HashMap();
174: try {
175: ItemService service = new ItemService();
176: itemKeywordMap = service.getItemsByKeyword(keyword);
177: } catch (Exception e) {
178: throw new AssessmentServiceException(e);
179: }
180:
181: return itemKeywordMap;
182: }
183: }
|