@Test public void shouldNotAllowInternalNodesAsReferrers() throws Exception { federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); Node doc1Federated = session.getNode("/testRoot/federated1"); Node externalNode = doc1Federated.addNode("federated1_1", null); externalNode.addMixin("mix:referenceable"); session.save(); Value weakRef = session.getValueFactory().createValue(externalNode, true); testRoot.setProperty("weakRef", weakRef); try { session.save(); fail( "It should not be possible to create weak references from internal nodes to external nodes"); } catch (RepositoryException e) { assertTrue(e.getCause() instanceof ConnectorException); } Value strongRef = session.getValueFactory().createValue(externalNode, false); testRoot.setProperty("strongRef", strongRef); try { session.save(); fail( "It should not be possible to create strong references from internal nodes to external nodes"); } catch (RepositoryException e) { assertTrue(e.getCause() instanceof ConnectorException); } }
/** * Builds from the root version node and from a language the object representation of a versioned * document and its history. * * @param rootVersionNode the root version node (master). * @param lang the aimed content language. * @return the instance of a versioned document. * @throws RepositoryException */ HistorisedDocument buildHistorisedDocument(Node rootVersionNode, String lang) throws RepositoryException { VersionManager versionManager = rootVersionNode.getSession().getWorkspace().getVersionManager(); HistorisedDocument historisedDocument = new HistorisedDocument(fillDocument(rootVersionNode, lang)); try { String path = rootVersionNode.getPath(); VersionHistory history = versionManager.getVersionHistory(path); Version root = history.getRootVersion(); String rootId = ""; if (root != null) { rootId = root.getIdentifier(); } Version base = versionManager.getBaseVersion(path); String baseId = ""; if (base != null) { baseId = base.getIdentifier(); } VersionIterator versionsIterator = history.getAllVersions(); List<SimpleDocumentVersion> documentHistory = new ArrayList<SimpleDocumentVersion>((int) versionsIterator.getSize()); int versionIndex = 0; SimpleDocumentVersion previousVersion = null; while (versionsIterator.hasNext()) { Version version = versionsIterator.nextVersion(); if (!version.getIdentifier().equals(rootId) && !version.getIdentifier().equals(baseId)) { SimpleDocumentVersion versionDocument = new SimpleDocumentVersion( fillDocument(version.getFrozenNode(), lang), historisedDocument); versionDocument.setNodeName(rootVersionNode.getName()); versionDocument.setVersionIndex(versionIndex++); versionDocument.setPreviousVersion(previousVersion); documentHistory.add(versionDocument); previousVersion = versionDocument; } } HistoryDocumentSorter.sortHistory((List) documentHistory); historisedDocument.setHistory(documentHistory); historisedDocument.setVersionIndex(versionIndex); } catch (RepositoryException ex) { if (ex.getCause() instanceof NoSuchItemStateException) { historisedDocument.setHistory(new ArrayList<SimpleDocumentVersion>(0)); } else { throw ex; } } return historisedDocument; }