/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.BaseProperty#getValue() */ @Override public Object getValue() { return getList(); }
/** * {@inheritDoc} * <p> * This is important.. Otherwise we can get a stackoverflow calling toXML() * * @see com.xpn.xwiki.objects.BaseProperty#toString() */ @Override public String toString() { if ((getList() instanceof PersistentCollection) && (!((PersistentCollection) getList()).wasInitialized())) { return ""; } return toXMLString(); } }
/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.BaseProperty#clone() */ @Override public Object clone() { ListProperty property = (ListProperty) super.clone(); List<String> list = new ArrayList<String>(); for (String entry : getList()) { list.add(entry); } property.setValue(list); return property; }
/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.BaseProperty#toFormString() */ @Override public String toFormString() { CharacterFilter filter = new CharacterFilter(); filter.addAttribute(this.formStringSeparator, "\\" + this.formStringSeparator); List<String> list = getList(); Iterator<String> it = list.iterator(); if (!it.hasNext()) { return ""; } StringBuffer result = new StringBuffer(); result.append(it.next()); while (it.hasNext()) { result.append(this.formStringSeparator); result.append(filter.process(it.next())); } return result.toString(); }
@Override public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) { List<String> selectlist; BaseProperty prop = (BaseProperty) object.safeget(name); if (prop == null) { selectlist = new ArrayList<String>(); } else if (prop instanceof ListProperty) { selectlist = ((ListProperty) prop).getList(); } else { selectlist = new ArrayList<String>(); selectlist.add(String.valueOf(prop.getValue())); } String result = displayFlatView(selectlist, context); if (result.equals("")) { super.displayView(buffer, name, prefix, object, context); } else { buffer.append(result); } }
@Override public BaseProperty newPropertyfromXML(Element ppcel) { if (!isMultiSelect()) { return super.newPropertyfromXML(ppcel); } @SuppressWarnings("unchecked") List<Element> elist = ppcel.elements("value"); BaseProperty lprop = newProperty(); if (lprop instanceof ListProperty) { List<String> llist = ((ListProperty) lprop).getList(); for (int i = 0; i < elist.size(); i++) { Element el = elist.get(i); llist.add(el.getText()); } } else { for (int i = 0; i < elist.size(); i++) { Element el = elist.get(i); ((StringProperty) lprop).setValue(el.getText()); } } return lprop; }
@Override public List<String> getMembersIds() { BaseObject familyObject = this.familyDocument.getXObject(CLASS_REFERENCE); if (familyObject == null) { return new LinkedList<>(); } ListProperty xwikiRelativesList; try { xwikiRelativesList = (ListProperty) familyObject.get(FAMILY_MEMBERS_FIELD); } catch (XWikiException e) { this.logger.error("Error reading family members: [{}]", e.getMessage(), e); return null; } if (xwikiRelativesList == null) { return Collections.emptyList(); } return xwikiRelativesList.getList(); }
@Override public List<String> getMembersIds() { BaseObject familyObject = getXDocument().getXObject(CLASS_REFERENCE); if (familyObject == null) { return new LinkedList<>(); } ListProperty xwikiRelativesList; try { xwikiRelativesList = (ListProperty) familyObject.get(FAMILY_MEMBERS_FIELD); } catch (XWikiException e) { this.logger.error("Error reading family members: [{}]", e.getMessage(), e); return null; } if (xwikiRelativesList == null) { return Collections.emptyList(); } return xwikiRelativesList.getList(); }
@Override public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) { List<String> selectlist; String separator = getSeparator(); BaseProperty prop = (BaseProperty) object.safeget(name); Map<String, ListItem> map = getMap(context); if (prop instanceof ListProperty) { selectlist = ((ListProperty) prop).getList(); List<String> newlist = new ArrayList<String>(); for (String entry : selectlist) { newlist.add(getDisplayValue(entry, name, map, context)); } buffer.append(StringUtils.join(newlist, separator)); } else { buffer.append(getDisplayValue(prop.getValue(), name, map, context)); } } }
@Override public IndexedPatientData<Disorder> load(Patient patient) { try { BaseObject data = patient.getXDocument().getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } List<Disorder> disorders = new ArrayList<>(); ListProperty values = (ListProperty) data.get(DIAGNOSIS_PROPERTY); if (values != null) { for (String value : values.getList()) { if (StringUtils.isNotBlank(value)) { disorders.add(new PhenoTipsDisorder(values, value)); } } } if (disorders.isEmpty()) { return null; } else { return new IndexedPatientData<>(getName(), disorders); } } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }
@Override public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) { List<String> selectlist; String separator = getSeparator(); BaseProperty prop = (BaseProperty) object.safeget(name); Map<String, ListItem> map = getMap(context); // Skip unset values. if (prop == null) { return; } if (prop instanceof ListProperty) { selectlist = ((ListProperty) prop).getList(); List<String> newlist = new ArrayList<String>(); for (String value : selectlist) { newlist.add(getDisplayValue(value, name, map, context)); } buffer.append(StringUtils.join(newlist, separator)); } else { buffer.append(getDisplayValue(prop.getValue(), name, map, context)); } }
@Override public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) { List<String> selectlist; BaseProperty prop = (BaseProperty) object.safeget(name); if (prop == null) { selectlist = new ArrayList<String>(); } else if (prop instanceof ListProperty) { selectlist = ((ListProperty) prop).getList(); } else { selectlist = new ArrayList<String>(); selectlist.add(String.valueOf(prop.getValue())); } if (isPicker()) { String result = displayTree(name, prefix, selectlist, "edit", context); if (result.equals("")) { displayTreeSelectEdit(buffer, name, prefix, object, context); } else { displayHidden(buffer, name, prefix, object, context); buffer.append(result); } } else { displayTreeSelectEdit(buffer, name, prefix, object, context); } }
for (String value : values.getList()) { if (StringUtils.isNotBlank(value)) { features.add(new PhenoTipsFeature(patient.getXDocument(), values, value));
@Override public IndexedPatientData<Disorder> load(Patient patient) { try { XWikiDocument doc = (XWikiDocument) this.documentAccessBridge.getDocument(patient.getDocument()); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } List<Disorder> disorders = new ArrayList<>(); for (String property : DISORDER_PROPERTIES) { ListProperty values = (ListProperty) data.get(property); if (values != null) { for (String value : values.getList()) { if (StringUtils.isNotBlank(value)) { disorders.add(new PhenoTipsDisorder(values, value)); } } } } if (disorders.isEmpty()) { return null; } else { return new IndexedPatientData<>(getName(), disorders); } } catch (Exception e) { this.logger.error("Failed to access patient data for [{}]: {}", patient.getDocument(), e.getMessage()); } return null; }
@Override public IndexedPatientData<Disorder> load(Patient patient) { try { XWikiDocument doc = (XWikiDocument) this.documentAccessBridge.getDocument(patient.getDocument()); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } List<Disorder> disorders = new ArrayList<>(); ListProperty values = (ListProperty) data.get(DIAGNOSIS_PROPERTY); if (values != null) { for (String value : values.getList()) { if (StringUtils.isNotBlank(value)) { disorders.add(new PhenoTipsDisorder(values, value)); } } } if (disorders.isEmpty()) { return null; } else { return new IndexedPatientData<>(getName(), disorders); } } catch (Exception e) { this.logger.error("Failed to access patient data for [{}]: {}", patient.getDocument(), e.getMessage()); } return null; }
@Override public PatientData<List<VocabularyTerm>> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } Map<String, List<VocabularyTerm>> result = new LinkedHashMap<>(); for (String propertyName : getProperties()) { PropertyInterface propertyValue = data.get(propertyName); List<VocabularyTerm> holder = new LinkedList<>(); if (propertyValue instanceof StringProperty) { String propertyValueString = ((StringProperty) propertyValue).getValue(); addTerms(propertyValueString, holder); } else if (propertyValue instanceof ListProperty) { for (String item : ((ListProperty) propertyValue).getList()) { addTerms(item, holder); } } result.put(propertyName, holder); } return new DictionaryPatientData<>(DATA_NAME, result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }
@Override public PatientData<List<VocabularyTerm>> load(Patient patient) { try { XWikiDocument doc = (XWikiDocument) this.documentAccessBridge.getDocument(patient.getDocument()); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } Map<String, List<VocabularyTerm>> result = new LinkedHashMap<>(); for (String propertyName : getProperties()) { PropertyInterface propertyValue = data.get(propertyName); List<VocabularyTerm> holder = new LinkedList<>(); if (propertyValue instanceof StringProperty) { String propertyValueString = ((StringProperty) propertyValue).getValue(); addTerms(propertyValueString, holder); } else if (propertyValue instanceof ListProperty) { for (String item : ((ListProperty) propertyValue).getList()) { addTerms(item, holder); } } result.put(propertyName, holder); } return new DictionaryPatientData<>(DATA_NAME, result); } catch (Exception e) { this.logger.error("Could not find requested document or some unforeseen" + " error has occurred during controller loading ", e.getMessage()); } return null; }
/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.BaseProperty#toXML() */ @Override public Element toXML() { Element el = new DOMElement(getName()); List<String> list = getList(); for (String value : list) { if (value != null) { Element vel = new DOMElement("value"); vel.setText(value); el.add(vel); } } return el; }
protected void displayTreeSelectEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) { select select = new select(prefix + name, 1); select.setMultiple(isMultiSelect()); select.setSize(getSize()); select.setName(prefix + name); select.setID(prefix + name); select.setDisabled(isDisabled()); Map<String, ListItem> map = getMap(context); Map<String, List<ListItem>> treemap = getTreeMap(context); List<String> selectlist; BaseProperty prop = (BaseProperty) object.safeget(name); if (prop == null) { selectlist = new ArrayList<String>(); } else if (prop instanceof ListProperty) { selectlist = ((ListProperty) prop).getList(); } else { selectlist = new ArrayList<String>(); selectlist.add(String.valueOf(prop.getValue())); } // Add options from Set addToSelect(select, selectlist, map, treemap, "", "", context); buffer.append(select.toString()); }