@Test public void shouldCreateProjectionWithAlias() throws Exception { // add an internal node testRoot.addNode("node1"); session.save(); // link the first external document federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1"); assertEquals(2, testRoot.getNodes().getSize()); Node doc1Federated = assertNodeFound("/testRoot/federated1"); assertEquals(testRoot.getIdentifier(), doc1Federated.getParent().getIdentifier()); assertEquals("a string", doc1Federated.getProperty("federated1_prop1").getString()); assertEquals(12, doc1Federated.getProperty("federated1_prop2").getLong()); // link a second external document with a sub-child federationManager.createProjection( "/testRoot", SOURCE_NAME, MockConnector.DOC2_LOCATION, "federated2"); assertEquals(3, testRoot.getNodes().getSize()); Node doc2Federated = assertNodeFound("/testRoot/federated2"); assertEquals(testRoot.getIdentifier(), doc2Federated.getParent().getIdentifier()); assertEquals("another string", doc2Federated.getProperty("federated2_prop1").getString()); assertEquals(false, doc2Federated.getProperty("federated2_prop2").getBoolean()); Node doc2FederatedChild = assertNodeFound("/testRoot/federated2/federated3"); assertEquals( "yet another string", doc2FederatedChild.getProperty("federated3_prop1").getString()); }
public CMISValueImpl(Node value, boolean weakReference) throws RepositoryException { if (weakReference) { this.value = value.getIdentifier(); this.type = PropertyType.WEAKREFERENCE; } else { this.value = value.getIdentifier(); this.type = PropertyType.REFERENCE; } }
@Override public CaoOperation create(JackElement parent, String name, boolean doSave) throws Exception { Node newNode = parent.getNode().addNode(name, "nt:folder"); Session session = ((JackConnection) parent.getConnection()).getSession(); if (doSave) session.save(); if (newNode != null) { parent.getConnection().fireElementCreated(newNode.getIdentifier()); parent.getConnection().fireElementLink(parent.getId(), newNode.getIdentifier()); } return null; }
private String getHandleUuid(final String documentPath) { if (documentPath == null) { return null; } final int idx = documentPath.lastIndexOf("/"); if (idx > 0) { final String handlePath = documentPath.substring(0, idx); try { final Node node = session.getNode(handlePath); if (node.isNodeType(HippoNodeType.NT_HANDLE)) { return node.getIdentifier(); } } catch (PathNotFoundException e) { log.debug( "Document handle '{}' was removed before we could log workflow event", handlePath); } catch (RepositoryException e) { log.error( "Failed to determine uuid of document handle at " + handlePath + " while logging workflow event", e); } } return null; }
protected Node processAttributeDeclaration( XSDAttributeDeclaration decl, Node parentNode, boolean isUse) throws RepositoryException { if (decl == null) { return null; } logger.debug( "Attribute declaration: '{0}' in ns '{1}' ", decl.getName(), decl.getTargetNamespace()); Node attributeDeclarationNode = parentNode.addNode(decl.getName(), XsdLexicon.ATTRIBUTE_DECLARATION); attributeDeclarationNode.setProperty(XsdLexicon.NC_NAME, decl.getName()); attributeDeclarationNode.setProperty(XsdLexicon.NAMESPACE, decl.getTargetNamespace()); if (decl.isGlobal() && !isUse) { registerForSymbolSpace( ATTRIBUTE_DECLARATIONS, decl.getTargetNamespace(), decl.getName(), attributeDeclarationNode.getIdentifier()); } XSDTypeDefinition type = decl.getType(); if (type != null) { attributeDeclarationNode.setProperty(XsdLexicon.TYPE_NAME, type.getName()); attributeDeclarationNode.setProperty(XsdLexicon.TYPE_NAMESPACE, type.getTargetNamespace()); } processAnnotation(decl.getAnnotation(), attributeDeclarationNode); processNonSchemaAttributes(type, attributeDeclarationNode); return attributeDeclarationNode; }
/** * Create a link to a file. There is no need to call a session.save, the change is persistent. * * @param fileNode The node that represents the file. This node has to be retrieved via the normal * user his {@link Session session}. If the userID equals {@link UserConstants.ANON_USERID} an * AccessDeniedException will be thrown. * @param linkPath The absolute path in JCR where the link should be placed. * @param slingRepository The {@link SlingRepository} to use to login as an administrative. * @return The newly created node. * @throws AccessDeniedException When the user is anonymous. * @throws RepositoryException Something else went wrong. */ public static boolean createLink(Node fileNode, String linkPath, SlingRepository slingRepository) throws AccessDeniedException, RepositoryException { Session session = fileNode.getSession(); String userId = session.getUserID(); if (UserConstants.ANON_USERID.equals(userId)) { throw new AccessDeniedException(); } boolean hasMixin = JcrUtils.hasMixin(fileNode, REQUIRED_MIXIN) && fileNode.canAddMixin(REQUIRED_MIXIN); // If the fileNode doesn't have the required referenceable mixin, we need to set it. if (!hasMixin) { // The required mixin is not on the node. // Set it. Session adminSession = null; try { adminSession = slingRepository.loginAdministrative(null); // Grab the node via the adminSession String path = fileNode.getPath(); Node adminFileNode = (Node) adminSession.getItem(path); if (!hasMixin) { adminFileNode.addMixin(REQUIRED_MIXIN); } if (adminSession.hasPendingChanges()) { adminSession.save(); } } finally { if (adminSession != null) { adminSession.logout(); } } } // Now that the file is referenceable, it has a uuid. // Use it for the link. // Grab the (updated) node via the user's session id. fileNode = (Node) session.getItem(fileNode.getPath()); // Create the link Node linkNode = JcrUtils.deepGetOrCreateNode(session, linkPath); if (!"sling:Folder".equals(linkNode.getPrimaryNodeType().getName())) { // sling folder allows single and multiple properties, no need for the mixin. if (linkNode.canAddMixin(REQUIRED_MIXIN)) { linkNode.addMixin(REQUIRED_MIXIN); } } linkNode.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, RT_SAKAI_LINK); linkNode.setProperty(SAKAI_LINK, fileNode.getIdentifier()); // Save link. if (session.hasPendingChanges()) { session.save(); } return true; }
private EcmDocument readDocumentByNode(Node node, int readType) throws EcmException { EcmDocument doc = null; try { if (node == null) { return doc; } doc = new EcmDocument(); Node resNode = node.getNode(Property.JCR_CONTENT); if (resNode == null) { return doc; } /** Load the document meta data */ DocumentMetadata meta = this.loadDocumentMetadata(resNode); meta.setFileName(node.getName()); meta.setIdentifier(node.getIdentifier()); String createdBy = node.getProperty(Property.JCR_CREATED_BY).getString(); Calendar createdDate = node.getProperty(Property.JCR_CREATED).getDate(); meta.setCreated(createdDate.getTime()); meta.setCreatedBy(createdBy); meta.setCheckedOut(node.isCheckedOut()); meta.setFullPath(node.getPath()); doc.setMetadata(meta); doc.setFileName(meta.getFileName()); doc.setParentFolder(node.getParent().getName()); /** Load the file content */ Property dataProperty = resNode.getProperty(Property.JCR_DATA); if (dataProperty != null && readType == 0) { doc.setInputStream(dataProperty.getBinary().getStream()); doc.getMetadata().setSize(dataProperty.getBinary().getSize()); } else if (dataProperty != null && readType == 1) { byte[] contents = convertToByteArray(dataProperty.getBinary()); doc.setContent(contents); doc.getMetadata().setSize(dataProperty.getBinary().getSize()); } } catch (PathNotFoundException e) { throw new EcmException( "Fail to read document from repository.", e, ErrorCodes.REPOSITROY_ERR_INVALID_PATH); } catch (RepositoryException e) { throw new EcmException( "Fail to read document from repository.", e, ErrorCodes.REPOSITROY_ERR_GENERIC); } catch (IOException e) { throw new EcmException( "Fail to read document from repository.", e, ErrorCodes.REPOSITROY_ERR_FAIL_TO_READ_CONTENT); } return doc; }
@Test @FixFor("MODE-1663") public void shouldMakeReferenceableNodesUsingCustomTypes() throws Exception { Node cars = session.getNode("/Cars"); cars.addNode("referenceableCar1", "car:referenceableCar"); Node refCar = cars.addNode("referenceableCar2"); refCar.setPrimaryType("car:referenceableCar"); session.save(); Node referenceableCar1 = session.getNode("/Cars/referenceableCar1"); String uuid = referenceableCar1.getProperty(JcrLexicon.UUID.getString()).getString(); assertEquals(referenceableCar1.getIdentifier(), uuid); Node referenceableCar2 = session.getNode("/Cars/referenceableCar2"); uuid = referenceableCar2.getProperty(JcrLexicon.UUID.getString()).getString(); assertEquals(referenceableCar2.getIdentifier(), uuid); }
/** @throws RepositoryException */ public void testFrozenNodeUUUID() throws RepositoryException { VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); String path = versionableNode.getPath(); Version v = versionManager.checkin(path); Node n = v.getFrozenNode(); String puuid = n.getProperty(jcrUUID).getValue().getString(); String nuuid = n.getIdentifier(); assertEquals("jcr:uuid needs to be equal to the getIdentifier() return value.", nuuid, puuid); }
public SimpleDocument convertNode(Node node, String lang) throws RepositoryException { if (isVersionedMaster(node)) { return buildHistorisedDocument(node, lang); } Node parentNode = node.getParent(); if (parentNode instanceof Version) { // Getting the parent node, the versionned one Node masterNode = getMasterNodeForVersion((Version) parentNode); // The historised document is built from the parent node HistorisedDocument document = buildHistorisedDocument(masterNode, lang); // Returning the version SimpleDocumentVersion version = document.getVersionIdentifiedBy(node.getIdentifier()); if (version != null) { return new HistorisedDocumentVersion(version); } throw new PathNotFoundException( "Version identified by " + node.getIdentifier() + " has not been found."); } return fillDocument(node, lang); }
@Test public void shouldCreateProjectionWithoutAlias() throws Exception { // link the first external document federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, null); assertEquals(1, testRoot.getNodes().getSize()); Node doc1Federated = assertNodeFound("/testRoot" + MockConnector.DOC1_LOCATION); assertEquals(testRoot.getIdentifier(), doc1Federated.getParent().getIdentifier()); assertEquals("a string", doc1Federated.getProperty("federated1_prop1").getString()); assertEquals(12, doc1Federated.getProperty("federated1_prop2").getLong()); }
SimpleDocument fillDocument(Node node, String lang) throws RepositoryException { SimpleDocumentPK pk = new SimpleDocumentPK( node.getIdentifier(), getStringProperty(node, SLV_PROPERTY_INSTANCEID)); long oldSilverpeasId = getLongProperty(node, SLV_PROPERTY_OLD_ID); pk.setOldSilverpeasId(oldSilverpeasId); String language = lang; if (language == null) { language = I18NHelper.defaultLanguage; } SimpleAttachment file = getAttachment(node, language); if (file == null) { Iterator<String> iter = I18NHelper.getLanguages(); while (iter.hasNext() && file == null) { file = getAttachment(node, iter.next()); } } SimpleDocument doc = new SimpleDocument( pk, getStringProperty(node, SLV_PROPERTY_FOREIGN_KEY), getIntProperty(node, SLV_PROPERTY_ORDER), getBooleanProperty(node, SLV_PROPERTY_VERSIONED), getStringProperty(node, SLV_PROPERTY_OWNER), getDateProperty(node, SLV_PROPERTY_RESERVATION_DATE), getDateProperty(node, SLV_PROPERTY_ALERT_DATE), getDateProperty(node, SLV_PROPERTY_EXPIRY_DATE), getStringProperty(node, SLV_PROPERTY_COMMENT), file); doc.setRepositoryPath(node.getPath()); doc.setCloneId(getStringProperty(node, SLV_PROPERTY_CLONE)); doc.setMajorVersion(getIntProperty(node, SLV_PROPERTY_MAJOR)); doc.setMinorVersion(getIntProperty(node, SLV_PROPERTY_MINOR)); doc.setStatus(getStringProperty(node, SLV_PROPERTY_STATUS)); doc.setDocumentType(DocumentType.fromFolderName(node.getParent().getName())); String nodeName = node.getName(); if ("jcr:frozenNode".equals(nodeName)) { nodeName = doc.computeNodeName(); doc.setNodeName(nodeName); if (!node.getSession().nodeExists(doc.getFullJcrPath())) { nodeName = SimpleDocument.VERSION_PREFIX + doc.getOldSilverpeasId(); } } doc.setNodeName(nodeName); doc.setPublicDocument(!doc.isVersioned() || doc.getMinorVersion() == 0); // Forbidden download for roles String forbiddenDownloadForRoles = getStringProperty(node, SLV_PROPERTY_FORBIDDEN_DOWNLOAD_FOR_ROLES); if (StringUtil.isDefined(forbiddenDownloadForRoles)) { doc.addRolesForWhichDownloadIsForbidden(SilverpeasRole.listFrom(forbiddenDownloadForRoles)); } return doc; }
/** @throws RepositoryException */ public void testFrozenChildUUUID() throws RepositoryException, NotExecutableException { Node n1 = versionableNode.addNode("child"); ensureMixinType(n1, mixReferenceable); versionableNode.getSession().save(); VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); String path = versionableNode.getPath(); Version v = versionManager.checkin(path); Node n = v.getFrozenNode().getNode("child"); String fuuid = n.getProperty(jcrFrozenUuid).getValue().getString(); String ruuid = n1.getIdentifier(); assertEquals( "jcr:frozenUuid needs to be equal to the getIdentifier() return value.", ruuid, fuuid); }
public void testConcurrentSessionMove() throws RepositoryException { testRootPath = testRootNode.getPath(); Node aa = testRootNode.addNode("a").addNode("aa"); Node b = testRootNode.addNode("b"); testRootNode.getSession().save(); String aaId = aa.getIdentifier(); String bId = b.getIdentifier(); Session session1 = getHelper().getReadWriteSession(); Session session2 = getHelper().getReadWriteSession(); // results in /b/a/aa session1.move(testRootPath + "/a", testRootPath + "/b/a"); assertEquals(testRootPath + "/b/a/aa", session1.getNodeByIdentifier(aaId).getPath()); // results in a/aa/b session2.move(testRootPath + "/b", testRootPath + "/a/aa/b"); assertEquals(testRootPath + "/a/aa/b", session2.getNodeByIdentifier(bId).getPath()); session1.save(); // path should not have changed after save. assertEquals(testRootPath + "/a/aa/b", session2.getNodeByIdentifier(bId).getPath()); try { session2.save(); fail("Save should have failed. Possible cyclic persistent path created."); } catch (InvalidItemStateException e) { // expect is a ex caused by a StaleItemStateException with "has been modified externally" if (!(e.getCause() instanceof StaleItemStateException)) { throw e; } } }
/** * Transforms JCR {@code Node} into {@code Profession} object * * @param node JCR {@code Node} * @return {@code Profession} object */ public static Profession nodeToProfession(Node node) { if (node == null) { throw new IllegalArgumentException("Node is null"); } Profession profession = null; try { profession = new Profession(); profession.setUuid(node.getIdentifier()); profession.setName(node.getProperty(PROP_NAME.toString()).getString()); } catch (RepositoryException ex) { logger.error("Failed to transform JCR Node to Profession. " + ex.getMessage()); } return profession; }
protected void processSimpleTypeDefinition(XSDSimpleTypeDefinition type, Node node) throws RepositoryException { boolean isAnonymous = type.getName() == null; String nodeName = isAnonymous ? XsdLexicon.SIMPLE_TYPE : type.getName(); // This is a normal simple type definition ... logger.debug("Simple type: '{0}' in ns '{1}' ", type.getName(), type.getTargetNamespace()); Node typeNode = node.addNode(nodeName, XsdLexicon.SIMPLE_TYPE_DEFINITION); typeNode.setProperty(XsdLexicon.NAMESPACE, type.getTargetNamespace()); if (!isAnonymous) { typeNode.setProperty(XsdLexicon.NC_NAME, type.getName()); registerForSymbolSpace( TYPE_DEFINITIONS, type.getTargetNamespace(), type.getName(), typeNode.getIdentifier()); } processTypeFacets(type, typeNode, type.getBaseType()); processNonSchemaAttributes(type, typeNode); }
/** * Obtain the actual location for the supplied node. * * @param node the existing node; may not be null * @return the actual location, with UUID if the node is "mix:referenceable" * @throws RepositoryException if there is an error */ public Location locationFor(Node node) throws RepositoryException { // Get the path to the node ... String pathStr = node.getPath(); Path path = factories.getPathFactory().create(pathStr); // Does the node have a UUID ... String uuidStr = node.getIdentifier(); if (uuidStr != null) { try { UUID uuid = UUID.fromString(uuidStr); return Location.create(path, uuid); } catch (IllegalArgumentException e) { // Ignore, since the identifier is not a valid UUID } } return Location.create(path); }
public Set<Node> getReferrers(Node document) throws RepositoryException { Set<Node> referrers = new TreeSet<Node>( new Comparator<Node>() { public int compare(Node node1, Node node2) { try { return node1.getIdentifier().compareTo(node2.getIdentifier()); } catch (UnsupportedRepositoryOperationException ex) { // cannot happen return 0; } catch (RepositoryException ex) { return 0; } } }); if (!document.isNodeType(HippoNodeType.NT_DOCUMENT)) { return null; } document = ((HippoNode) document).getCanonicalNode(); Node handle = document.getParent(); if (!handle.isNodeType(HippoNodeType.NT_HANDLE) || !handle.isNodeType(HippoNodeType.NT_HARDHANDLE)) { return null; } String uuid = handle.getIdentifier(); QueryManager queryManager = document.getSession().getWorkspace().getQueryManager(); String statement = "//*[@hippo:docbase='" + uuid + "']"; Query query = queryManager.createQuery(statement, Query.XPATH); QueryResult result = query.execute(); for (NodeIterator iter = result.getNodes(); iter.hasNext(); ) { Node node = iter.nextNode(); while (node != null && !node.isNodeType(HippoNodeType.NT_DOCUMENT)) { node = (node.getDepth() > 0 ? node.getParent() : null); } if (node != null) { if (node.isNodeType("hippostd:publishable") && node.hasProperty("hippostd:state") && node.getProperty("hippostd:state").getString().equals("published")) { referrers.add(node); } } } return referrers; }
@Test public void shouldReturnFalseFromIsSameIfTheNodeUuidIsDifferent() throws Exception { // Set up the store ... InMemoryRepositorySource source2 = new InMemoryRepositorySource(); source2.setName("store"); Graph store2 = Graph.create(source2, context); store2 .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml")) .into("/"); JcrSession jcrSession2 = mock(JcrSession.class); when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes); when(jcrSession2.isLive()).thenReturn(true); SessionCache cache2 = new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2); Workspace workspace2 = mock(Workspace.class); JcrRepository repository2 = mock(JcrRepository.class); RepositoryLockManager repoLockManager2 = mock(RepositoryLockManager.class); when(jcrSession2.getWorkspace()).thenReturn(workspace2); when(jcrSession2.getRepository()).thenReturn(repository2); when(workspace2.getName()).thenReturn("workspace1"); WorkspaceLockManager lockManager = new WorkspaceLockManager(context, repoLockManager2, "workspace2", null); JcrLockManager jcrLockManager = new JcrLockManager(jcrSession2, lockManager); when(jcrSession2.lockManager()).thenReturn(jcrLockManager); // Use the same id and location; use 'Nissan Altima' // since the UUIDs will be different (cars.xml doesn't define on this node) ... javax.jcr.Node altima2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Nissan Altima")); altima2.addMixin("mix:referenceable"); altima.addMixin("mix:referenceable"); String altimaUuid = altima.getIdentifier(); String altimaUuid2 = altima2.getIdentifier(); assertThat(altimaUuid, is(not(altimaUuid2))); assertThat(altima2.isSame(altima), is(false)); // Check the properties ... javax.jcr.Property model = altima.getProperty("vehix:model"); javax.jcr.Property model2 = altima2.getProperty("vehix:model"); assertThat(model.isSame(model2), is(false)); }
protected void processAttributeGroupDefinition(XSDAttributeGroupDefinition defn, Node parentNode) throws RepositoryException { if (defn == null) { return; } Node attributeGroupNode = null; if (defn.isAttributeGroupDefinitionReference()) { XSDAttributeGroupDefinition resolved = defn.getResolvedAttributeGroupDefinition(); logger.debug( "Attribute Group definition (ref): '{0}' in ns '{1}' ", resolved.getName(), resolved.getTargetNamespace()); attributeGroupNode = parentNode.addNode(resolved.getName(), XsdLexicon.ATTRIBUTE_GROUP); setReference( attributeGroupNode, XsdLexicon.REF, ATTRIBUTE_GROUP_DEFINITIONS, resolved.getTargetNamespace(), resolved.getName()); } else { logger.debug( "Attribute Group definition: '{0}' in ns '{1}' ", defn.getName(), defn.getTargetNamespace()); attributeGroupNode = parentNode.addNode(defn.getName(), XsdLexicon.ATTRIBUTE_GROUP); registerForSymbolSpace( ATTRIBUTE_GROUP_DEFINITIONS, defn.getTargetNamespace(), defn.getName(), attributeGroupNode.getIdentifier()); attributeGroupNode.setProperty(XsdLexicon.NC_NAME, defn.getName()); attributeGroupNode.setProperty(XsdLexicon.NAMESPACE, defn.getTargetNamespace()); for (Object child : defn.getContents()) { if (child instanceof XSDAttributeUse) { processAttributeUse((XSDAttributeUse) child, attributeGroupNode); } else if (child instanceof XSDWildcard) { processWildcard((XSDWildcard) child, attributeGroupNode); } } } processAnnotation(defn.getAnnotation(), attributeGroupNode); processNonSchemaAttributes(defn, attributeGroupNode); }
@Test public void shouldReturnTrueFromIsSameIfTheNodeUuidAndWorkspaceNameAndRepositoryInstanceAreSame() throws Exception { // Set up the store ... InMemoryRepositorySource source2 = new InMemoryRepositorySource(); source2.setName("store"); Graph store2 = Graph.create(source2, context); store2 .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml")) .into("/"); JcrSession jcrSession2 = mock(JcrSession.class); when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes); when(jcrSession2.isLive()).thenReturn(true); SessionCache cache2 = new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2); Workspace workspace2 = mock(Workspace.class); when(jcrSession2.getWorkspace()).thenReturn(workspace2); when(jcrSession2.getRepository()).thenReturn(repository); when(workspace2.getName()).thenReturn("workspace1"); WorkspaceLockManager lockManager = new WorkspaceLockManager(context, repoLockManager, "workspace2", null); JcrLockManager jcrLockManager = new JcrLockManager(jcrSession2, lockManager); when(jcrSession2.lockManager()).thenReturn(jcrLockManager); // Use the same id and location ... javax.jcr.Node prius2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Toyota Prius")); prius2.addMixin("mix:referenceable"); prius.addMixin("mix:referenceable"); String priusUuid = prius.getIdentifier(); String priusUuid2 = prius2.getIdentifier(); assertThat(priusUuid, is(priusUuid2)); assertThat(prius2.isSame(prius), is(true)); // Check the properties ... javax.jcr.Property model = prius.getProperty("vehix:model"); javax.jcr.Property model2 = prius2.getProperty("vehix:model"); javax.jcr.Property year2 = prius2.getProperty("vehix:year"); assertThat(model.isSame(model2), is(true)); assertThat(model.isSame(year2), is(false)); }
protected void processComplexTypeDefinition(XSDComplexTypeDefinition type, Node parentNode) throws RepositoryException { logger.debug("Complex type: '{0}' in ns '{1}' ", type.getName(), type.getTargetNamespace()); boolean isAnonymous = type.getName() == null; String nodeName = isAnonymous ? XsdLexicon.COMPLEX_TYPE : type.getName(); Node typeNode = parentNode.addNode(nodeName, XsdLexicon.COMPLEX_TYPE_DEFINITION); typeNode.setProperty(XsdLexicon.NAMESPACE, type.getTargetNamespace()); if (!isAnonymous) { typeNode.setProperty(XsdLexicon.NC_NAME, type.getName()); registerForSymbolSpace( TYPE_DEFINITIONS, type.getTargetNamespace(), type.getName(), typeNode.getIdentifier()); } XSDTypeDefinition baseType = type.getBaseType(); if (baseType == type) { // The base type is the anytype ... baseType = type.getSchema() .getSchemaForSchema() .resolveComplexTypeDefinition("http://www.w3.org/2001/XMLSchema", "anyType"); } if (baseType != null) { typeNode.setProperty(XsdLexicon.BASE_TYPE_NAME, baseType.getName()); typeNode.setProperty(XsdLexicon.BASE_TYPE_NAMESPACE, baseType.getTargetNamespace()); } typeNode.setProperty(XsdLexicon.ABSTRACT, type.isAbstract()); typeNode.setProperty(XsdLexicon.MIXED, type.isMixed()); @SuppressWarnings("unchecked") List<XSDProhibitedSubstitutions> blocks = type.getBlock(); processEnumerators(blocks, typeNode, XsdLexicon.BLOCK); @SuppressWarnings("unchecked") List<XSDSimpleFinal> finalFacets = type.getFinal(); processEnumerators(finalFacets, typeNode, XsdLexicon.FINAL); processComplexTypeContent(type.getContent(), typeNode); processAnnotation(type.getAnnotation(), typeNode); processNonSchemaAttributes(type, typeNode); }
/** * Transforms JCR {@code Node} into {@code UserDTO} object * * @param node JCR {@code Node} * @return {@code UserDTO} object */ public static UserDTO nodeToUserDTO(Node node) { if (node == null) { throw new IllegalArgumentException("Node is null"); } UserDTO user = null; try { user = new UserDTO(); user.setUuid(node.getIdentifier()); user.setName(node.getProperty(PROP_NAME.toString()).getString()); user.setProfession( nodeToProfession( node.getSession() .getNodeByIdentifier(node.getProperty(PROP_PROFESSION.toString()).getString()))); } catch (RepositoryException ex) { logger.error("Failed to transform JCR Node to UserDTO. " + ex.getMessage()); } return user; }
protected Map<?, ?> assertSequencingEventInfo( Node sequencedNode, String expectedUserId, String expectedSequencerName, String expectedSelectedPath, String expectedOutputPath) throws RepositoryException { Map<?, ?> sequencingEventInfo = getSequencingEventInfo(sequencedNode); Assert.assertEquals(expectedUserId, sequencingEventInfo.get(Event.Sequencing.USER_ID)); Assert.assertEquals( expectedSequencerName, sequencingEventInfo.get(Event.Sequencing.SEQUENCER_NAME)); Assert.assertEquals( sequencedNode.getIdentifier(), sequencingEventInfo.get(Event.Sequencing.SEQUENCED_NODE_ID)); Assert.assertEquals( sequencedNode.getPath(), sequencingEventInfo.get(Event.Sequencing.SEQUENCED_NODE_PATH)); Assert.assertEquals( expectedSelectedPath, sequencingEventInfo.get(Event.Sequencing.SELECTED_PATH)); Assert.assertEquals(expectedOutputPath, sequencingEventInfo.get(Event.Sequencing.OUTPUT_PATH)); return sequencingEventInfo; }
private void updateResouceNodePropertyAsStream(Node fileNode, Node resNode, EcmDocument document) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, UnsupportedRepositoryOperationException, RepositoryException { resNode.setProperty(Property.JCR_MIMETYPE, document.getMetadata().getMimeType()); resNode.setProperty(Property.JCR_ENCODING, document.getMetadata().getEncoding()); resNode.setProperty(Property.JCR_DATA, convertToBinary(document.getInputStream())); /** Set last updated date time */ Calendar now = Calendar.getInstance(); now.setTime(new Date()); resNode.setProperty(Property.JCR_LAST_MODIFIED, now); /** Update the user information */ String userName = this.getSession().getUserID(); resNode.setProperty(Property.JCR_LAST_MODIFIED_BY, userName); /** Update document identifier */ if (document.getMetadata() != null) { document.getMetadata().setIdentifier(fileNode.getIdentifier()); } }
private RepositoryFile internalCreateFolder( final Session session, final Serializable parentFolderId, final RepositoryFile folder, final RepositoryFileAcl acl, final String versionMessage) throws RepositoryException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary( session, pentahoJcrConstants, parentFolderId); Node folderNode = JcrRepositoryFileUtils.createFolderNode( session, pentahoJcrConstants, parentFolderId, folder); // we must create the acl during checkout JcrRepositoryFileAclUtils.createAcl( session, pentahoJcrConstants, folderNode.getIdentifier(), acl == null ? defaultAclHandler.createDefaultAcl(folder) : acl); session.save(); if (folder.isVersioned()) { JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary( session, pentahoJcrConstants, folderNode, versionMessage); } JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary( session, pentahoJcrConstants, parentFolderId, Messages.getInstance() .getString( "JcrRepositoryFileDao.USER_0001_VER_COMMENT_ADD_FOLDER", folder.getName(), (parentFolderId == null ? "root" : parentFolderId.toString()))); // $NON-NLS-1$ //$NON-NLS-2$ return JcrRepositoryFileUtils.nodeToFile( session, pentahoJcrConstants, pathConversionHelper, lockHelper, folderNode); }
/** * Transforms JCR {@code Node} into {@code User} object * * @param node JCR {@code Node} * @return {@code User} object */ public static User nodeToUser(Node node) { if (node == null) { throw new IllegalArgumentException("Node is null"); } User user = null; try { user = new User(); user.setUuid(node.getIdentifier()); user.setPassword(node.getProperty(PROP_PASSWORD.toString()).getString()); user.setEmail(node.getProperty(PROP_EMAIL.toString()).getString()); user.setName(node.getProperty(PROP_NAME.toString()).getString()); user.setPrivileged(node.getProperty(PROP_PRIVILEGED.toString()).getBoolean()); user.setProfession( nodeToProfession( node.getSession() .getNodeByIdentifier(node.getProperty(PROP_PROFESSION.toString()).getString()))); } catch (RepositoryException ex) { logger.error("Failed to transform JCR Node to User. " + ex.getMessage()); } return user; }
public void testConcurrentWorkspaceMove() throws RepositoryException { testRootPath = testRootNode.getPath(); testRootNode.addNode("b"); Node aa = testRootNode.addNode("a").addNode("aa"); testRootNode.getSession().save(); String aaId = aa.getIdentifier(); Session session1 = getHelper().getReadWriteSession(); Session session2 = getHelper().getReadWriteSession(); // results in /b/a/aa session1.getWorkspace().move(testRootPath + "/a", testRootPath + "/b/a"); assertEquals(testRootPath + "/b/a/aa", session1.getNodeByIdentifier(aaId).getPath()); // try to move b into a/aa (should fail as the above move is persisted try { session2.getWorkspace().move(testRootPath + "/b", testRootPath + "/a/aa/b"); fail("Workspace.move() should not have succeeded. Possible cyclic path created."); } catch (PathNotFoundException e) { // expected. } }
private void buildContent(int level, Node base) throws RepositoryException { if (level > 1) { for (int i = 0; i < FANOUT; i++) { if (log.isDebugEnabled()) { if (level == DEPTH) { System.err.println(i); } else if (level == DEPTH - 1) { System.err.println(" " + i); } } Node folder = addFolder(base, "folder" + i); buildContent(level - 1, folder); } } else { for (int i = 0; i < FANOUT; i++) { Node document = addDocument(base, "document" + i); documents.add(document.getIdentifier()); if (++saveCounter >= SAVECNT) { session.save(); saveCounter = 0; } } } }
protected void setUp() throws Exception { super.setUp(); VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); String path = versionableNode.getPath(); version = versionManager.checkin(path); versionManager.checkout(path); version2 = versionManager.checkin(path); versionManager.checkout(path); rootVersion = versionManager.getVersionHistory(path).getRootVersion(); // build a second versionable node below the testroot try { versionableNode2 = createVersionableNode(testRootNode, nodeName2, versionableNodeType); } catch (RepositoryException e) { fail("Failed to create a second versionable node: " + e.getMessage()); } try { wSuperuser = getHelper().getSuperuserSession(workspaceName); } catch (RepositoryException e) { fail( "Failed to retrieve superuser session for second workspace '" + workspaceName + "': " + e.getMessage()); } // test if the required nodes exist in the second workspace if not try to clone them try { testRootNode.getCorrespondingNodePath(workspaceName); } catch (ItemNotFoundException e) { // clone testRoot wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), testRoot, testRoot, true); } try { versionableNode.getCorrespondingNodePath(workspaceName); } catch (ItemNotFoundException e) { // clone versionable node wSuperuser .getWorkspace() .clone( superuser.getWorkspace().getName(), versionableNode.getPath(), versionableNode.getPath(), true); } try { versionableNode2.getCorrespondingNodePath(workspaceName); } catch (ItemNotFoundException e) { // clone second versionable node wSuperuser .getWorkspace() .clone( superuser.getWorkspace().getName(), versionableNode2.getPath(), versionableNode2.getPath(), true); } try { // set node-fields (wTestRoot, wVersionableNode, wVersionableNode2) // and check versionable nodes out. wTestRoot = (Node) wSuperuser.getItem(testRootNode.getPath()); wVersionableNode = wSuperuser.getNodeByIdentifier(versionableNode.getIdentifier()); wVersionableNode .getSession() .getWorkspace() .getVersionManager() .checkout(wVersionableNode.getPath()); wVersionableNode2 = wSuperuser.getNodeByIdentifier(versionableNode2.getIdentifier()); wVersionableNode2 .getSession() .getWorkspace() .getVersionManager() .checkout(wVersionableNode2.getPath()); } catch (RepositoryException e) { fail("Failed to setup test environment in workspace: " + e.toString()); } // create persistent versionable CHILD-node below wVersionableNode in workspace 2 // that is not present in the default workspace. try { wVersionableChildNode = createVersionableNode(wVersionableNode, nodeName4, versionableNodeType); } catch (RepositoryException e) { fail("Failed to create versionable child node in second workspace: " + e.getMessage()); } // create a version of the versionable child node VersionManager wVersionManager = wVersionableChildNode.getSession().getWorkspace().getVersionManager(); String wPath = wVersionableChildNode.getPath(); wVersionManager.checkout(wPath); wChildVersion = wVersionManager.checkin(wPath); wVersionManager.checkout(wPath); }