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() }
}
Hi Anna,
If I understand your requirement correctly, then you need to add item rather than issue.
So the following line will be
forestSource.apply (new ForestAction.Add (CoreIdentities.project(projectId), 0, 0, 0))
instead of
forestSource.apply (new ForestAction.Add (CoreIdentities.issue(projectIssueRoot), 0, 0, 0))
Where projectId would have to contain project or project Id, rather than issue or issue id.
Please, let me know if this helps. If however, you need to add grouping by project, that would be a different requirement - please, clarify if you are planning to copy structure's automation.
Regards,
Egor Tasa
ALM Works Support
Thank you very much for your help. It really helped. How could it be possible to group by project or by issue with type 'Project'? As an example, this is the structure
It would be very interesting. How can i copy structure's automation?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anna,
To group by project in the first place, you'd have to use Automation+>Group and then select Project. This will put a project item at the top of your hierarchy. It is dependent on how your structure is built, the screenshot does not show any generators, so I assume it was manually built. Here you can find some information about automation and generators.
Copying generators can be done using GeneratorManager interface.
I wonder what is the usecase behind the task you have, so far it looks like my guess was a bit off even if the info I provided appeared to be useful. If you only need to copy structure from one instance to another, you can use Backup/Restore function, provided the issues are copied first. But if you describe what you are trying to achieve, I may be able to render a better advice.
Regards,
Egor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.