检索使用ScriptRunner的空间内的所有页面。

huangapple go评论65阅读模式
英文:

Retrieve all the pages within a space with ScriptRunner

问题

我正在脚本控制台中编写代码,以列出特定空间(名为IWIKI)中的页面。我正在使用以下代码:

import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.api.service.content.SpaceService
import com.atlassian.confluence.api.model.content.Space
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.api.service.content.SpaceService
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)

String spaceKey = "IWIKI"
SpaceService spaceService = ScriptRunnerImpl.getPluginComponent(SpaceService)

// 这里是棘手的部分,继续进行

Space space = spaceService.find().withKeys(spaceKey).fetch()
List<Page> pages = pageManager.getPages(space, true)

我遇到以下错误:

检索使用ScriptRunner的空间内的所有页面。

有人知道问题是什么吗?我认为spaceService.find().withKeys(spaceKey).fetch()返回的是com.atlassian.confluence.api.model.content.Space类型的对象,而下一行pageManager.getPages(space, true)需要一个com.atlassian.confluence.spaces.Space类型的空间参数。

英文:

I am writing code in the script console to list the pages in a specific space called IWIKI. I am using the following code: 

import com.atlassian.confluence.pages.Page

import com.atlassian.confluence.pages.PageManager

import com.atlassian.confluence.spaces.Space

import com.atlassian.confluence.spaces.SpaceManager

import com.atlassian.sal.api.component.ComponentLocator

import com.atlassian.confluence.api.service.content.SpaceService

import com.atlassian.confluence.api.model.content.Space

import com.atlassian.confluence.spaces.Space

import com.atlassian.confluence.api.service.content.SpaceService

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

def spaceManager = ComponentLocator.getComponent(SpaceManager)

def pageManager = ComponentLocator.getComponent(PageManager)

&#160;

String spaceKey = &quot;IWIKI&quot;

SpaceService spaceService = ScriptRunnerImpl.getPluginComponent(SpaceService)

// here&#39;s the tricky part, just go with it

Space space = spaceService.find().withKeys(spaceKey).fetch()

List&lt;Page&gt; pages = pageManager.getPages(space, true)

I am getting the following error:

检索使用ScriptRunner的空间内的所有页面。

Anyone knows what the problem is? I think spaceService.find().withKeys(spaceKey).fetch() is returning an object of type com.atlassian.confluence.api.model.content.Space and the next line pageManager.getPage(space, true) is expecting a space parameter of type com.atlassian.confluence.spaces.Space

答案1

得分: 0

    import com.atlassian.confluence.links.OutgoingLink
    import com.atlassian.confluence.pages.Page
    import com.atlassian.confluence.pages.PageManager
    import com.atlassian.confluence.spaces.Space
    import com.atlassian.confluence.spaces.SpaceManager
    import com.atlassian.sal.api.component.ComponentLocator
    import org.apache.log4j.Logger
    import com.atlassian.confluence.user.UserAccessor
    import com.atlassian.sal.api.user.UserKey
    
    SpaceManager spaceManager = ComponentLocator.getComponent(SpaceManager)
    PageManager pageManager = ComponentLocator.getComponent(PageManager)
    UserAccessor userAccessor = ComponentLocator.getComponent(UserAccessor)
    
    Space space = spaceManager.getSpace("IWIKI")
    
    
    for (Page page : pageManager.getPages(space, true)) {
        if(page.getCreator()==null){
                log.warn(page.toString()+",null")
        }
        else{
                String userID=page.getCreator().getName()
                String fullName =userAccessor.getUserByKey(page.getCreator().getKey()).getFullName()
                log.warn(page.toString()+","+userID+","+fullName+","+page.getLastModificationDate())
    
        }
    
       
    }
英文:
import com.atlassian.confluence.links.OutgoingLink
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import org.apache.log4j.Logger
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.user.UserKey

SpaceManager spaceManager = ComponentLocator.getComponent(SpaceManager)
PageManager pageManager = ComponentLocator.getComponent(PageManager)
UserAccessor userAccessor = ComponentLocator.getComponent(UserAccessor)

Space space = spaceManager.getSpace(&quot;IWIKI&quot;)


for (Page page : pageManager.getPages(space, true)) {
    if(page.getCreator()==null){
            log.warn(page.toString()+&quot;,null&quot;)
    }
    else{
            String userID=page.getCreator().getName()
            String fullName =userAccessor.getUserByKey(page.getCreator().getKey()).getFullName()
            log.warn(page.toString()+&quot;,&quot;+userID+&quot;,&quot;+fullName+&quot;,&quot;+page.getLastModificationDate())

    }

   
}

答案2

得分: 0

import com.atlassian.confluence.pages.Page;
import com.atlassian.confluence.pages.PageManager;
import com.atlassian.confluence.spaces.Space;
import com.atlassian.confluence.spaces.SpaceManager;
import com.atlassian.sal.api.component.ComponentLocator;
import com.atlassian.confluence.user.UserAccessor;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

Logger logger = LogManager.getLogger("my.logger");

SpaceManager spaceManager = ComponentLocator.getComponent(SpaceManager);
PageManager pageManager = ComponentLocator.getComponent(PageManager);
UserAccessor userAccessor = ComponentLocator.getComponent(UserAccessor);
Space space = spaceManager.getSpace("IWIKI");

for (Page page : pageManager.getPages(space, true)) {
if (page.getCreator() == null) {
logger.warn("${page.toString()} is null");
} else {
String userID = page.getCreator().getName();
String fullName = userAccessor.getUserByKey(page.getCreator().getKey()).getFullName();
logger.warn("${page.toString()}, ${userID}, ${fullName}, ${page.getLastModificationDate()}");
}
}

英文:

Formatted code:

import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.user.UserAccessor
import org.apache.logging.log4j.Logger
import org.apache.logging.log4j.LogManager

Logger logger = LogManager.getLogger(&quot;my.logger&quot;)

SpaceManager spaceManager = ComponentLocator.getComponent(SpaceManager)
PageManager pageManager = ComponentLocator.getComponent(PageManager)
UserAccessor userAccessor = ComponentLocator.getComponent(UserAccessor)
Space space = spaceManager.getSpace(&quot;IWIKI&quot;)

for (Page page : pageManager.getPages(space, true)) {
   if (page.getCreator() == null) {
      logger.warn(&quot;${page.toString()} is null&quot;)
   } else {
      String userID = page.getCreator().getName()
      String fullName = userAccessor.getUserByKey(page.getCreator().getKey()).getFullName()
      logger.warn(&quot;${page.toString()}, ${userID}, ${fullName}, ${page.getLastModificationDate()}&quot;)
   }
}

huangapple
  • 本文由 发表于 2023年7月3日 18:36:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603936.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定