I'm attempting to move an issue between jira core projects using code I've seen from others who claim success. So far I get to invoking MoveIssueUpdateFields doExecute() method, but get a null pointer exception with the following stack trace:
java.lang.reflect.InvocationTargetException
at ProjectIssueMove.moveIssueToAnotherProject(Script514.groovy:110)
at ProjectIssueMove$moveIssueToAnotherProject.call(Unknown Source) at Script514.run(Script514.groovy:41)
Caused by: java.lang.NullPointerException at com.atlassian.jira.web.action.issue.AbstractIssueSelectAction.readPrepopulatedIssueFromRequest(AbstractIssueSelectAction.java:124)
at com.atlassian.jira.web.action.issue.AbstractIssueSelectAction.getIssueResultFromRequestOrDatabase(AbstractIssueSelectAction.java:102)
at com.atlassian.jira.web.action.issue.AbstractIssueSelectAction.access$100(AbstractIssueSelectAction.java:30)
at com.atlassian.jira.web.action.issue.AbstractIssueSelectAction$IssueGetter.get(AbstractIssueSelectAction.java:519)
at com.atlassian.jira.web.action.issue.SelectedIssue.fetchIssueResult(SelectedIssue.java:85)
at com.atlassian.jira.web.action.issue.SelectedIssue.exists(SelectedIssue.java:73)
at com.atlassian.jira.web.action.issue.AbstractIssueSelectAction.isIssueExists(AbstractIssueSelectAction.java:60)
at com.atlassian.jira.web.action.issue.AbstractIssueSelectAction.assertIssueIsValid(AbstractIssueSelectAction.java:488)
at com.atlassian.jira.web.action.issue.AbstractIssueSelectAction.getIssueObject(AbstractIssueSelectAction.java:157)
at com.atlassian.jira.web.action.issue.MoveIssueUpdateFields.doExecute(MoveIssueUpdateFields.java:241)
... 3 moreI can't seem to find what the null object is, any help would be greatly appreciated.
The following is the code used:
import com.atlassian.core.ofbiz.util.CoreTransactionUtil
import com.atlassian.jira.bc.issue.comment.CommentService
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.event.issue.IssueEventBundleFactory
import com.atlassian.jira.event.issue.txnaware.TxnAwareEventFactory
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.config.StatusManager
import com.atlassian.jira.config.properties.JiraSystemProperties
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.security.IssueSecurityHelper
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.web.SessionKeys
import com.atlassian.jira.web.action.issue.MoveIssueConfirm
import com.atlassian.jira.web.action.issue.MoveIssueUpdateFields
import com.atlassian.jira.web.bean.MoveIssueBean
import org.apache.log4j.Category
import org.apache.log4j.Logger
import org.apache.log4j.Level
import java.lang.reflect.Method
import webwork.action.ActionContext
//For testing one issue at a time//----------------------------------------
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueService = ComponentAccessor.getComponentOfType(IssueService.class)
MutableIssue issue = issueService.getIssue(user,212961).getIssue() //enter issue id here
//-------------------------------------------------------------------------
ProjectIssueMove pim = new ProjectIssueMove()
String newProjectKey = "LN"
String issueType = issue.getIssueType().getName()
String statusName = issue.getStatus().getName()
pim.moveIssueToAnotherProject(newProjectKey,issueType,statusName,issue)
class ProjectIssueMove {
Category log = Category.getInstance(ProjectIssueMove.class)
public void moveIssueToAnotherProject(String newProjectKey, String newIssueType, String newStatusName, MutableIssue targetIssue) {
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.INFO)
MoveIssueBean moveIssueBean = new MoveIssueBean(ComponentAccessor.getConstantsManager(), ComponentAccessor.getProjectManager())
moveIssueBean.getFieldValuesHolder().put(IssueFieldConstants.PROJECT, getProjectFromKey(newProjectKey).id)
moveIssueBean.getFieldValuesHolder().put(IssueFieldConstants.ISSUE_TYPE, getTargetIssueType(newIssueType).id)
moveIssueBean.setIssueId(targetIssue.getId())
moveIssueBean.setTargetStatusId(getStatusToSet(newStatusName).id)
moveIssueBean.setSourceIssueKey(targetIssue.getKey())
moveIssueBean.setUpdatedIssue(targetIssue)
ActionContext.getSession().put(SessionKeys.MOVEISSUEBEAN, moveIssueBean)
MoveIssueUpdateFields moveIssueUpdateFields = new MoveIssueUpdateFields(
ComponentAccessor.getSubTaskManager(),
ComponentAccessor.getConstantsManager(),
ComponentAccessor.getWorkflowManager(),
ComponentAccessor.getFieldManager(),
ComponentAccessor.getFieldLayoutManager(),
ComponentAccessor.getIssueFactory(),
ComponentAccessor.getFieldScreenRendererFactory(),
ComponentAccessor.getComponentOfType(CommentService.class),
ComponentAccessor.getComponentOfType(IssueSecurityHelper.class),
ComponentAccessor.getUserUtil()
)
MoveIssueConfirm moveIssueConfirm = new MoveIssueConfirm(
ComponentAccessor.getSubTaskManager(),
ComponentAccessor.getComponentOfType(AttachmentManager.class),
ComponentAccessor.getConstantsManager(),
ComponentAccessor.getWorkflowManager(),
ComponentAccessor.getFieldManager(),
ComponentAccessor.getFieldLayoutManager(),
ComponentAccessor.getIssueFactory(),
ComponentAccessor.getFieldScreenRendererFactory(),
ComponentAccessor.getComponentOfType(CommentService.class),
ComponentAccessor.getComponentOfType(IssueSecurityHelper.class),
ComponentAccessor.getIssueManager(),
ComponentAccessor.getUserUtil(),
ComponentAccessor.getIssueEventManager(),
ComponentAccessor.getComponentOfType(IssueEventBundleFactory.class),
ComponentAccessor.getComponentOfType(TxnAwareEventFactory.class)
)
JiraSystemProperties.getInstance()
moveIssueUpdateFields.setId(targetIssue.getId())
Method privateUpdateFieldsDoExecute = MoveIssueUpdateFields.class.getDeclaredMethod("doExecute")
privateUpdateFieldsDoExecute.setAccessible(true)
privateUpdateFieldsDoExecute.invoke(moveIssueUpdateFields) //fails here
moveIssueConfirm.setId(targetIssue.getId())
Method privateIssueConfirmDoExecute = MoveIssueConfirm.class.getDeclaredMethod("doExecute")
privateIssueConfirmDoExecute.setAccessible(true)
privateIssueConfirmDoExecute.invoke(moveIssueConfirm)
CoreTransactionUtil.commit(true)
}
private Project getProjectFromKey(String projectKey) { //get the projectObject from a String key
ProjectManager projectManager = ComponentAccessor.getProjectManager()
return projectManager.getProjectObjByKeyIgnoreCase(projectKey)
}
def getStatusToSet(String statusName) { //find the status object from a status name
StatusManager statusManager = ComponentAccessor.getComponentOfType(StatusManager.class)
def statuses = statusManager.getStatuses()
def iterator = statuses.iterator()
while (iterator.hasNext()) {
def status = iterator.next()
if (status.getName() == statusName) {
return status
}
}
return null
}
def IssueType getTargetIssueType(String issueTypeName) { //Find the issue type object from a issue type name
ConstantsManager constantsManager = ComponentAccessor.getConstantsManager()
def issueTypes = constantsManager.getAllIssueTypeObjects()
def issuetypeiterator = issueTypes.iterator()
while (issuetypeiterator.hasNext()) {
def issueType = issuetypeiterator.next()
if (issueType.name.toLowerCase() == issueTypeName.toLowerCase()) {
return issueType
}
}
return null
}
}
Main Reference question:
Hi Carissa,
Happy to help! Is this concerning the Confluence server site again, or is it Cloud? If you want an exact duplicate of a page section, you can use the Excerpt include macro.
I'm not clear what you're using to generate the progress bar. Is there an add-on that you're using? If you're unsure, please share a screenshot, and I can try to determine what add-on you're using.
I hope to hear from you soon!
Take care,
Shannon
Hi Shannon,
I am using the Progress Bar container. For Excerpt Include, how does it know what to import from the other page? I noticed that it only displays the first heading. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Shannon S , one more question, is it possible to include the CSS Stylesheet along with the content excerpt? Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Carissa,
Thank you for letting me know. It looks like the Progress Bar container is something from Adaptavist's Content Formatting Macros. I've moved your question over to the Adaptavist collection so they can answer.
For your 2nd question, I don't think I understand the question, but it may also be because it's related to Adaptavist's macro. Are you trying to reference Confluence's CSS stylesheet using an Excerpt macro or the one you generated using the Adaptavist add-on? What do you need to do exactly?
Take care,
Shannon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shannon,
I have a Progress Bar with an associated CSS Stylesheet I am trying to replicate and link in subsequent pages such that when I edit the links, color, etc., I won't have to go into every page and make the change. Hope that's slightly clearer!
Thanks,
Carissa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Carissa,
In that case, it does sound like someone familiar with the Content Formatting add-on will need to answer, so I'll leave this in Adaptavist's collection so they can help you. Unfortunately, the features you're mentioning aren't native to Confluence, so I won't be able to assist you with this.
I recommend you also try raising a ticket with Adaptavist using their support portal:
I hope this helps!
Take care,
Shannon
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.