JB,
Thank you for the answer!

Below is the resulting use case.
***
* Command use case of getting companyName from customerInfo configuration PID 
***

import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;

@Service
@Command(scope = "customer", name = "info")
public class InfoCommand implements Action {
    @Reference
    private ConfigurationAdmin configAdmin;

    @Override
    public Object execute() {
        Configuration[] configs = 
configAdmin.listConfigurations("(service.pid=customerInfo)");
        if (configs != null && configs.length == 1) {
           String companyName = (String) 
configs[0].getProperties().get("companyName");
           System.out.println("Company name = " + companyName);
        } 
    }
}


Paul Spencer

> On May 13, 2022, at 3:23 PM, Jean-Baptiste Onofré <j...@nanthrax.net> wrote:
> 
> I don't understand your question, sorry ;)
> 
> You want to display companyName ?
> 
> String companyName = null;
> Configuration[] configs =
> configAdmin.listConfiguration("(service.pid=customerInfo)");
> if (configs != null && configs.length == 1) {
>  companyName = configs[0].getProperties().get("companyName");
> }
> 
> Regards
> JB
> 
> On Fri, May 13, 2022 at 8:57 PM Paul Spencer <paulspen...@mindspring.com> 
> wrote:
>> 
>> JB,
>> The configuration PID files already exist and are used by other components.
>> 
>> Below are two use cases that will print the companyName property from the 
>> companyInfo configuration PID.  The component use case  works today.  Please 
>> complete the command use case.
>> 
>> ***
>> * /etc/companyInfo.cfg
>> ***
>> companyName = FooBar Inc.
>> 
>> ***
>> * Component use case of getting companyName from customerInfo configuration 
>> PID
>> ***
>> @Component configuationPid = {"customerInfo"})
>> public class Foo implements FooService {
>> 
>>  @Activate
>>  protected activate(final Map<String,Object> configProperties) {
>>    String companyName = configProperties.get("companyName").toString();
>>    log.info("Foo Service activated for " companyName);
>>  }
>> }
>> 
>> ***
>> * Command use case if getting companyName from customerInfo configuration PID
>> ***
>> @Service
>> @Command(scope = "customer", name = "info")
>> public class InfoCommand implements Action {
>> 
>>  @Override
>>  public Object execute(){
>>     // How to populate company name for customerInfo configuration PID?
>>     String companyName = ??
>> 
>>     // Print company info
>>     System.out.println("Company name = " + companyName);
>>  }
>> 
>> Paul Spencer
>> 
>> 
>>> On May 13, 2022, at 12:53 PM, Jean-Baptiste Onofré <j...@nanthrax.net> 
>>> wrote:
>>> 
>>> No, you don't need to have a cfg file.
>>> 
>>> You can create the config like this, if the pid doesn't exist, it will
>>> be created and populated with config:property-set.
>>> 
>>> Regards
>>> JB
>>> 
>>> On Fri, May 13, 2022 at 3:27 PM Paul Spencer <paulspen...@mindspring.com> 
>>> wrote:
>>>> 
>>>> JB,
>>>> The command needs to use values stored in pid.cfg files, like instance 
>>>> specific CustomerName, just like other components.
>>>> 
>>>> Paul Spencer
>>>> 
>>>>> On May 13, 2022, at 1:46 AM, Jean-Baptiste Onofré <j...@nanthrax.net> 
>>>>> wrote:
>>>>> 
>>>>> Hi Paul,
>>>>> 
>>>>> Not sure I understand exactly the request, but you can do:
>>>>> 
>>>>> config:edit pid
>>>>> config:property-list ...
>>>>> config:cancel | config:commit
>>>>> 
>>>>> Regards
>>>>> JB
>>>>> 
>>>>> On Thu, May 12, 2022 at 6:38 PM Paul Spencer <paulspen...@mindspring.com> 
>>>>> wrote:
>>>>>> 
>>>>>> Karaf 4.3.6
>>>>>> I am looking to load configuration into a shell command, but I do not 
>>>>>> see where to set the configuration PID nor do I see where the 
>>>>>> configuration is passed or injected into the Action class.
>>>>>> 
>>>>>> 
>>>>>> In a component, the configuration loaded by @Activate is defined by 
>>>>>> @Component and the configurationPid attribute. What are the equivalents 
>>>>>> for shell commands, class that implement 
>>>>>> org.apache.karaf.shell.api.action.Action?
>>>>>> 
>>>>>> Paul Spencer
>>>> 
>> 

Reply via email to