/** * Set the read-only flag of a directory entry. To be used by EntryAdaptor implementations for instance. * * @since 5.3.2 */ public static void setReadOnlyEntry(DocumentModel entry) { entry.putContextData(READONLY_ENTRY_FLAG, Boolean.TRUE); }
/** * Unset the read-only flag of a directory entry. To be used by EntryAdaptor implementations for instance. * * @since 5.3.2 */ public static void setReadWriteEntry(DocumentModel entry) { entry.putContextData(READONLY_ENTRY_FLAG, Boolean.FALSE); }
protected void restoreEvents(DocumentModel doc) { doc.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, null); doc.putContextData(NotificationConstants.DISABLE_NOTIFICATION_SERVICE, null); doc.putContextData(NXAuditEventsService.DISABLE_AUDIT_LOGGER, null); doc.putContextData(VersioningService.DISABLE_AUTO_CHECKOUT, null); }
protected void disableEvents(DocumentModel doc) { doc.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, TRUE); doc.putContextData(NotificationConstants.DISABLE_NOTIFICATION_SERVICE, TRUE); doc.putContextData(NXAuditEventsService.DISABLE_AUDIT_LOGGER, TRUE); doc.putContextData(VersioningService.DISABLE_AUTO_CHECKOUT, TRUE); }
@Override protected void beforeCreateDocument(DocumentModel doc) { doc.putContextData(CTX_MAP_KEY, TURN_OFF); } }
protected void saveDocument(CoreSession session, DocumentModel doc) { doc.putContextData(VersioningService.DISABLE_AUTO_CHECKOUT, Boolean.TRUE); doc.putContextData(DISABLE_VERSIONING, Boolean.TRUE); doc.putContextData(DISABLE_DUBLINCORE_LISTENER, Boolean.TRUE); doc.putContextData(DISABLE_AUDIT_LOGGER, Boolean.TRUE); session.saveDocument(doc); }
private void throwUpdateComments(DocumentModel changeableDocument) { if (comment != null && !"".equals(comment)) { changeableDocument.putContextData("comment", comment); } }
/** * Fills the {@code doc} context data with a comment from the {@code Update-Comment} header if present. * * @since 9.3 */ protected void updateCommentFromHeader(HttpHeaders headers) { List<String> updateCommentHeader = headers.getRequestHeader(RestConstants.UPDATE_COMMENT_HEADER); if (updateCommentHeader != null && !updateCommentHeader.isEmpty()) { String comment = updateCommentHeader.get(0); doc.putContextData("comment", comment); } } }
protected void setTags(DocumentModel docModel, List<Map<String, Serializable>> tags) { try { if (docModel.isVersion()) { docModel.putContextData(ALLOW_VERSION_WRITE, Boolean.TRUE); } docModel.setPropertyValue(TAG_LIST, (Serializable) tags); } catch (PropertyNotFoundException e) { log.warn( "Setting tags on {} failed since {} is missing on {} document type. This operation will be ignored.", docModel::getPathAsString, () -> TAG_FACET, docModel::getType); } } }
protected void resetTranscodedVideos(DocumentModel doc) { log.warn(String.format("No original video to transcode, resetting transcoded videos of document %s.", doc)); setStatus("No video to process"); doc.setPropertyValue(TRANSCODED_VIDEOS_PROPERTY, null); if (doc.isVersion()) { doc.putContextData(ALLOW_VERSION_WRITE, Boolean.TRUE); } session.saveDocument(doc); }
@Override public void updateDocuments(CoreSession session, DocumentModel sourceDoc, List<DocumentModel> targetDocs) { List<String> propertiesToCopy = getPropertiesToCopy(sourceDoc); if (propertiesToCopy.isEmpty()) { return; } for (DocumentModel targetDoc : targetDocs) { for (String propertyToCopy : propertiesToCopy) { try { targetDoc.setPropertyValue(propertyToCopy, sourceDoc.getPropertyValue(propertyToCopy)); } catch (PropertyNotFoundException e) { String message = "%s property does not exist on %s"; log.warn(String.format(message, propertyToCopy, targetDoc)); } } targetDoc.putContextData(CoreSession.SOURCE, "bulkEdit"); session.saveDocument(targetDoc); } }
protected void saveNewTranscodedVideo(DocumentModel doc, TranscodedVideo transcodedVideo) { @SuppressWarnings("unchecked") List<Map<String, Serializable>> transcodedVideos = (List<Map<String, Serializable>>) doc.getPropertyValue( TRANSCODED_VIDEOS_PROPERTY); if (transcodedVideos == null) { transcodedVideos = new ArrayList<>(); } else { transcodedVideos = transcodedVideos.stream() .filter(map -> !transcodedVideo.getName().equals(map.get("name"))) .collect(Collectors.toList()); } transcodedVideos.add(transcodedVideo.toMap()); doc.setPropertyValue(TRANSCODED_VIDEOS_PROPERTY, (Serializable) transcodedVideos); if (doc.isVersion()) { doc.putContextData(ALLOW_VERSION_WRITE, Boolean.TRUE); } session.saveDocument(doc); }
protected DocumentModel loadDocument() throws DocumentNotFoundException { final DocumentRef docRef = getDocument().getDocRef(); DocumentModel doc = session.getDocument(docRef); doc.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true); return doc; }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws ConcurrentUpdateException, IOException { if (changeToken != null) { // Check for dirty update doc.putContextData(CoreSession.CHANGE_TOKEN, changeToken); } DocumentHelper.setProperties(session, doc, properties); if (save) { doc = session.saveDocument(doc); // may throw ConcurrentUpdateException if bad change token } return doc; }
protected void undeleteDocument(CoreSession session, DocumentModel doc) { String name = doc.getName(); if (!TRUE.equals(doc.getContextData(DISABLE_TRASH_RENAMING))) { String newName = unmangleName(doc); if (!newName.equals(name)) { session.move(doc.getRef(), doc.getParentRef(), newName); } } doc.putContextData(FROM_LIFE_CYCLE_TRASH_SERVICE, TRUE); session.followTransition(doc, LifeCycleConstants.UNDELETE_TRANSITION); }
@Override public DocumentModel saveParams(List<TemplateInput> params, boolean save) { String dataPath = getTemplateParamsXPath(); String xml = XMLSerializer.serialize(params); adaptedDoc.setPropertyValue(dataPath, xml); adaptedDoc.putContextData(TemplateSourceDocument.INIT_DONE_FLAG, true); if (save) { doSave(); } return adaptedDoc; }
protected void trashDocument(CoreSession session, DocumentModel doc) { if (doc.getParentRef() == null) { // handle placeless document session.removeDocument(doc.getRef()); } else { if (!TRUE.equals(doc.getContextData(DISABLE_TRASH_RENAMING))) { String name = mangleName(doc); session.move(doc.getRef(), doc.getParentRef(), name); } doc.putContextData(FROM_LIFE_CYCLE_TRASH_SERVICE, TRUE); session.followTransition(doc, LifeCycleConstants.DELETE_TRANSITION); } }
public static DocumentModel updateDocument(WebContext ctx, DocumentModel doc) { FormData form = ctx.getForm(); form.fillDocument(doc); doc.putContextData(VersioningService.VERSIONING_OPTION, form.getVersioningOption()); doc = ctx.getCoreSession().saveDocument(doc); ctx.getCoreSession().save(); return doc; }
@Override public void handleEvent(Event event) { EventContext ctx = event.getContext(); if (!(ctx instanceof DocumentEventContext)) { return; } BinaryMetadataService binaryMetadataService = Framework.getService(BinaryMetadataService.class); DocumentEventContext docCtx = (DocumentEventContext) ctx; DocumentModel doc = docCtx.getSourceDocument(); Boolean disable = (Boolean) event.getContext().getProperty( BinaryMetadataConstants.DISABLE_BINARY_METADATA_LISTENER); if (ABOUT_TO_CREATE.equals(event.getName()) && !doc.isProxy() && disable == null) { binaryMetadataService.writeMetadata(doc); } else if (BEFORE_DOC_UPDATE.equals(event.getName()) && !doc.isProxy() && disable == null) { doc.putContextData(BinaryMetadataConstants.DISABLE_BINARY_METADATA_LISTENER, Boolean.TRUE); binaryMetadataService.handleSyncUpdate(doc); } }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws Exception { if (!doc.hasFacet(FacetNames.VERSIONABLE)) { throw new NuxeoException(String.format( "The document (id:'%s') with title '%s' doesn't have 'versionable' facet", doc.getId(), doc.getTitle())); } // Create major version tagging it as explicit doc.putContextData(VersioningService.VERSIONING_OPTION, VersioningOption.MAJOR); doc.addFacet(ToutaticeNuxeoStudioConst.CST_FACET_EXPLICIT_VERSION); DocumentHelper.saveDocument(session, doc); doc.removeFacet(ToutaticeNuxeoStudioConst.CST_FACET_EXPLICIT_VERSION); return session.getLastDocumentVersion(doc.getRef()); }