Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.atlassian.crowd.embedded.api.Group
- import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
- import com.atlassian.jira.bc.projectroles.ProjectRoleService
- import com.atlassian.jira.component.ComponentAccessor
- import com.atlassian.jira.security.roles.ProjectRoleActor
- import com.atlassian.jira.security.roles.ProjectRoleManager
- import com.atlassian.jira.util.SimpleErrorCollection
- import org.apache.log4j.Logger
- import org.apache.log4j.Level
- import java.nio.file.Files
- import java.nio.file.Path
- import java.nio.file.Paths
- import java.util.stream.Stream
- def log = Logger.getLogger("com.valiantys.scriptrunner")
- log.setLevel(Level.INFO)
- File file = new File("C:\\Program Files\\Atlassian\\Application Data\\JIRA\\data\\attachments\\NAV\\10000\\NAV-2\\10000")
- Stream<String> lines = Files.lines(file)
- def groupManager = ComponentAccessor.getGroupManager()
- def userManager = ComponentAccessor.getUserManager()
- String groupName = "";
- Group currentGroup;
- lines.forEach(
- {
- String ProjectID = it.split(";")[0];
- log.info("Project ID : ${ProjectID}")
- String ProjectName = it.split(";")[1];
- log.info("Project Name : ${ProjectName}")
- log.info("......................................................")
- Thread executorThread = new Thread(new Runnable() {
- void run() {
- def copyProject = new CopyProject()
- def inputs = [
- (CopyProject.FIELD_SOURCE_PROJECT) : 'NAV',
- (CopyProject.FIELD_TARGET_PROJECT) : ProjectID,
- (CopyProject.FIELD_TARGET_PROJECT_NAME) : ProjectName,
- (CopyProject.FIELD_COPY_VERSIONS) : false,
- (CopyProject.FIELD_COPY_COMPONENTS) : false,
- (CopyProject.FIELD_COPY_ISSUES) : false,
- (CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
- ]
- def errorCollection = copyProject.doValidate(inputs, false)
- if(errorCollection.hasAnyErrors()) {
- log.warn("Couldn't create project: $errorCollection")
- }
- else {
- log.info("Project created")
- log.info("......................................................")
- log.info("......................................................")
- def util = ComponentAccessor.getUserUtil()
- def adminsGroup = util.getGroupObject("jira-administrators")
- assert adminsGroup // must have jira-administrators group defined
- def admins = util.getAllUsersInGroups([adminsGroup])
- assert admins // must have at least one admin
- ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(util.getUserByName(admins.first().name))
- copyProject.doScript(inputs)
- }
- }
- })
- executorThread.start()
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement