@Override public void setProperty( @Nonnull final XWikiDocument doc, @Nullable final DocumentReference classReference, @Nullable final String propertyName, @Nullable final Object propertyValue) { XWikiContext xcontext = this.xcontextProvider.get(); BaseObject obj = doc.getXObject(classReference, true, xcontext); if (obj != null) { obj.set(propertyName, propertyValue, xcontext); doc.setAuthorReference(getCurrentUser()); doc.setMetaDataDirty(true); } } }
private boolean savePatientDocument(XWikiDocument patientDocument, String documentHistoryComment, XWikiContext context) { try { patientDocument.setAuthorReference(context.getUserReference()); context.getWiki().saveDocument(patientDocument, documentHistoryComment, context); } catch (XWikiException e) { this.logger.error("Error saving patient [{}] document for commit {}: [{}]", patientDocument.getId(), documentHistoryComment, e.getMessage()); return false; } return true; }
document.setAuthorReference(context.getUserReference());
if (creator != null) { doc.setCreatorReference(creator); doc.setAuthorReference(creator); doc.setContentAuthorReference(creator);
private boolean savePatientDocument(XWikiDocument patientDocument, String documentHistoryComment, XWikiContext context) { try { patientDocument.setAuthorReference(context.getUserReference()); context.getWiki().saveDocument(patientDocument, documentHistoryComment, context); } catch (XWikiException e) { this.logger.error("Error saving patient [{}] document for commit {}: [{}]", patientDocument.getId(), documentHistoryComment, e.getMessage()); return false; } return true; }
/** * Add a tag to a document. The document is saved (minor edit) after this operation. * * @param tag tag to set. * @param document the document. * @param context XWiki context. * @return the {@link TagOperationResult result} of the operation * @throws XWikiException if document save fails (possible failures: insufficient rights, DB access problems, etc). */ public TagOperationResult addTagToDocument(String tag, XWikiDocument document, XWikiContext context) throws XWikiException { List<String> tags = getTagsFromDocument(document); if (!StringUtils.isBlank(tag) && !tags.contains(tag)) { tags.add(tag); setDocumentTags(document, tags, context); String comment = localizePlainOrKey(DOC_COMMENT_TAG_ADDED, tag); // Since we're changing the document we need to set the new author document.setAuthorReference(context.getUserReference()); context.getWiki().saveDocument(document, comment, true, context); return TagOperationResult.OK; } return TagOperationResult.NO_EFFECT; }
document.setAuthorReference(context.getUserReference());
private synchronized boolean saveFamilyDocument(Family family, String documentHistoryComment, XWikiContext context) { try { family.getXDocument().setAuthorReference(context.getUserReference()); context.getWiki().saveDocument(family.getXDocument(), documentHistoryComment, context); } catch (XWikiException e) { this.logger.error("Error saving family [{}] document for commit {}: [{}]", family.getId(), documentHistoryComment, e.getMessage()); return false; } return true; }
private synchronized boolean saveFamilyDocument(Family family, String documentHistoryComment, XWikiContext context) { try { family.getDocument().setAuthorReference(context.getUserReference()); context.getWiki().saveDocument(family.getDocument(), documentHistoryComment, context); } catch (XWikiException e) { this.logger.error("Error saving family [{}] document for commit {}: [{}]", family.getId(), documentHistoryComment, e.getMessage()); return false; } return true; }
/** * HACK: Save the given document without changing the content author because the document may loose or win * programming and script rights as a consequence and this is not the intent of this operation. Even though the * document content field was modified, the change is purely syntactic; the semantic is not affected so it's not * clear whether the content author deserves to be updated or not (even without the side effects). * * @param document the document to be saved * @param comment the revision comment * @param minorEdit whether it's a minor edit or not * @throws XWikiException if saving the document fails */ private void saveDocumentPreservingContentAuthor(XWikiDocument document, String comment, boolean minorEdit) throws XWikiException { XWikiContext xcontext = this.xcontextProvider.get(); // Preserve the content author. document.setContentDirty(false); // Make sure the version is incremented. document.setMetaDataDirty(true); document.setAuthorReference(xcontext.getUserReference()); xcontext.getWiki().saveDocument(document, comment, minorEdit, xcontext); } }
/** * Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument. * * @deprecated since 3.0M3 use {@link #setAuthorReference} instead */ @Deprecated public void setAuthor(String author) { // Note: Consider "" or null as the same, i.e. the author not being set DocumentReference authorReference = null; if (author != null && author.length() > 0) { authorReference = this.explicitReferenceDocumentReferenceResolver.resolve( this.xClassEntityReferenceResolver.resolve(author, EntityType.DOCUMENT), getDocumentReference()); } if ((getAuthorReference() == null && authorReference != null) || (getAuthorReference() != null && !getAuthorReference().equals(authorReference))) { setMetaDataDirty(true); } setAuthorReference(authorReference); }
private boolean setWikiMacroClassesDocumentFields(XWikiDocument doc, String title) { boolean needsUpdate = false; if (StringUtils.isBlank(doc.getCreator())) { needsUpdate = true; doc.setCreator(XWikiRightService.SUPERADMIN_USER); } if (StringUtils.isBlank(doc.getAuthor())) { needsUpdate = true; doc.setAuthorReference(doc.getCreatorReference()); } if (StringUtils.isBlank(doc.getParent())) { needsUpdate = true; doc.setParent("XWiki.XWikiClasses"); } if (StringUtils.isBlank(doc.getTitle())) { needsUpdate = true; doc.setTitle(title); } if (StringUtils.isBlank(doc.getContent()) || !Syntax.XWIKI_2_0.equals(doc.getSyntax())) { needsUpdate = true; doc.setContent("{{include document=\"XWiki.ClassSheet\" /}}"); doc.setSyntax(Syntax.XWIKI_2_0); } return needsUpdate; }
@Override public synchronized E create(DocumentReference creator) { try { XWikiContext context = this.xcontextProvider.get(); DocumentReference newDoc = getNextDocument(); XWikiDocument doc = (XWikiDocument) this.bridge.getDocument(newDoc); DocumentReference template = getEntityXClassReference(); template = new DocumentReference(template.getName().concat("Template"), template.getLastSpaceReference()); if (!this.bridge.exists(template)) { template = new DocumentReference(template.getName().replaceAll("Class(Template)$", "$1"), template.getLastSpaceReference()); } if (this.bridge.exists(template)) { doc.readFromTemplate(template, context); } if (creator != null) { doc.setCreatorReference(creator); doc.setAuthorReference(creator); doc.setContentAuthorReference(creator); } context.getWiki().saveDocument(doc, context); return load(doc); } catch (Exception ex) { this.logger.warn("Failed to create entity: {}", ex.getMessage(), ex); return null; } }
@Override public synchronized E create(DocumentReference creator) { try { XWikiContext context = this.xcontextProvider.get(); DocumentReference newDoc = getNextDocument(); XWikiDocument doc = (XWikiDocument) this.bridge.getDocument(newDoc); DocumentReference template = getEntityXClassReference(); template = new DocumentReference(template.getName().concat("Template"), template.getLastSpaceReference()); if (!this.bridge.exists(template)) { template = new DocumentReference(template.getName().replaceAll("Class(Template)$", "$1"), template.getLastSpaceReference()); } if (this.bridge.exists(template)) { doc.readFromTemplate(template, context); } if (creator != null) { doc.setCreatorReference(creator); doc.setAuthorReference(creator); doc.setContentAuthorReference(creator); } context.getWiki().saveDocument(doc, context); return load(doc); } catch (Exception ex) { this.logger.warn("Failed to create entity: {}", ex.getMessage(), ex); return null; } }
private void saveGroupDocument(XWikiDocument document, String message) throws WikiUserManagerException { // Get the XWiki objects XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); // The document should be hidden document.setHidden(true); // The document must have a creator if (document.getCreatorReference() == null) { document.setCreatorReference(xcontext.getUserReference()); } // The document must have an author if (document.getAuthorReference() == null) { document.setAuthorReference(xcontext.getUserReference()); } // Save the document try { xwiki.saveDocument(document, message, xcontext); } catch (XWikiException e) { throw new WikiUserManagerException("Fail to save the member group", e); } }
@Override public void save(WikiPropertyGroup group, String wikiId) throws WikiPropertyGroupException { XWikiContext context = xcontextProvider.get(); XWiki xwiki = context.getWiki(); WikiTemplatePropertyGroup templateGroup = (WikiTemplatePropertyGroup) group; try { XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId); BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS, true, context); object.setIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, templateGroup.isTemplate() ? 1 : 0); // The document must have a creator if (descriptorDocument.getCreatorReference() == null) { descriptorDocument.setCreatorReference(context.getUserReference()); } // The document must have an author if (descriptorDocument.getAuthorReference() == null) { descriptorDocument.setAuthorReference(context.getUserReference()); } xwiki.saveDocument(descriptorDocument, String.format("Changed property group [%s].", GROUP_NAME), context); } catch (WikiManagerException e) { throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e); } catch (XWikiException e) { throw new WikiPropertyGroupException("Unable to save descriptor document.", e); } }
private void setDescriptorDocMetadata(XWikiDocument descriptorDoc) { XWikiContext context = xcontextProvider.get(); // Set the document as hidden descriptorDoc.setHidden(true); // The document must have a creator if (descriptorDoc.getCreatorReference() == null) { descriptorDoc.setCreatorReference(context.getUserReference()); } // The document must have an author if (descriptorDoc.getAuthorReference() == null) { descriptorDoc.setAuthorReference(context.getUserReference()); } // Set the document parent if (descriptorDoc.getParentReference() == null) { EntityReference parentReference = new EntityReference("WebHome", EntityType.DOCUMENT); parentReference.appendParent(new EntityReference("WikiManager", EntityType.SPACE)); descriptorDoc.setParentReference(parentReference); } } }
document.setAuthorReference(context.getUserReference());
private synchronized XWikiDocument createFamilyDocument(User creator) throws IllegalArgumentException, QueryException, XWikiException { XWikiContext context = this.provider.get(); XWiki wiki = context.getWiki(); long nextId = getLastUsedId(); DocumentReference newFamilyRef; do { newFamilyRef = this.entityReferenceResolver.resolve(new EntityReference( String.format("%s%07d", PREFIX, ++nextId), EntityType.DOCUMENT, Family.DATA_SPACE)); } while (wiki.exists(newFamilyRef, context)); XWikiDocument newFamilyDoc = wiki.getDocument(newFamilyRef, context); // Copying all objects from template to family newFamilyDoc.readFromTemplate( this.entityReferenceResolver.resolve(FAMILY_TEMPLATE), context); // Adding additional values to family BaseObject ownerObject = newFamilyDoc.newXObject(Owner.CLASS_REFERENCE, context); ownerObject.set("owner", creator == null ? "" : creator.getId(), context); BaseObject familyObject = newFamilyDoc.getXObject(Family.CLASS_REFERENCE); familyObject.set("identifier", nextId, context); if (creator != null) { DocumentReference creatorRef = creator.getProfileDocument(); newFamilyDoc.setCreatorReference(creatorRef); newFamilyDoc.setAuthorReference(creatorRef); newFamilyDoc.setContentAuthorReference(creatorRef); } this.updateFamilyPermissions(new PhenotipsFamily(newFamilyDoc), context, false); wiki.saveDocument(newFamilyDoc, context); return newFamilyDoc; }
public LDAPProfileXClass(XWikiContext context) throws XWikiException { this.context = context; XWikiDocument ldapClassDoc = context.getWiki().getDocument(LDAPPROFILECLASS_REFERENCE, context); this.ldapClass = ldapClassDoc.getXClass(); boolean needsUpdate = this.ldapClass.addTextField(LDAP_XFIELD_DN, LDAP_XFIELDPN_DN, 80); needsUpdate |= this.ldapClass.addTextField(LDAP_XFIELD_UID, LDAP_XFIELDPN_UID, 80); if (ldapClassDoc.getCreatorReference() == null) { needsUpdate = true; ldapClassDoc.setCreator(XWikiRightService.SUPERADMIN_USER); } if (ldapClassDoc.getAuthorReference() == null) { needsUpdate = true; ldapClassDoc.setAuthorReference(ldapClassDoc.getCreatorReference()); } if (!ldapClassDoc.isHidden()) { needsUpdate = true; ldapClassDoc.setHidden(true); } if (needsUpdate) { context.getWiki().saveDocument(ldapClassDoc, "Update LDAP user profile class", context); } }