Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Component name is not unique, java.lang.IllegalArgumentException:

Mouna Hammoudi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2023

I am writing code to create a new linked issue and I am having the following error thrown 

Capture1.PNG

void createFeature(Issue issue, Collection<ProjectComponent> componentList){

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def authenticationContext = ComponentAccessor.jiraAuthenticationContext

def issueFactory = ComponentAccessor.getIssueFactory()

def issueManager = ComponentAccessor.getIssueManager()

def userManager = ComponentAccessor.getUserUtil()

 def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

long issueLinkType= 10070 as long

long sequence =1 as long

long newissueTypeID= 19 as long

long myissueID= issue.getId() as long

// the key of the project under which the version will get created

 final String projectKey = "SF"

// the start date - optional

final Date startDate = null

// the release date - optional

final Date releaseDate = null

// a description for the new version - optional

final String description = null

// id of the version to schedule after the given version object - optional

final Long scheduleAfterVersion = null

// true if this is a released version

final boolean released = false

def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey)

assert project : "Could not find project with key $projectKey"

def projectComponentManager = ComponentAccessor.getProjectComponentManager()

         int counter=0

        for(ProjectComponent component: componentList){

                    MutableIssue newissue= ComponentAccessor.issueFactory.getIssue()

                                        //set values

                    newissue.setIssueTypeId("19")

                    newissue.setSummary("MOUNA CAMELIA")

                    newissue.setDescription("MOUNA CAMELIA")

                    newissue.reporter = issue.getReporter()

                     // you can *add* labels like this (using the syntax above would overwrite all labels)

                    // newissue = newissue.update {

                    //     setLabels {

                    //         add('SF-Child')

                    //     }

                    // }

                    String componentName= component.getName()

                    log.warn("MOUNA CAMELIA HELLO 5 "+component)

                    def shortenedComponentName = componentName.substring(componentName.indexOf("-")+1)

                    def projectName = componentName.substring(0, componentName.indexOf("-"))

                    log.warn("MOUNA CAMELIA HELLO 6 projectName--"+projectName+"--" )

                    def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)

                    newissue.setProjectObject(newIssueproject)

                    log.warn("MOUNA CAMELIA ISSUE GET VERSIONS "+newIssueproject.getVersions()+"-========= ")

                    List<String> newIssueProjectVersionIDs= new ArrayList<String>()

                    for(Version myver: newIssueproject.getVersions()){

                            newIssueProjectVersionIDs.add(myver.getName())

                    }

                     log.warn("MOUNA CAMELIA newIssueProjectVersionIDs "+newIssueProjectVersionIDs+"-========= ")

                 

                    def mynewVersions = new ArrayList <Version> ()

                    for( Version v: issue.getFixVersions()){

                        log.warn("MOUNA CAMELIA VERSION V "+v.getName())

                        if(newIssueProjectVersionIDs.contains(v.getName())){

                                 Version mynewVersion= ComponentAccessor.versionManager.createVersion(v.getName()+"-Inbox", startDate, releaseDate, description, newIssueproject.id, scheduleAfterVersion, released)

                                 mynewVersions.add(mynewVersion)

                                 log.warn("MOUNA CAMELIA TRUE")

                        }else{

                               log.warn("MOUNA CAMELIA FALSE")

                        }

               

                    }

                    newissue.setFixVersions(mynewVersions)

                    def customField =  ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10790");// here replace the ID with ID of your custom field.

                     Integer value = issue.getCustomFieldValue(customField) as Integer;

                    // def sampleTextField = getFieldByName(value)

                    log.warn("MOUNA CAMELIA VALUE "+value )

                    log.warn("MOUNA CAMELIA HELLO 6 newIssueproject "+newIssueproject )

                    log.warn("MOUNA CAMELIA HELLO 7 component.getDescription() "+component.getDescription() )

                    log.warn("MOUNA CAMELIA HELLO 8  component.getLead() "+ component.getLead() )

                    log.warn("MOUNA CAMELIA HELLO 9  component.assigneeType() "+ component.assigneeType )

                    log.warn("MOUNA CAMELIA HELLO 10  component.getProjectId() "+ component.getProjectId() )

                    log.warn("MOUNA CAMELIA HELLO 11--"+shortenedComponentName+"--")

                 

                     ProjectComponent newComponent = projectComponentManager.create(shortenedComponentName,component.getDescription(),

                   component.getLead(),component.getAssigneeType(),component.getProjectId())

                    log.warn("MOUNA CAMELIA HELLO 7 "+newComponent.getName())

                    List<ProjectComponent> mynewComponentList = new ArrayList<ProjectComponent>()

                    mynewComponentList.add(newComponent)

                    newissue.setComponent(mynewComponentList)

                 

                    log.warn(" MOUNA CAMELIA ==========================COMPONENT NUMBER "+counter +" "+component)

                           

                    def newIssueCreated = issueManager.createIssueObject(currentUserObj, newissue)

                    log.warn(" MOUNA CAMELIA 2 ==========================")

                    long newIssueCreatedID= newIssueCreated.getId() as long

                   

                    def labelManager = ComponentAccessor.getComponent(LabelManager)

                    labelManager.addLabel(authenticationContext.getLoggedInUser(), newIssueCreatedID, "SF-Child", false)

                   

                    def issueToLink = issueManager.getIssueObject(newIssueCreated.getKey())

                    log.warn(" MOUNA CAMELIA 4 ==========================")

                     log.warn("MOUNA CAMELIA ===== myissueID ====="+ myissueID+" =====newissueTypeID ====="+newIssueCreated.getId()

                      +" =====issueLinkType ====="+issueLinkType

                     +" =====sequence ====="+ sequence +" =====authenticationContext.getLoggedInUser() ====="+authenticationContext.getLoggedInUser()

                     )      

                     

                    issueLinkManager.createIssueLink(newIssueCreatedID, myissueID, issueLinkType, sequence, authenticationContext.getLoggedInUser())

                 

                    counter++

                             

         }

}

The line causing the problem is: 

  issueLinkManager.createIssueLink(newIssueCreatedID, myissueID, issueLinkType, sequence, authenticationContext.getLoggedInUser())

Anyone knows how to fix this problem? 

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Champion
September 24, 2023

Hi @Mouna Hammoudi ,

try to update your code from :

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def authenticationContext = ComponentAccessor.jiraAuthenticationContext

def issueFactory = ComponentAccessor.getIssueFactory()

def issueManager = ComponentAccessor.getIssueManager()

def userManager = ComponentAccessor.getUserUtil()

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
...

to this

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
IssueFactory issueFactory = ComponentAccessor.getIssueFactory();
IssueManager issueManager = ComponentAccessor.getIssueManager();
UserUtil userManager = ComponentAccessor.getUserUtil();
ApplicationUser currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
...

It should fix your issue.

Fabio

Mouna Hammoudi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2023

Capture1.PNG

@Fabio Racobaldo _Herzum_ I have replaced the code and I am still having the same error.

Fabio Racobaldo _Herzum_
Community Champion
September 26, 2023

Hey @Mouna Hammoudi , 

I don't see WebReader in your code.

Mouna Hammoudi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2023

@Fabio Racobaldo _Herzum_ it is the component that I am applying my code to

Suggest an answer

Log in or Sign up to answer