It's all about the answers!

Ask a question

Create new enumeration type using Java API


Marcin Blacha (14617) | asked Mar 13 '18, 7:18 a.m.

I've searched, but I only find how to add enumeration value to existing enum. But did anyone created new enumeration type?
We wan't to use database stored enums in projects, but they can't be specified in process template, and I'm trying to write custom follow up action to handle this.

2 answers



permanent link
Marcin Blacha (14617) | answered Mar 13 '18, 10:30 a.m.

It looks that I found way to create new enumeration type stored in database:

public class OperationParticipant extends AbstractService implements
        IOperationParticipant {
    
    private IProjectArea fProjectArea;
    
    private class enumDetails {
        public String id;
        public String name;
        
        public enumDetails(String identifier, String displayName) {
            id = identifier;
            name = displayName;
        }
    }
    
    @SuppressWarnings("restriction")
    @Override
    public void run(AdvisableOperation operation, IProcessConfigurationElement participantConfig,
            IParticipantInfoCollector collector, IProgressMonitor monitor)
            throws TeamRepositoryException {
        // TODO Auto-generated method stub
        
        List<enumDetails> enumsToCreate = new ArrayList<OperationParticipant.enumDetails>();
        enumsToCreate.add(new enumDetails("hwVersion", "Found In HW"));
        enumsToCreate.add(new enumDetails("mechanicVersion", "Mechanic Version"));
        
        IRepositoryItemService itemService = (IRepositoryItemService)getService(IRepositoryItemService.class);
        this.fProjectArea = ((IProjectArea)itemService.fetchItem(operation.getProcessArea(), IRepositoryItemService.COMPLETE));
        IEnumerationService enumServ = (IEnumerationService) getService(IEnumerationService.class);
        
        for (enumDetails enumDetails : enumsToCreate) {
            Enumeration enumToCreate = EnumerationFactory.eINSTANCE.createEnumeration();
            enumToCreate.initNew();
            enumToCreate.setContextId(fProjectArea.getContextId());
            enumToCreate.setName(enumDetails.name);
            enumToCreate.setIdentifier(enumDetails.id);
            enumToCreate.setProjectArea(fProjectArea);
            enumToCreate.setItemId(UUID.generate());
            enumServ.save(enumToCreate);
        }
        
    }


permanent link
Ralph Schoon (61.1k33643) | answered Mar 13 '18, 7:35 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

As far as I know, you would have to directly modify the process XML and save it.
You can check how the Eclipse client does it, but I am almost certain that you will have to use internal API if you try to do that. I have been looking for some stuff with respect to make attributes read only long time ago and I gave up because it was so hard.

All in all this might not be part of the public API, some code might just be rich client code, and is likely not considered as supported.


Comments
Marcin Blacha commented Mar 13 '18, 7:46 a.m.

I've tried to search in process XML, but database stored enumerations are not saved there, everything is stored in database only.


Ralph Schoon commented Mar 13 '18, 7:52 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

They are created in the Eclipse Rich client, so you can try to search the RTC Client SDK, what the code does. It is likely still unsupported internal API.

Your answer


Register or to post your answer.