public Object getUserMembership(XWikiDocument projectMembers, String user, XWikiContext context) throws XWikiException { Vector objs = projectMembers.getObjects("XWiki.XWikiGroups"); Iterator it = objs.iterator(); BaseObject obj; while (it.hasNext()) { obj = (BaseObject) it.next(); if (user.equals(obj.get("member"))) { return new Object(obj, context); } } return null; } }
private static void fillObjectSummary(ObjectSummary objectSummary, ObjectFactory objectFactory, URI baseUri, Document doc, BaseObject xwikiObject) throws XWikiException { objectSummary.setId(String.format("%s:%s", doc.getPrefixedFullName(), xwikiObject.getGuid())); objectSummary.setGuid(xwikiObject.getGuid()); objectSummary.setPageId(doc.getPrefixedFullName()); objectSummary.setWiki(doc.getWiki()); objectSummary.setSpace(doc.getSpace()); objectSummary.setPageName(doc.getName()); objectSummary.setClassName(xwikiObject.getClassName()); objectSummary.setNumber(xwikiObject.getNumber()); String[] propertyNames = xwikiObject.getPropertyNames(); if (propertyNames.length > 0) { objectSummary.setHeadline(xwikiObject.get(propertyNames[0]).toFormString()); } }
@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(); }
/** * Find the XObject that contains metadata for this feature, if any. * * @param doc the patient's XDocument, where metadata objects are stored * @return the found object, or {@code null} if one wasn't found * @throws XWikiException if accessing the data fails */ private BaseObject findMetadataObject(XWikiDocument doc) throws XWikiException { List<BaseObject> objects = doc.getXObjects(FeatureMetadatum.CLASS_REFERENCE); if (objects != null && !objects.isEmpty()) { for (BaseObject o : objects) { if (o == null) { continue; } StringProperty nameProperty = (StringProperty) o.get(META_PROPERTY_NAME); StringProperty valueProperty = (StringProperty) o.get(META_PROPERTY_VALUE); if (nameProperty != null && StringUtils.equals(nameProperty.getValue(), this.propertyName) && valueProperty != null && StringUtils.equals(valueProperty.getValue(), this.getValue())) { return o; } } } return null; }
/** * Find the XObject that contains metadata for this feature, if any. * * @param doc the patient's XDocument, where metadata objects are stored * @return the found object, or {@code null} if one wasn't found * @throws XWikiException if accessing the data fails */ private BaseObject findMetadataObject(XWikiDocument doc) throws XWikiException { List<BaseObject> objects = doc.getXObjects(FeatureMetadatum.CLASS_REFERENCE); if (objects != null && !objects.isEmpty()) { for (BaseObject o : objects) { if (o == null) { continue; } StringProperty nameProperty = (StringProperty) o.get(META_PROPERTY_NAME); StringProperty valueProperty = (StringProperty) o.get(META_PROPERTY_VALUE); if (nameProperty != null && StringUtils.equals(nameProperty.getValue(), this.propertyName) && valueProperty != null && StringUtils.equals(valueProperty.getValue(), this.getValue())) { return o; } } } return null; }
/** * Find the XObject that contains the custom categories for this non-standard feature, if any. * * @param doc the patient's XDocument, where objects are stored * @return the found object, or {@code null} if one wasn't found * @throws XWikiException if accessing the data fails */ private BaseObject findCategoriesObject(XWikiDocument doc) throws XWikiException { List<BaseObject> objects = doc.getXObjects(CATEGORY_CLASS_REFERENCE); if (objects != null && !objects.isEmpty()) { for (BaseObject o : objects) { if (o == null) { continue; } StringProperty nameProperty = (StringProperty) o.get(META_PROPERTY_NAME); StringProperty valueProperty = (StringProperty) o.get(META_PROPERTY_VALUE); if (nameProperty != null && StringUtils.equals(nameProperty.getValue(), this.propertyName) && valueProperty != null && StringUtils.equals(valueProperty.getValue(), this.getValue())) { return o; } } } return null; } }
@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(); }
private void updateComment(String geneName, XWikiDocument doc, String commentAppend, DocumentReference geneClassReference) throws HibernateException, XWikiException { List<BaseObject> genes = doc.getXObjects(geneClassReference); for (BaseObject gene : genes) { if (gene == null) { continue; } StringProperty geneNameProp = (StringProperty) gene.get(GENE_NAME); if (geneNameProp != null && geneNameProp.getValue().equals(geneName)) { LargeStringProperty oldGeneCommentsProp = (LargeStringProperty) gene.get(COMMENTS_NAME); if (oldGeneCommentsProp == null || StringUtils.isBlank(oldGeneCommentsProp.getValue())) { gene.setLargeStringValue(COMMENTS_NAME, commentAppend); } else { gene.setLargeStringValue(COMMENTS_NAME, oldGeneCommentsProp.getValue() + commentAppend); } } } } }
private void updateComment(String geneName, XWikiDocument doc, String commentAppend, DocumentReference geneClassReference) throws HibernateException, XWikiException { List<BaseObject> genes = doc.getXObjects(geneClassReference); for (BaseObject gene : genes) { if (gene == null) { continue; } StringProperty geneNameProp = (StringProperty) gene.get(GENE_NAME); if (geneNameProp != null && geneNameProp.getValue().equals(geneName)) { LargeStringProperty oldGeneCommentsProp = (LargeStringProperty) gene.get(COMMENTS_NAME); if (oldGeneCommentsProp == null || StringUtils.isBlank(oldGeneCommentsProp.getValue())) { gene.setLargeStringValue(COMMENTS_NAME, commentAppend); } else { gene.setLargeStringValue(COMMENTS_NAME, oldGeneCommentsProp.getValue() + commentAppend); } } } } }
@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; }
public boolean validateObject(BaseObject obj, XWikiContext context) throws XWikiException { boolean isValid = true; Object[] props = getPropertyNames(); for (int i = 0; i < props.length; i++) { String propname = (String) props[i]; BaseProperty property = (BaseProperty) obj.get(propname); PropertyClass propclass = (PropertyClass) get(propname); isValid &= propclass.validateProperty(property, context); } String validSript = getValidationScript(); if ((validSript != null) && (!validSript.trim().equals(""))) { isValid &= executeValidationScript(obj, validSript, context); } return isValid; }
@Override public String getExternalId() { BaseObject familyObject = this.familyDocument.getXObject(Family.CLASS_REFERENCE); StringProperty externalId = null; String externalIdString = ""; try { externalId = (StringProperty) familyObject.get("external_id"); if (externalId != null) { externalIdString = externalId.getValue(); } } catch (XWikiException e) { this.logger.error("Error reading external id of family [{}]: [{}]", getId(), e.getMessage()); } return externalIdString; }
private void migrateObstetricHistory(XWikiDocument doc, XWikiContext context) throws HibernateException, XWikiException { BaseObject parentalObject = doc.getXObject(PARENTAL_INFORMATION_CLASS); BaseObject obstetricObject = doc.getXObject(OBSTETRIC_HISTORY_CLASS, true, context); for (String propName : PROPERTIES) { IntegerProperty oldProp = (IntegerProperty) parentalObject.get(OLD_PREFIX + propName); if (oldProp != null) { Integer propValue = (Integer) oldProp.getValue(); migrateValue(parentalObject, obstetricObject, propValue, propName); } } }
private void migrateSolvedGenes(XWikiDocument doc, XWikiContext context, List<String> geneList) throws HibernateException, XWikiException { BaseObject patient = doc.getXObject(this.patientClassReference); StringProperty oldTarget = (StringProperty) patient.get(SOLVED_NAME); if (oldTarget == null) { return; } patient.removeField(SOLVED_NAME); String geneName = oldTarget.getValue(); if (!StringUtils.isBlank(geneName)) { BaseObject gene = doc.newXObject(this.geneClassReference, context); gene.setStringValue(GENE_NAME, geneName); gene.setStringValue(STATUS_NAME, "solved"); geneList.add(geneName); } }
private void migrateSolvedGenes(XWikiDocument doc, XWikiContext context, List<String> geneList) throws HibernateException, XWikiException { BaseObject patient = doc.getXObject(this.patientClassReference); StringProperty oldTarget = (StringProperty) patient.get(SOLVED_NAME); if (oldTarget == null) { return; } patient.removeField(SOLVED_NAME); String geneName = oldTarget.getValue(); if (!StringUtils.isBlank(geneName)) { BaseObject gene = doc.newXObject(this.geneClassReference, context); gene.setStringValue(GENE_NAME, geneName); gene.setStringValue(STATUS_NAME, "solved"); geneList.add(geneName); } }
@Override public String getExternalId() { BaseObject familyObject = getXDocument().getXObject(Family.CLASS_REFERENCE); StringProperty externalId; String externalIdString = ""; try { externalId = (StringProperty) familyObject.get("external_id"); if (externalId != null) { externalIdString = externalId.getValue(); } } catch (XWikiException e) { this.logger.error("Error reading external id of family [{}]: [{}]", getId(), e.getMessage()); } return externalIdString; }
/** * {@inheritDoc} * * @see DocumentAccessBridge#getProperty(String, String, String) */ @Deprecated public Object getProperty(String documentReference, String className, String propertyName) { Object value; try { XWikiContext xcontext = getContext(); XWikiDocument doc = xcontext.getWiki().getDocument(documentReference, xcontext); BaseObject object = doc.getObject(className); BaseProperty property = (BaseProperty) object.get(propertyName); value = property.getValue(); } catch (Exception ex) { value = null; } return value; }
/** * {@inheritDoc} * * @see DocumentAccessBridge#getProperty(String, String, int, String) */ public Object getProperty(String documentReference, String className, int objectNumber, String propertyName) { try { XWikiContext xcontext = getContext(); return ((BaseProperty) xcontext.getWiki().getDocument(documentReference, xcontext).getObject(className, objectNumber).get(propertyName)).getValue(); } catch (Exception ex) { return null; } }
/** * {@inheritDoc} * * @see DocumentAccessBridge#getProperty(String, String) */ public Object getProperty(String documentReference, String propertyName) { try { XWikiContext xcontext = getContext(); return ((BaseProperty) xcontext.getWiki().getDocument(documentReference, xcontext).getFirstObject( propertyName, xcontext).get(propertyName)).getValue(); } catch (Exception ex) { return null; } }
/** * {@inheritDoc} * * @see DocumentAccessBridge#getProperty(DocumentReference, DocumentReference, String) */ public Object getProperty(DocumentReference documentReference, DocumentReference classReference, String propertyName) { Object value; try { XWikiContext xcontext = getContext(); XWikiDocument doc = xcontext.getWiki().getDocument(documentReference, xcontext); BaseObject object = doc.getXObject(classReference); BaseProperty property = (BaseProperty) object.get(propertyName); value = property.getValue(); } catch (Exception ex) { value = null; } return value; }