/** * @since 2.2.3 */ public void setLargeStringValue(EntityReference classReference, String fieldName, String value) { BaseObject bobject = prepareXObject(classReference); bobject.setLargeStringValue(fieldName, value); }
private void updatePatientGenesComment(XWikiDocument doc) { if (StringUtils.isNotBlank(this.commentsFromEmptyGenes)) { BaseObject patient = doc.getXObject(this.patientClassReference); patient.setLargeStringValue(GENETIC_NOTES_NAME, this.commentsFromEmptyGenes); } this.commentsFromEmptyGenes = ""; }
private void updatePatientGenesComment(XWikiDocument doc) { if (StringUtils.isNotBlank(this.commentsFromEmptyGenes)) { BaseObject patient = doc.getXObject(this.patientClassReference); patient.setLargeStringValue(GENETIC_NOTES_NAME, this.commentsFromEmptyGenes); } this.commentsFromEmptyGenes = ""; }
private void setRights(BaseObject rightsObject, String field, String value) { String currentValue = rightsObject.getStringValue(field); if (!StringUtils.isEmpty(currentValue)) { currentValue += ","; } rightsObject.setLargeStringValue(field, currentValue + value); } }
/** * Clears all users and groups from the existing rights objects. Stores the old rights in case of reversion. */ private void clearRights(Map<String, BaseObject> rightsObjects, Map<String, Map<String, String>> oldRights) { for (BaseObject right : rightsObjects.values()) { Map<String, String> entityList = new HashMap<>(); entityList.put(GROUPS, right.getStringValue(GROUPS)); entityList.put(USERS, right.getStringValue(USERS)); oldRights.put(right.getStringValue("levels"), entityList); right.setLargeStringValue(GROUPS, ""); right.setLargeStringValue(USERS, ""); } }
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); } } } } }
private void setRights(DocumentReference editor, XWikiDocument doc, XWikiContext context) throws XWikiException { BaseObject rights = doc.newXObject(RIGHTS_CLASS_REFERENCE, context); rights.setIntValue("allow", 1); rights.setStringValue("levels", "edit"); rights.setLargeStringValue("groups", editor.toString()); } }
private void setRights(DocumentReference editor, XWikiDocument doc, XWikiContext context) throws XWikiException { BaseObject rights = doc.newXObject(RIGHTS_CLASS_REFERENCE, context); rights.setIntValue("allow", 1); rights.setStringValue("levels", "edit"); rights.setLargeStringValue("groups", editor.toString()); } }
public void protectUserPage(String userName, String userRights, XWikiDocument doc, XWikiContext context) throws XWikiException { BaseClass rclass = getRightsClass(context); EntityReference rightClassReference = this.localReferenceEntityReferenceSerializer.serialize(rclass.getDocumentReference()); // Add protection to the page BaseObject newrightsobject = doc.newXObject(rightClassReference, context); newrightsobject.setLargeStringValue("groups", "XWiki.XWikiAdminGroup"); newrightsobject.setStringValue("levels", userRights); newrightsobject.setIntValue("allow", 1); BaseObject newuserrightsobject = doc.newXObject(rightClassReference, context); newuserrightsobject.setLargeStringValue("users", userName); newuserrightsobject.setStringValue("levels", userRights); newuserrightsobject.setIntValue("allow", 1); }
/** * Create the XWiki rights object in the cleaner job document. * * @param doc Cleaner job document * @param context the XWiki context * @return true if the document has been updated, false otherwise * @throws XWikiException if the object creation fails */ private boolean createWatchListJobRightsObject(XWikiDocument doc, XWikiContext context) throws XWikiException { BaseObject rights = doc.getObject(XWIKI_RIGHTS_CLASS); if (rights == null) { int index = doc.createNewObject(XWIKI_RIGHTS_CLASS, context); rights = doc.getObject(XWIKI_RIGHTS_CLASS, index); rights.setLargeStringValue("groups", "XWiki.XWikiAdminGroup"); rights.setStringValue("levels", "edit,delete"); rights.setIntValue("allow", 1); return true; } return false; }
editRights.setLargeStringValue(XWIKI_RIGHTS_CLASS_GROUPS_PROPERTY, "XWiki.XWikiAdminGroup"); editRights.setStringValue(XWIKI_RIGHTS_CLASS_LEVELS_PROPERTY, "edit,delete"); editRights.setIntValue(XWIKI_RIGHTS_CLASS_ALLOW_PROPERTY, 1); viewRights.setLargeStringValue(XWIKI_RIGHTS_CLASS_GROUPS_PROPERTY, "XWiki.XWikiAllGroup"); viewRights.setStringValue(XWIKI_RIGHTS_CLASS_LEVELS_PROPERTY, "view"); viewRights.setIntValue(XWIKI_RIGHTS_CLASS_ALLOW_PROPERTY, 1);
@Override public void refuseInvitation(MemberCandidacy invitation, String message) throws WikiUserManagerException { // Set the values invitation.setUserComment(message); invitation.setStatus(MemberCandidacy.Status.REJECTED); invitation.setDateOfClosure(new Date()); // Get the group document XWikiDocument groupDoc = getMembersGroupDocument(invitation.getWikiId()); // Get the candidacy object BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, invitation.getId()); // Set the new values object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, invitation.getUserComment()); object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, invitation.getDateOfClosure()); object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, invitation.getStatus().name().toLowerCase()); // Save the document saveGroupDocument(groupDoc, String.format("User [%s] has rejected the invitation to join the wiki.", invitation.getUserId())); } }
@Override public void refuseRequest(MemberCandidacy request, String message, String privateComment) throws WikiUserManagerException { // Update the candidacy object XWikiContext xcontext = xcontextProvider.get(); // Set the values request.setAdminId(documentReferenceSerializer.serialize(xcontext.getUserReference())); request.setAdminComment(message); request.setAdminPrivateComment(privateComment); request.setStatus(MemberCandidacy.Status.REJECTED); request.setDateOfClosure(new Date()); // Get the group document XWikiDocument groupDoc = getMembersGroupDocument(request.getWikiId()); // Get the candidacy object BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, request.getId()); // Set the new values object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, request.getAdminId()); object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, request.getAdminComment()); object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT, request.getAdminPrivateComment()); object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, request.getDateOfClosure()); object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, request.getStatus().name().toLowerCase()); // Save the document saveGroupDocument(groupDoc, String.format("Reject join request from user [%s]", request.getUserId())); }
/** * Saves the data specified in {@code medication}. * * @param docX the {@link XWikiDocument} * @param medication a {@link Medication} to save * @param context the {@link XWikiContext} */ private void saveMedication( @Nonnull final XWikiDocument docX, @Nonnull final Medication medication, @Nonnull final XWikiContext context) { try { final BaseObject o = docX.newXObject(Medication.CLASS_REFERENCE, context); o.setStringValue(Medication.NAME, medication.getName()); o.setStringValue(Medication.GENERIC_NAME, medication.getGenericName()); o.setStringValue(Medication.DOSE, medication.getDose()); o.setStringValue(Medication.FREQUENCY, medication.getFrequency()); if (medication.getDuration() != null) { o.setIntValue(DURATION_YEARS, medication.getDuration().getYears()); o.setIntValue(DURATION_MONTHS, medication.getDuration().getMonths()); } if (medication.getEffect() != null) { o.setStringValue(Medication.EFFECT, medication.getEffect().toString()); } o.setLargeStringValue(Medication.NOTES, medication.getNotes()); } catch (final Exception ex) { this.logger.error("Failed to save medication data: [{}]", ex.getMessage()); } }
@Override public void acceptRequest(MemberCandidacy request, String message, String privateComment) throws WikiUserManagerException { // Add the user to the members addMember(request.getUserId(), request.getWikiId()); // Then, update the candidacy object XWikiContext xcontext = xcontextProvider.get(); // Set the values request.setAdminId(documentReferenceSerializer.serialize(xcontext.getUserReference())); request.setAdminComment(message); request.setAdminPrivateComment(privateComment); request.setStatus(MemberCandidacy.Status.ACCEPTED); request.setDateOfClosure(new Date()); // Get the group document XWikiDocument groupDoc = getMembersGroupDocument(request.getWikiId()); // Get the candidacy object BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, request.getId()); // Set the new values object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, request.getAdminId()); object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, request.getAdminComment()); object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT, request.getAdminPrivateComment()); object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, request.getDateOfClosure()); object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, request.getStatus().name().toLowerCase()); // Save the document saveGroupDocument(groupDoc, String.format("Accept join request from user [%s]", request.getUserId())); }
@Override public void acceptInvitation(MemberCandidacy invitation, String message) throws WikiUserManagerException { // Add the user to the members addMember(invitation.getUserId(), invitation.getWikiId()); // Set the values invitation.setUserComment(message); invitation.setStatus(MemberCandidacy.Status.ACCEPTED); invitation.setDateOfClosure(new Date()); // Get the group document XWikiDocument groupDoc = getMembersGroupDocument(invitation.getWikiId()); // Get the candidacy object BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, invitation.getId()); // Set the new values object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, invitation.getUserComment()); object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, invitation.getDateOfClosure()); object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, invitation.getStatus().name().toLowerCase()); // Save the document saveGroupDocument(groupDoc, String.format("User [%s] has accepted to join the wiki. ", invitation.getUserId())); }
o.setStringValue(Medication.EFFECT, m.getEffect().toString()); o.setLargeStringValue(Medication.NOTES, m.getNotes());
@Override public void store(EntityReference entity, byte[] signature) throws SignatureStoreException { checkArguments(entity); // TODO: Support object property as parent DocumentReference docRef = this.resolver.resolve(entity.getParent()); XWikiContext context = this.contextProvider.get(); try { XWikiDocument document = context.getWiki().getDocument(docRef, context); DocumentReference signatureClass = new DocumentReference(SIGNATURECLASS, docRef.getWikiReference()); // TODO: Support any kind of entity by serializing the reference and its type properly String entityReference = entity.getName(); BaseObject object = document.getXObject(signatureClass, SIGNATURECLASS_PROP_REFERENCE, entityReference); if (object == null) { object = document.newXObject(SIGNATURECLASS, context); object.setStringValue(SIGNATURECLASS_PROP_REFERENCE, entityReference); } object.setLargeStringValue(SIGNATURECLASS_PROP_SIGNATURE, this.base64.encode(signature, 64)); context.getWiki().saveDocument(document, context); } catch (XWikiException e) { throw new SignatureStoreException("Error while storing signature for entity [" + entity + "]", e); } catch (IOException e) { throw new SignatureStoreException("Error while encoding signature for entity [" + entity + "]", e); } }
private void storeKeyPair(StoreReference store, CertifiedPublicKey certificate, byte[] privateKey) throws KeyStoreException { XWikiContext context = getXWikiContext(); XWikiDocument document; try { document = storeCertificate(store, certificate, context); } catch (CertificateStoreException e) { throw new KeyStoreException("Error while preparing certificate to store a key pair in [" + store + "]", e); } try { BaseObject obj = document.getXObject(PRIVATEKEYCLASS); if (obj == null) { obj = document.newXObject(PRIVATEKEYCLASS, context); } obj.setLargeStringValue(PRIVATEKEYCLASS_PROP_KEY, getEncoder().encode(privateKey, 64)); context.getWiki().saveDocument(document, context); } catch (IOException e) { throw new KeyStoreException("Error while preparing private key for [" + document.getDocumentReference() + "]", e); } catch (XWikiException e) { throw new KeyStoreException("Error while saving key pair for [" + document.getDocumentReference() + "]", e); } }