Foren

Problem accessing company specific properties using PropsUtil

Stefan Rauch, geändert vor 17 Jahren.

Problem accessing company specific properties using PropsUtil

New Member Beiträge: 5 Beitrittsdatum: 03.08.06 Neueste Beiträge
Hi,

we have build a working environment to host multiple portal instances. Right now everything works quite fine except accessing the portal-companyid.properties.

Environment is liferay 4.1.1 on Jboss using CAS on separate Tomcat.

We define some extra properties in portal-ext.properties and some more in portal-abc.mydomain.fun.properties and portal-xyz.mydomain.fun.properties

Building works fine and we get one liferay.ear containing portal-web-abc.war and portal-web-xyz.war.

Also accessing each portal-instance works fine.

But when accessing http://abc.mydomain.fun and trying to read some of the extra properties defined in portal-abc.mydomain.fun.properties by using PropsUtil.get("myprop") we do not get the expected result.
If "myprop" is defined in portal-ext.properties or portal.properties we get the value defined there (portal-ext.properties overriding portal.properties), but not the one defined in portal-abc.mydomain.fun.properties.
If "myprop" is defined only in portal-abc.mydomain.fun.properties we get null.

I understand that using CompanyPropsUtil would bypass this problem, but that doesn't seem to be a good option to me as I would have to know the companyId at compile-time. This is definitely not wanted, as the piece of code using "myprop" is used for all of our portal instances.

Whilst searching around I found the folllowing peace of code from com.germinus.easyconf.ConfigurationLoader (included in easyconfig.jar):

public ComponentProperties readPropertiesConfiguration(String companyId, String componentName) {
[indent] AggregatedProperties properties = new AggregatedProperties(companyId, componentName);
// if (companyId != null) {
// properties.addGlobalFileName(Conventions.GLOBAL_CONFIGURATION_FILE + Conventions.SLASH + companyId
// + Conventions.PROPERTIES_EXTENSION);
// }
properties.addGlobalFileName(Conventions.GLOBAL_CONFIGURATION_FILE +
Conventions.PROPERTIES_EXTENSION);
// if (companyId != null) {
// properties.addBaseFileName(componentName + Conventions.SLASH + companyId +
// Conventions.PROPERTIES_EXTENSION);
// }
properties.addBaseFileName(componentName + Conventions.PROPERTIES_EXTENSION);

log.info("Properties for " + componentName + " loaded from " + properties.loadedSources());
return new ComponentProperties(properties);
[/indent] }


I believe the out commented piece of code would solve our problem, but am really not sure about this.

Is this rather a bug, a feature or did I overlook something?

I would be glad, if anyone could help us.

Cheers

Stefan.
thumbnail
Jorge Ferrer, geändert vor 17 Jahren.

RE: Problem accessing company specific properties using PropsUtil

Liferay Legend Beiträge: 2871 Beitrittsdatum: 31.08.06 Neueste Beiträge
Hi Stefan,

As you say, you must use CompanyPropsUtil if you want Liferay to read the configuration that is dependent on a given companyId. You don't have to hardcode the companyId in the call to this class, as it can be retrieved from the request, the session or even the servlet context.

Related to the EasyConf code you point to, it is old code that should remain commented out. Starting with EasyConf 0.9 (the one used in Liferay 4) the name of the file specific for one company is configured in the base properties file. In the case of Liferay, check the first lines of portal.properties and you'll see:

include-and-override=portal-${easyconf:companyId}.properties


So this is the lines that says that for company 'portalA' the file 'portal-portalA.properties' will be read and will override the default values.

Let me know if calling CompanyPropsUtil has solved your problem.
Stefan Rauch, geändert vor 17 Jahren.

RE: Problem accessing company specific properties using PropsUtil

New Member Beiträge: 5 Beitrittsdatum: 03.08.06 Neueste Beiträge
Hi Jorge,

probably you're right that I want need to hardcode the company id, but wouldn't it still be better that PropsUtil would return the value of a property belonging to the current portal instance?

And if not I do think that there should be a convenience method like PropsUtil.get(String key, boolean useCompanyProperty) to preserve people from duplicating the piece of code to determine the current company id. Actually I believ the default behaviour of PropsUtil.get(String key) should be to return the specific value of the current portal instance (company id)

What do you think?

Stefan.
thumbnail
Jorge Ferrer, geändert vor 17 Jahren.

RE: Problem accessing company specific properties using PropsUtil

Liferay Legend Beiträge: 2871 Beitrittsdatum: 31.08.06 Neueste Beiträge
Hi Stefan,

I agree that it would be a good idea if PropsUtil automatically added the current companyId, but currently it has no way to access its value, because it does not have access to the request, session nor servletContext.

Do you have an idea to implement that in a way that wouldn't require many changes to the source code?
Stefan Rauch, geändert vor 17 Jahren.

RE: Problem accessing company specific properties using PropsUtil

New Member Beiträge: 5 Beitrittsdatum: 03.08.06 Neueste Beiträge
;-))

That's why I would have to hardcode the company id in the example givven above. I hoped to find a solution here...;-)
thumbnail
Brian Chan, geändert vor 17 Jahren.

RE: Problem accessing company specific properties using PropsUtil

Liferay Master Beiträge: 753 Beitrittsdatum: 05.08.04 Neueste Beiträge
CompanyPropsUtil actually wraps PropsUtil...

Perhaps we can set it in... the thread context?
thumbnail
Jorge Ferrer, geändert vor 17 Jahren.

RE: Problem accessing company specific properties using PropsUtil

Liferay Legend Beiträge: 2871 Beitrittsdatum: 31.08.06 Neueste Beiträge
Brian Chan:
Perhaps we can set it in... the thread context?


Yes, I think that setting the company_id in a ThreadLocal variable would be a great idea. If we do it that way there is no longer a need to store it in the request or session anymore.