Skip to main content
Content Starts Here

We've Moved!

Please note that we have moved to our New Forum site.


Ask Search:
Eder CarneiroEder Carneiro 

Update Object Example

Well,

I'm new to the Genesys SDK. Anyway, I'm trying to modify or create some new 'option' in the config server. This is the sample that exists in the api docs:

ConfObjectDelta delta0 = new ConfObjectDelta(metadata, CfgObjectType.CFGApplication);
ConfObject inDelta = (ConfObject) delta0.getOrCreatePropertyValue("deltaApplication");
inDelta.setPropertyValue("DBID", objCreated.getObjectDbid());
inDelta.setPropertyValue("name", "ConfObject-new-name");
 
ConfIntegerCollection delTenants = (ConfIntegerCollection)
        delta0.getOrCreatePropertyValue("deletedTenantDBIDs");
delTenants.add(105);
 
RequestUpdateObject reqUpdate = RequestUpdateObject.create();
reqUpdate.setObjectDelta(delta0);
 
Message resp = protocol.request(reqUpdate);
if (resp == null) {
    // timeout
} else if (resp instanceof EventObjectUpdated) {
    // the object has been updated
} else if (resp instanceof EventError) {
    // fail((EventError) resp);
} else {
    // unexpected server response
}
 

Well, I cannot guess how it works, since there is no change in delta0. Changes are made in the ConfObject, but anyway the object used to request changes is the delta0. Can anyone explain how that works at all ?

Best Answer chosen by Eder Carneiro
Ed ValdezEd Valdez
My main trouble was updating the user properties in the annex tab, but here's how I got it to work ...

I have a wrapper around the protocol and connection, where I defined this method: 
@Override
    public void updateConfigObject(ConfObjectDelta configObj) {
        
        if(!canWrite())
            throw new IllegalStateException("Unable to update configuation object because connection is not ready!");
        
        Guard.argumentNotNull(configObj, "configObj");
        int id = configObj.getObjectDbid();
        
        RequestUpdateObject req = RequestUpdateObject.create();
        req.setObjectDelta(configObj);
        
        Message resp = connection.request(req);        
        if(resp instanceof EventObjectUpdated) {
            logger.info("ConfigWriter.createConfigObject: Object [{}] updated successfully!", id);
            return;
        } 
        
        String errMsg = "Failed to update object [" + id + "]! ";
        if(resp instanceof EventError)
            errMsg += ((EventError)resp).getDescription();
        else
            errMsg += "Unexpected response [" + (resp == null ? "null" : resp.messageName()) + "]";
        
        logger.error("ConfigWriter.updateConfigObject: {}", errMsg);
        throw new MessagingException(errMsg);        
    }

Then from the client code (in this case a simple JUnit test):
ConfObjectDelta deltaObj = new ConfObjectDelta(connection.getConfigServerContextMetadata(), CfgObjectType.CFGApplication);
        
        KeyValueCollection s2 = new KeyValueCollection();
        s2.addString("o1", "FOO!");

        KeyValueCollection changedProps = new KeyValueCollection();
        deltaObj.setPropertyValue("changedUserProperties", changedProps);
        changedProps = (KeyValueCollection)deltaObj.getOrCreatePropertyValue("changedUserProperties");
        changedProps.addList("s2", s2);
                    
        ConfObject obj = (ConfObject)deltaObj.getOrCreatePropertyValue("deltaApplication");
        obj.setPropertyValue(DBID, id);
        obj.setPropertyValue(STATE, CfgObjectState.CFGDisabled.asInteger());
        
        writer.updateConfigObject(deltaObj);

Note that the getOrCreatePropertyValue method does not seem to work for KVList collections like "changedUserProperties", or "deletedUserProperties", it just returns null.  So I had to create a new KeyValueCollection myself, set it as a property on the delta object with the expected attribute name - see https://docs.genesys.com/Documentation/PSDK/latest/ConfigLayerRef/CfgDeltaApplication

Cheers!

All Answers

Ed ValdezEd Valdez
My main trouble was updating the user properties in the annex tab, but here's how I got it to work ...

I have a wrapper around the protocol and connection, where I defined this method: 
@Override
    public void updateConfigObject(ConfObjectDelta configObj) {
        
        if(!canWrite())
            throw new IllegalStateException("Unable to update configuation object because connection is not ready!");
        
        Guard.argumentNotNull(configObj, "configObj");
        int id = configObj.getObjectDbid();
        
        RequestUpdateObject req = RequestUpdateObject.create();
        req.setObjectDelta(configObj);
        
        Message resp = connection.request(req);        
        if(resp instanceof EventObjectUpdated) {
            logger.info("ConfigWriter.createConfigObject: Object [{}] updated successfully!", id);
            return;
        } 
        
        String errMsg = "Failed to update object [" + id + "]! ";
        if(resp instanceof EventError)
            errMsg += ((EventError)resp).getDescription();
        else
            errMsg += "Unexpected response [" + (resp == null ? "null" : resp.messageName()) + "]";
        
        logger.error("ConfigWriter.updateConfigObject: {}", errMsg);
        throw new MessagingException(errMsg);        
    }

Then from the client code (in this case a simple JUnit test):
ConfObjectDelta deltaObj = new ConfObjectDelta(connection.getConfigServerContextMetadata(), CfgObjectType.CFGApplication);
        
        KeyValueCollection s2 = new KeyValueCollection();
        s2.addString("o1", "FOO!");

        KeyValueCollection changedProps = new KeyValueCollection();
        deltaObj.setPropertyValue("changedUserProperties", changedProps);
        changedProps = (KeyValueCollection)deltaObj.getOrCreatePropertyValue("changedUserProperties");
        changedProps.addList("s2", s2);
                    
        ConfObject obj = (ConfObject)deltaObj.getOrCreatePropertyValue("deltaApplication");
        obj.setPropertyValue(DBID, id);
        obj.setPropertyValue(STATE, CfgObjectState.CFGDisabled.asInteger());
        
        writer.updateConfigObject(deltaObj);

Note that the getOrCreatePropertyValue method does not seem to work for KVList collections like "changedUserProperties", or "deletedUserProperties", it just returns null.  So I had to create a new KeyValueCollection myself, set it as a property on the delta object with the expected attribute name - see https://docs.genesys.com/Documentation/PSDK/latest/ConfigLayerRef/CfgDeltaApplication

Cheers!
This was selected as the best answer
Eder CarneiroEder Carneiro
Nice, it worked here in my code. Have you ever managed to insert some new user option in a existing object ?