Hello! Can you help me? I 'm creating a new project by copy from a template-project. The new project is creating, all issues are copyng, but i can't add issue with the type 'Project' to the structure. Structure content not changed. I don't see there my issue. But i don't receive any errormessage. I have one default structure with name "default" and id=1. Jira version 7.6.0, Scriptrunner 5.3.1, Structure 4.5.1. What need i do to apply structure content changes?
try{
StructureComponents structureComponents=ScriptRunnerImpl.getPluginComponent(StructureComponents)
ProjectManager PM = ComponentAccessor.getProjectManager()
Project project = PM.getProjectByCurrentKey(key)
log.error "New project - " + project.toString()
if(project!=null){
return Response.status(Status.BAD_REQUEST).entity(new JsonBuilder([Res: "Проект с таким ключом уже есть"]).toString()).build()
}
else {
def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : template,
(CopyProject.FIELD_TARGET_PROJECT) : key,
(CopyProject.FIELD_TARGET_PROJECT_NAME) : name,
(CopyProject.FIELD_COPY_VERSIONS) : true,
(CopyProject.FIELD_COPY_COMPONENTS) : true,
(CopyProject.FIELD_COPY_ISSUES) : true,
//(CopyProject.FIELD_COPY_GREENHOPPER) : false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
// (CopyProject.FIELD_ORDER_BY) : "Rank",
]
def errorCollection = copyProject.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
return Response.status(Status.BAD_REQUEST).entity(new JsonBuilder([Res: errorCollection.toString()]).toString()).build()
}
else {
GroupManager GM = ComponentAccessor.getGroupManager()
def adminsGroup = GM.getGroup("jira-local-administrators")
assert adminsGroup // must have jira-administrators group defined
Collection<ApplicationUser> admins = GM.getUsersInGroup(adminsGroup)
assert admins // must have at least one admin
ComponentAccessor.getProjectManager().refresh()
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(admins.first())
copyProject.doScript(inputs)
ComponentAccessor componentAccessor = new ComponentAccessor()
PM = componentAccessor.getProjectManager()
Project p = PM.getProjectByCurrentKey(key)
ApplicationUser user = JIRASystem.getCurrentUser()
IssueManager IM = ComponentAccessor.getIssueManager()
if(p!=null){
ProjectH.AddPermissionScheme(p, "Projects Draft")
Long pid = p.getId()
Collection <Long> IssueIds = IM.getIssueIdsForProject(pid)
List<Issue> Issues = IM.getIssueObjects(IssueIds)
//root issue with ProjectName to add to structure
Issue projectIssue
for (Issue i : Issues) {
MutableIssue mi = i
if((i.getIssueType().getName() =='Проект')) {
mi.setSummary(name)
projectIssue=i
}
mi.setReporter(user)
IM.updateIssue(user, mi, EventDispatchOption.DO_NOT_DISPATCH, false)
}
//
StructureManager structureManager = structureComponents.getStructureManager()
List<Structure> structures = structureManager.getStructuresByName("default", PermissionLevel.EDIT)
Long structureId
if (structures.size() == 1) {
structureId = structures.get(0).getId();
}
else {
structureId=1
}
ForestSpec forestSpec = ForestSpec.structure(structureId)
ForestSource forestSource = myStructureComponents.getForestService().getForestSource(forestSpec);
forestSource.apply (new ForestAction.Add (CoreIdentities.issue(projectIssueRoot), 0, 0, 0))
}
return Response.ok(new JsonBuilder([key: key]).toString()).build()
}
}
catch(Exception ex){Response.status(Status.BAD_REQUEST).entity(new JsonBuilder([Res: ex.toString()]).toString()).build() }
}