Groovy-JIRA (Script Runner) Quick Reference

To get a user;

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
userManager = (UserManager) ComponentAccessor.getUserManager();
User user = userManager.getUser('my-user');

To get an issue;

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
ComponentManager componentManager = ComponentManager.getInstance()
MutableIssue myIssue = componentManager.getIssueManager().getIssueObject('ABC-1234')

To set a reporter for an issue;

myIssue.setReporter(user);

Get a custom field;

CustomField nameCustomField = customFieldManager.getCustomFieldObject('customfield_10123')
myIssue.setCustomFieldValue(nameCustomField, "my name")

https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions

.

JIRA Groovy (ScriptRunner) – Assigning Users

The following Groovy code is used to get an issue, and update it’s assigned user;

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.event.issue.AbstractIssueEventListener

// uncomment if this snippet is being used as post-function
//MutableIssue myIssue = (MutableIssue)issue;
userManager = (UserManager) ComponentAccessor.getUserManager()

ComponentManager componentManager = ComponentManager.getInstance()

MutableIssue myIssue = componentManager.getIssueManager().getIssueObject('ABC-1234')
User user = userManager.getUser('my-user');
myIssue.setReporter(user);
myIssue.store();

To get a user;

User user = userManager.getUser('my-user');

To get an issue;

MutableIssue myIssue = componentManager.getIssueManager().getIssueObject('ABC-1234')

To set a reporter for an issue;

myIssue.setReporter(user);

Jetty & Comet

  1. Install Java (http://degreesofzero.com/article/21);
    aptitude install openjdk-7-jre
  2. Download Jetty from: http://www.eclipse.org/jetty/downloads.php

Ref: http://degreesofzero.com/article/19

Spring & Tomcat – custom errors

In spending a few hours on trying to get the error-page tag in tomcat’s web.xml working, i’ve found a better way to do it – one which uses spring to take on exception handling rather than Tomcat itself – something which also lets spring give the error-page visibility on other view-objects and business-rules.

Simple enough to implement and works wonderfully! 🙂

Eg;

<bean>
<property name="exceptionMappings">
<map>
<entry key="project.exception.RecordNotFoundException" value="recordNotFoundException" />
</map></property>
</bean>

http://developingdeveloper.wordpress.com/2008/03/09/handling-exceptions-in-spring-mvc-part-2/

Spring Interceptors

To add an interceptor to your application, do the following;

Add the following to your application-context.xml file;

<context:component-scan base-package="com.test" />

<mvc:annotation-driven/>

<mvc:interceptors>
	<bean .... />
</mvc:interceptors>

http://forum.springsource.org/showpost.php?p=289544&postcount=4

Spring-EL Expressions

To enable spring security EL expressions, add the following to the <http> element in your application-security.xml file;

use-expressions="true"

A few gotcha’s when enabling this; each of your <intercept-url … role=”ROLE_USER” needs to be changed to role=”hasRole(‘ROLE_USER’)

Also – the following exception will be thrown unless you change ‘IS_AUTHENTICATED_ANONYMOUSLY’ to ‘permitAll’;

Failed to evaluate expression 'IS_AUTHENTICATED_ANONYMOUSLY'

In your JSP pages the following can be used for securing portions of pages;

<sec:authorize access="hasRole('ROLE_MANAGER')">
...
</sec:authorize>

A few other useful links;

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/springsecurity-single.html
http://ambisoft.pl/blog/

Spring – c:foreach and hibernate’s maps / lists

iterating over a list / set can be done via;

<c:forEach items=”${job.jobPhotos}” var=”photo” varStatus=”idx”>
<form:hidden path=”jobPhotos[${idx.index}].id” />

Iterating over a map can be done via;

<c:forEach items=”${job.jobPhotos}” var=”current”>
<form:hidden path=”jobPhotos[${current.key}].id” />

${current.key} and ${current.value.id} are equilivant (both equate to the ID of the row being iterated over)

http://www.steve-farmer.com/examples/jstl/ui/c-foreach-map.jsp
http://blog.vergiss-blackjack.de/2010/04/iterating-over-nested-objects-in-a-spring-form/

Hibernate Annotations – Bidirectional One-To-Many