Java Code Examples for javax.jcr.Node#addMixin()
The following examples show how to use
javax.jcr.Node#addMixin() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 6 votes |
@Override public RepositoryFile createProject(String projectName, User user,boolean classify) throws Exception{ if(!permissionService.isAdmin()){ throw new NoPermissionException(); } repositoryInteceptor.createProject(projectName); Node rootNode=getRootNode(); if(rootNode.hasNode(projectName)){ throw new RuleException("Project ["+projectName+"] already exist."); } Node projectNode=rootNode.addNode(projectName); projectNode.addMixin("mix:versionable"); projectNode.setProperty(FILE, true); projectNode.setProperty(CRATE_USER,user.getUsername()); projectNode.setProperty(COMPANY_ID, user.getCompanyId()); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); DateValue dateValue = new DateValue(calendar); projectNode.setProperty(CRATE_DATE, dateValue); session.save(); createResourcePackageFile(projectName,user); createClientConfigFile(projectName, user); RepositoryFile projectFileInfo=buildProjectFile(projectNode, null ,classify,null); return projectFileInfo; }
Example 2
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
private Node getOrAddNodeByPath(Node baseNode, String name, String nodeType, boolean primaryType) throws RepositoryException { log.debug("getOrAddNodeByPath " + baseNode + " " + name + " " + nodeType); Node node = baseNode; for (String n : name.split("/")) { if (nodeType != null && primaryType) { node = JcrUtils.getOrAddNode(node, n, nodeType); } else { node = JcrUtils.getOrAddNode(node, n); if (nodeType != null && !node.isNodeType(nodeType)) { node.addMixin(nodeType); } } if (!node.hasProperty("id")) { node.setProperty("id", n); } } return node; }
Example 3
Source File: JcrACLManagement.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public boolean ensureAccessControllable(Node node, String policyPrimaryType) throws RepositoryException { boolean modified = false; if ("rep:ACL".equals(policyPrimaryType)) { if (!node.isNodeType("rep:AccessControllable")) { node.addMixin("rep:AccessControllable"); modified = true; } if (isRootNode(node) && !node.isNodeType("rep:RepoAccessControllable")) { node.addMixin("rep:RepoAccessControllable"); modified = true; } } else if ("rep:CugPolicy".equals(policyPrimaryType)) { if (!node.isNodeType("rep:CugMixin")) { node.addMixin("rep:CugMixin"); modified = true; } } else if ("rep:PrincipalPolicy".equals(policyPrimaryType)) { if (!node.isNodeType("rep:PrincipalBasedMixin")) { node.addMixin("rep:PrincipalBasedMixin"); modified = true; } } return modified; }
Example 4
Source File: JcrPackageRegistry.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * Creates a new jcr vault package. * * @param parent the parent node * @param pid the package id of the new package. * @param bin the binary containing the zip * @param archive the archive with the meta data * @return the created jcr vault package. * @throws RepositoryException if an repository error occurs * @throws IOException if an I/O error occurs * * @since 3.1 */ @NotNull private JcrPackage createNew(@NotNull Node parent, @NotNull PackageId pid, @NotNull Binary bin, @NotNull MemoryArchive archive) throws RepositoryException, IOException { Node node = parent.addNode(Text.getName(getInstallationPath(pid) + ".zip"), JcrConstants.NT_FILE); Node content = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); content.addMixin(JcrPackage.NT_VLT_PACKAGE); Node defNode = content.addNode(JcrPackage.NN_VLT_DEFINITION); JcrPackageDefinitionImpl def = new JcrPackageDefinitionImpl(defNode); def.set(JcrPackageDefinition.PN_NAME, pid.getName(), false); def.set(JcrPackageDefinition.PN_GROUP, pid.getGroup(), false); def.set(JcrPackageDefinition.PN_VERSION, pid.getVersionString(), false); def.touch(null, false); content.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance()); content.setProperty(JcrConstants.JCR_MIMETYPE, JcrPackage.MIME_TYPE); content.setProperty(JcrConstants.JCR_DATA, bin); def.unwrap(archive, false); dispatch(PackageEvent.Type.CREATE, pid, null); return new JcrPackageImpl(this, node); }
Example 5
Source File: TestAtomicCounter.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * Tests if installing a package with a mix:atomicCounter works (update) */ @Test public void updateAtomicCounter() throws RepositoryException, IOException, PackageException { Assume.assumeTrue(isOak()); Node tmp = JcrUtils.getOrAddNode(admin.getRootNode(), "tmp", NodeType.NT_UNSTRUCTURED); Node testroot = JcrUtils.getOrAddNode(tmp, "testroot", NodeType.NT_UNSTRUCTURED); testroot.addMixin("mix:atomicCounter"); testroot.setProperty("oak:increment", 5); admin.save(); assertEquals(5L, testroot.getProperty("oak:counter").getLong()); JcrPackage pack = packMgr.upload(getStream("/test-packages/atomic-counter-test.zip"), false); assertNotNull(pack); ImportOptions opts = getDefaultOptions(); pack.install(opts); assertProperty("/tmp/testroot/oak:counter", "42"); }
Example 6
Source File: RCPTest.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Test public void testAddMixin() throws IOException, RepositoryException, ConfigurationException { Node a = JcrUtils.getOrCreateByPath(SRC_TEST_NODE_PATH, NodeType.NT_FOLDER, NodeType.NT_FOLDER, admin, true); RepositoryCopier rcp = new RepositoryCopier(); rcp.copy(admin, SRC_PATH, admin, DST_PATH, true); assertNodeExists(DST_TEST_NODE_PATH); assertPropertyMissing(DST_TEST_NODE_PATH + "/jcr:title"); a.addMixin(NodeType.MIX_TITLE); a.setProperty("jcr:title", "Hello"); admin.save(); assertProperty(SRC_TEST_NODE_PATH + "/jcr:title", "Hello"); rcp = new RepositoryCopier(); rcp.setOnlyNewer(false); rcp.setUpdate(true); rcp.copy(admin, SRC_PATH, admin, DST_PATH, true); assertProperty(DST_TEST_NODE_PATH + "/jcr:title", "Hello"); assertProperty(DST_TEST_NODE_PATH + "/jcr:mixinTypes", new String[]{"mix:title"}); }
Example 7
Source File: StorageUpdate14.java From nextreports-server with Apache License 2.0 | 5 votes |
private void createIFrameSettings() throws RepositoryException, IOException { LOG.info("Add IFrame Settings Node"); Node rootNode = getTemplate().getRootNode(); Node settingsNode = rootNode.getNode(StorageConstants.NEXT_SERVER_FOLDER_NAME + StorageConstants.PATH_SEPARATOR + StorageConstants.SETTINGS_FOLDER_NAME); Node iframeNode = settingsNode.addNode(StorageConstants.IFRAME); iframeNode.addMixin("mix:referenceable"); iframeNode.setProperty("className", IFrameSettings.class.getName()); iframeNode.setProperty(StorageConstants.IFRAME_ENABLE, true); iframeNode.setProperty(StorageConstants.IFRAME_AUTH, false); iframeNode.setProperty(StorageConstants.IFRAME_ENC, "next$"); getTemplate().save(); }
Example 8
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
private Node getOrAddProjectNode(Session jcrSession, String repositoryId, String namespace, String projectId) throws RepositoryException { Node namespaceNode = getOrAddNamespaceNode(jcrSession, repositoryId, namespace); Node node = JcrUtils.getOrAddNode(namespaceNode, projectId, FOLDER_TYPE); if (!node.isNodeType(PROJECT_MIXIN_TYPE)) { node.addMixin(PROJECT_MIXIN_TYPE); } if (!node.hasProperty("id")) { node.setProperty("id", projectId); } return node; }
Example 9
Source File: PageServiceImpl.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
private static Node convertPageToNode(Node node, Page page, String createdUser) { try { node.addMixin(NodeType.MIX_VERSIONABLE); node.setProperty("wiki:subject", page.getSubject()); node.setProperty("wiki:content", page.getContent()); node.setProperty("wiki:status", page.getStatus()); node.setProperty("wiki:category", page.getCategory()); node.setProperty("wiki:isLock", page.isLock()); node.setProperty("wiki:createdUser", createdUser); return node; } catch (Exception e) { throw new MyCollabException(e); } }
Example 10
Source File: StorageUpdate19.java From nextreports-server with Apache License 2.0 | 5 votes |
private void createIntegrationSettings() throws RepositoryException, IOException { LOG.info("Add Integration Settings Node"); Node rootNode = getTemplate().getRootNode(); Node settingsNode = rootNode.getNode(StorageConstants.NEXT_SERVER_FOLDER_NAME + StorageConstants.PATH_SEPARATOR + StorageConstants.SETTINGS_FOLDER_NAME); Node iframeNode = settingsNode.addNode(StorageConstants.INTEGRATION); iframeNode.addMixin("mix:referenceable"); iframeNode.setProperty("className", IntegrationSettings.class.getName()); iframeNode.setProperty(StorageConstants.INTEGRATION_DRILL_URL, ""); iframeNode.setProperty(StorageConstants.INTEGRATION_NOTIFY_URL, ""); getTemplate().save(); }
Example 11
Source File: ImportTests.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testSubArchiveExtract() throws IOException, RepositoryException, ConfigurationException { ZipArchive archive = new ZipArchive(getTempFile("/test-packages/tmp_with_thumbnail.zip")); archive.open(true); Node rootNode = admin.getRootNode(); Node tmpNode = rootNode.addNode("tmp"); Node fileNode = tmpNode.addNode("package.zip", "nt:file"); Node contentNode = fileNode.addNode("jcr:content", "nt:resource"); contentNode.setProperty("jcr:data", ""); contentNode.setProperty("jcr:lastModified", 0); contentNode.addMixin("vlt:Package"); Node defNode = contentNode.addNode("vlt:definition", "vlt:PackageDefinition"); ImportOptions opts = getDefaultOptions(); Archive subArchive = archive.getSubArchive("META-INF/vault/definition", true); DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter(); filter.add(new PathFilterSet(defNode.getPath())); Importer importer = new Importer(opts); importer.getOptions().setAutoSaveThreshold(Integer.MAX_VALUE); importer.getOptions().setFilter(filter); importer.run(subArchive, defNode); admin.save(); assertFalse("Importer must not have any errors", importer.hasErrors()); assertNodeExists("/tmp/package.zip/jcr:content/vlt:definition/thumbnail.png"); }
Example 12
Source File: StorageUpdate22.java From nextreports-server with Apache License 2.0 | 5 votes |
private void createAnalysisNode() throws RepositoryException { LOG.info("Creating analysis node"); Node rootNode = getTemplate().getRootNode(); Node nextServerNode = rootNode.getNode(StorageConstants.NEXT_SERVER_FOLDER_NAME); Node analysisNode = nextServerNode.addNode(StorageConstants.ANALYSIS_FOLDER_NAME); analysisNode.addMixin("mix:referenceable"); analysisNode.setProperty("className", Folder.class.getName()); getTemplate().save(); }
Example 13
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 5 votes |
@Override public void lockPath(String path,User user) throws Exception{ path = processPath(path); int pos=path.indexOf(":"); if(pos!=-1){ path=path.substring(0,pos); } Node rootNode=getRootNode(); if (!rootNode.hasNode(path)) { throw new RuleException("File [" + path + "] not exist."); } Node fileNode = rootNode.getNode(path); String topAbsPath=fileNode.getPath(); if(lockManager.isLocked(topAbsPath)){ String owner=lockManager.getLock(topAbsPath).getLockOwner(); throw new NodeLockException("【"+path+"】已被"+owner+"锁定,您不能进行再次锁定!"); } List<Node> nodeList=new ArrayList<Node>(); unlockAllChildNodes(fileNode, user, nodeList, path); for(Node node:nodeList){ if(!lockManager.isLocked(node.getPath())){ continue; } Lock lock=lockManager.getLock(node.getPath()); lockManager.unlock(lock.getNode().getPath()); } if(!fileNode.isNodeType(NodeType.MIX_LOCKABLE)){ if (!fileNode.isCheckedOut()) { versionManager.checkout(fileNode.getPath()); } fileNode.addMixin("mix:lockable"); session.save(); } lockManager.lock(topAbsPath, true, true, Long.MAX_VALUE, user.getUsername()); }
Example 14
Source File: RCPTest.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
@Test public void testMixin() throws IOException, RepositoryException, ConfigurationException { Node a = JcrUtils.getOrCreateByPath(SRC_TEST_NODE_PATH, NodeType.NT_FOLDER, NodeType.NT_FOLDER, admin, true); RepositoryCopier rcp = new RepositoryCopier(); a.addMixin(NodeType.MIX_TITLE); a.setProperty("jcr:title", "Hello"); admin.save(); rcp.copy(admin, SRC_PATH, admin, DST_PATH, true); assertProperty(DST_TEST_NODE_PATH + "/jcr:title", "Hello"); assertProperty(DST_TEST_NODE_PATH + "/jcr:mixinTypes", new String[]{"mix:title"}); }
Example 15
Source File: JcrPackageRegistry.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Creates a new jcr vault package. * * @param parent the parent node * @param pid the package id of the new package. * @param pack the underlying zip package or null. * @param autoSave if {@code true} the changes are persisted immediately * @return the created jcr vault package. * @throws RepositoryException if an repository error occurs * @throws IOException if an I/O error occurs * * @since 2.3.0 */ @NotNull public JcrPackage createNew(@NotNull Node parent, @NotNull PackageId pid, @Nullable VaultPackage pack, boolean autoSave) throws RepositoryException, IOException { Node node = parent.addNode(Text.getName(getInstallationPath(pid) + ".zip"), JcrConstants.NT_FILE); Node content = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); content.addMixin(JcrPackage.NT_VLT_PACKAGE); Node defNode = content.addNode(JcrPackage.NN_VLT_DEFINITION); JcrPackageDefinition def = new JcrPackageDefinitionImpl(defNode); def.set(JcrPackageDefinition.PN_NAME, pid.getName(), false); def.set(JcrPackageDefinition.PN_GROUP, pid.getGroup(), false); def.set(JcrPackageDefinition.PN_VERSION, pid.getVersionString(), false); def.touch(null, false); content.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance()); content.setProperty(JcrConstants.JCR_MIMETYPE, JcrPackage.MIME_TYPE); InputStream in = new ByteArrayInputStream(new byte[0]); try { if (pack != null && pack.getFile() != null) { in = FileUtils.openInputStream(pack.getFile()); } // stay jcr 1.0 compatible //noinspection deprecation content.setProperty(JcrConstants.JCR_DATA, in); if (pack != null) { def.unwrap(pack, true, false); } if (autoSave) { parent.getSession().save(); } } finally { IOUtils.closeQuietly(in); } dispatch(PackageEvent.Type.CREATE, pid, null); return new JcrPackageImpl(this, node, (ZipVaultPackage) pack); }
Example 16
Source File: JcrPackageImpl.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** * Tries to unwrap the definition of this package. * @throws IOException if an I/O error occurs or if the underlying file is not a package * @throws RepositoryException if a repository error occurs */ public void tryUnwrap() throws IOException, RepositoryException { if (isValid()) { return; } if (node == null) { return; } VaultPackage pack = getPackage(); Node content = getContent(); if (content == null) { return; } boolean ok = false; try { content.addMixin(NT_VLT_PACKAGE); Node defNode = content.addNode(NN_VLT_DEFINITION); JcrPackageDefinition def = new JcrPackageDefinitionImpl(defNode); def.unwrap(pack, true, false); node.getSession().save(); ok = true; } finally { if (!ok) { try { node.getSession().refresh(false); } catch (RepositoryException e) { // ignore } } } }
Example 17
Source File: RepositoryServiceImpl.java From urule with Apache License 2.0 | 5 votes |
private void createFileNode(String path, String content,User user,boolean isFile) throws Exception{ String createUser=user.getUsername(); repositoryInteceptor.createFile(path,content); Node rootNode=getRootNode(); path = processPath(path); try { if (rootNode.hasNode(path)) { throw new RuleException("File [" + path + "] already exist."); } Node fileNode = rootNode.addNode(path); fileNode.addMixin("mix:versionable"); fileNode.addMixin("mix:lockable"); Binary fileBinary = new BinaryImpl(content.getBytes()); fileNode.setProperty(DATA, fileBinary); if(isFile){ fileNode.setProperty(FILE, true); } fileNode.setProperty(CRATE_USER, createUser); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); DateValue dateValue = new DateValue(calendar); fileNode.setProperty(CRATE_DATE, dateValue); session.save(); } catch (Exception ex) { throw new RuleException(ex); } }
Example 18
Source File: StorageUpdate2.java From nextreports-server with Apache License 2.0 | 5 votes |
private void createDashboardsNode() throws RepositoryException { LOG.info("Creating dashboards node"); Node rootNode = getTemplate().getRootNode(); Node nextServerNode = rootNode.getNode(StorageConstants.NEXT_SERVER_FOLDER_NAME); Node dashboardsNode = nextServerNode.addNode(StorageConstants.DASHBOARDS_FOLDER_NAME); dashboardsNode.addMixin("mix:referenceable"); dashboardsNode.setProperty("className", Folder.class.getName()); getTemplate().save(); }
Example 19
Source File: StorageUpdate0.java From nextreports-server with Apache License 2.0 | 4 votes |
private void createSystemNodes() throws RepositoryException { LOG.info("Creating system nodes"); Node rootNode = getTemplate().getRootNode(); Node nextServerNode = rootNode.addNode(StorageConstants.NEXT_SERVER_FOLDER_NAME); nextServerNode.addMixin("mix:referenceable"); nextServerNode.setProperty("className", Folder.class.getName()); nextServerNode.setProperty("version", "-1"); Node reportsNode = nextServerNode.addNode(StorageConstants.REPORTS_FOLDER_NAME); reportsNode.addMixin("mix:referenceable"); reportsNode.setProperty("className", Folder.class.getName()); Node datasourcesNode = nextServerNode.addNode(StorageConstants.DATASOURCES_FOLDER_NAME); datasourcesNode.addMixin("mix:referenceable"); datasourcesNode.setProperty("className", Folder.class.getName()); Node schedulersNode = nextServerNode.addNode(StorageConstants.SCHEDULER_FOLDER_NAME); schedulersNode.addMixin("mix:referenceable"); schedulersNode.setProperty("className", Folder.class.getName()); Node securityNode = nextServerNode.addNode(StorageConstants.SECURITY_FOLDER_NAME); securityNode.addMixin("mix:referenceable"); securityNode.setProperty("className", Folder.class.getName()); Node usersNode = securityNode.addNode(StorageConstants.USERS_FOLDER_NAME); usersNode.addMixin("mix:referenceable"); usersNode.setProperty("className", Folder.class.getName()); Node groupsNode = securityNode.addNode(StorageConstants.GROUPS_FOLDER_NAME); groupsNode.addMixin("mix:referenceable"); groupsNode.setProperty("className", Folder.class.getName()); Node adminNode = usersNode.addNode(StorageConstants.ADMIN_USER_NAME); adminNode.addMixin("mix:referenceable"); adminNode.setProperty("className", User.class.getName()); adminNode.setProperty("admin", true); PasswordEncoder passwordEncoder = new Md5PasswordEncoder(); adminNode.setProperty("password", passwordEncoder.encodePassword("1", null)); getTemplate().save(); }
Example 20
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 4 votes |
private Node addNodeWithUUID(Node parentNode, Entity entity, String UUID) { try { Node node; JcrNode jcrNode = ReflectionUtils.getJcrNodeAnnotation(entity.getClass()); // check if we should use a specific node type if (jcrNode == null || jcrNode.nodeType().equals("nt:unstructured")) { if (parentNode instanceof NodeImpl) { node = ((NodeImpl) parentNode).addNodeWithUuid(entity.getName(), UUID); } else { node = parentNode.addNode(entity.getName()); } } else { if (parentNode instanceof NodeImpl) { node = ((NodeImpl) parentNode).addNodeWithUuid(entity.getName(), jcrNode.nodeType(), UUID); } else { node = parentNode.addNode(entity.getName(), jcrNode.nodeType()); } } // add annotated mixin types if (jcrNode != null && jcrNode.mixinTypes() != null) { for (String mixinType : jcrNode.mixinTypes()) { if (node.canAddMixin(mixinType)) { node.addMixin(mixinType); } } } // update the object name and path setNodeName(entity, node.getName()); setNodePath(entity, node.getPath()); if (node.hasProperty("jcr:uuid")) { setUUID(entity, node.getIdentifier()); } // map the class name to a property if (jcrNode != null && !jcrNode.classNameProperty().equals("none")) { node.setProperty(jcrNode.classNameProperty(), entity.getClass().getCanonicalName()); } // do update to make internal jcrom business! getJcrom().updateNode(node, entity); return node; } catch (Exception e) { throw new JcrMappingException("Could not create node from object", e); } }