From: <ap...@vh...> - 2006-06-11 21:15:28
|
Author: apevec Date: 2006-06-11 23:11:03 +0200 (Sun, 11 Jun 2006) New Revision: 1156 Modified: trunk/ccm-ldn-aplaws/src/com/arsdigita/aplaws/AutoCategorisation.java trunk/ccm-ldn-aplaws/src/com/arsdigita/aplaws/ui/ItemCategoryPicker.java Log: derive IPSV/LGCL from manually assigned LGCL/IPSV expose useful code buried in ui.ItemCategoryPicker Modified: trunk/ccm-ldn-aplaws/src/com/arsdigita/aplaws/AutoCategorisation.java =================================================================== --- trunk/ccm-ldn-aplaws/src/com/arsdigita/aplaws/AutoCategorisation.java 2006-06-10 20:33:39 UTC (rev 1155) +++ trunk/ccm-ldn-aplaws/src/com/arsdigita/aplaws/AutoCategorisation.java 2006-06-11 21:11:03 UTC (rev 1156) @@ -7,7 +7,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; -import java.util.List; import java.util.StringTokenizer; import javax.xml.parsers.ParserConfigurationException; @@ -21,12 +20,11 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; +import com.arsdigita.aplaws.ui.ItemCategoryPicker; import com.arsdigita.categorization.Category; +import com.arsdigita.cms.ContentBundle; import com.arsdigita.cms.ContentItem; -import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentSection; -import com.arsdigita.cms.ContentSectionCollection; -import com.arsdigita.cms.ContentSectionConfig; import com.arsdigita.cms.dispatcher.ItemResolver; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DomainCollection; @@ -41,7 +39,7 @@ import com.arsdigita.persistence.DataAssociationCursor; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; -import com.arsdigita.persistence.Session; +import com.arsdigita.persistence.Filter; import com.arsdigita.persistence.SessionManager; import com.arsdigita.web.Application; /** @@ -115,14 +113,21 @@ String urlid; String url; ContentItem item; + ContentBundle bundle; String scheme; Collection keywords = new HashSet(); Collection terms = new HashSet(); + Domain ipsv, lgcl, gcl, lgsl, lgdl; public SearchlightHandler(boolean isDebug, boolean isVerbose, boolean persistChanges) { this.isDebug = isDebug; this.isVerbose = isVerbose; this.persistChanges = persistChanges; + ipsv = Domain.retrieve("IPSV"); + lgcl = Domain.retrieve("LGCL"); + gcl = Domain.retrieve("GCL"); + lgsl = Domain.retrieve("LGSL"); + lgdl = Domain.retrieve("LGDL"); } public void startDocument() throws SAXException { @@ -148,6 +153,7 @@ urlid = null; url = null; item = null; + bundle = null; } else if ("unformated_data".equals(qName)) { keywords.clear(); terms.clear(); @@ -158,9 +164,10 @@ scheme = attributes.getValue("scheme"); } // if qName } - // XXX term@id is *NOT* Term.uniqueID, use category_date and retrieve terms by name + // XXX term@id is *NOT* Term.uniqueID, use unformated_data/category_data + // and retrieve terms by name /* example from CAMDEN.xml - * <tags> + <tags> <terms> <term score="40" thesarus="LGTL" id="9087">A to Z</term> <term score="6" thesarus="LGCS" id="8030">Development control</term> @@ -178,7 +185,7 @@ <category_data scheme="LGSL">Development Control</category_data> <category_data scheme="IPSV">Domestic violence; Planning (town and country)</category_data> </unformated_data> - * </tags> + </tags> */ public void endElement(String uri, String localName, String qName) throws SAXException { @@ -330,11 +337,12 @@ private void assignTerms() { if (item != null) { + bundle = (ContentBundle) item.getParent(); Collection manualCategories = new HashSet(); Collection oldAutoCategories = new HashSet(); Collection newAutoCategories = new LinkedList(); DataAssociationCursor cursor = ((DataAssociation)DomainServiceInterfaceExposer - .get(item, "categories")).cursor(); + .get(bundle, "categories")).cursor(); // cat_object_category_map.auto_p // cursor.addEqualsFilter("link.isAuto", Boolean.FALSE); while (cursor.next()) { @@ -347,34 +355,39 @@ } } // assign all new auto-derived terms, unless it's already assigned - // prefer manual IPSV/LGCL over auto IPSV, deriving GCL, LGSL, LGDL + // prefer manual IPSV/LGCL over auto IPSV // check existing manual terms - boolean foundIPSVLGCL = false; + Collection manualIPSV = new LinkedList(); + Collection manualLGCL = new LinkedList(); if (!manualCategories.isEmpty()) { DataCollection dc = SessionManager.getSession().retrieve(Term.BASE_DATA_OBJECT_TYPE); - dc.addEqualsFilter("model.id", manualCategories); + Filter f = dc.addFilter("model.id IN :manualCats"); + f.set("manualCats", manualCategories); dc.addFilter("domain.key IN ('IPSV','LGCL')"); - while (!foundIPSVLGCL && dc.next()) { - foundIPSVLGCL = true; - if (isVerbose) { - out("manual IPSV/LGCL found"); + while (dc.next()) { + String domainKey = (String)dc.get("domain.key"); + if ("IPSV".equals(domainKey)) { + manualIPSV.add(dc.get("model.id")); + } else if ("LGCL".equals(domainKey)) { + manualLGCL.add(dc.get("model.id")); } } - dc.close(); } - if (!foundIPSVLGCL) { + if (manualIPSV.isEmpty() && manualLGCL.isEmpty()) { + // neither IPSV nor LGCL were manually assigned + // free to auto assign everything for (Iterator iter=terms.iterator();iter.hasNext();) { Term t = (Term) iter.next(); BigDecimal categoryID = t.getModel().getID(); if ( !manualCategories.contains(categoryID)) { if (!oldAutoCategories.contains(categoryID)) { if (persistChanges) { - t.addObject(item); + t.addObject(bundle); } newAutoCategories.add(categoryID); // to be marked isAuto if (isVerbose) { - out("ASSIGN " + t + " to " - + item); + out("autoASSIGN " + t + " to " + + bundle); } } else { oldAutoCategories.remove(categoryID); @@ -390,33 +403,47 @@ for (Iterator iter=oldAutoCategories.iterator(); iter.hasNext(); ) { Category category = new Category((BigDecimal) iter.next()); if (persistChanges) { - category.removeChild(item); + category.removeChild(bundle); } if (isVerbose){ - out("removing oldAuto "+category+" from "+item); + out("removing oldAuto "+category+" from "+bundle); } } if (!newAutoCategories.isEmpty()) { - cursor = ((DataAssociation)DomainServiceInterfaceExposer - .get(item, "categories")).cursor(); - cursor.addEqualsFilter("id", newAutoCategories); + cursor = ((DataAssociation) DomainServiceInterfaceExposer + .get(bundle, "categories")).cursor(); + Filter f = cursor.addFilter("id IN :newAutoCats"); + f.set("newAutoCats", newAutoCategories); while (cursor.next()) { Object categoryID = cursor.get("id"); if (persistChanges) { DataObject link = cursor.getLink(); - link.set("isAuto",Boolean.TRUE); + link.set("isAuto", Boolean.TRUE); } if (isVerbose) { - out("isAuto=TRUE for new categoryID="+categoryID+"/"+item); + out("isAuto=TRUE for new categoryID=" + + categoryID + "/" + bundle); } + } } } else { - // TODO derive other domains from assigned terms using mappings + // derive empty LGCL or IPSV from the other manually if (isVerbose) { out("derive from manual LGCL/IPSV"); } + // only one manual* can be empty + if (manualLGCL.isEmpty()) { + // TODO move getRelatedTerms etc. out of UI code + Collection relatedLGCL = ItemCategoryPicker.getRelatedTerms(manualIPSV, lgcl); + ItemCategoryPicker.assignTerms(relatedLGCL, bundle); + } + if (manualIPSV.isEmpty()) { + Collection relatedIPSV = ItemCategoryPicker.getRelatedTerms(manualLGCL, ipsv); + ItemCategoryPicker.assignTerms(relatedIPSV, bundle); + } } + // TODO assign related GCL, LGSL, LGDL - move that code out of UI (ItemCategoryPicker) } } Modified: trunk/ccm-ldn-aplaws/src/com/arsdigita/aplaws/ui/ItemCategoryPicker.java =================================================================== --- trunk/ccm-ldn-aplaws/src/com/arsdigita/aplaws/ui/ItemCategoryPicker.java 2006-06-10 20:33:39 UTC (rev 1155) +++ trunk/ccm-ldn-aplaws/src/com/arsdigita/aplaws/ui/ItemCategoryPicker.java 2006-06-11 21:11:03 UTC (rev 1156) @@ -19,12 +19,14 @@ package com.arsdigita.aplaws.ui; import com.arsdigita.aplaws.Aplaws; +import com.arsdigita.bebop.Label; import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.BigDecimalParameter; import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionListener; +import com.arsdigita.bebop.form.Widget; import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.DataCollection; import com.arsdigita.domain.DomainCollection; @@ -36,6 +38,7 @@ import com.arsdigita.cms.CMS; import com.arsdigita.cms.ui.authoring.ItemCategoryForm; +import java.util.Collection; import java.util.List; import java.util.LinkedList; import java.util.Iterator; @@ -49,7 +52,8 @@ private BigDecimalParameter m_root; public ItemCategoryPicker(BigDecimalParameter root, - StringParameter mode) { + StringParameter mode) { + m_form = new ItemCategoryForm(root, mode, new TermWidget(mode, this)); m_root = root; @@ -57,6 +61,16 @@ m_form.addCompletionListener(new ItemCategoryFormCompletion()); } + public ItemCategoryPicker(BigDecimalParameter root, + StringParameter mode, + Widget widget) { + m_form = new ItemCategoryForm(root, mode, widget); + m_root = root; + + add(m_form); + m_form.addCompletionListener(new ItemCategoryFormCompletion()); + } + private class ItemCategoryFormCompletion implements ActionListener { public void actionPerformed(ActionEvent ev) { @@ -91,9 +105,9 @@ Domain aplawsNav = Domain.retrieve("APLAWS-NAV"); List lgclTerms = getCurrentCategories(domain, bundle); - List lgslTerms = getRelatedTerms(lgclTerms, lgsl); - List gclTerms = getRelatedTerms(lgclTerms, gcl); - List aplawsNavTerms = null; + Collection lgslTerms = getRelatedTerms(lgclTerms, lgsl); + Collection gclTerms = getRelatedTerms(lgclTerms, gcl); + Collection aplawsNavTerms = null; if (lgclOverrideAnav) { aplawsNavTerms = getRelatedTerms(lgclTerms, aplawsNav); } @@ -126,7 +140,7 @@ // do LGSL -> LGCL -> GCL instead. List lgslTerms = getCurrentCategories(lgsl, bundle); - List lgclTerms = getRelatedTerms(lgslTerms, lgcl); + Collection lgclTerms = getRelatedTerms(lgslTerms, lgcl); LinkedList lgclIDs = new LinkedList(); Iterator i = lgclTerms.iterator(); @@ -135,7 +149,7 @@ lgclIDs.add(term.getModel().getID()); } - List gclTerms = getRelatedTerms(lgclIDs, gcl); + Collection gclTerms = getRelatedTerms(lgclIDs, gcl); clearTerms(lgcl, bundle); assignTerms(lgclTerms, bundle); @@ -182,7 +196,8 @@ return current; } - protected List getRelatedTerms(List src, + // TODO move out of UI code + public static Collection getRelatedTerms(Collection src, Domain domain) { if (s_log.isDebugEnabled()) { s_log.debug("Getting related terms to " + domain); @@ -224,7 +239,8 @@ } - protected void assignTerms(List terms, + // TODO move out of UI code + public static void assignTerms(Collection terms, ContentBundle bundle) { if (s_log.isDebugEnabled()) { s_log.debug("Assigning terms to " + bundle); |