Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created July 10, 2014 20:06
Show Gist options
  • Save jechlin/dd5a9fe43f104494ea2a to your computer and use it in GitHub Desktop.
Save jechlin/dd5a9fe43f104494ea2a to your computer and use it in GitHub Desktop.
package examples
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.streams.api.UserProfile
import com.atlassian.streams.api.common.Either
import com.atlassian.streams.thirdparty.api.Activity
import com.atlassian.streams.thirdparty.api.ActivityService
import com.atlassian.streams.thirdparty.api.ValidationErrors
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import org.joda.time.DateTime
import static com.atlassian.streams.api.Html.html
import static com.atlassian.streams.api.common.Option.some
import static com.atlassian.streams.thirdparty.api.Application.application
@WithPlugin("com.atlassian.streams.streams-thirdparty-plugin")
@PluginModule
ActivityService activityService
@PluginModule
ApplicationProperties applicationProperties
User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Either<ValidationErrors, Activity> result =
new Activity.Builder(application("Groovy stream", URI.create(applicationProperties.getBaseUrl())),
new DateTime(),
new UserProfile.Builder(user.getName()).fullName(user.getDisplayName()).build())
.content(some(html("Enter some <b>content</b> here...")))
.title(some(html(user.getDisplayName() + " did something ")))
.url(some(URI.create(applicationProperties.getBaseUrl())))
.build();
for (Activity activity : result.right()) {
activityService.postActivity(activity);
}
for (ValidationErrors errors : result.left()) {
log.error("Errors encountered attempting to post activity: " + errors.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment