Advertisement
Guest User

create_projects

a guest
Jan 7th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.99 KB | None | 0 0
  1. import com.atlassian.crowd.embedded.api.Group
  2. import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
  3. import com.atlassian.jira.bc.projectroles.ProjectRoleService
  4. import com.atlassian.jira.component.ComponentAccessor
  5. import com.atlassian.jira.security.roles.ProjectRoleActor
  6. import com.atlassian.jira.security.roles.ProjectRoleManager
  7. import com.atlassian.jira.util.SimpleErrorCollection
  8. import org.apache.log4j.Logger
  9. import org.apache.log4j.Level
  10. import java.nio.file.Files
  11. import java.nio.file.Path
  12. import java.nio.file.Paths
  13. import java.util.stream.Stream
  14.  
  15.  
  16. def log = Logger.getLogger("com.valiantys.scriptrunner")
  17. log.setLevel(Level.INFO)
  18.  
  19. File file = new File("C:\\Program Files\\Atlassian\\Application Data\\JIRA\\data\\attachments\\NAV\\10000\\NAV-2\\10000")
  20. Stream<String> lines = Files.lines(file)
  21.  
  22. def groupManager = ComponentAccessor.getGroupManager()
  23. def userManager = ComponentAccessor.getUserManager()
  24. String groupName = "";
  25. Group currentGroup;
  26. lines.forEach(
  27.     {
  28.         String ProjectID = it.split(";")[0];
  29.         log.info("Project ID : ${ProjectID}")
  30.         String ProjectName = it.split(";")[1];
  31.         log.info("Project Name : ${ProjectName}")
  32.         log.info("......................................................")
  33.  
  34.  
  35.         Thread executorThread = new Thread(new Runnable() {
  36.             void run() {
  37.                 def copyProject = new CopyProject()
  38.                 def inputs = [
  39.                     (CopyProject.FIELD_SOURCE_PROJECT) : 'NAV',
  40.                     (CopyProject.FIELD_TARGET_PROJECT) : ProjectID,
  41.                     (CopyProject.FIELD_TARGET_PROJECT_NAME) : ProjectName,
  42.                     (CopyProject.FIELD_COPY_VERSIONS) : false,
  43.                     (CopyProject.FIELD_COPY_COMPONENTS) : false,
  44.                     (CopyProject.FIELD_COPY_ISSUES) : false,
  45.                     (CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
  46.                 ]
  47.                 def errorCollection = copyProject.doValidate(inputs, false)
  48.                 if(errorCollection.hasAnyErrors()) {
  49.                     log.warn("Couldn't create project: $errorCollection")
  50.                 }
  51.                 else {
  52.                     log.info("Project created")
  53.                     log.info("......................................................")
  54.                     log.info("......................................................")
  55.                     def util = ComponentAccessor.getUserUtil()
  56.                     def adminsGroup = util.getGroupObject("jira-administrators")
  57.                     assert adminsGroup // must have jira-administrators group defined
  58.                     def admins = util.getAllUsersInGroups([adminsGroup])
  59.                     assert admins // must have at least one admin
  60.                     ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(util.getUserByName(admins.first().name))
  61.                     copyProject.doScript(inputs)
  62.                 }
  63.             }
  64.         })
  65.         executorThread.start()
  66.     }
  67. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement