[closed] Adding a new enumeration value with server-side Java API in RTC
Luca Martinucci (1.0k●3●97●112)
| asked Mar 07 '17, 5:41 a.m.
closed Jan 22, 10:00 a.m. by Ralph Schoon (63.5k●3●36●46) I have an attribute of type "enumeration list"; the enumeration is of type "database".
|
The question has been closed for the following reason: "The question is answered, right answer was accepted" by rschoon Jan 22, 10:00 a.m.
Accepted answer
Luca Martinucci (1.0k●3●97●112)
| answered Mar 14 '17, 8:51 a.m.
edited Mar 14 '17, 8:59 a.m. by Ralph Schoon (63.5k●3●36●46) Working Code: @SuppressWarnings("unchecked") public void addEnumerationLiteral (IAttribute attribute, String identifierName, String identifierCode) Ralph Schoon selected this answer as the correct answer
|
3 other answers
Ralph Schoon (63.5k●3●36●46)
| answered Mar 07 '17, 6:42 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER I have never seen code for that. It is obviously somehow possible, as the Eclipse client and the Web UI provide this. All you can do is to search for IEnumeration and hope to find something that hints how this can be done.
I found com.ibm.team.workitem.service.internal.WorkItemRepositoryService.addLiteralToPersistedEnumeration(IEnumerationService, IAttribute, Identifier) doing so and that could be an entry point for you into the SDK. Good luck!
Comments
Luca Martinucci
commented Mar 14 '17, 8:46 a.m.
Ralph, actually, it worked.
Luca, you are most likely seeing a cash refresh delay. Another customer mentioned something here on the forum.
Ralph Schoon
commented Mar 14 '17, 9:01 a.m.
| edited Mar 14 '17, 9:01 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
ps, you can use the "View HTM Source" button looks like a paper with <> on it to the top right" and add a [pre] [/pre] tag (with <, and .>) To make the code easier to read.
I did that to your code below, you can use edit and the "View HTM Source" button to see what I did.
|
Hi All
The accepted answer is really useful! Thanks.
I am sharing the following code that i used to add new literals through Java Plain APIs (Client Side SDK) and it's working fine.
@SuppressWarnings("unchecked") public static void addEnumerationLiteral(IAttribute attribute, String identifierName, String iconUrl) throws TeamRepositoryException { IEnumerationService enumerationService = (IEnumerationService) ((TeamRepository) CLMConnection.teamRepository) .getServiceInterface(IEnumerationService.class); Enumeration enumeration = (Enumeration) enumerationService.resolveEnumeration(attribute); if (enumeration != null) { Enumeration enumerationCopy = (Enumeration) enumeration.getWorkingCopy(); List<literal> literalsCopy = enumerationCopy.getLiterals(); Literal newLiteral = EnumerationFactory.eINSTANCE.createLiteral(); newLiteral.setIdentifier(getNewLiteralIdentifier(enumeration)); newLiteral.setName(identifierName); newLiteral.setSequenceValue(((Enumeration) enumeration).getLiterals().size() - 1); newLiteral.setIconUrl(iconUrl); literalsCopy.add(newLiteral); if (literalsCopy.size() == 1) { enumerationCopy.setDefaultLiteralId(newLiteral.getIdentifier()); } enumerationService.update(enumerationCopy); } } </literal> public static String getNewLiteralIdentifier(Enumeration enumeration) { Literal lastLiteral = (Literal) enumeration.getLiterals().get(enumeration.getLiterals().size() - 1); String lastLiteralIdentifier = lastLiteral.getIdentifier(); return getNextId(lastLiteralIdentifier); } public static String getNextId(String id) { String[] parts = id.split("(?=\d+$)", 2); return parts[0] + String.format("%0" + parts[1].length() + "d", Integer.parseInt(parts[1]) + 1); }
Hope this helps someone!
Thanks,
Mohammad Alawneh
|
Hi @Mohammad
I tried the way you have implemented. Looks no error but i am getting null value at
Enumeration enumeration = (Enumeration) enumerationService.resolveEnumeration(attribute);
Also tried
enumerationService.resolveEnumerations(getProjectArea());
which is giving empty array.
Can you please help me what am i missing here.
I am using EWM 7.0.2 SR1 version.
Thanks in advance,
Manju
Comments Hi Manju,
Make sure the attribute type you are using is Database Enumeration. You should see these options whenever you're creating a new enumeration:
Add Enumeration
<button aria-label="close" class="jazz-ui-Dialog-close-button" dojoattachpoint="closeButton" style="border-color: transparent; border-style: solid; cursor: pointer; font-family: inherit; font-size: 12px; height: 48px; overflow: hidden; padding: 12px; position: absolute; right: 0px; top: 0px; transition: background-color 0.11s cubic-bezier(0.2, 0, 0.38, 0.9) 0s; width: 48px;">
Manju Gowda
commented Jan 22, 6:56 a.m.
Hi @Mohammed,
Thanks for your reply.
So this code only works for the DB level Enums. Currently we are using Process Config type.
Thanks again
Manju
Please do not answer with questions on an existing question. Create your own question. This is especially true, if the question is very old or already correctly answered.
|