我的目标是以编程方式移动资产。我发现AssetManager有一个moveAsset方法。但是,我在groovy脚本中初始化AssetManager对象时遇到问题。以下是我正在使用的代码。如何初始化非null的AssetManager对象?
import javax.jcr.query.*
import com.day.cq.dam.api.*
def query = createSQL2Query("/content/dam/3d-renders/application-notes/wcc-migration") //CHANGE THIS
def result = query.execute()
def rows = result.rows
rows.each { row ->
Resource res = resourceResolver.getResource(null,row.path)
AssetManager am = res.adaptTo(AssetManager.class)
am.getAsset('/content/dam/3d-renders/application-notes/wcc-migration/Q60_ILL000347_iAPP.psd')
println res.path + ' ' + am
//am.moveAsset('/content/dam/3d-renders/application-notes/wcc-migration/2015/Q3X-Color-Mark-Sensing.psd','/content/dam/3d-renders/test-folder/Q3X-Color-Mark-Sensing.psd')
}
def createSQL2Query(startPage) {
def queryManager = session.workspace.queryManager
def statement = "select * from [nt:base] as p where (isdescendantnode (p, '$startPage')) and p.[jcr:primaryType] = 'dam:Asset'"
def query = queryManager.createQuery(statement, Query.JCR_SQL2)
query
}
答案 0 :(得分:0)
尝试像这样获取资产经理:
AssetManager am = resourceResolver.adaptTo(AssetManager.class)
ResourceResolver
实现了Adaptable
,即定义adaptTo(Class)
方法的接口。