0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/questionpool/QuestionPoolBean.java $
0003: * $Id: QuestionPoolBean.java 29122 2007-04-18 22:40:06Z ajpoland@iupui.edu $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
0007: *
0008: * Licensed under the Educational Community License, Version 1.0 (the"License");
0009: * you may not use this file except in compliance with the License.
0010: * You may obtain a copy of the License at
0011: *
0012: * http://www.opensource.org/licenses/ecl1.php
0013: *
0014: * Unless required by applicable law or agreed to in writing, software
0015: * distributed under the License is distributed on an "AS IS" BASIS,
0016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: * See the License for the specific language governing permissions and
0018: * limitations under the License.
0019: *
0020: **********************************************************************************/package org.sakaiproject.tool.assessment.ui.bean.questionpool;
0021:
0022: import java.io.Serializable;
0023: import java.util.ArrayList;
0024: import java.util.Collection;
0025: import java.util.Collections;
0026: import java.util.Date;
0027: import java.util.HashMap;
0028: import java.util.HashSet;
0029: import java.util.Iterator;
0030: import java.util.List;
0031: import java.util.Map;
0032: import org.sakaiproject.util.ResourceLoader;
0033: import java.util.Set;
0034:
0035: import javax.faces.application.FacesMessage;
0036: import javax.faces.context.FacesContext;
0037: import javax.faces.event.ActionEvent;
0038: import javax.faces.model.ListDataModel;
0039: import javax.faces.model.SelectItem;
0040:
0041: import org.apache.commons.logging.Log;
0042: import org.apache.commons.logging.LogFactory;
0043: import org.apache.struts.upload.FormFile;
0044: import org.sakaiproject.tool.assessment.business.questionpool.QuestionPoolTreeImpl;
0045: import org.sakaiproject.tool.assessment.data.dao.assessment.ItemMetaData;
0046: import org.sakaiproject.tool.assessment.data.ifc.questionpool.QuestionPoolDataIfc;
0047: import org.sakaiproject.tool.assessment.data.model.Tree;
0048: import org.sakaiproject.tool.assessment.facade.AgentFacade;
0049: import org.sakaiproject.tool.assessment.facade.ItemFacade;
0050: import org.sakaiproject.tool.assessment.facade.QuestionPoolFacade;
0051: import org.sakaiproject.tool.assessment.facade.QuestionPoolIteratorFacade;
0052: import org.sakaiproject.tool.assessment.services.ItemService;
0053: import org.sakaiproject.tool.assessment.services.QuestionPoolService;
0054: import org.sakaiproject.tool.assessment.ui.bean.author.ItemAuthorBean;
0055: import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil;
0056: import org.sakaiproject.tool.assessment.util.BeanSort;
0057:
0058: // from navigo
0059:
0060: /**
0061: * This holds question pool information.
0062: *
0063: * Used to be org.navigoproject.ui.web.form.questionpool.QuestionPoolForm
0064: *
0065: * @author Rachel Gollub <rgollub@stanford.edu>
0066: * @author Lydia Li<lydial@stanford.edu>
0067: * $Id: QuestionPoolBean.java 29122 2007-04-18 22:40:06Z ajpoland@iupui.edu $
0068: */
0069: public class QuestionPoolBean implements Serializable {
0070:
0071: /** Use serialVersionUID for interoperability. */
0072: private final static long serialVersionUID = 418920360211039758L;
0073:
0074: private String name;
0075: private Collection pools;
0076: private QuestionPoolDataBean currentPool;
0077: private QuestionPoolDataBean parentPool;
0078:
0079: private String currentItemId;
0080: private ItemFacade currentItem;
0081:
0082: private boolean allPoolsSelected;
0083: private boolean allItemsSelected;
0084: private boolean rootPoolSelected;
0085: private List poolListSelectItems;
0086: private List poolsToDelete;
0087: private List itemsToDelete;
0088: private String[] selectedPools;
0089: private String[] selectedQuestions;
0090: private String[] destPools = {}; // for multibox
0091: private String[] destItems = {}; // items to delete
0092: private String destPool = ""; // for Move Pool Destination
0093: private FormFile filename; // for import /export
0094: private int htmlIdLevel; // pass this to javascript:collapseAll()
0095: private String questionType; // the question type to add
0096: private int parentPoolSize = 0; // the question type to add
0097: private ArrayList allItems;
0098:
0099: // for search Question
0100: private String[] searchByTypes = {}; // for multibox
0101: private String searchQtext;
0102: private String searchQkeywords;
0103: private String searchQobj;
0104: private String searchQrubrics;
0105:
0106: // import questions from pool to assessment
0107: private String assessmentID;
0108: private String selectedAssessment;
0109: private String selectedSection;
0110: private boolean importToAuthoring;
0111: private String actionType;
0112: private String sortProperty = "title";
0113: private boolean sortAscending = true;
0114: private String sortCopyPoolProperty = "title";
0115: private boolean sortCopyPoolAscending = true;
0116: private String sortMovePoolProperty = "title";
0117: private boolean sortMovePoolAscending = true;
0118: private String sortSubPoolProperty = "title";
0119: private boolean sortSubPoolAscending = true;
0120: private String sortQuestionProperty = "text";
0121: private boolean sortQuestionAscending = true;
0122:
0123: private ArrayList addedPools;
0124: private ArrayList addedQuestions;
0125:
0126: private ItemFacade itemToPreview;
0127:
0128: private static Log log = LogFactory.getLog(QuestionPoolBean.class);
0129:
0130: // for JSF
0131: private Tree tree;
0132: private Collection qpools;
0133: private Collection copyQpools;
0134: private Collection moveQpools;
0135: private Collection sortedSubqpools;
0136: // private QuestionPoolDataModel qpDataModel;
0137:
0138: private String addOrEdit;
0139: private String outcome;
0140: private String outcomeEdit;
0141: private String deletePoolSource; // either from poolList.jsp , or from editPool.jsp
0142: private String addPoolSource; // either from poolList.jsp , or from editPool.jsp
0143:
0144: private ResourceLoader rb = new ResourceLoader(
0145: "org.sakaiproject.tool.assessment.bundle.QuestionPoolMessages");
0146:
0147: /**
0148: * Creates a new QuestionPoolBean object.
0149: */
0150: public QuestionPoolBean() {
0151: resetFields();
0152: }
0153:
0154: public QuestionPoolDataModel getQpools() {
0155: // daisyf note:
0156: // #1 - buildTree() returns all branches immediate under the root as well as
0157: // individual branches, e.g. you will get a branch 1 with its subsidiary 1.1 & 1.2 attached
0158: // and branch 2 with its subsidiary 2.1 & 2.2 attached. Plus all 4 secondary branches 1.1,
0159: // 1.2, 1.3 and 1.4, each with their subsidiaries attached to them.
0160: buildTree();
0161:
0162: // #2 - tree.sortByProperty sort ALL the branches regardless of their level based on
0163: // this.getSortProperty(). I am not sure what tree.getSortProperty() is used for.
0164: // tree.sortByProperty(this.getSortProperty(),this.getSortAscending());
0165:
0166: // #3 - tree.getSortedObjects() doesn't sort, it just return a list of QuestionPoolFacade
0167: // Think of it as all the nodes in the trees. You can drill down each node using methods
0168: // provided by the tree to get to the children nodes.
0169: Collection objects = tree.getSortedObjects();
0170:
0171: // #4 - construct the sortedList, pools need to be sorted one level at a time so the hierachical
0172: // structure can be maintained. Here, we start from root = 0,
0173: if (objects != null) {
0174: ArrayList sortedList = sortPoolByLevel(new Long("0"),
0175: objects, getSortProperty(), getSortAscending());
0176: //printTree(sortedList);
0177:
0178: ListDataModel model = new ListDataModel((List) sortedList);
0179: QuestionPoolDataModel qpDataModel = new QuestionPoolDataModel(
0180: tree, model);
0181: return qpDataModel;
0182: } else
0183: return null;
0184: }
0185:
0186: public QuestionPoolDataModel getCopyQpools() {
0187: if (tree == null) {
0188: buildTree();
0189: }
0190: tree.sortByProperty(this .getSortCopyPoolProperty(), this
0191: .getSortCopyPoolAscending());
0192:
0193: Collection objects = tree.getSortedObjects();
0194: ListDataModel model = new ListDataModel((List) objects);
0195: QuestionPoolDataModel qpDataModel = new QuestionPoolDataModel(
0196: tree, model);
0197: return qpDataModel;
0198: }
0199:
0200: public QuestionPoolDataModel getMoveQpools() {
0201: if (tree == null) {
0202: buildTree();
0203: }
0204: tree.sortByProperty(this .getSortMovePoolProperty(), this
0205: .getSortMovePoolAscending());
0206:
0207: Collection objects = tree.getSortedObjects();
0208: ListDataModel model = new ListDataModel((List) objects);
0209: QuestionPoolDataModel qpDataModel = new QuestionPoolDataModel(
0210: tree, model);
0211: return qpDataModel;
0212: }
0213:
0214: public QuestionPoolDataModel getSortedSubqpools() {
0215: if (tree == null)
0216: buildTree();
0217:
0218: ArrayList subpools = (ArrayList) tree
0219: .getSortedObjects(getCurrentPool().getId());
0220: if (subpools != null) {
0221: ArrayList sortedList = sortPoolByLevel(getCurrentPool()
0222: .getId(), subpools, getSortSubPoolProperty(),
0223: getSortSubPoolAscending());
0224: //printTree(sortedList);
0225:
0226: ListDataModel model = new ListDataModel((List) sortedList);
0227: QuestionPoolDataModel qpDataModel = new QuestionPoolDataModel(
0228: tree, model);
0229: return qpDataModel;
0230: } else
0231: return null;
0232: }
0233:
0234: public void sortSubqpoolsByProperty(ArrayList sortedList,
0235: String sortProperty, boolean sortAscending) {
0236: BeanSort sort = new BeanSort(sortedList, sortProperty);
0237:
0238: if (sortProperty.equals("lastModified")) {
0239: sort.toDateSort();
0240: } else {
0241: sort.toStringSort();
0242: }
0243:
0244: sort.sort();
0245:
0246: if (!sortAscending) {
0247: Collections.reverse(sortedList);
0248: }
0249:
0250: }
0251:
0252: public void sortQpoolsByProperty(ArrayList sortedList,
0253: String sortProperty, boolean sortAscending) {
0254: BeanSort sort = new BeanSort(sortedList, sortProperty);
0255:
0256: if (sortProperty.equals("lastModified")) {
0257: sort.toDateSort();
0258: } else {
0259: sort.toStringSort();
0260: }
0261:
0262: sortedList = (ArrayList) sort.sort();
0263:
0264: if (!sortAscending) {
0265: Collections.reverse(sortedList);
0266: }
0267: }
0268:
0269: public void setAllItems(ArrayList list) {
0270: allItems = list;
0271:
0272: }
0273:
0274: public ArrayList getAllItems() {
0275: return allItems;
0276: }
0277:
0278: public void setSortedSubqpools(Collection spools) {
0279: sortedSubqpools = spools;
0280:
0281: }
0282:
0283: // This builds the tree.
0284: public void buildTree() {
0285: try {
0286: QuestionPoolService delegate = new QuestionPoolService();
0287: // getAllPools() returns pool in ascending order of poolId
0288: // then a tree which represent the pool structure is built - daisyf
0289: //System.out.println("****** QPBean: build tree");
0290: tree = new QuestionPoolTreeImpl(
0291: (QuestionPoolIteratorFacade) delegate
0292: .getAllPools(AgentFacade.getAgentString()));
0293:
0294: tree.getSortedObjects();
0295: //Collection objects = tree.getSortedObjects();
0296: //printTree(objects);
0297: } catch (Exception e) {
0298: throw new RuntimeException(e);
0299: }
0300: }
0301:
0302: private void printChildrenPool(Tree tree, QuestionPoolDataIfc pool,
0303: String stars) {
0304: List children = tree.getChildList(pool.getQuestionPoolId());
0305: Map childrenMap = tree.getChildren(pool.getQuestionPoolId());
0306: stars += "**";
0307: for (int i = 0; i < children.size(); i++) {
0308: QuestionPoolDataIfc child = (QuestionPoolDataIfc) childrenMap
0309: .get(children.get(i).toString());
0310: //System.out.println(stars+child.getTitle()+":"+child.getLastModified());
0311: printChildrenPool(tree, child, stars);
0312: }
0313: }
0314:
0315: /**
0316: * DOCUMENTATION PENDING
0317: *
0318: * @return DOCUMENTATION PENDING
0319: */
0320: public List getPoolListSelectItems() {
0321: if (poolListSelectItems == null) {
0322: poolListSelectItems = new ArrayList();
0323:
0324: Collection objects = tree.getSortedObjects();
0325: Iterator iter = objects.iterator();
0326: while (iter.hasNext()) {
0327: try {
0328: QuestionPoolFacade pool = (QuestionPoolFacade) iter
0329: .next();
0330: poolListSelectItems.add(new SelectItem((pool
0331: .getQuestionPoolId().toString()), pool
0332: .getDisplayName()));
0333: } catch (Exception e) {
0334: throw new RuntimeException(e);
0335: }
0336: }
0337:
0338: }
0339: return poolListSelectItems;
0340:
0341: }
0342:
0343: /**
0344: * DOCUMENTATION PENDING
0345: *
0346: * @return DOCUMENTATION PENDING
0347: */
0348: public void setItemsToDelete(List qpools) {
0349: itemsToDelete = qpools;
0350: }
0351:
0352: public List getItemsToDelete() {
0353: return itemsToDelete;
0354: }
0355:
0356: /**
0357: * DOCUMENTATION PENDING
0358: *
0359: * @return DOCUMENTATION PENDING
0360: */
0361: public void setPoolsToDelete(List qpools) {
0362: poolsToDelete = qpools;
0363: }
0364:
0365: /**
0366: * DOCUMENTATION PENDING
0367: *
0368: * @return DOCUMENTATION PENDING
0369: */
0370: public List getPoolsToDelete() {
0371:
0372: List poolsToDeleteList = new ArrayList();
0373: if (poolsToDelete != null) {
0374: Iterator iter = poolsToDelete.iterator();
0375: while (iter.hasNext()) {
0376: try {
0377: QuestionPoolFacade pool = (QuestionPoolFacade) iter
0378: .next();
0379: poolsToDeleteList.add(pool);
0380: } catch (Exception e) {
0381: throw new RuntimeException(e);
0382: }
0383:
0384: }
0385: }
0386:
0387: return poolsToDeleteList;
0388: }
0389:
0390: /**
0391: * DOCUMENTATION PENDING
0392: *
0393: * @return DOCUMENTATION PENDING
0394: */
0395: public Tree getTree() {
0396: return tree;
0397: }
0398:
0399: /**
0400: * DOCUMENTATION PENDING
0401: *
0402: * @param newPools DOCUMENTATION PENDING
0403: */
0404: public void setTree(Tree newtree) {
0405: tree = newtree;
0406: }
0407:
0408: /**
0409: * DOCUMENTATION PENDING
0410: *
0411: * @return DOCUMENTATION PENDING
0412: */
0413: public Collection getPools() {
0414: return pools;
0415: }
0416:
0417: /**
0418: * DOCUMENTATION PENDING
0419: *
0420: * @return DOCUMENTATION PENDING
0421: */
0422: public Object[] getPoolArray() {
0423: return pools.toArray();
0424: }
0425:
0426: /**
0427: * DOCUMENTATION PENDING
0428: *
0429: * @param newPools DOCUMENTATION PENDING
0430: */
0431: public void setPools(Collection newPools) {
0432: pools = newPools;
0433: }
0434:
0435: /**
0436: * DOCUMENTATION PENDING
0437: *
0438: * @param newtype DOCUMENTATION PENDING
0439: */
0440: public void setQuestionType(String newtype) {
0441: questionType = newtype;
0442: }
0443:
0444: /**
0445: * DOCUMENTATION PENDING
0446: *
0447: * @return DOCUMENTATION PENDING
0448: */
0449: public String getQuestionType() {
0450: return questionType;
0451: }
0452:
0453: /**
0454: * DOCUMENTATION PENDING
0455: *
0456: * @param newtype DOCUMENTATION PENDING
0457: */
0458: public void setSearchQtext(String pstr) {
0459: searchQtext = pstr;
0460: }
0461:
0462: /**
0463: * DOCUMENTATION PENDING
0464: *
0465: * @return DOCUMENTATION PENDING
0466: */
0467: public String getSearchQtext() {
0468: return searchQtext;
0469: }
0470:
0471: /**
0472: * DOCUMENTATION PENDING
0473: *
0474: * @param newtype DOCUMENTATION PENDING
0475: */
0476: public void setSearchQkeywords(String pstr) {
0477: searchQkeywords = pstr;
0478: }
0479:
0480: /**
0481: * DOCUMENTATION PENDING
0482: *
0483: * @return DOCUMENTATION PENDING
0484: */
0485: public String getSearchQkeywords() {
0486: return searchQkeywords;
0487: }
0488:
0489: /**
0490: * DOCUMENTATION PENDING
0491: *
0492: * @param newtype DOCUMENTATION PENDING
0493: */
0494: public void setSearchQobj(String pstr) {
0495: searchQobj = pstr;
0496: }
0497:
0498: /**
0499: * DOCUMENTATION PENDING
0500: *
0501: * @return DOCUMENTATION PENDING
0502: */
0503: public String getSearchQobj() {
0504: return searchQobj;
0505: }
0506:
0507: /**
0508: * DOCUMENTATION PENDING
0509: *
0510: * @param newtype DOCUMENTATION PENDING
0511: */
0512: public void setSearchQrubrics(String pstr) {
0513: searchQrubrics = pstr;
0514: }
0515:
0516: /**
0517: * DOCUMENTATION PENDING
0518: *
0519: * @return DOCUMENTATION PENDING
0520: */
0521: public String getSearchQrubrics() {
0522: return searchQrubrics;
0523: }
0524:
0525: public String getCurrentItemId() {
0526: return currentItemId;
0527: }
0528:
0529: public void setCurrentItemId(String pstr) {
0530: currentItemId = pstr;
0531: }
0532:
0533: public ItemFacade getCurrentItem() {
0534: return currentItem;
0535: }
0536:
0537: public void setCurrentItem(ItemFacade param) {
0538: currentItem = param;
0539: }
0540:
0541: public ItemFacade getItemToPreview() {
0542:
0543: /*
0544: String result = previewQuestion();
0545: */
0546: return itemToPreview;
0547: }
0548:
0549: public void setItemToPreview(ItemFacade param) {
0550: itemToPreview = param;
0551: }
0552:
0553: /**
0554: * DOCUMENTATION PENDING
0555: *
0556: * @return DOCUMENTATION PENDING
0557: */
0558: public QuestionPoolDataBean getCurrentPool() {
0559: return currentPool;
0560: }
0561:
0562: /**
0563: * DOCUMENTATION PENDING
0564: *
0565: * @param newPool DOCUMENTATION PENDING
0566: */
0567: public void setCurrentPool(QuestionPoolDataBean newPool) {
0568: currentPool = newPool;
0569: }
0570:
0571: /**
0572: * DOCUMENTATION PENDING
0573: *
0574: * @return DOCUMENTATION PENDING
0575: */
0576: public QuestionPoolDataBean getParentPool() {
0577: return parentPool;
0578: }
0579:
0580: /**
0581: * DOCUMENTATION PENDING
0582: *
0583: * @param newPool DOCUMENTATION PENDING
0584: */
0585: public void setParentPool(QuestionPoolDataBean newPool) {
0586: parentPool = newPool;
0587: }
0588:
0589: /**
0590: * DOCUMENTATION PENDING
0591: *
0592: * @param newPool DOCUMENTATION PENDING
0593: */
0594: public void setParentPoolSize(int n) {
0595: parentPoolSize = n;
0596: }
0597:
0598: public int getParentPoolSize() {
0599: return parentPoolSize;
0600: }
0601:
0602: /**
0603: * DOCUMENTATION PENDING
0604: *
0605: * @return DOCUMENTATION PENDING
0606: */
0607: public String getName() {
0608: return name;
0609: }
0610:
0611: /**
0612: * DOCUMENTATION PENDING
0613: *
0614: * @param newName DOCUMENTATION PENDING
0615: */
0616: public void setName(String newName) {
0617: name = newName;
0618: }
0619:
0620: /**
0621: * DOCUMENTATION PENDING
0622: *
0623: * @param newName DOCUMENTATION PENDING
0624: */
0625: public void setRootPoolSelected(boolean pallpools) {
0626: rootPoolSelected = pallpools;
0627: }
0628:
0629: /**
0630: * DOCUMENTATION PENDING
0631: *
0632: * @return DOCUMENTATION PENDING
0633: */
0634: public boolean getRootPoolSelected() {
0635: return rootPoolSelected;
0636: }
0637:
0638: /**
0639: * DOCUMENTATION PENDING
0640: *
0641: * @param newName DOCUMENTATION PENDING
0642: */
0643: public void setAllPoolsSelected(boolean pallpools) {
0644: allPoolsSelected = pallpools;
0645: }
0646:
0647: public void setAllItemsSelected(boolean pallpools) {
0648: allItemsSelected = pallpools;
0649: }
0650:
0651: public boolean getAllItemsSelected() {
0652: return allItemsSelected;
0653: }
0654:
0655: /**
0656: * DOCUMENTATION PENDING
0657: *
0658: * @return DOCUMENTATION PENDING
0659: */
0660: public boolean getAllPoolsSelected() {
0661: return allPoolsSelected;
0662: }
0663:
0664: /**
0665: * DOCUMENTATION PENDING
0666: *
0667: * @param pPool DOCUMENTATION PENDING
0668: */
0669: public void setDestPool(String pPool) {
0670: destPool = pPool;
0671: }
0672:
0673: /**
0674: * DOCUMENTATION PENDING
0675: *
0676: * @return DOCUMENTATION PENDING
0677: */
0678: public String getDestPool() {
0679: return destPool;
0680: }
0681:
0682: /**
0683: * DOCUMENTATION PENDING
0684: *
0685: * @param pPool DOCUMENTATION PENDING
0686: */
0687: public void setDestPools(String[] pPool) {
0688: destPools = pPool;
0689: }
0690:
0691: /**
0692: * DOCUMENTATION PENDING
0693: *
0694: * @return DOCUMENTATION PENDING
0695: */
0696: public String[] getDestPools() {
0697: return destPools;
0698: }
0699:
0700: /**
0701: * DOCUMENTATION PENDING
0702: *
0703: * @param pPool DOCUMENTATION PENDING
0704: */
0705: public void setDestItems(String[] pPool) {
0706: destItems = pPool;
0707: }
0708:
0709: /**
0710: * DOCUMENTATION PENDING
0711: *
0712: * @return DOCUMENTATION PENDING
0713: */
0714: public String[] getDestItems() {
0715: return destItems;
0716: }
0717:
0718: /**
0719: * DOCUMENTATION PENDING
0720: *
0721: * @param pPool DOCUMENTATION PENDING
0722: */
0723: public void setSearchByTypes(String[] pstr) {
0724: searchByTypes = pstr;
0725: }
0726:
0727: /**
0728: * DOCUMENTATION PENDING
0729: *
0730: * @return DOCUMENTATION PENDING
0731: */
0732: public String[] getSearchByTypes() {
0733: return searchByTypes;
0734: }
0735:
0736: public String getAssessmentID() {
0737: return assessmentID;
0738: }
0739:
0740: public void setAssessmentID(String pstr) {
0741: assessmentID = pstr;
0742: }
0743:
0744: public String getSelectedAssessment() {
0745: return selectedAssessment;
0746: }
0747:
0748: public void setSelectedAssessment(String pstr) {
0749: selectedAssessment = pstr;
0750: }
0751:
0752: public String getSelectedSection() {
0753: return selectedSection;
0754: }
0755:
0756: public void setSelectedSection(String pstr) {
0757: selectedSection = pstr;
0758: }
0759:
0760: public boolean getImportToAuthoring() {
0761: return importToAuthoring;
0762: }
0763:
0764: public void setImportToAuthoring(boolean pstr) {
0765: importToAuthoring = pstr;
0766: }
0767:
0768: public boolean getSortAscending() {
0769: return sortAscending;
0770: }
0771:
0772: public void setSortAscending(boolean pstr) {
0773: sortAscending = pstr;
0774: }
0775:
0776: public boolean getSortCopyPoolAscending() {
0777: return sortCopyPoolAscending;
0778: }
0779:
0780: public void setSortCopyPoolAscending(boolean pstr) {
0781: sortCopyPoolAscending = pstr;
0782: }
0783:
0784: public boolean getSortMovePoolAscending() {
0785: return sortMovePoolAscending;
0786: }
0787:
0788: public void setSortMovePoolAscending(boolean pstr) {
0789: sortMovePoolAscending = pstr;
0790: }
0791:
0792: public boolean getSortSubPoolAscending() {
0793: return sortSubPoolAscending;
0794: }
0795:
0796: public void setSortSubPoolAscending(boolean pstr) {
0797: sortSubPoolAscending = pstr;
0798: }
0799:
0800: public boolean getSortQuestionAscending() {
0801: return sortQuestionAscending;
0802: }
0803:
0804: public void setSortQuestionAscending(boolean pstr) {
0805: sortQuestionAscending = pstr;
0806: }
0807:
0808: public String getActionType() {
0809: return actionType;
0810: }
0811:
0812: public void setActionType(String pstr) {
0813: actionType = pstr;
0814: }
0815:
0816: public String getSortProperty() {
0817: return sortProperty;
0818: }
0819:
0820: public void setSortProperty(String newProperty) {
0821: sortProperty = newProperty;
0822: }
0823:
0824: public String getSortCopyPoolProperty() {
0825: return sortCopyPoolProperty;
0826: }
0827:
0828: public void setSortCopyPoolProperty(String newProperty) {
0829: sortCopyPoolProperty = newProperty;
0830: }
0831:
0832: public String getSortMovePoolProperty() {
0833: return sortMovePoolProperty;
0834: }
0835:
0836: public void setSortMovePoolProperty(String newProperty) {
0837: sortMovePoolProperty = newProperty;
0838: }
0839:
0840: public String getSortSubPoolProperty() {
0841: return sortSubPoolProperty;
0842: }
0843:
0844: public void setSortSubPoolProperty(String newProperty) {
0845: sortSubPoolProperty = newProperty;
0846: }
0847:
0848: public String getSortQuestionProperty() {
0849: return sortQuestionProperty;
0850: }
0851:
0852: public void setSortQuestionProperty(String newProperty) {
0853: sortQuestionProperty = newProperty;
0854: }
0855:
0856: public String getAddOrEdit() {
0857: return addOrEdit;
0858: }
0859:
0860: /**
0861: * @param param
0862: */
0863: public void setAddOrEdit(String param) {
0864: this .addOrEdit = param;
0865: }
0866:
0867: public String getOutcome() {
0868: return outcome;
0869: }
0870:
0871: /**
0872: * set the outcome for doit()
0873: * @param param
0874: */
0875: public void setOutcome(String param) {
0876: this .outcome = param;
0877: }
0878:
0879: public String getOutcomeEdit() {
0880: return outcomeEdit;
0881: }
0882:
0883: /**
0884: * set the outcome for doit()
0885: * @param param
0886: */
0887: public void setOutcomeEdit(String param) {
0888: this .outcomeEdit = param;
0889: }
0890:
0891: public String getDeletePoolSource() {
0892: return deletePoolSource;
0893: }
0894:
0895: /**
0896: * set the outcome for doit()
0897: * @param param
0898: */
0899: public void setDeletePoolSource(String param) {
0900: this .deletePoolSource = param;
0901: }
0902:
0903: public String getAddPoolSource() {
0904: return addPoolSource;
0905: }
0906:
0907: public void setAddPoolSource(String param) {
0908: this .addPoolSource = param;
0909: }
0910:
0911: /**
0912: * DOCUMENTATION PENDING
0913: *
0914: * @param pPool DOCUMENTATION PENDING
0915: */
0916: public void setSelectedQuestions(String[] pPool) {
0917: selectedQuestions = pPool;
0918: }
0919:
0920: /**
0921: * DOCUMENTATION PENDING
0922: *
0923: * @param pPool DOCUMENTATION PENDING
0924: */
0925: public void setSelectedPools(String[] pPool) {
0926: selectedPools = pPool;
0927: }
0928:
0929: /**
0930: * DOCUMENTATION PENDING
0931: *
0932: * @return DOCUMENTATION PENDING
0933: */
0934: public String[] getSelectedQuestions() {
0935: return selectedQuestions;
0936: }
0937:
0938: /**
0939: * DOCUMENTATION PENDING
0940: *
0941: * @return DOCUMENTATION PENDING
0942: */
0943: public String[] getSelectedPools() {
0944: return selectedPools;
0945: }
0946:
0947: /**
0948: * DOCUMENTATION PENDING
0949: *
0950: * @param file DOCUMENTATION PENDING
0951: */
0952: public void setFilename(FormFile file) {
0953: filename = file;
0954: }
0955:
0956: /**
0957: * DOCUMENTATION PENDING
0958: *
0959: * @param file DOCUMENTATION PENDING
0960: */
0961: public FormFile getFilename() {
0962: return filename;
0963: }
0964:
0965: /**
0966: * DOCUMENTATION PENDING
0967: *
0968: * @param int DOCUMENTATION PENDING
0969: */
0970: public int getHtmlIdLevel() {
0971: return htmlIdLevel;
0972: }
0973:
0974: /**
0975: * DOCUMENTATION PENDING
0976: *
0977: * @param int DOCUMENTATION PENDING
0978: */
0979: public void setHtmlIdLevel(int plevel) {
0980: htmlIdLevel = plevel;
0981: }
0982:
0983: /**
0984: * DOCUMENTATION PENDING
0985: */
0986: public void resetFields() {
0987: pools = new ArrayList();
0988: }
0989:
0990: // Item level actions
0991: public String startCopyQuestion() {
0992: getCheckedQuestion();
0993: return "copyPool";
0994: }
0995:
0996: public String startMoveQuestion() {
0997: getCheckedQuestion();
0998: return "movePool";
0999: }
1000:
1001: public String moveQuestion() {
1002: String sourceId = "";
1003: String destId = "";
1004: sourceId = this .getCurrentPool().getId().toString();
1005: String sourceItemId = this .getCurrentItemId();
1006:
1007: destId = ContextUtil.lookupParam("movePool:selectedRadioBtn");
1008:
1009: if ((sourceId != null) && (destId != null)
1010: && (sourceItemId != null)) {
1011: try {
1012: if (hasItemInDestPool(sourceItemId, destId)) {
1013: return "movePool";
1014: } else {
1015: QuestionPoolService delegate = new QuestionPoolService();
1016: delegate.moveItemToPool(sourceItemId, new Long(
1017: sourceId), new Long(destId));
1018: }
1019: } catch (Exception e) {
1020: e.printStackTrace();
1021: throw new RuntimeException(e);
1022: }
1023: }
1024:
1025: buildTree();
1026:
1027: return "poolList";
1028:
1029: }
1030:
1031: public boolean hasItemInDestPool(String sourceItemId, String destId) {
1032:
1033: QuestionPoolService delegate = new QuestionPoolService();
1034: // check if the item already exists in the destPool
1035: if (delegate.hasItem(sourceItemId, new Long(destId))) {
1036: // we do not want to add duplicated items, show message
1037:
1038: FacesContext context = FacesContext.getCurrentInstance();
1039: String err;
1040: err = rb.getString("copy_duplicate_error");
1041: context.addMessage(null, new FacesMessage(err));
1042: return true;
1043: } else {
1044: return false;
1045: }
1046: }
1047:
1048: public String copyQuestion() {
1049:
1050: //Long sourceId = new Long(0);
1051: String destId = "";
1052: String sourceItemId = this .getCurrentItemId();
1053:
1054: ArrayList destpools = ContextUtil
1055: .paramArrayValueLike("checkboxes");
1056: //sourceId = this.getCurrentPool().getId();
1057:
1058: Iterator iter = destpools.iterator();
1059: while (iter.hasNext()) {
1060:
1061: destId = (String) iter.next();
1062: if ((sourceItemId != null) && (destId != null)) {
1063:
1064: try {
1065: if (hasItemInDestPool(sourceItemId, destId)) {
1066: return "copyPool";
1067: } else {
1068: QuestionPoolService questionPoolService = new QuestionPoolService();
1069: String copyItemFacadeId = questionPoolService
1070: .copyItemFacade(
1071: this .getCurrentItem().getData())
1072: .toString();
1073:
1074: QuestionPoolService delegate = new QuestionPoolService();
1075: delegate.addItemToPool(copyItemFacadeId,
1076: new Long(destId));
1077: }
1078: } catch (Exception e) {
1079: e.printStackTrace();
1080: throw new RuntimeException(e);
1081: }
1082: }
1083: }
1084:
1085: buildTree();
1086: return "poolList";
1087:
1088: }
1089:
1090: public String removeQuestionsFromPool() {
1091: String sourceId = this .getCurrentPool().getId().toString();
1092:
1093: List itemlist = this .getItemsToDelete();
1094:
1095: Iterator iter = itemlist.iterator();
1096: while (iter.hasNext()) {
1097:
1098: ItemFacade itemfacade = (ItemFacade) iter.next();
1099: String itemid = itemfacade.getItemIdString();
1100: QuestionPoolService delegate = new QuestionPoolService();
1101: delegate.removeQuestionFromPool(itemid, new Long(sourceId));
1102:
1103: // check to see if any pools are linked to this item
1104: List poollist = delegate.getPoolIdsByItem(itemfacade
1105: .getItemIdString());
1106: if (poollist.isEmpty()) {
1107:
1108: if (itemfacade.getSection() == null) {
1109: // if no assessment refers to this pool then delete this item from db
1110: ItemService itemdelegate = new ItemService();
1111: itemdelegate.deleteItem(itemfacade.getItemId(),
1112: AgentFacade.getAgentString());
1113: } else {
1114: // if has assessment refers , remove metadata for selectedPool .
1115: ItemService itemdelegate = new ItemService();
1116: itemdelegate.deleteItemMetaData(itemfacade
1117: .getItemId(), ItemMetaData.POOLID,
1118: AgentFacade.getAgentString());
1119:
1120: /*
1121: Set itemmetadataSet= itemfacade.getItemMetaDataSet();
1122: ItemMetaData metaTodelete= null;
1123: Iterator metaiter = itemmetadataSet.iterator();
1124: while (metaiter.hasNext()){
1125: ItemMetaData meta= (ItemMetaData) metaiter.next();
1126: if (meta.getLabel().equals(ItemMetaData.POOLID)){
1127: metaTodelete= meta;
1128: }
1129: }
1130: if (metaTodelete!=null) {
1131: itemmetadataSet.remove(metaTodelete);
1132: }
1133: itemfacade.setItemMetaDataSet(itemmetadataSet);
1134: itemdelegate.saveItem(itemfacade);
1135: */
1136:
1137: }
1138: }
1139: }
1140:
1141: this .startEditPoolAgain(sourceId); // return to edit pool
1142: return "editPool";
1143: }
1144:
1145: public void getCheckedQuestion() {
1146: String itemId = ContextUtil.lookupParam("itemid");
1147: ItemService delegate = new ItemService();
1148: ItemFacade itemfacade = delegate.getItem(new Long(itemId),
1149: AgentFacade.getAgentString());
1150: setCurrentItemId(itemId);
1151: setCurrentItem(itemfacade);
1152: setActionType("item");
1153: }
1154:
1155: // Pool level actions
1156: public String startCopyPool() {
1157: getCheckedPool();
1158: setActionType("pool");
1159: return "copyPool";
1160: }
1161:
1162: public String startMovePool() {
1163: getCheckedPool();
1164: setActionType("pool");
1165: return "movePool";
1166: }
1167:
1168: public void getCheckedPool() {
1169: try {
1170: QuestionPoolDataBean pool = new QuestionPoolDataBean();
1171:
1172: String qpid = (String) FacesContext.getCurrentInstance()
1173: .getExternalContext().getRequestParameterMap().get(
1174: "qpid");
1175: if ((qpid != null) && (!qpid.equals("null"))) {
1176: pool.setId(new Long(qpid));
1177: } else {
1178: // This should not ococur. It should always have an id.
1179: return;
1180: }
1181:
1182: // Get all data from the database
1183: QuestionPoolService delegate = new QuestionPoolService();
1184: QuestionPoolFacade thepool = delegate.getPool(
1185: new Long(qpid), AgentFacade.getAgentString());
1186: tree.setCurrentId(thepool.getQuestionPoolId());
1187:
1188: pool.setDisplayName(thepool.getDisplayName());
1189: pool.setParentPoolId(thepool.getParentPoolId());
1190: pool.setDescription(thepool.getDescription());
1191: pool.setOwner(thepool.getOwnerDisplayName());
1192: //pool.setOwner(thepool.getOwnerId());
1193: pool.setObjectives(thepool.getObjectives());
1194: pool.setKeywords(thepool.getKeywords());
1195: pool.setOrganizationName(thepool.getOrganizationName());
1196: // pool.setProperties((QuestionPoolData) thepool.getData());
1197: // TODO which one should I use?
1198: // pool.setNumberOfSubpools(
1199: // new Integer(tree.getChildList(thepool.getQuestionPoolId()).size()).toString());
1200: pool.setNumberOfSubpools(thepool.getSubPoolSize()
1201: .toString());
1202: pool.setNumberOfQuestions(thepool.getQuestionSize()
1203: .toString());
1204: //pool.setDateCreated(thepool.getDateCreated());
1205:
1206: pool.setLastModified(new Date());
1207:
1208: this .setCurrentPool(pool);
1209: } catch (RuntimeException e) {
1210: e.printStackTrace();
1211: throw e;
1212: }
1213:
1214: }
1215:
1216: public String copyPool() {
1217:
1218: Long sourceId = new Long(0);
1219: String destId = "";
1220: boolean isUnique = true;
1221:
1222: ArrayList destpools = ContextUtil
1223: .paramArrayValueLike("checkboxes");
1224: sourceId = this .getCurrentPool().getId();
1225: String currentName = this .getCurrentPool().getDisplayName();
1226: Iterator iter = destpools.iterator();
1227:
1228: while (iter.hasNext()) {
1229:
1230: destId = (String) iter.next();
1231: QuestionPoolService delegate = new QuestionPoolService();
1232:
1233: if ((sourceId.longValue() != 0) && (destId != null)) {
1234: try {
1235: QuestionPoolFacade oldPool = delegate.getPool(
1236: sourceId, AgentFacade.getAgentString());
1237: //if dest != source's parent, then throw error if dest has a duplicate pool name
1238: if (!destId.equals((oldPool.getParentPoolId())
1239: .toString())) {
1240: isUnique = delegate.poolIsUnique("0",
1241: currentName, destId, AgentFacade
1242: .getAgentString());
1243: if (!isUnique) {
1244: String err1 = rb
1245: .getString("copy_duplicateName_error");
1246: FacesContext context = FacesContext
1247: .getCurrentInstance();
1248: context.addMessage(null, new FacesMessage(
1249: err1));
1250:
1251: return "copyPool";
1252: }
1253: }
1254:
1255: // if dest = source's parent,i.e copying to it's own parent , then if there is an existing pool with the same name, copyPool() will create a new pool with Copy prepended in the pool name
1256: ResourceLoader rb = new ResourceLoader(
1257: "org.sakaiproject.tool.assessment.bundle.QuestionPoolMessages");
1258: String copy = rb.getString("prepend_copy");
1259: String of = rb.getString("prepend_of");
1260: delegate.copyPool(tree, AgentFacade
1261: .getAgentString(), sourceId, new Long(
1262: destId), copy, of);
1263: } catch (Exception e) {
1264: e.printStackTrace();
1265: throw new RuntimeException(e);
1266:
1267: }
1268: }
1269: }
1270:
1271: buildTree();
1272: return "poolList";
1273:
1274: }
1275:
1276: public String movePool() {
1277: String sourceId = "";
1278: String destId = "";
1279: sourceId = this .getCurrentPool().getId().toString();
1280: String currentName = this .getCurrentPool().getDisplayName();
1281: boolean isUnique = true;
1282: destId = ContextUtil.lookupParam("movePool:selectedRadioBtn");
1283:
1284: // added check for "".equals(destId) SAK-4435 , when no dest is selected
1285: if ((sourceId != null) && (destId != null)
1286: && (!"".equals(destId))) {
1287: try {
1288: QuestionPoolService delegate = new QuestionPoolService();
1289: isUnique = delegate.poolIsUnique("0", currentName,
1290: destId, AgentFacade.getAgentString());
1291: if (!isUnique) {
1292: String err1 = rb
1293: .getString("move_duplicateName_error");
1294: FacesContext context = FacesContext
1295: .getCurrentInstance();
1296: context.addMessage(null, new FacesMessage(err1));
1297:
1298: return "movePool";
1299: }
1300: delegate.movePool(AgentFacade.getAgentString(),
1301: new Long(sourceId), new Long(destId));
1302:
1303: } catch (Exception e) {
1304: e.printStackTrace();
1305: throw new RuntimeException(e);
1306: }
1307: }
1308:
1309: buildTree();
1310:
1311: return "poolList";
1312: }
1313:
1314: public String addPool() {
1315: String addsource = "poollist";
1316: addsource = (String) FacesContext.getCurrentInstance()
1317: .getExternalContext().getRequestParameterMap().get(
1318: "addsource");
1319: this .setAddPoolSource(addsource);
1320: startCreatePool();
1321: this .setAddOrEdit("add");
1322:
1323: QuestionPoolDataBean pool = new QuestionPoolDataBean();
1324: setPoolInfo(pool);
1325: this .setParentPool(pool);
1326: return "addPool";
1327: }
1328:
1329: public void startCreatePool() {
1330: try {
1331: QuestionPoolDataBean pool = new QuestionPoolDataBean();
1332: int htmlIdLevel = 0;
1333:
1334: // create a new pool with 2 properties: owner and parentpool
1335: pool.setOwner(AgentFacade.getDisplayName(AgentFacade
1336: .getAgentString()));
1337:
1338: String qpid = (String) FacesContext.getCurrentInstance()
1339: .getExternalContext().getRequestParameterMap().get(
1340: "qpid");
1341: if ((qpid != null) && (!qpid.equals("0")))
1342: // qpid = 0 if creating a new pool at root level
1343: {
1344: pool.setParentPoolId(new Long(qpid));
1345:
1346: }
1347:
1348: // need to set indivdiual pool properties
1349: pool.setLastModified(new Date());
1350: this .setCurrentPool(pool);
1351: this .setHtmlIdLevel(htmlIdLevel);
1352: } catch (Exception e) {
1353: e.printStackTrace();
1354: throw new RuntimeException(e);
1355: }
1356: }
1357:
1358: public String confirmRemovePool() {
1359: // used by the editpool.jsp to remove one subpool at a time
1360: this .setDeletePoolSource("editpool");
1361:
1362: //ItemAuthorBean itemauthorbean= (ItemAuthorBean) ContextUtil.lookupBean("itemauthor");
1363: String poolId = ContextUtil.lookupParam("qpid");
1364:
1365: // we are adding one pool to an arrayList so we can reuse the deletePool() method, because deletePool() method expects an arrayList of pools to be deleted. It is used by the poolList.jsp to delete multiple pools.
1366:
1367: List qpools = new ArrayList();
1368: QuestionPoolService delegate = new QuestionPoolService();
1369: QuestionPoolFacade qPool = delegate.getPool(new Long(poolId),
1370: AgentFacade.getAgentString());
1371: qpools.add(qPool);
1372:
1373: this .setPoolsToDelete(qpools);
1374: return "removePool";
1375: }
1376:
1377: public String startRemovePool() {
1378: // need to check if the pool is used by any random draw assessments
1379:
1380: // used by the poolList.jsp
1381: this .setDeletePoolSource("poollist");
1382: String poolId = "";
1383:
1384: ArrayList destpools = ContextUtil
1385: .paramArrayValueLike("removeCheckbox");
1386:
1387: List qpools = new ArrayList();
1388: Iterator iter = destpools.iterator();
1389: while (iter.hasNext()) {
1390:
1391: poolId = (String) iter.next();
1392:
1393: QuestionPoolService delegate = new QuestionPoolService();
1394: QuestionPoolFacade qPool = delegate.getPool(
1395: new Long(poolId), AgentFacade.getAgentString());
1396: qpools.add(qPool);
1397:
1398: }
1399:
1400: this .setPoolsToDelete(qpools);
1401: return "removePool";
1402: }
1403:
1404: public String removePool() {
1405:
1406: QuestionPoolService delegate = new QuestionPoolService();
1407: List qpools = this .getPoolsToDelete();
1408: Iterator iter = qpools.iterator();
1409: while (iter.hasNext()) {
1410:
1411: QuestionPoolFacade pool = (QuestionPoolFacade) iter.next();
1412: Long poolId = pool.getQuestionPoolId();
1413:
1414: delegate.deletePool(poolId, AgentFacade.getAgentString(),
1415: tree);
1416: }
1417: buildTree();
1418:
1419: if (this .getDeletePoolSource().equals("editpool")) {
1420: // #1a - so reset subpools tree
1421: Collection objects = tree.getSortedObjects(this
1422: .getCurrentPool().getId());
1423: this .setSortedSubqpools(objects);
1424: QuestionPoolFacade thepool = delegate.getPool(this
1425: .getCurrentPool().getId(), AgentFacade
1426: .getAgentString());
1427: this .getCurrentPool().setNumberOfSubpools(
1428: thepool.getSubPoolSize().toString());
1429:
1430: return "editPool";
1431: } else {
1432: return "poolList";
1433: }
1434: }
1435:
1436: public String importPool() {
1437: return "importPool";
1438: }
1439:
1440: public String importQuestion() {
1441: return "importQuestion";
1442: }
1443:
1444: public String exportPool() {
1445: return "exportPool";
1446: }
1447:
1448: public String exportQuestion() {
1449: return "exportQuestion";
1450: }
1451:
1452: public String returnToAuthoring() {
1453: return "author";
1454: }
1455:
1456: public String editPool() {
1457: startEditPool();
1458: this .setAddOrEdit("edit");
1459:
1460: return "editPool";
1461: }
1462:
1463: public void startEditPool() {
1464: String qpid = (String) FacesContext.getCurrentInstance()
1465: .getExternalContext().getRequestParameterMap().get(
1466: "qpid");
1467: startEditPoolAgain(qpid);
1468: }
1469:
1470: public void startEditPoolAgain(String qpid) {
1471: try {
1472: QuestionPoolDataBean pool = new QuestionPoolDataBean();
1473: int htmlIdLevel = 0;
1474: ArrayList allparentPools = new ArrayList();
1475:
1476: /*
1477: String qpid = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("qpid");
1478: */
1479:
1480: if (qpid != null) {
1481: pool.setId(new Long(qpid));
1482: } else {
1483: // should always have an id.
1484: return;
1485: }
1486:
1487: // Get all data from the database
1488: QuestionPoolService delegate = new QuestionPoolService();
1489: QuestionPoolFacade thepool = delegate.getPool(
1490: new Long(qpid), AgentFacade.getAgentString());
1491: tree.setCurrentId(thepool.getQuestionPoolId());
1492:
1493: Long ppoolid = thepool.getParentPoolId();
1494:
1495: pool.setParentPools(allparentPools);
1496: pool.setParentPoolsArray(allparentPools);
1497: while (!ppoolid.toString().equals("0")) {
1498: QuestionPoolFacade ppool = delegate.getPool(ppoolid,
1499: AgentFacade.getAgentString());
1500: if (ppool != null) {
1501: allparentPools.add(0, ppool);
1502: ppoolid = ppool.getParentPoolId();
1503: }
1504:
1505: }
1506:
1507: if (allparentPools != null) {
1508: pool.setParentPools(allparentPools);
1509: pool.setParentPoolsArray(allparentPools);
1510: }
1511:
1512: this .setParentPoolSize(allparentPools.size());
1513: String htmlID = tree.getCurrentObjectHTMLId();
1514:
1515: // pass the htmlIdLevel to the collapseRowByLevel javascript
1516: String[] result = htmlID.split("-");
1517: htmlIdLevel = result.length + 1;
1518:
1519: pool.setDisplayName(thepool.getDisplayName());
1520: pool.setParentPoolId(thepool.getParentPoolId());
1521: pool.setDescription(thepool.getDescription());
1522: pool.setOwner(thepool.getOwnerDisplayName());
1523: pool.setObjectives(thepool.getObjectives());
1524: pool.setOrganizationName(thepool.getOrganizationName());
1525: pool.setKeywords(thepool.getKeywords());
1526:
1527: // pool.setProperties((QuestionPoolData) thepool.getData());
1528: // pool.setNumberOfSubpools(
1529: // new Integer(tree.getChildList(thepool.getQuestionPoolId()).size()).toString());
1530: pool.setNumberOfSubpools(thepool.getSubPoolSize()
1531: .toString());
1532: pool.setNumberOfQuestions(thepool.getQuestionSize()
1533: .toString());
1534: pool.setDateCreated(thepool.getDateCreated());
1535:
1536: Collection objects = tree.getSortedObjects(thepool
1537: .getQuestionPoolId());
1538: this .setSortedSubqpools(objects);
1539:
1540: pool.setLastModified(new Date());
1541: this .setCurrentPool(pool);
1542: this .setHtmlIdLevel(htmlIdLevel);
1543:
1544: ArrayList list = delegate.getAllItemsSorted(this
1545: .getCurrentPool().getId(), this
1546: .getSortQuestionProperty(), String.valueOf(this
1547: .getSortQuestionAscending()));
1548: this .setAllItems(list);
1549:
1550: } catch (Exception e) {
1551: e.printStackTrace();
1552: throw new RuntimeException(e);
1553: }
1554: }
1555:
1556: public String selectQuestionType() {
1557: ItemAuthorBean itemauthorbean = (ItemAuthorBean) ContextUtil
1558: .lookupBean("itemauthor");
1559: String poolid = ContextUtil.lookupParam("poolId");
1560: if (poolid != null) {
1561: itemauthorbean.setQpoolId(poolid);
1562: itemauthorbean.setTarget(ItemAuthorBean.FROM_QUESTIONPOOL);
1563:
1564: itemauthorbean.setItemType("");
1565: itemauthorbean.setItemTypeString("");
1566:
1567: //QuestionPoolDataBean pool = new QuestionPoolDataBean();
1568: QuestionPoolDataBean pool = this .getCurrentPool();
1569: this .setPoolInfo(pool);
1570: this .setCurrentPool(pool);
1571: return "selectQuestionType";
1572: } else {
1573: return "editPool"; // should not come to this
1574: }
1575: }
1576:
1577: public String sortByColumnHeader() {
1578: String sortString = ContextUtil.lookupParam("orderBy");
1579: String ascending = ContextUtil.lookupParam("ascending");
1580: this .setSortProperty(sortString);
1581: this .setSortAscending((Boolean.valueOf(ascending))
1582: .booleanValue());
1583: //System.out.println("****sortByColumnHeader ="+ sortString);
1584: return "poolList";
1585: }
1586:
1587: public String sortCopyPoolByColumnHeader() {
1588:
1589: String sortString = ContextUtil.lookupParam("copyPoolOrderBy");
1590: String ascending = ContextUtil.lookupParam("copyPoolAscending");
1591: this .setSortCopyPoolProperty(sortString);
1592: this .setSortCopyPoolAscending((Boolean.valueOf(ascending))
1593: .booleanValue());
1594:
1595: return "copyPool";
1596: }
1597:
1598: public String sortMovePoolByColumnHeader() {
1599:
1600: String sortString = ContextUtil.lookupParam("movePoolOrderBy");
1601: String ascending = ContextUtil.lookupParam("movePoolAscending");
1602: this .setSortMovePoolProperty(sortString);
1603: this .setSortMovePoolAscending((Boolean.valueOf(ascending))
1604: .booleanValue());
1605:
1606: return "movePool";
1607: }
1608:
1609: public String sortSubPoolByColumnHeader() {
1610:
1611: String sortString = ContextUtil.lookupParam("subPoolOrderBy");
1612: String ascending = ContextUtil.lookupParam("subPoolAscending");
1613: this .setSortSubPoolProperty(sortString);
1614: this .setSortSubPoolAscending((Boolean.valueOf(ascending))
1615: .booleanValue());
1616:
1617: return "editPool";
1618: }
1619:
1620: public String doit() {
1621: return outcome;
1622: }
1623:
1624: public void previewQuestion(ActionEvent event) {
1625:
1626: ItemService delegate = new ItemService();
1627: String itemId = ContextUtil.lookupParam("itemid");
1628:
1629: ItemFacade itemf = delegate.getItem(new Long(itemId),
1630: AgentFacade.getAgentString());
1631: setCurrentItem(itemf);
1632:
1633: }
1634:
1635: public String previewQuestion() {
1636:
1637: ItemService delegate = new ItemService();
1638: String itemId = ContextUtil.lookupParam("itemid");
1639:
1640: ItemFacade itemf = delegate.getItem(new Long(itemId),
1641: AgentFacade.getAgentString());
1642: setCurrentItem(itemf);
1643:
1644: return "previewItem";
1645: }
1646:
1647: public String cancelImport() {
1648:
1649: ItemAuthorBean itemauthorbean = (ItemAuthorBean) ContextUtil
1650: .lookupBean("itemauthor");
1651: this .setImportToAuthoring(false);
1652: itemauthorbean.setItemTypeString("");
1653: return "editAssessment";
1654:
1655: }
1656:
1657: public boolean getSelfOrDescendant() {
1658: // check if currentPool is ancester of tree.getCurrentObject
1659: boolean isDescendant = false;
1660: boolean isSelf = false;
1661:
1662: isDescendant = tree.isDescendantOf(tree.getCurrentId(), this
1663: .getCurrentPool().getId());
1664: if (tree.getCurrentId().equals(this .getCurrentPool().getId())) {
1665: isSelf = true;
1666: }
1667: if (isSelf || isDescendant) {
1668: return true;
1669: } else {
1670: return false;
1671: }
1672:
1673: }
1674:
1675: private HashMap buildHash(Collection objects) {
1676: HashMap map = new HashMap();
1677: Iterator iter = objects.iterator();
1678: while (iter.hasNext()) {
1679: QuestionPoolDataIfc pool = (QuestionPoolDataIfc) iter
1680: .next();
1681: Long parentPoolId = pool.getParentPoolId();
1682: ArrayList poolList = (ArrayList) map.get(parentPoolId);
1683: if (poolList == null) {
1684: poolList = new ArrayList();
1685: map.put(parentPoolId, poolList);
1686: }
1687: poolList.add(pool);
1688: }
1689: return map;
1690: }
1691:
1692: private ArrayList sortPoolByLevel(Long level, Collection objects,
1693: String sortProperty, boolean sortAscending) {
1694: HashMap map = buildHash(objects);
1695: Set keys = map.keySet();
1696: Iterator iter = keys.iterator();
1697: while (iter.hasNext()) {
1698: Long parentPoolId = (Long) iter.next();
1699: ArrayList poolList = (ArrayList) map.get(parentPoolId);
1700: sortQpoolsByProperty(poolList, sortProperty, sortAscending);
1701: }
1702: // poolList in each level has been sorted, now we would put them in the right order
1703: ArrayList sortedList = new ArrayList();
1704: ArrayList firstLevelPoolList = (ArrayList) map.get(level);
1705: if (firstLevelPoolList != null)
1706: addPoolByLevel(sortedList, map, firstLevelPoolList);
1707: return sortedList;
1708: }
1709:
1710: private void addPoolByLevel(ArrayList sortedList, HashMap map,
1711: ArrayList poolList) {
1712: for (int i = 0; i < poolList.size(); i++) {
1713: QuestionPoolDataIfc pool = (QuestionPoolDataIfc) poolList
1714: .get(i);
1715: sortedList.add(pool);
1716: ArrayList nextLevelPoolList = (ArrayList) map.get(pool
1717: .getQuestionPoolId());
1718: if (nextLevelPoolList != null)
1719: addPoolByLevel(sortedList, map, nextLevelPoolList);
1720: }
1721: }
1722:
1723: /*
1724: private void printTree(Collection objects){
1725: Iterator iter = objects.iterator();
1726: String stars="********";
1727: while(iter.hasNext())
1728: {
1729: QuestionPoolDataIfc pool = (QuestionPoolDataIfc) iter.next();
1730: //System.out.println();
1731: //System.out.println("****** QPBean: "+pool.getTitle()+":"+pool.getLastModified());
1732: printChildrenPool(tree, pool, stars);
1733: }
1734: }
1735: */
1736:
1737: /**
1738: * DOCUMENTATION PENDING
1739: *
1740: * @return DOCUMENTATION PENDING
1741: */
1742: public ArrayList getAddedPools() {
1743: return addedPools;
1744: }
1745:
1746: /**
1747: * DOCUMENTATION PENDING
1748: *
1749: * @param pPool DOCUMENTATION PENDING
1750: */
1751: public void setAddedPools(ArrayList addedPools) {
1752: this .addedPools = addedPools;
1753: }
1754:
1755: /**
1756: * DOCUMENTATION PENDING
1757: *
1758: * @return DOCUMENTATION PENDING
1759: */
1760: public ArrayList getAddedQuestions() {
1761: return addedQuestions;
1762: }
1763:
1764: /**
1765: * DOCUMENTATION PENDING
1766: *
1767: * @param pPool DOCUMENTATION PENDING
1768: */
1769: public void setAddedQuestions(ArrayList addedQuestions) {
1770: this .addedQuestions = addedQuestions;
1771: }
1772:
1773: private void setPoolInfo(QuestionPoolDataBean pool) {
1774: String nameField = ContextUtil.lookupParam("namefield");
1775: String orgField = ContextUtil.lookupParam("orgfield");
1776: String descField = ContextUtil.lookupParam("descfield");
1777: String objField = ContextUtil.lookupParam("objfield");
1778: String keyField = ContextUtil.lookupParam("keyfield");
1779:
1780: pool.setDisplayName(nameField);
1781: pool.setOrganizationName(orgField);
1782: pool.setDescription(descField);
1783: pool.setObjectives(objField);
1784: pool.setKeywords(keyField);
1785: }
1786: }
|