I am trying to replicate a reponse same as the API "/issue/createmeta" this API's have Project -> Issue Type - > Fields. Under this fields they have metadata regarding the field. I am trying to achieve the same with ComponentAccesor. Is it possible to access those metadata with ComponentAccesor. If yes, Then how can it be achieved?
I am able to get IssueTypes and the Fields associated with the Issue Types.
MutableIssue issuePattern = ComponentAccessor.getComponentOfType(IssueFactory.class).getIssue();
issuePattern.setProjectId(project.getId());
issuePattern.setIssueTypeId(issueType.getId());
IssueCreationHelperBean issueCreationHelperBean = ComponentAccessor.getComponentOfType(IssueCreationHelperBean.class);
List<OrderableField> orderableFields = issueCreationHelperBean.getFieldsForCreate(ComponentAccessor.getJiraAuthenticationContext().getUser(), issuePattern);
JsonArray fields = new JsonArray();
for(OrderableField orderableField : orderableFields) {
JsonObject field = new JsonObject();
field.addProperty("name", orderableField.getName());
field.addProperty("key", orderableField.getNameKey());
fields.add(field);
}
Have found the Solution please find below
List<Project> extProjects = new ArrayList<Project>();
if(projectIds != null && !projectIds.isEmpty()) {
Long projectId = Long.parseLong(projectIds);
Project project = ComponentAccessor.getProjectManager().getProjectObj(projectId);
if(project != null) {
extProjects.add(project);
}
}else {
extProjects.addAll(ComponentAccessor.getProjectManager().getProjects());
}
JsonArray projJsonArray = new JsonArray();
if(extProjects != null && !extProjects.isEmpty()) {
for (int i = 0; i < extProjects.size(); i++) {
Project project = extProjects.get(i);
List<IssueType> issueTypes = new ArrayList<IssueType>();
issueTypes.addAll(project.getIssueTypes());
JsonObject projectJson = new JsonObject();
projectJson.addProperty("id", project.getId());
projectJson.addProperty("key", project.getKey());
projectJson.addProperty("name", project.getName());
JsonArray issueTypesJsonArray = new JsonArray();
for(IssueType issueType : issueTypes) {
JsonObject issueTypeJson = new JsonObject();
issueTypeJson.addProperty("id", issueType.getId());
issueTypeJson.addProperty("description", issueType.getDescription());
issueTypeJson.addProperty("name", issueType.getName());
issueTypeJson.addProperty("subtask", issueType.isSubTask());
issueTypeJson.addProperty("expand", "fields");
MutableIssue issuePattern = ComponentAccessor.getComponentOfType(IssueFactory.class).getIssue();
issuePattern.setProjectId(project.getId());
issuePattern.setIssueTypeId(issueType.getId());
IssueCreationHelperBean issueCreationHelperBean = ComponentAccessor.getComponentOfType(IssueCreationHelperBean.class);
FieldScreenRenderer fieldScreenRenderer = issueCreationHelperBean.createFieldScreenRenderer(issuePattern);
Map<String, FieldMetaBean> fieldsMap = getFieldMetadataBeans(issuePattern,issueType,project,fieldScreenRenderer);
Gson gson = new Gson();
issueTypeJson.add("fields", gson.toJsonTree(fieldsMap));
issueTypesJsonArray.add(issueTypeJson);
}
projectJson.add("issuetypes", issueTypesJsonArray);
projJsonArray.add(projectJson);
}
}
JsonObjectjsonObject = new JsonObject();
jsonObject.add("projects", projJsonArray);
jsonObject.addProperty("expand", "projects");
jsonObject.addProperty("total", Integer.valueOf(projJsonArray.size()));
return jsonObject;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.