英文:
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)
我遇到以下错误:
有人知道问题是什么吗?我认为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)
 
String spaceKey = "IWIKI"
SpaceService spaceService = ScriptRunnerImpl.getPluginComponent(SpaceService)
// here's the tricky part, just go with it
Space space = spaceService.find().withKeys(spaceKey).fetch()
List<Page> pages = pageManager.getPages(space, true)
I am getting the following error:
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("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())
}
}
答案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("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()}")
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论