/** * Clears any stored feature data. * * @param docX the {@link XWikiDocument} * @param dataHolder the {@link BaseObject} holding features data * @param context the {@link XWikiContext} */ private void clearFeatureData( @Nonnull final XWikiDocument docX, @Nonnull final BaseObject dataHolder, @Nonnull final XWikiContext context) { Arrays.stream(PHENOTYPE_PROPERTIES).forEach(type -> dataHolder.set(type, null, context)); docX.removeXObjects(FeatureMetadatum.CLASS_REFERENCE); docX.removeXObjects(PhenoTipsFeature.CATEGORY_CLASS_REFERENCE); }
/** * Remove all the objects of a given type (XClass) from the document. The object counter is left unchanged, so that * future objects will have new (different) numbers. However, on some storage engines the counter will be reset if * the document is removed from the cache and reloaded from the persistent storage. * * @param className The class name of the objects to be removed. * @return {@code true} if the objects were successfully removed, {@code false} if no object from the target class * was in the current document. * @deprecated since 2.2M1 use {@link #removeXObjects(org.xwiki.model.reference.DocumentReference)} instead */ @Deprecated public boolean removeObjects(String className) { return removeXObjects(resolveClassReference(className)); }
doc.removeXObjects(VARIANT_CLASS_REFERENCE); return;
/** * Saves {@code variants} data for {@code patient} according to the provided {@code policy}. * * @param docX the {@link XWikiDocument} for patient * @param patient the {@link Patient} object of interest * @param variants the newly added variant data * @param policy the policy according to which data should be saved * @param context the {@link XWikiContext} object */ private void saveVariants( @Nonnull final XWikiDocument docX, @Nonnull final Patient patient, @Nonnull final PatientData<Map<String, String>> variants, @Nonnull final PatientWritePolicy policy, @Nonnull final XWikiContext context) { if (PatientWritePolicy.MERGE.equals(policy)) { final Map<String, Map<String, String>> mergedVariants = getMergedVariantsMap(variants, load(patient)); docX.removeXObjects(VARIANT_CLASS_REFERENCE); mergedVariants.forEach((id, variant) -> saveVariant(docX, variant, context)); } else { docX.removeXObjects(VARIANT_CLASS_REFERENCE); variants.forEach(variant -> saveVariant(docX, variant, context)); } }
/** * Saves the identifiers data specified in the {@link PatientData} class. * * @param doc the XWiki document for the patient * @param patient the patient object with data to be saved * @param identifiers a {@link PatientData} object defining existing external identifiers for the patient * @param doc the XWiki document for the patient */ private void saveIdentifiers( @Nonnull final XWikiDocument doc, @Nonnull final Patient patient, @Nonnull final PatientData<Pair<String, String>> identifiers, @Nonnull final PatientWritePolicy policy) { if (PatientWritePolicy.MERGE.equals(policy)) { final List<Pair<String, String>> mergedEids = getMergedIdentifiers(load(patient), identifiers); doc.removeXObjects(IDENTIFIER_CLASS_REFERENCE); mergedEids.forEach(identifier -> saveIdentifier(identifier, doc)); } else { doc.removeXObjects(IDENTIFIER_CLASS_REFERENCE); identifiers.forEach(identifier -> saveIdentifier(identifier, doc)); } }
@Override public void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy) { try { final XWikiDocument docX = patient.getXDocument(); final PatientData<Gene> genes = patient.getData(getName()); if (genes == null) { if (PatientWritePolicy.REPLACE.equals(policy)) { docX.removeXObjects(Gene.GENE_CLASS); } } else if (!genes.isIndexed()) { this.logger.info("Wrong data type for gene data"); } else { saveGenes(docX, patient, genes, policy, this.xcontextProvider.get()); } } catch (final Exception ex) { this.logger.error("Failed to save genes data: {}", ex.getMessage(), ex); } }
: null; doc.removeXObjects(CLASS_REFERENCE); if (storedImages == null || storedImages.size() == 0) { images.forEach(image -> saveAttachment(doc, image, context));
@Override public void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy) { try { final XWikiDocument docX = patient.getXDocument(); final PatientData<Map<String, String>> variants = patient.getData(getName()); if (variants == null) { if (PatientWritePolicy.REPLACE.equals(policy)) { docX.removeXObjects(VARIANT_CLASS_REFERENCE); } } else { if (!variants.isIndexed()) { this.logger.error(ERROR_MESSAGE_DATA_IN_MEMORY_IN_WRONG_FORMAT); return; } saveVariants(docX, patient, variants, policy, this.xcontextProvider.get()); } } catch (final Exception ex) { this.logger.error("Failed to save variant list data: {}", ex.getMessage(), ex); } }
@Override public void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy) { try { final XWikiDocument docX = patient.getXDocument(); final PatientData<Attachment> images = patient.getData(getName()); if (images == null) { if (PatientWritePolicy.REPLACE.equals(policy)) { docX.removeXObjects(CLASS_REFERENCE); } } else { if (!images.isIndexed()) { this.logger.error(ERROR_MESSAGE_DATA_IN_MEMORY_IN_WRONG_FORMAT); return; } saveAttachments(docX, patient, images, policy, this.contextProvider.get()); } } catch (final Exception ex) { this.logger.error("Failed to save attachment: {}", ex.getMessage(), ex); } }
@Override public void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy) { try { final XWikiDocument doc = patient.getXDocument(); final PatientData<Pair<String, String>> identifiers = patient.getData(IDENTIFIERS_STRING); if (identifiers == null) { if (PatientWritePolicy.REPLACE.equals(policy)) { doc.removeXObjects(IDENTIFIER_CLASS_REFERENCE); } } else { if (!identifiers.isIndexed()) { this.logger.error(ERROR_MESSAGE_DATA_IN_MEMORY_IN_WRONG_FORMAT); return; } saveIdentifiers(doc, patient, identifiers, policy); } } catch (final Exception ex) { this.logger.error("Failed to save labeled external identifiers data: {}", ex.getMessage(), ex); } }
@Override public void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy) { try { final XWikiDocument docX = patient.getXDocument(); final PatientData<Medication> medications = patient.getData(getName()); if (medications == null) { if (PatientWritePolicy.REPLACE.equals(policy)) { docX.removeXObjects(Medication.CLASS_REFERENCE); } } else { if (!medications.isIndexed()) { this.logger.error(ERROR_MESSAGE_DATA_IN_MEMORY_IN_WRONG_FORMAT); return; } saveMedications(docX, patient, medications, policy, this.xcontext.get()); } } catch (final Exception ex) { this.logger.error("Failed to save medication data: {}", ex.getMessage(), ex); } }
@Override public void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy) { try { final XWikiDocument docX = patient.getXDocument(); final PatientData<Attachment> files = patient.getData(getName()); if (files == null) { if (PatientWritePolicy.REPLACE.equals(policy)) { docX.removeXObjects(CLASS_REFERENCE); } } else { if (!files.isIndexed()) { this.logger.error(ERROR_MESSAGE_DATA_IN_MEMORY_IN_WRONG_FORMAT); return; } saveAttachments(docX, patient, files, policy, this.contextProvider.get()); } } catch (final Exception ex) { this.logger.error("Failed to save attachment: {}", ex.getMessage(), ex); } }
/** * Saves {@code genes} data for {@code patient} according to the provided {@code policy}. * * @param docX the {@link XWikiDocument} for patient * @param patient the {@link Patient} object of interest * @param data the newly added gene data * @param policy the policy according to which data should be saved * @param context the {@link XWikiContext} object */ private void saveGenes( @Nonnull final XWikiDocument docX, @Nonnull final Patient patient, @Nonnull final PatientData<Gene> data, @Nonnull final PatientWritePolicy policy, @Nonnull final XWikiContext context) { docX.removeXObjects(Gene.GENE_CLASS); if (PatientWritePolicy.MERGE.equals(policy)) { final Map<String, Gene> mergedGenes = getMergedGenes(data, load(patient)); mergedGenes.forEach((id, gene) -> saveGene(docX, gene, context)); } else { data.forEach(gene -> saveGene(docX, gene, context)); } }
@Override public void save(Patient patient, DocumentModelBridge doc) { PatientData<Map<String, String>> genes = patient.getData(this.getName()); if (genes == null || !genes.isIndexed()) { return; } if (doc == null) { throw new NullPointerException(ERROR_MESSAGE_NO_PATIENT_CLASS); } XWikiContext context = this.xcontextProvider.get(); ((XWikiDocument) doc).removeXObjects(GENE_CLASS_REFERENCE); Iterator<Map<String, String>> iterator = genes.iterator(); while (iterator.hasNext()) { try { Map<String, String> gene = iterator.next(); BaseObject xwikiObject = ((XWikiDocument) doc).newXObject(GENE_CLASS_REFERENCE, context); for (String property : this.getProperties()) { String value = gene.get(property); if (value != null) { xwikiObject.set(property, value, context); } } } catch (Exception e) { this.logger.error("Failed to save a specific gene: [{}]", e.getMessage()); } } }
private void updateCategories(PatientData<Feature> features, XWikiDocument doc, XWikiContext context) throws XWikiException { doc.removeXObjects(PhenoTipsFeature.CATEGORY_CLASS_REFERENCE); Iterator<Feature> iterator = features.iterator(); while (iterator.hasNext()) { Feature feature = iterator.next(); List<String> categories = feature.getCategories(); if (categories.isEmpty()) { continue; } BaseObject categoriesObject = doc.newXObject(PhenoTipsFeature.CATEGORY_CLASS_REFERENCE, context); categoriesObject.set(PhenoTipsFeature.META_PROPERTY_NAME, feature.getPropertyName(), context); categoriesObject.set(PhenoTipsFeature.META_PROPERTY_VALUE, feature.getValue(), context); categoriesObject.set(PhenoTipsFeature.META_PROPERTY_CATEGORIES, categories, context); } }
@Override public boolean unlockPatientRecord(Patient patient) { try { XWikiDocument patientDocument = this.getPatientDocument(patient); if (this.isDocumentLocked(patientDocument) && this.hasLockingPermission(patient)) { XWikiContext context = this.contextProvider.get(); XWiki xwiki = context.getWiki(); patientDocument.removeXObjects(this.lockClassReference); xwiki.saveDocument(patientDocument, "Unlocked patient record", true, context); return true; } else { return false; } } catch (XWikiException | NullPointerException e) { return false; } }
@Override public boolean unlockPatientRecord(Patient patient) { try { XWikiDocument patientDocument = patient.getXDocument(); if (this.isDocumentLocked(patientDocument) && this.hasLockingPermission(patient)) { XWikiContext context = this.contextProvider.get(); XWiki xwiki = context.getWiki(); patientDocument.removeXObjects(this.lockClassReference); xwiki.saveDocument(patientDocument, "Unlocked patient record", true, context); return true; } else { return false; } } catch (XWikiException | NullPointerException e) { return false; } }
private void updateMetaData(PatientData<Feature> features, XWikiDocument doc, XWikiContext context) throws XWikiException { doc.removeXObjects(FeatureMetadatum.CLASS_REFERENCE); Iterator<Feature> iterator = features.iterator(); while (iterator.hasNext()) { Feature feature = iterator.next(); @SuppressWarnings("unchecked") Map<String, FeatureMetadatum> metadataMap = (Map<String, FeatureMetadatum>) feature.getMetadata(); if (metadataMap.isEmpty() && feature.getNotes().isEmpty()) { continue; } BaseObject metaObject = doc.newXObject(FeatureMetadatum.CLASS_REFERENCE, context); metaObject.set(PhenoTipsFeature.META_PROPERTY_NAME, feature.getPropertyName(), context); metaObject.set(PhenoTipsFeature.META_PROPERTY_VALUE, feature.getValue(), context); for (String type : metadataMap.keySet()) { PhenoTipsFeatureMetadatum metadatum = (PhenoTipsFeatureMetadatum) metadataMap.get(type); metaObject.set(type, metadatum.getId(), context); } metaObject.set("comments", feature.getNotes(), context); } }
/** * Given a {@link XWikiDocument}, update the document XObjects to the new NotificationPreferenceFilterClass. * * @param document the document to migrate */ private void migrateDocument(XWikiDocument document) throws XWikiException { final DocumentReference oldClassReference = getOldClassReference(); List<BaseObject> oldXObjects = document.getXObjects(oldClassReference); for (BaseObject oldXObject : oldXObjects) { document.addXObject(generateNewXObject(oldXObject)); } document.removeXObjects(oldClassReference); XWikiContext context = contextProvider.get(); context.getWiki().saveDocument(document, "[UPGRADE] XObject migration from ScopeNotificationFilterClass to NotificationPreferenceFilterClass.", context); }
@Override public boolean setCollaborators(Patient patient, Collection<Collaborator> newCollaborators) { try { XWikiDocument patientDoc = (XWikiDocument) this.bridge.getDocument(patient.getDocument()); DocumentReference classReference = this.partialEntityResolver.resolve(Collaborator.CLASS_REFERENCE, patient.getDocument()); XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); patientDoc.removeXObjects(classReference); for (Collaborator collaborator : newCollaborators) { BaseObject o = patientDoc.newXObject(classReference, context); o.setStringValue("collaborator", this.entitySerializer.serialize(collaborator.getUser())); o.setStringValue("access", collaborator.getAccessLevel().getName()); } context.getWiki().saveDocument(patientDoc, "Updated collaborators", true, context); return true; } catch (Exception e) { // This should not happen; } return false; }