/** * Get content of document node. Content is got by exo:content or exo:text or exo:summary * * @param node * @return * @throws Exception */ private DocumentContent getArticleContent(Node node, List<Node> taxonomyTrees) throws Exception { DocumentContent documentContent = new DocumentContent(node.getName(), getIcon(node), "", getType(node)); // If node is added mix rss-enabled then get exo:content property if (node.hasProperty("exo:content")) { documentContent.setContent(node.getProperty("exo:content").getString()); } // Some node have exo:text so we override value of exo:content if (node.hasProperty("exo:text")) { documentContent.setContent(node.getProperty("exo:text").getString()); } // Some node have exo:summary so we override value of exo:content if (node.hasProperty("exo:summary")) { documentContent.setContent(node.getProperty("exo:summary").getString()); } List<Node> categories = taxonomyService_.getAllCategories(node); CategoryNode categoryNode; for (Node category : categories) { categoryNode = getCategoryNode(category, ""); for (Node taxonomyTree : taxonomyTrees) { if (category.getPath().contains(taxonomyTree.getPath())) { categoryNode.setParentPath( (category.getParent().getPath().replace(taxonomyTree.getParent().getPath(), ""))); break; } } if (categoryNode != null) documentContent.getCategories().add(categoryNode); } return documentContent; }
@Override public ResultNode createData(Node node, Row row) { try { PortalRequestContext portalRequestContext = Util.getPortalRequestContext(); PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance(); PortletRequest portletRequest = portletRequestContext.getRequest(); StringBuffer baseURI = new StringBuffer(); baseURI .append(portletRequest.getScheme()) .append("://") .append(portletRequest.getServerName()); if (portletRequest.getServerPort() != 80) { baseURI.append(":").append(String.format("%s", portletRequest.getServerPort())); } baseURI.append(portalRequestContext.getPortalContextPath()); if (node.isNodeType("mop:pagelink")) { node = node.getParent(); } if (node.isNodeType("gtn:language")) { node = node.getParent().getParent(); } String userNaviUri = baseURI.toString() + "/" + PageDataCreator.getUserNavigationURI(node).toString(); if (userNavigationUriList.contains(userNaviUri)) { return null; } userNavigationUriList.add(userNaviUri); return new ResultNode(node, row, userNaviUri); } catch (Exception e) { return null; } }
@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 Location move(Node original, Node newParent, Name newName, Node beforeSibling) throws RepositoryException { // Determine whether the node needs to move ... if (newParent == null && beforeSibling != null) { newParent = beforeSibling.getParent(); } if (newName != null || (newParent != null && !original.getParent().equals(newParent))) { // This is not just a reorder, so we definitely have to move first ... String destAbsPath = newParent != null ? newParent.getPath() : original.getParent().getPath(); assert !destAbsPath.endsWith("/"); String newNameStr = newName != null ? stringFor(newName) : original.getName(); destAbsPath += '/' + newNameStr; session.move(original.getPath(), destAbsPath); } if (beforeSibling != null) { // Even if moved, the 'orginal' node should still point to the node we just moved ... String siblingName = nameFor(beforeSibling); String originalName = nameFor(original); original.getParent().orderBefore(originalName, siblingName); } return locationFor(original); }
private String makePath(Node node, Node rootTree) { try { return node.getParent().getPath().replace(rootTree.getParent().getPath(), ""); } catch (Exception e) { LOG.error("Make Path fail", e); } return ""; }
@Test public void testCreateObjectWithHierarchy() throws Exception { when(mockNode.getParent()).thenReturn(mockParent); when(mockParent.getParent()).thenReturn(mockRoot); when(mockParent.isNew()).thenReturn(true); when(mockRoot.getNode("foo/bar")).thenReturn(mockNode); when(mockNode.getDepth()).thenReturn(1); when(mockNode.isNew()).thenReturn(true); final Node actual = getJcrNode(testObj.findOrCreate(mockSession, "/foo/bar")); assertEquals(mockNode, actual); verify(mockParent).addMixin(FedoraTypes.FEDORA_PAIRTREE); }
@Test(expected = TombstoneException.class) public void testThrowsTombstoneExceptionOnCreateOnTombstone() throws RepositoryException { when(mockNode.getParent()).thenReturn(mockParent); when(mockParent.getParent()).thenReturn(mockRoot); when(mockParent.isNew()).thenReturn(false); when(mockParent.isNodeType(FEDORA_TOMBSTONE)).thenReturn(true); when(mockSession.nodeExists("/foo")).thenReturn(true); when(mockSession.getNode("/foo")).thenReturn(mockParent); when(mockRoot.getNode("foo/bar")).thenReturn(mockNode); when(mockNode.isNew()).thenReturn(true); testObj.findOrCreate(mockSession, "/foo/bar"); }
public VoidReturn execute(Session session) throws Exception { String objectId = null; String description = null; objectId = path.substring(path.lastIndexOf("/") + 1); Node node = null; if (objectId.contains("post")) { while (node == null) { try { node = (Node) getCurrentSession().getItem(path); } catch (PathNotFoundException pn) { path = path.substring(0, path.lastIndexOf("/")); node = null; } } while (node.isNodeType("exo:forumCategory") || node.isNodeType("exo:forum") || node.isNodeType("exo:topic")) { description = new PropertyReader(node).string("exo:description", " "); removeItemInFeed(objectId, node, description); node = node.getParent(); } } else { path = path.substring(0, path.lastIndexOf("/")); while (node == null) { try { node = (Node) getCurrentSession().getItem(path); } catch (PathNotFoundException pn) { objectId = path.substring(path.lastIndexOf("/") + 1); path = path.substring(0, path.lastIndexOf("/")); node = null; } } while (node.isNodeType("exo:forumCategory") || node.isNodeType("exo:forum") || node.isNodeType("exo:topic")) { description = new PropertyReader(node).string("exo:description", " "); if (node.isNodeType("exo:forum") || node.isNodeType("exo:forumCategory")) { removeRSSItem(objectId, node, description); } else { removeItemInFeed(objectId, node, description); } node = node.getParent(); } } return VoidReturn.VALUE; }
private Node populateCache(HtmlLibrary library, String root, Session session) { Node cacheNode = null; try { String libPath = (new StringBuilder(CACHE_PATH).append(library.getPath(false))).toString(); Node src = JcrUtils.getNodeIfExists(libPath, session); cacheNode = session.getNode(root); if (null != src) { // this.lock.readLock().lock(); // produced closure compiled src String compiled = compile(library, this.optimization, JcrUtils.readFile(src)); // this.lock.readLock().unlock(); // this.lock.writeLock().lock(); // JcrUtils.putFile( cacheNode.getParent(), getLibraryName(library), library.getType().contentType, IOUtils.toInputStream(compiled, "UTF-8")); session.save(); // this.lock.writeLock().unlock(); } } catch (RepositoryException re) { log.debug(re.getMessage()); } catch (IOException ioe) { log.debug(ioe.getMessage()); } return cacheNode; }
/** A LockException is thrown if a lock prevents the copy. */ public void testMoveNodesLocked() throws RepositoryException { // we assume repository supports locking String dstAbsPath = node2.getPath() + "/" + node1.getName(); // get other session Session otherSession = helper.getReadWriteSession(); try { // get lock target node in destination wsp through other session Node lockTarget = (Node) otherSession.getItem(node2.getPath()); // add mixin "lockable" to be able to lock the node if (!lockTarget.getPrimaryNodeType().isNodeType(mixLockable)) { lockTarget.addMixin(mixLockable); lockTarget.getParent().save(); } // lock dst parent node using other session lockTarget.lock(true, true); try { workspace.move(node1.getPath(), dstAbsPath); fail("LockException was expected."); } catch (LockException e) { // successful } finally { lockTarget.unlock(); } } finally { otherSession.logout(); } }
public static String getRealNodePath(Node node) throws Exception { if (node.isNodeType("nt:frozenNode")) { Node realNode = getRealNode(node); return Text.escape(realNode.getPath(), '%', true) + "?version=" + node.getParent().getName(); } return Text.escape(node.getPath(), '%', true); }
private JcrNodeModel getPhysicalNode(JcrNodeModel model) { Node node = model.getNode(); if (node != null) { try { if (node.isNodeType("nt:version")) { Node frozen = node.getNode("jcr:frozenNode"); String uuid = frozen.getProperty("jcr:frozenUuid").getString(); try { Node docNode = node.getSession().getNodeByUUID(uuid); if (docNode.getDepth() > 0) { Node parent = docNode.getParent(); if (parent.isNodeType(HippoNodeType.NT_HANDLE)) { return new JcrNodeModel(parent); } } return new JcrNodeModel(docNode); } catch (ItemNotFoundException infe) { // node doesn't exist anymore. If it's a document, the handle // should still be available though. if (frozen.hasProperty(HippoNodeType.HIPPO_PATHS)) { Value[] ancestors = frozen.getProperty(HippoNodeType.HIPPO_PATHS).getValues(); if (ancestors.length > 1) { uuid = ancestors[1].getString(); return new JcrNodeModel(node.getSession().getNodeByUUID(uuid)); } } throw infe; } } } catch (RepositoryException ex) { log.error(ex.getMessage()); } } return model; }
@Override public FedoraResource getVersionedAncestor() { try { if (!isFrozenResource()) { return null; } Node versionableFrozenNode = getNode(); FedoraResource unfrozenResource = getUnfrozenResource(); // traverse the frozen tree looking for a node whose unfrozen equivalent is versioned while (!unfrozenResource.isVersioned()) { if (versionableFrozenNode.getDepth() == 0) { return null; } // node in the frozen tree versionableFrozenNode = versionableFrozenNode.getParent(); // unfrozen equivalent unfrozenResource = new FedoraResourceImpl(versionableFrozenNode).getUnfrozenResource(); } return new FedoraResourceImpl(versionableFrozenNode); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
/** {@inheritDoc} */ public void undeleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException { Node fileToUndeleteNode = session.getNodeByIdentifier(fileId.toString()); String trashFileIdNodePath = fileToUndeleteNode.getParent().getPath(); String origParentFolderPath = getOriginalParentFolderPath(session, pentahoJcrConstants, fileToUndeleteNode, false); String absDestPath = origParentFolderPath + RepositoryFile.SEPARATOR + fileToUndeleteNode.getName(); if (session.itemExists(absDestPath)) { RepositoryFile file = JcrRepositoryFileUtils.nodeToFile( session, pentahoJcrConstants, pathConversionHelper, lockHelper, (Node) session.getItem(absDestPath)); throw new RepositoryFileDaoFileExistsException(file); } session.move(fileToUndeleteNode.getPath(), absDestPath); session.getItem(trashFileIdNodePath).remove(); }
@Test public void shouldReadFederatedNodeInProjection() throws Exception { Node git = gitNode(); assertThat(git, is(notNullValue())); assertThat(git.getParent(), is(sameInstance(testRoot))); assertThat(git.getPath(), is(testRoot.getPath() + "/git-modeshape")); assertThat(git.getName(), is("git-modeshape")); }
/** * initializes fields * * @throws Exception */ public void initParams() throws Exception { // get current node // name field if (currentNode.hasProperty("exo:title")) { nameValue_ = currentNode.getProperty("exo:title").getValue().getString(); } if (currentNode.hasNode("jcr:content")) { Node content = currentNode.getNode("jcr:content"); if (content.hasProperty("dc:title")) { try { nameValue_ = content.getProperty("dc:title").getValues()[0].getString(); } catch (Exception e) { nameValue_ = null; } } } if (nameValue_ == null) nameValue_ = currentNode.getName(); boolean hasNavigableMixinType = currentNode.isNodeType("exo:navigable"); if (hasNavigableMixinType) { isVisible = true; if (currentNode.getParent().isNodeType("exo:navigable")) { if (currentNode.hasProperty("exo:index")) { index_ = currentNode.getProperty("exo:index").getLong(); } renderIndexField = true; } if (currentNode.hasProperty("exo:navigationNode")) { navigationNode_ = currentNode.getProperty("exo:navigationNode").getString(); } if (currentNode.hasProperty("exo:clickable")) { if (currentNode.getProperty("exo:clickable").getBoolean()) { isClickable = true; } else isClickable = false; } if (currentNode.hasProperty("exo:page")) { listTargetPage_ = currentNode.getProperty("exo:page").getString(); } if (currentNode.hasProperty("exo:pageParamId")) { listShowClvBy_ = currentNode.getProperty("exo:pageParamId").getString(); } if (currentNode.hasProperty("exo:childrenPage")) { detailTargetPage_ = currentNode.getProperty("exo:childrenPage").getString(); } if (currentNode.hasProperty("exo:childrenPageParamId")) { detailShowClvBy_ = currentNode.getProperty("exo:childrenPageParamId").getString(); } } }
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; }
private Date getDeletedDate( final Node trashFileNode, final PentahoJcrConstants pentahoJcrConstants) throws RepositoryException { if (trashFileNode.getParent().hasProperty(pentahoJcrConstants.getPHO_DELETEDDATE())) { return trashFileNode .getParent() .getProperty(pentahoJcrConstants.getPHO_DELETEDDATE()) .getDate() .getTime(); } else { // legacy mode return trashFileNode .getParent() .getProperty(pentahoJcrConstants.getPHO_DELETEDDATE()) .getDate() .getTime(); } }
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; }
protected Node getNodeToCheckState(Node node) throws Exception { Node displayNode = node; if (displayNode.isNodeType("nt:resource")) { displayNode = node.getParent(); } // return exo:webContent when exo:htmlFile found if (displayNode.isNodeType("exo:htmlFile")) { Node parent = displayNode.getParent(); if (parent.isNodeType("exo:webContent")) return parent; return displayNode; } // String[] contentTypes = queryCriteria.getContentTypes(); if (contentTypes != null && contentTypes.length > 0) { String primaryNodeType = displayNode.getPrimaryNodeType().getName(); if (!ArrayUtils.contains(contentTypes, primaryNodeType)) return null; } return displayNode; }
@Before public void setUp() throws RepositoryException { testObj = new ContainerServiceImpl(); when(mockSession.getRootNode()).thenReturn(mockRoot); when(mockSession.nodeExists("/")).thenReturn(true); when(mockSession.getNode("/")).thenReturn(mockRoot); when(mockRoot.getNode(testPath.substring(1))).thenReturn(mockNode); when(mockNode.getParent()).thenReturn(mockRoot); when(mockRoot.isNew()).thenReturn(false); }
@Override public boolean importContent(ImportContext context, boolean isCollection) throws IOException { if (!canImport(context, isCollection)) { throw new IOException(getName() + ": Cannot import " + context.getSystemId()); } boolean success = false; try { Node contentNode = getContentNode(context, isCollection); String ext = FilenameUtils.getExtension(context.getSystemId()); if (ext.equals("saiku")) { contentNode.getParent().addMixin("nt:saikufiles"); } else if (ext.equals("xml")) { contentNode.getParent().addMixin("nt:mondrianschema"); } else if (ext.equals("sds")) { contentNode.getParent().addMixin("nt:olapdatasource"); } else if (isCollection) { contentNode.getParent().addMixin("nt:saikufolders"); } // contentNode.addNode("jcr:content", "nt:resource"); success = importData(context, isCollection, contentNode); if (success) { success = importProperties(context, isCollection, contentNode); } } catch (RepositoryException e) { success = false; throw new IOException(e.getMessage()); } finally { // revert any changes made in case the import failed. if (!success) { try { context.getImportRoot().refresh(false); } catch (RepositoryException e) { throw new IOException(e.getMessage()); } } } return success; }
/** * Compute the name of the output node. If the selected node is named "jcr:content", this method * assumes that the selected node is a child of an 'nt:file' node, and so it returns the name of * that 'nt:file' node. Otherwise, this method returns the name of the selected node. * * @param selectedNode the node that was selected for sequencing; may not be null * @return the name that should be used for the output node; never null * @throws RepositoryException if there is a problem accessing the repository content */ protected final String computeOutputNodeName(Node selectedNode) throws RepositoryException { String selectedNodeName = selectedNode.getName(); if (selectedNodeName.equals(JcrConstants.JCR_CONTENT)) { try { return selectedNode.getParent().getName(); } catch (ItemNotFoundException e) { // selected node must be the root node ?!?! } } return selectedNodeName; }
@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()); }
protected Node getNodeToCheckState(Node node) throws Exception { Node displayNode = node; if (node.getPath().contains("web contents/site artifacts")) { return null; } if (displayNode.isNodeType("nt:resource")) { displayNode = node.getParent(); } if (displayNode.isNodeType("exo:htmlFile")) { Node parent = displayNode.getParent(); if (queryCriteria.isSearchWebContent()) { if (parent.isNodeType("exo:webContent")) return parent; return null; } if (parent.isNodeType("exo:webContent")) return null; return displayNode; } /* if(queryCriteria.isSearchWebContent()) { if(!queryCriteria.isSearchDocument()) { if(!displayNode.isNodeType("exo:webContent")) return null; } if(queryCriteria.isSearchWebpage()) { if (!displayNode.isNodeType("publication:webpagesPublication")) return null; } } else if(queryCriteria.isSearchWebpage()) { if (queryCriteria.isSearchDocument()) { return displayNode; } else if (!displayNode.isNodeType("publication:webpagesPublication")) return null; } */ String[] contentTypes = queryCriteria.getContentTypes(); if (contentTypes != null && contentTypes.length > 0) { String primaryNodeType = displayNode.getPrimaryNodeType().getName(); if (!ArrayUtils.contains(contentTypes, primaryNodeType)) return null; } return displayNode; }
/* Check the current node is eligible to add mix:versionable or not * * @param node the current node * @param nodetypes The list of node types have child nodes which are not add mix:versionaboe while enrolling. * @throws Exception the exception */ public static boolean isMakeVersionable(Node node, String[] nodetypes) throws Exception { boolean isMakeVersionable = true; int deep = node.getDepth(); for (int i = 0; i < deep; i++) { Node parent = node.getParent(); for (String nodetype : nodetypes) { if (nodetype != null && nodetype.length() > 0 && parent.isNodeType(nodetype)) return false; } node = parent; } return isMakeVersionable; }
@Test public void shouldFindMasterBranchAsPrimaryItemUnderTreeNode() throws Exception { Node git = gitNode(); Node tree = git.getNode("tree"); Item primaryItem = tree.getPrimaryItem(); assertThat(primaryItem, is(notNullValue())); assertThat(primaryItem, is(instanceOf(Node.class))); Node primaryNode = (Node) primaryItem; assertThat(primaryNode.getName(), is("master")); assertThat(primaryNode.getParent(), is(sameInstance(tree))); assertThat(primaryNode, is(sameInstance(tree.getNode("master")))); }
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; }
private Node prepNode(ResourceResolver resolver, String path) throws RepositoryException { // Get the encoding node, remove it (as a way to easily remove all the existing presets), then // create the node again // Session session = resolver.adaptTo(Session.class); Node targetNode = JcrResourceUtil.createPath(path, "nt:unstructured", "nt:unstructured", session, false); Node parent = targetNode.getParent(); String nodeName = targetNode.getName(); targetNode.remove(); return parent.addNode(nodeName); }
private Topic getTopic(Node topicNode) throws Exception { if (topicNode == null) return null; Topic topicNew = new Topic(); PropertyReader reader = new PropertyReader(topicNode); topicNew.setId(topicNode.getName()); topicNew.setPath(topicNode.getPath()); topicNew.setIcon(reader.string(ForumNodeTypes.EXO_ICON)); topicNew.setTopicType(reader.string(ForumNodeTypes.EXO_TOPIC_TYPE, " ")); topicNew.setTopicName(reader.string(ForumNodeTypes.EXO_NAME)); topicNew.setOwner(reader.string(ForumNodeTypes.EXO_OWNER)); topicNew.setCreatedDate(reader.date(ForumNodeTypes.EXO_CREATED_DATE)); topicNew.setDescription(reader.string(ForumNodeTypes.EXO_DESCRIPTION)); topicNew.setLastPostBy(reader.string(ForumNodeTypes.EXO_LAST_POST_BY)); topicNew.setLastPostDate(reader.date(ForumNodeTypes.EXO_LAST_POST_DATE)); topicNew.setIsSticky(reader.bool(ForumNodeTypes.EXO_IS_STICKY)); if (topicNode.getParent().getProperty(ForumNodeTypes.EXO_IS_LOCK).getBoolean()) topicNew.setIsLock(true); else topicNew.setIsLock(topicNode.getProperty(ForumNodeTypes.EXO_IS_LOCK).getBoolean()); topicNew.setIsClosed(reader.bool(ForumNodeTypes.EXO_IS_CLOSED)); topicNew.setIsApproved(reader.bool(ForumNodeTypes.EXO_IS_APPROVED)); topicNew.setIsActive(reader.bool(ForumNodeTypes.EXO_IS_ACTIVE)); topicNew.setIsWaiting(reader.bool(ForumNodeTypes.EXO_IS_WAITING)); topicNew.setIsActiveByForum(reader.bool(ForumNodeTypes.EXO_IS_ACTIVE_BY_FORUM)); topicNew.setIsPoll(reader.bool(ForumNodeTypes.EXO_IS_POLL)); topicNew.setPostCount(reader.l(ForumNodeTypes.EXO_POST_COUNT)); topicNew.setViewCount(reader.l(ForumNodeTypes.EXO_VIEW_COUNT)); topicNew.setNumberAttachment(reader.l(ForumNodeTypes.EXO_NUMBER_ATTACHMENTS)); topicNew.setUserVoteRating(reader.strings(ForumNodeTypes.EXO_USER_VOTE_RATING)); topicNew.setVoteRating(reader.d(ForumNodeTypes.EXO_VOTE_RATING)); // update more properties for topicNew. topicNew.setModifiedBy(reader.string(ForumNodeTypes.EXO_MODIFIED_BY)); topicNew.setModifiedDate(reader.date(ForumNodeTypes.EXO_MODIFIED_DATE)); topicNew.setIsModeratePost(reader.bool(ForumNodeTypes.EXO_IS_MODERATE_POST)); topicNew.setIsNotifyWhenAddPost( reader.string(ForumNodeTypes.EXO_IS_NOTIFY_WHEN_ADD_POST, null)); topicNew.setLink(reader.string(ForumNodeTypes.EXO_LINK)); topicNew.setTagId(reader.strings(ForumNodeTypes.EXO_TAG_ID)); topicNew.setCanView(reader.strings(ForumNodeTypes.EXO_CAN_VIEW, new String[] {})); topicNew.setCanPost(reader.strings(ForumNodeTypes.EXO_CAN_POST, new String[] {})); if (topicNode.isNodeType(ForumNodeTypes.EXO_FORUM_WATCHING)) topicNew.setEmailNotification( reader.strings(ForumNodeTypes.EXO_EMAIL_WATCHING, new String[] {})); try { if (topicNew.getNumberAttachment() > 0) { // String idFirstPost = topicNode.getName().replaceFirst(Utils.TOPIC, Utils.POST); // Node FirstPostNode = topicNode.getNode(idFirstPost); // topicNew.setAttachments(getAttachmentsByNode(FirstPostNode)); } } catch (Exception e) { // log.debug("Failed to set attachments in topicNew.", e); } return topicNew; }