protected long getVersion(Document doc, String prop) { Object propVal = doc.getPropertyValue(prop); if (propVal instanceof Long) { return ((Long) propVal).longValue(); } else { return 0; } }
DocumentModelRefresh refresh = new DocumentModelRefresh(); refresh.instanceFacets = new HashSet<>(Arrays.asList(doc.getFacets())); Set<String> docSchemas = DocumentModelImpl.computeSchemas(doc.getType(), refresh.instanceFacets, doc.isProxy()); refresh.lifeCycleState = doc.getLifeCycleState(); refresh.lifeCyclePolicy = doc.getLifeCyclePolicy(); refresh.isCheckedOut = doc.isCheckedOut(); refresh.isLatestVersion = doc.isLatestVersion(); refresh.isMajorVersion = doc.isMajorVersion(); refresh.isLatestMajorVersion = doc.isLatestMajorVersion(); refresh.isVersionSeriesCheckedOut = doc.isVersionSeriesCheckedOut(); refresh.versionSeriesId = doc.getVersionSeriesId(); refresh.checkinComment = doc.getCheckinComment(); for (int i = 0; i < schemas.length; i++) { DocumentPart part = new DocumentPartImpl(typeProvider.getSchema(schemas[i])); doc.readDocumentPart(part); parts[i] = part;
@Override public DocumentRef[] getParentDocumentRefs(DocumentRef docRef) { final List<DocumentRef> docRefs = new ArrayList<>(); final Document doc = resolveReference(docRef); Document parentDoc = doc.getParent(); while (parentDoc != null) { final DocumentRef parentDocRef = new IdRef(parentDoc.getUUID()); docRefs.add(parentDocRef); parentDoc = parentDoc.getParent(); } DocumentRef[] refs = new DocumentRef[docRefs.size()]; return docRefs.toArray(refs); }
@Override public int compare(Document doc1, Document doc2) { String p1 = doc1.getPath(); String p2 = doc2.getPath(); if (p1 == null && p2 == null) { return sign * doc1.getUUID().compareTo(doc2.getUUID()); } else if (p1 == null) { return sign; } else if (p2 == null) { return -1 * sign; } return sign * p1.compareTo(p2); } }
@Override public VersioningOption doPreSave(CoreSession session, Document doc, boolean isDirty, VersioningOption option, String checkinComment, Map<String, Serializable> options) { option = validateOption(doc, option); boolean increment = option != VersioningOption.NONE; if (increment) { if (doc.isCheckedOut()) { doc.checkIn(null, checkinComment); // auto-label } } if (!doc.isCheckedOut() && (isDirty || increment)) { doc.checkOut(); } return option; }
/** * Returns the first {@code Document} with the given {@code facet}, recursively going up the parent hierarchy. * Returns {@code null} if there is no more parent. * <p> * This method does not check security rights. */ protected Document getFirstParentDocumentWithFacet(DocumentRef docRef, String facet) { Document doc = resolveReference(docRef); while (doc != null && !doc.hasFacet(facet)) { doc = doc.getParent(); } return doc; }
DocumentType type = doc.getType(); if (type == null) { throw new NuxeoException("Type not found for doc " + doc); DocumentRef docRef = new IdRef(doc.getUUID()); Document parent = doc.getParent(); DocumentRef parentRef = parent == null ? null : new IdRef(parent.getUUID()); Document sourceDoc = doc.getSourceDocument(); String sourceId = sourceDoc == null ? null : sourceDoc.getUUID(); boolean immutable = doc.isVersion() || (doc.isProxy() && sourceDoc.isVersion()); // NOSONAR (proxy has source) Set<String> facets = new HashSet<>(Arrays.asList(doc.getFacets())); if (immutable) { facets.add(FacetNames.IMMUTABLE); String repositoryName = doc.getRepositoryName(); String p = doc.getPath(); Path path = p == null ? null : new Path(p); DocumentModelImpl docModel = new DocumentModelImpl(sid, type.getName(), doc.getUUID(), path, docRef, parentRef, null, facets, sourceId, repositoryName, doc.isProxy()); docModel.setPosInternal(doc.getPos()); if (doc.isVersion()) { docModel.setIsVersion(true);
String[] additionalPrincipals) { if (ModelConstants.UNUM_DOCTYPE.equals(doc.getType().getName())) { try { boolean shareable = BooleanUtils.isTrue((Boolean) doc.getPropertyValue(ModelConstants.UNUM_XPATH_SHAREABLE_PROP)); if (shareable) { sessionSystem = CoreInstance.openCoreSessionSystem(doc.getRepositoryName()); IdRef docRef = new IdRef(doc.getUUID()); IdRef parentDocRef = new IdRef(doc.getParent().getUUID()); DocumentModelList proxies = sessionSystem.getProxies(docRef, parentDocRef);
if (!doc.validateUserVisibleChangeToken(changeToken)) { throw new ConcurrentUpdateException(doc.getUUID()); doc.markUserChange(); addedFacets.remove(FacetNames.IMMUTABLE); for (String facet : addedFacets) { changed = doc.addFacet(facet) || changed; changed = doc.removeFacet(facet) || changed; WriteContext writeContext = doc.getWriteContext(); for (DataModel dm : docModel.getDataModelsCollection()) { // only loaded if (dm.isDirty()) { DocumentPart part = ((DataModelImpl) dm).getDocumentPart(); changed = doc.writeDocumentPart(part, writeContext) || changed;
if (doc.isVersion()) { return "Proxy " + proxies.iterator().next().getUUID() + " targets version " + doc.getUUID(); Document working = doc.getSourceDocument(); if (working != null) { Document baseVersion = working.getBaseVersion(); if (baseVersion != null && !baseVersion.isCheckedOut() && baseVersion.getUUID().equals(doc.getUUID())) { return "Working copy " + working.getUUID() + " is checked in with base version " + doc.getUUID(); : "Missing permission '" + WRITE_VERSION + "' on working copy " + working.getUUID(); } else { return "Missing permission '" + REMOVE + "' on document " + doc.getUUID(); Document parent = doc.getParent(); if (parent == null) { return null; // ok : "Missing permission '" + REMOVE_CHILDREN + "' on parent document " + parent.getUUID();
if (dst == null) { dstDoc = srcDoc.getParent(); checkPermission(dstDoc, WRITE_PROPERTIES); } else { dstDoc = resolveReference(dst); checkPermission(dstDoc, ADD_CHILDREN); checkPermission(srcDoc.getParent(), REMOVE_CHILDREN); checkPermission(srcDoc, REMOVE); options.put(CoreEventConstants.DESTINATION_PATH, dstDoc.getPath()); options.put(CoreEventConstants.DESTINATION_NAME, name); options.put(CoreEventConstants.DESTINATION_EXISTS, dstDoc.hasChild(name)); String comment = srcDoc.getRepositoryName() + ':' + srcDoc.getParent().getUUID();
@Override public void removeVersions(Session session, Document doc, CoreSession coreSession) { Collection<Document> proxies = session.getProxies(doc, null); if (doc.isProxy()) { if (proxies.isEmpty()) { Document source = doc.getSourceDocument(); if (source.isVersion()) { source = source.getSourceDocument(); } catch (DocumentNotFoundException e) { List<String> versionsIds = doc.getVersionsIds(); if (log.isDebugEnabled()) { log.debug(String.format("Removing %s versions for: %s", versionsIds.size(), doc.getUUID())); DocumentModel docModel = coreSession.getDocument(new IdRef(doc.getUUID())); EventContext evtctx = new EventContextImpl(coreSession, coreSession.getPrincipal(), new ShallowDocumentModel(docModel), versionsIds);
doc = getSession().move(doc, doc.getParent(), name); boolean setReadWrite = allowVersionWrite && doc.isVersion() && doc.isReadOnly(); doc.setReadOnly(false); doc.setReadOnly(true); DocumentRef checkedInVersionRef = new IdRef(checkedInDoc.getUUID()); notifyCheckedInVersion(docModel, checkedInVersionRef, options, checkinComment);
if (!skipSnapshotCreation && doc.isCheckedOut()) { String checkinComment = (String) docModel.getContextData(VersioningService.CHECKIN_COMMENT); docModel.putContextData(VersioningService.CHECKIN_COMMENT, null); Document ver = getVersioningService().doCheckIn(doc, null, checkinComment); docModel.refresh(DocumentModel.REFRESH_STATE, null); notifyCheckedInVersion(docModel, new IdRef(ver.getUUID()), null, checkinComment); final Long majorVer = (Long) doc.getPropertyValue("major_version"); final Long minorVer = (Long) doc.getPropertyValue("minor_version"); if (majorVer != null || minorVer != null) { options.put(VersioningDocument.CURRENT_DOCUMENT_MAJOR_VERSION_KEY, majorVer); String versionUUID = version.getUUID(); options.put(VersioningDocument.RESTORED_VERSION_UUID_KEY, versionUUID); writeModel(doc, docModel); doc.restore(version); log.debug("Document restored to version:" + version.getUUID()); return docModel;
if (overwriteExistingProxy) { if (docModel.isVersion()) { Document base = resolveReference(new IdRef(doc.getVersionSeriesId())); proxy = updateExistingProxies(base, sec, target); String checkinComment = (String) docModel.getContextData(VersioningService.CHECKIN_COMMENT); docModel.putContextData(VersioningService.CHECKIN_COMMENT, null); if (doc.isCheckedOut() || doc.getLastVersion() == null) { if (!doc.isCheckedOut()) { Document version = getVersioningService().doCheckIn(doc, null, checkinComment); docModel.refresh(DocumentModel.REFRESH_STATE | DocumentModel.REFRESH_CONTENT_LAZY, null); notifyCheckedInVersion(docModel, new IdRef(version.getUUID()), null, checkinComment); target = doc.getBaseVersion(); if (overwriteExistingProxy) { proxy = updateExistingProxies(doc, sec, target);
protected final void checkPermission(Document doc, String permission) throws DocumentSecurityException { if (isAdministrator()) { return; } if (!hasPermission(doc, permission)) { log.debug("Permission '" + permission + "' is not granted to '" + getPrincipal().getName() + "' on document " + doc.getPath() + " (" + doc.getUUID() + " - " + doc.getType().getName() + ")"); throw new DocumentSecurityException( "Privilege '" + permission + "' is not granted to '" + getPrincipal().getName() + "'"); } }
@Override public void doCheckOut(Document doc) { Document base = doc.getBaseVersion(); doc.checkOut(); // set version number to that of the latest version // nothing to do if base is latest version, already at proper version if (!base.isLatestVersion()) { // this doc was restored from a non-latest version, find the latest one Document last = doc.getLastVersion(); if (last != null) { try { setVersion(doc, getMajor(last), getMinor(last)); } catch (PropertyNotFoundException e) { // ignore } } } }
name = srcDoc.getName(); } else { PathRef.checkName(name); options.put(CoreEventConstants.DESTINATION_PATH, dstDoc.getPath()); options.put(CoreEventConstants.DESTINATION_NAME, name); options.put(CoreEventConstants.DESTINATION_EXISTS, dstDoc.hasChild(name)); options.put(CoreEventConstants.RESET_LIFECYCLE, CopyOption.isResetLifeCycle(copyOptions)); options.put(CoreEventConstants.RESET_CREATOR, CopyOption.isResetCreator(copyOptions)); String comment = srcDoc.getRepositoryName() + ':' + src.toString(); notifyEvent(DocumentEventTypes.DOCUMENT_CREATED_BY_COPY, docModel, options, null, comment, true, false); docModel = writeModel(doc, docModel); comment = doc.getRepositoryName() + ':' + docModel.getRef().toString();
protected VersionModel getVersionModel(Document version) { VersionModel versionModel = new VersionModelImpl(); versionModel.setId(version.getUUID()); versionModel.setCreated(version.getVersionCreationDate()); versionModel.setDescription(version.getCheckinComment()); versionModel.setLabel(version.getVersionLabel()); return versionModel; }
protected String getProviderId(Document doc, Blob blob, String blobXPath) { if (useRepositoryName) { return doc.getRepositoryName(); Object value; if (xpath.equals(REPOSITORY_NAME)) { value = doc.getRepositoryName(); } else if (xpath.startsWith(BLOB_PREFIX)) { switch (xpath.substring(BLOB_PREFIX.length())) { value = doc.getValue(xpath); } catch (PropertyNotFoundException e) { try { value = doc.getPropertyValue(xpath); } catch (PropertyNotFoundException e2) { allClausesMatch = false;