@Override public List<Value> getFullPath(String valueId, String treeId) throws PdcException { List<Value> fullPath = new ArrayList<Value>(); Value value = getValue(treeId, valueId); fullPath.add(value); while (value.hasFather()) { value = getValue(treeId, value.getFatherId()); fullPath.add(0, value); } return fullPath; }
private Value findTerm(String term, final List<Value> inValues) { Value valueOfTerm = null; for (Value value : inValues) { if (value.getName().equals(term)) { valueOfTerm = value; break; } } if (valueOfTerm == null) { throw new RuntimeException("The term to find should exist!"); } return valueOfTerm; }
private void addPosition(final ClassifyPosition position) { ClassificationPlan pdc = aClassificationPlan(); for (ClassifyValue classifyValue : position.getValues()) { if (classifyValue.getFullPath() == null || classifyValue.getFullPath().isEmpty()) { Value value = new Value(); value.setAxisId(classifyValue.getAxisId()); String path = classifyValue.getValue(); path = path.substring(0, path.length() - 1); int indexOfTermId = path.lastIndexOf("/") + 1; value.setValuePK(new ValuePK(path.substring(indexOfTermId))); value.setPath(path.substring(0, indexOfTermId)); classifyValue.setFullPath(pdc.getPathInTreeOfValue(value)); } } position.setPositionId(positions.size()); positions.add(position); }
public PdcClassification buildWithNoSynonyms() { ClassificationPlan pdc = aClassificationPlan(); List<ClassifyPosition> positions = new ArrayList<ClassifyPosition>(); List<ClassifyValue> positionValues = new ArrayList<ClassifyValue>(); List<Value> values = pdc.getValuesOfAxisByName("Technologie"); Value value = values.get(0); ClassifyValue classifyValue = new ClassifyValue(toValueId(value.getAxisId()), toValue(value.getFullPath())); classifyValue.setFullPath(pdc.getPathInTreeOfValue(value)); positionValues.add(classifyValue); positions.add(new ClassifyPosition(positionValues)); return aClassificationFromPositions(positions) .ofContent(contentId) .inComponentInstance(componentId); }
public PdcClassification build() { ClassificationPlan pdc = aClassificationPlan(); List<ClassifyPosition> positions = new ArrayList<ClassifyPosition>(); List<ClassifyValue> positionValues = new ArrayList<ClassifyValue>(); List<Value> values = pdc.getValuesOfAxisByName("Pays"); Value value = findTerm("Grenoble", values); ClassifyValue classifyValue = new ClassifyValue(toValueId(value.getAxisId()), toValue(value.getFullPath())); classifyValue.setFullPath(pdc.getPathInTreeOfValue(value)); positionValues.add(classifyValue); values = pdc.getValuesOfAxisByName("PĂ©riode"); value = findTerm("Moyen-Age", values); classifyValue = new ClassifyValue(toValueId(value.getAxisId()), toValue(value.getFullPath())); classifyValue.setFullPath(pdc.getPathInTreeOfValue(value)); positionValues.add(classifyValue); positions.add(new ClassifyPosition(positionValues)); positionValues = new ArrayList<ClassifyValue>(); values = pdc.getValuesOfAxisByName("Religion"); value = findTerm("Christianisme", values); classifyValue = new ClassifyValue(toValueId(value.getAxisId()), toValue(value.getFullPath())); classifyValue.setFullPath(pdc.getPathInTreeOfValue(value)); positionValues.add(classifyValue); positions.add(new ClassifyPosition(positionValues)); PdcClassification classification = aClassificationFromPositions(positions).inComponentInstance(getComponentId()); if (getContentId() != null) { classification = classification.ofContent(getContentId()); } else if (getNodeId() != null) { classification = classification.forNode(getNodeId()); } return classification; }
@Override public Value getValue(String axisId, String valueId) throws PdcException { Value theValue = null; ClassificationPlan pdc = aClassificationPlan(); for (Value aValue : pdc.getValuesOfAxisById(axisId)) { if (aValue.getPK().getId().equals(valueId)) { theValue = aValue; break; } } if (theValue == null) { throw new PdcException( getClass().getSimpleName() + ".getValue()", SilverpeasException.ERROR, "root.NO_EX_MESSAGE"); } return theValue; }
@Override public List<Value> getPertinentDaughterValuesByInstanceIds( SearchContext searchContext, String axisId, String valueId, List<String> instanceIds) throws PdcException { List<Value> pertinentValues = new ArrayList<Value>(); ClassificationPlan pdc = aClassificationPlan(); UsedAxis theAxis = pdc.getAxis(axisId); if (instanceIds.contains(theAxis.getInstanceId())) { List<Value> values = pdc.getValuesUsedInClassification(axisId); List<SearchCriteria> criteria = searchContext.getCriterias(); if (criteria.isEmpty()) { return values; } for (Value aValue : values) { for (SearchCriteria criterion : criteria) { if (criterion.getAxisId() == Integer.valueOf(aValue.getAxisId()) && criterion.getValue().equals(aValue.getFullPath())) { pertinentValues.add(aValue); } } } } return pertinentValues; }
@Override public int doStartTag() throws JspException { if (pdcBm == null) { pdcBm = (PdcBm) new PdcBmImpl(); } List<SearchAxis> primaryAxis = null; List daughters = null; try { if (StringUtil.isDefined(m_spaceOrSubSpace)) { List<String> availableComponentIds = new ArrayList<String>(); SearchContext searchContext = new SearchContext(); if (StringUtil.isDefined(componentId)) { primaryAxis = pdcBm.getPertinentAxisByInstanceId(searchContext, "P", componentId); } else { String a[] = oganisationController.getAvailCompoIds( m_spaceOrSubSpace, mainSessionController.getUserId()); availableComponentIds = Arrays.asList(a); if (!availableComponentIds.isEmpty()) { primaryAxis = pdcBm.getPertinentAxisByInstanceIds(searchContext, "P", availableComponentIds); } } if (primaryAxis != null && !primaryAxis.isEmpty()) { if (!"".equals(selectedAxisId)) { if (StringUtil.isDefined(componentId)) { daughters = pdcBm.getPertinentDaughterValuesByInstanceId( searchContext, selectedAxisId, selectedAxisPath, componentId); } else { daughters = pdcBm.getPertinentDaughterValuesByInstanceIds( searchContext, selectedAxisId, selectedAxisPath, availableComponentIds); } } else { SearchAxis searchAxis = primaryAxis.get(0); String axisId = new Integer(searchAxis.getAxisId()).toString(); daughters = pdcBm.getPertinentDaughterValuesByInstanceIds( searchContext, axisId, "", availableComponentIds); } } } // end if } catch (PdcException e) { throw new JspTagException("PdcException occured : " + e.toString()); } try { pageContext.getOut().println("<tr class='intfdcolor51'>"); pageContext.getOut().println(" <td width='100%'>"); pageContext .getOut() .println(" <table border='0' cellspacing='0' cellpadding='0' width='100%'>"); pageContext.getOut().println(" <tr>"); pageContext.getOut().println(" <td> </td>"); pageContext.getOut().println(" <td width='100%'><span class='txtnote'>"); pageContext .getOut() .println(" <table cellpadding=0 cellspacing=0 border=0 width='100%'>"); pageContext.getOut().println(" <tr><td>"); // il peut y avoir aucun axe primaire dans un 1er temps if ((primaryAxis != null) && !primaryAxis.isEmpty()) { String text_link = ""; for (SearchAxis searchAxis : primaryAxis) { String axisId = new Integer(searchAxis.getAxisId()).toString(); String axisRootId = new Integer(searchAxis.getAxisRootId()).toString(); String axisName = EncodeHelper.javaStringToHtmlString(searchAxis.getAxisName()); int nbPositions = searchAxis.getNbObjects(); if (nbPositions == 0 && componentId != null) { continue; } String objectLinked = ""; String link = "javascript:top.scriptFrame.axisClick('" + axisId + "','');"; text_link = webContext + "/RpdcSearch/jsp/showaxishfromhomepage?query=&AxisId=" + axisId + "&ValueId=/" + axisRootId + "/&SearchContext=isNotEmpty&component_id=" + componentId + "&space_id=" + m_spaceOrSubSpace; if (axisId.equals(selectedAxisId)) { if (daughters != null) { if ("".equals(selectedAxisPath)) { if ("off".equals(state)) { pageContext .getOut() .println( HomePageFunctions.urlFactory( link, text_link, axisId, "", objectLinked, axisName, " (" + nbPositions + ")", HomePageFunctions.AXIS, HomePageFunctions.AXIS_COLLAPSED, "", webContext)); continue; } } pageContext .getOut() .println( HomePageFunctions.urlFactory( link, text_link, axisId, "", objectLinked, axisName, " (" + nbPositions + ")", HomePageFunctions.AXIS, HomePageFunctions.AXIS_EXPANDED, "", webContext)); // **************Begin daughters int d_size = daughters.size(); int[][] tree_gui_represintation = new int[d_size][d_size]; int selected_x = -1; int selected_y = 0; for (int j = 0; j < d_size; j++) { Value value = (Value) daughters.get(j); int valueLevel = value.getLevelNumber(); String path = value.getFullPath(); HomePageFunctions.setTreeNode(tree_gui_represintation, valueLevel, j, d_size); if (selectedAxisPath.equals(path)) { selected_x = valueLevel; selected_y = j; } } HomePageFunctions.closeTreeNodes(tree_gui_represintation, 0, d_size, d_size); if (selected_x >= 0) { if (state.equals("on")) { selected_x++; selected_y++; } HomePageFunctions.collapseTree( tree_gui_represintation, selected_x, selected_y, d_size); } for (int j = 1; j < d_size; j++) { Value value = (Value) daughters.get(j); String valueName = EncodeHelper.javaStringToHtmlString(value.getName()); int valueLevel = value.getLevelNumber(); int valueNbObjects = value.getNbObjects(); if (valueNbObjects == 0 && componentId != null) { continue; } String valueFullPath = value.getFullPath(); link = "javascript:top.scriptFrame.axisClick('" + axisId + "','" + valueFullPath + "');"; text_link = webContext + "/RpdcSearch/jsp/showaxishfromhomepage?query=&AxisId=" + axisId + "&ValueId=" + valueFullPath + "&SearchContext=isNotEmpty&component_id=" + componentId + "&space_id=" + m_spaceOrSubSpace; if (tree_gui_represintation[0][j] == HomePageFunctions.T_HIDED_NODE) { continue; } String offset = HomePageFunctions.getTreeNodeOffset( tree_gui_represintation, j, d_size, webContext); int node_type; if (tree_gui_represintation[valueLevel][j] == HomePageFunctions.T_OPENED_NODE) { node_type = HomePageFunctions.AXIS_EXPANDED; } else { node_type = HomePageFunctions.AXIS_COLLAPSED; } if (selectedAxisPath.equals("")) { if (valueLevel == 1) { pageContext .getOut() .println( HomePageFunctions.urlFactory( link, text_link, valueFullPath, "", objectLinked, valueName, " (" + valueNbObjects + ")", HomePageFunctions.AXIS_LAST, HomePageFunctions.AXIS_COLLAPSED, offset, webContext)); } continue; } else { pageContext .getOut() .println( HomePageFunctions.urlFactory( link, text_link, valueFullPath, "", objectLinked, valueName, " (" + valueNbObjects + ")", HomePageFunctions.AXIS_LAST, node_type, offset, webContext)); } } } } else { pageContext .getOut() .println( HomePageFunctions.urlFactory( link, text_link, axisId, "", objectLinked, axisName, " (" + nbPositions + ")", HomePageFunctions.AXIS, HomePageFunctions.AXIS_COLLAPSED, "", webContext)); } } // fin du for } pageContext.getOut().println(" </td></tr>"); pageContext.getOut().println(" </table>"); pageContext.getOut().println(" </span></td>"); pageContext.getOut().println(" </tr>"); pageContext.getOut().println(" </table>"); pageContext.getOut().println(" </td>"); pageContext.getOut().println(" <td><img src='icons/1px.gif'></td>"); pageContext.getOut().println(" <td class='intfdcolor'><img src='icons/1px.gif'></td>"); pageContext.getOut().println("</tr>"); } catch (IOException ioe) { throw new JspTagException("IO_ERROR"); } return SKIP_BODY; }