private boolean fixValue(StringProperty property) { if (property == null) { return false; } boolean modified = false; String value = property.getValue(); if (this.translations.containsKey(value)) { R54690PhenoTips1195DataMigration.this.logger.debug( "Replacing {} with {}", value, this.translations.get(value)); property.setValue(this.translations.get(value)); modified = true; } return modified; } }
private boolean fixValue(StringProperty property) { if (property == null) { return false; } boolean modified = false; String value = property.getValue(); if (this.translations.containsKey(value)) { R54690PhenoTips1195DataMigration.this.logger.debug( "Replacing {} with {}", value, this.translations.get(value)); property.setValue(this.translations.get(value)); modified = true; } return modified; } }
/** * Constructor that copies the data from an XProperty. * * @param data the XProperty representing this meta-feature in XWiki */ PhenoTipsFeatureMetadatum(StringProperty data) { super(data.getValue()); this.type = Type.valueOf(data.getName().toUpperCase(Locale.ROOT)); }
/** * Constructor that copies the data from an XProperty. * * @param data the XProperty representing this meta-feature in XWiki */ PhenoTipsFeatureMetadatum(StringProperty data) { super(data.getValue()); this.type = Type.valueOf(data.getName().toUpperCase(Locale.ROOT)); }
/** * @param obj the translation object * @return the {@link Scope} stored in the object, null not assigned or unknown */ private Scope getScope(BaseObject obj) { if (obj != null) { StringProperty scopeProperty = (StringProperty) obj.getField(TranslationDocumentModel.TRANSLATIONCLASS_PROP_SCOPE); if (scopeProperty != null) { String scopeString = scopeProperty.getValue(); return EnumUtils.getEnum(Scope.class, scopeString.toUpperCase()); } } return null; }
public Object doInHibernate(Session session) throws HibernateException { Query q = session.createQuery("select s from BaseObject o, StringProperty s where o.className like 'XWiki.XWiki%Rights' and o.id=s.id and (s.name='users' or s.name='groups')"); List lst = q.list(); if (lst.size()==0) return null; List lst2 = new ArrayList(lst.size()); for (Iterator it=lst.iterator(); it.hasNext(); ) { StringProperty sp = (StringProperty) it.next(); LargeStringProperty lsp = new LargeStringProperty(); lsp.setId(sp.getId()); lsp.setName(sp.getName()); lsp.setValue(sp.getValue()); lst2.add(lsp); } for (Iterator it=lst.iterator(); it.hasNext(); ) session.delete(it.next()); for (Iterator it=lst2.iterator(); it.hasNext(); ) session.save(it.next()); 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; } }
/** * 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; } }
/** * 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; }
@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; }
/** * Sets the value to Ensembl ID for a given property. * * @param baseObject {@code BaseObject} containing the property name * @param propertyName the name of the property, for example {@code gene} * @return {@code StringProperty} for the provided property name * @throws XWikiException if property value cannot be set */ private StringProperty setPropertyValue(final BaseObject baseObject, final String propertyName) throws XWikiException { if (baseObject == null) { return null; } final StringProperty oldBaseObjProp = (StringProperty) baseObject.get(propertyName); if (oldBaseObjProp == null) { return null; } // Want to return oldBaseObjProp in case it is not null, that way it can still be renamed if the // genesymbol property, for whatever reason, contains no value. final String geneSymbol = oldBaseObjProp.getValue(); if (StringUtils.isBlank(geneSymbol)) { return oldBaseObjProp; } final String ensemblId = getEnsemblId(geneSymbol); baseObject.setStringValue(propertyName, ensemblId); return oldBaseObjProp; }
/** * Sets the value to Ensembl ID for a given property. * * @param baseObject {@code BaseObject} containing the property name * @param propertyName the name of the property, for example {@code gene} * @return {@code StringProperty} for the provided property name * @throws XWikiException if property value cannot be set */ private StringProperty setPropertyValue(final BaseObject baseObject, final String propertyName) throws XWikiException { if (baseObject == null) { return null; } final StringProperty oldBaseObjProp = (StringProperty) baseObject.get(propertyName); if (oldBaseObjProp == null) { return null; } // Want to return oldBaseObjProp in case it is not null, that way it can still be renamed if the // genesymbol property, for whatever reason, contains no value. final String geneSymbol = oldBaseObjProp.getValue(); if (StringUtils.isBlank(geneSymbol)) { return oldBaseObjProp; } final String ensemblId = getEnsemblId(geneSymbol); baseObject.setStringValue(propertyName, ensemblId); return oldBaseObjProp; }
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; }
@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; }
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); } } } } }