Hey Community,
i try to develop a Jira Plugin. In this Plugin i want to Create new Issue Types. At the moment we use :
issueTypeManager.createIssueType(String name, String description, String iconUrl);
This function will be soon deprecated. So i decided to change to use:
createIssueType(String name, String description, Long avatarId)
Now to my problem. I create a Avatar and get a Id but the images can not be loaded like before.
Avatar tmpAvatar = AvatarImpl.createSystemAvatar(iconUrl, "image/png", IconType.ISSUE_TYPE_ICON_TYPE);
Avatar issueAvatar = ComponentAccessor.getAvatarManager().create(tmpAvatar);
issueTypeManager.createIssueType(String name, String description, issueAvatar.getId());
Do i have to change the Url i am loading from or is there a other problem with this function?
1 Like
Hi @tim.kuchenbuch,
Kindly try the following approach. I tested it and the images were loaded accordingly. In your sample, the image data is not yet loaded, hence, I passed an InputStream parameter to the AvataterManager#create.
InputStream inputStream = com.atlassian.core.util.ClassLoaderUtils.getResourceAsStream(String resourceName, Class className);
Avatar tmpAvatar = AvatarImpl.createCustomAvatar(String filename, "image/png", String ownerId, IconType.ISSUE_TYPE_ICON_TYPE);
Avatar issueAvatar = null;
try {
issueAvatar = ComponentAccessor.getAvatarManager().create(tmpAvatar, inputStream, null);
} catch (DataAccessException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
issueTypeManager.createIssueType(String name, String description, issueAvatar.getId());
Please try it out and tell us how it goes.
Cheers,
Ian
1 Like
Thanks @ianRagudo! We can create issue types with avatars now.
It was a little bit difficult to find out that we had to pass the filename of the image to the getResourceAsStream method but not its name used in the atlassian-plugin.xml:
String issueTypeFileName = getFileName(issueTypeName);
InputStream inputStream = ClassLoaderUtils.getResourceAsStream("images/" + issueTypeFileName, PluginInitializer.class);
Avatar tmpAvatar = AvatarImpl.createCustomAvatar(issueTypeFileName, "image/png", "0", IconType.ISSUE_TYPE_ICON_TYPE);
Avatar issueAvatar = null;
try {
issueAvatar = ComponentAccessor.getAvatarManager().create(tmpAvatar, inputStream, null);
if (issueAvatar != null) {
issueTypeManager.createIssueType(issueTypeName, issueTypeName, issueAvatar.getId());
}
} catch (DataAccessException | IOException e) {
LOGGER.error("Issue type " + issueTypeName + " could not be created.");
e.printStackTrace();
}
Thanks for the help. You can close this issue now. Our code to create issue types with avatars can be found on this page:
GitHub Page of ConDec JIRA Plug-In
1 Like
Hi,
I have the same problem, but your code does not work for me…
the “tmpAvatar” get’s created, but for any reason the image path changed from “/image/icons/test.png” to “/images/icons/testjrvtg.png” and this causes a file not found exception in the AvatarManager.
java.io.FileNotFoundException: C:\develop\target\jira\home\data\avatars\10900_xxxlarge@3x_\images\icons\testjrvtg.png (Das System kann den angegebenen Pfad nicht finden)
If I use the method ComponentAccessor.getAvatarManager().create(tmpAvatar), so without the input stream, the IssueType get’s created but the image is not displayed…
Any advise??