can't create product space confluence

baptistemuller February 27, 2020

hi everyone, i need your help because in my confluence administration i created some REST Endpoint to create product space with this script :

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import com.onresolve.scriptrunner.canned.confluence.admin.CopySpace
import com.onresolve.scriptrunner.canned.confluence.admin.TreeDelete
import com.onresolve.scriptrunner.canned.util.SimpleBuiltinScriptErrors
import com.atlassian.confluence.pages.AbstractPage
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.labels.SpaceLabelManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.confluence.spaces.Space

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

createProductSpace(httpMethod: "POST", groups: ["confluence-users"]) { MultivaluedMap queryParams, String body ->
def jsonSlurper = new JsonSlurper()
def object = (Map) jsonSlurper.parseText(body)
log.info(" ### object : "+object+" ###")

String customer = object.customer
log.info(" ### customer : "+customer+" ###")
String product = object.product
log.info(" ### product : "+product+" ###")
String spacekey = object.spacekey
log.info(" ### spacekey : "+spacekey+" ###")
String id = object.id
log.info(" ### id : "+id+" ###")

def inputs = [
(CopySpace.FIELD_SRC_SPACE_ID): "TPLPRODUCT",
(CopySpace.FIELD_TARGET_SPACE_NAME): 'P - ' + customer + ' - ' + product,
(CopySpace.FIELD_TARGET_SPACE_KEY): spacekey
]
log.info(" ### inputs : "+inputs+" ###")


def copySpace = new CopySpace()
log.info(copySpace)
def errorCollection = (SimpleBuiltinScriptErrors) copySpace.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
log.warn("Could not copy space: $errorCollection")
return Response.serverError().entity([error: errorCollection.getErrorMessages()]).build();
} else {
//Perform the actual copy
def output = copySpace.doScript((Map<String,Object>) inputs)
log.debug("createProductSpaceOutput=${output}")

// add label
def spaceManager = ComponentLocator.getComponent(SpaceManager)
Space space = spaceManager.getSpace(spacekey)
def spaceLabelManager = ComponentLocator.getComponent(SpaceLabelManager)
spaceLabelManager.addLabel(space, "product")

// rename Home page
def pageManager = ComponentLocator.getComponent(PageManager);
pageManager.renamePage(pageManager.getPage(spacekey, "HOME"), customer + ' - ' + product);

// delete Project TPL Project pages - didnt manage to get TreeDelete to work...
def projectTplPage = pageManager.getPage(spacekey, 'Project XXX');

pageManager.getDescendants(projectTplPage).each {
pageManager.trashPage(it);
}
pageManager.trashPage(projectTplPage);

// delete Maintenance TPL pages - didnt manage to get TreeDelete to work...
def maintenanceTplPage = pageManager.getPage(spacekey, 'Maintenance XXXX');

pageManager.getDescendants(maintenanceTplPage).each {
pageManager.trashPage(it);
}
pageManager.trashPage(maintenanceTplPage);

// done

return Response.ok(new JsonBuilder([
title: 'P - ' + customer + ' - ' + product,
spacekey: spacekey
]).toString()).build();
}
}

and there is an error with the line which create a new copy space and i've search but i can't resolve it, in my logs, i have this error :

2020-02-27 17:15:36,499 INFO [runner.AbstractScriptRunner]:  ### object : [customer:TEST, product:TEST, spacekey:TEST] ###
2020-02-27 17:15:36,501 INFO [runner.AbstractScriptRunner]:  ### customer : TEST ###
2020-02-27 17:15:36,502 INFO [runner.AbstractScriptRunner]:  ### product : TEST ###
2020-02-27 17:15:36,504 INFO [runner.AbstractScriptRunner]:  ### spacekey : TEST ###
2020-02-27 17:15:36,506 INFO [runner.AbstractScriptRunner]:  ### id : null ###
2020-02-27 17:15:36,507 INFO [runner.AbstractScriptRunner]:  ### inputs : [FIELD_SRC_SPACE_ID:TPLPRODUCT, FIELD_TARGET_SPACE_NAME:P - TEST - TEST, FIELD_TARGET_SPACE_KEY:TEST] ###
2020-02-27 17:15:36,511 ERROR [common.UserCustomScriptEndpoint]: *************************************************************************************
2020-02-27 17:15:36,513 ERROR [common.UserCustomScriptEndpoint]: Script endpoint failed on method: POST createProductSpace
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.onresolve.scriptrunner.canned.confluence.admin.CopySpace()
	at Script15$_run_closure1.doCall(Script15.groovy:42)
	at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint$_doEndpoint_closure2.doCall(UserCustomScriptEndpoint.groovy:219)
	at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint$_doEndpoint_closure2.doCall(UserCustomScriptEndpoint.groovy)
	at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl.execute(DiagnosticsManagerImpl.groovy:314)
	at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:209)
	at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.postUserEndpoint(UserCustomScriptEndpoint.groovy:117)

 tell me if you want more informations,

 

thank you.

0 answers

Suggest an answer

Log in or Sign up to answer