I am making a jira plugin where the client side executes a jira api:
PUT - ${BASEURL}/rest/api/2/project/SAMPLE/properties/HT
On the backend I have a rest module trying to access the project properties data I created. This is the code I have so far...
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
ProjectPropertyService projectPeopertyService = ComponentAccessor.getComponent(ProjectPropertyService.class);
EntityPropertyService.PropertyResult propertyValues = projectPeopertyService.getProperty(user, "SAMPLE", "HT"); //THIS SHOULD CONTAIN MY PROPERTIES
Option<EntityProperty> jsonValues = propertyValues.getEntityProperty();
jsonValues.get();
How do I parse the json data that is returned to me. I am not sure how to access it? I am trying to return jsonValues.get() but it's giving me a no serializer found exception.
Is this the correct way to extract the project properties data through component access?
Hello,
That is how you can access it:
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.property.ProjectPropertyService
import com.atlassian.jira.entity.property.EntityPropertyService
import com.atlassian.jira.entity.property.EntityProperty
import com.atlassian.fugue.Option
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
ProjectPropertyService projectPeopertyService = ComponentAccessor.getComponent(ProjectPropertyService.class);
EntityPropertyService.PropertyResult propertyValues = projectPeopertyService.getProperty(user, "SAMPLE", "HT"); //THIS SHOULD CONTAIN MY PROPERTIES
Option<EntityProperty> jsonValues = propertyValues.getEntityProperty();
def value1 = jsonValues.getOrNull()
log.error(value1.getValue());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexey,
Thanks for this very informative reply. I've followed your recipe, and my unit tests work fine (where I have mocked the EntityProperty interface).
However, in the real world my plugin is not so good. I cannot retrieve the value of the project lead from a project. It could be because I am passing the wrong strings for key and/or property name, or it could be that the ProjectPropertyService is not connecting to the project in the H2 database properly.
My wired test creates a project using the testkit backdoor (I know this works, because after the test has run I can view this project in the Jira Web UI):
Here's the code that always returns Optional.empty() when the wired test case invokes it with projectKey = "SAM" and propertyName = "lead":
@Override
public Optional<String> getProjectProperty(String projectKey, String propertyName) {
final JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();
final ApplicationUser user = jiraAuthenticationContext.getLoggedInUser();
if(user == null) {
return Optional.empty();
}
final ProjectPropertyService projectPropertyService = ComponentAccessor.getComponent(ProjectPropertyService.class);
final EntityPropertyService.PropertyResult propertyValues = projectPropertyService.getProperty(user, projectKey, propertyName);
if(propertyValues == null) {
return Optional.empty();
}
final Option<EntityProperty> entityProperty = propertyValues.getEntityProperty();
final EntityProperty propertyValue = entityProperty.getOrNull();
return (propertyValue == null) ? Optional.empty() : Optional.of(propertyValue.getValue());
}
I have single-stepped in the debugger to verify that the ApplicationUser, ProjectPropertyService and PropertyResult objects are valid objects and that the user is named "admin". The entityProperty, however, just contains "none()".
Any advice would be gratefully received - e.g. any commands or methods I can use to verify that the ProjectPropertyService is properly initialised and connected to the right database.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've resolved my own problem by reading around the subject - but it was jolly difficult to find a lot of this information.
Essentially, the ProjectPropertyService does NOT support what I assumed it did, i.e. properties of a project. Instead, retrieve the ProjectManager from the ComponentAccessor, retrieve the Project from the ProjectManager by its key and then enquire of the Project - e.g. getProjectLead() returning an ApplicationUser object.
For a more fully worked example, see https://community.atlassian.com/t5/Agile-articles/Three-ways-to-update-an-issue-in-Jira-Java-Api/ba-p/736585
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you have a chance to get project properties with Jira Server recent version (8.x)?
Using getEntityProperty brings to the following error:
java.lang.NoSuchMethodError: com.atlassian.jira.entity.property.EntityPropertyService$PropertyServiceResult.getEntityProperty()Lcom/atlassian/fugue/Option;
Details are in:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.