How to retreive instance scoped configuration in Liferay 7.4.3 (ga104)?

31 Views Asked by At

I have a configuration interface defined with annotation

@ExtendedObjectClassDefinition(
       category = "logging",
       scope = ExtendedObjectClassDefinition.Scope.COMPANY
)

so that I can configure liferay instances separately. How can I retreive the configuration in my code?

I tried using

ConfigurableUtil.createConfigurable(MyConfig.class, properties)

in my activate method, however it only receives the system wide configuration values.

1

There are 1 best solutions below

0
Olaf Kock On BEST ANSWER

To figure this out, I always grep Liferay's source, in this case for ExtendedObjectClassDefinition.Scope.COMPANY, and see how it is used.

One sample (second order, the configuration in question is AWSTranslatorConfiguration) from AWSTranslator - see the isEnabled method:

@Component(
    configurationPid = "com.liferay.translation.translator.aws.internal.configuration.AWSTranslatorConfiguration",
    service = Translator.class
)
public class AWSTranslator implements Translator {

    public boolean isEnabled(long companyId) throws ConfigurationException {
        AWSTranslatorConfiguration awsTranslatorConfiguration =
            _configurationProvider.getCompanyConfiguration(
                AWSTranslatorConfiguration.class, companyId);

        return awsTranslatorConfiguration.enabled();
    }

    @Reference
    private ConfigurationProvider _configurationProvider;

    // other irrelevant code omitted

}

Key is: In order to get the scoped value, you'll definitely need to provide the scope - in this case the companyId.