Fórumok
"Activating" programatically created organization sites
Piña Kanpokaldean, módosítva 9 év-val korábban
"Activating" programatically created organization sites
Junior Member Bejegyzések: 79 Csatlakozás dátuma: 2012.04.14. Legújabb bejegyzések
On my application, I've just implemented a system where organizations are created dynamically, and those organizations include a site linked to a template. So far so good, took me a while but it all works and I was happy. However, as it turns out, it appears these sites need to be "activated", or initialized, or I don't know what word to use. I'll elaborate.
In order to access the public page, I went to the sites section of the control panel and clicked on "view pages". This shows me the page with my template and whatnot, so great. Then, through my application I set links that mimicked the one I got from "view pages", and it all seemed fine. The problem is that with freshly created sites, the links will get a "not found" error. Yet, if I go to the sites section and enter the new site, that seems enough for my other links to start to work.
Is there any initialization that needs to be set up on the sites for them to start working? I don't see anything distinctive on the group_ table of the database, either.
For the record, the code I'm using (liferay 6.2) to create both organization and site is:
Edit: I've tried simply creating an organization, including the site with the template, from the control panel and then go directly to the site and check the url: it works. Which, to my understanding, that means the code here (EditOrganizationAction) should do the work. But as far as I can tell, the code is basically the same, excluding the reminder queries. I can't figure out what is missing on my side, I'd appreciate any tip.
In order to access the public page, I went to the sites section of the control panel and clicked on "view pages". This shows me the page with my template and whatnot, so great. Then, through my application I set links that mimicked the one I got from "view pages", and it all seemed fine. The problem is that with freshly created sites, the links will get a "not found" error. Yet, if I go to the sites section and enter the new site, that seems enough for my other links to start to work.
Is there any initialization that needs to be set up on the sites for them to start working? I don't see anything distinctive on the group_ table of the database, either.
For the record, the code I'm using (liferay 6.2) to create both organization and site is:
String friendlyURL = projectName;
Organization organization = OrganizationLocalServiceUtil.addOrganization(serviceContext.getGuestOrUserId(),
Constants.getIntiativesParentOrganizationId(serviceContext.getCompanyId()), friendlyURL,
"regular-organization", 0, 0, 12017, "", true, serviceContext);
project.setOrganizationId(organization.getOrganizationId());
Group organizationGroup = organization.getGroup();
SitesUtil.updateLayoutSetPrototypesLinks(organizationGroup,
Constants.INITIATIVE_PUBLIC_SITE_TEMPLATE_ID,
Constants.INITIATIVE_PRIVATE_SITE_TEMPLATE_ID,
true, true);
Edit: I've tried simply creating an organization, including the site with the template, from the control panel and then go directly to the site and check the url: it works. Which, to my understanding, that means the code here (EditOrganizationAction) should do the work. But as far as I can tell, the code is basically the same, excluding the reminder queries. I can't figure out what is missing on my side, I'd appreciate any tip.
Willem Vermeer, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Junior Member Bejegyzések: 32 Csatlakozás dátuma: 2012.03.30. Legújabb bejegyzések
Hi Pina,
Did you ever find a solution? I'm facing the exact same issue. I've tried reindexing the organisation after creating it, but still the site remains inactive.
Thanks,
Willem
Did you ever find a solution? I'm facing the exact same issue. I've tried reindexing the organisation after creating it, but still the site remains inactive.
Thanks,
Willem
Jan Geißler, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Liferay Master Bejegyzések: 735 Csatlakozás dátuma: 2011.07.05. Legújabb bejegyzések
What does
organization.getGroup().getActive()
tell you if you check it after the creation of the Organization?
organization.getGroup().getActive()
tell you if you check it after the creation of the Organization?
Willem Vermeer, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Junior Member Bejegyzések: 32 Csatlakozás dátuma: 2012.03.30. Legújabb bejegyzések
The value of organization.getGroup().getActive() is true directly after adding the organization by:
Organization organization =
OrganizationServiceUtil.addOrganization(0, companyName, OrganizationConstants.TYPE_REGULAR_ORGANIZATION, 0, 0,
ListTypeConstants.ORGANIZATION_STATUS_DEFAULT, "", true, serviceContext);
The serviceContext is created by :
ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
on a request submitted by the default Liferay admin user.
Organization organization =
OrganizationServiceUtil.addOrganization(0, companyName, OrganizationConstants.TYPE_REGULAR_ORGANIZATION, 0, 0,
ListTypeConstants.ORGANIZATION_STATUS_DEFAULT, "", true, serviceContext);
The serviceContext is created by :
ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
on a request submitted by the default Liferay admin user.
Jan Geißler, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Liferay Master Bejegyzések: 735 Csatlakozás dátuma: 2011.07.05. Legújabb bejegyzések
I experienced this behavior, when I tried to navigate to a site, while the template was still being assigned. This is something which can happen on large site templates.
Piña Kanpokaldean, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Junior Member Bejegyzések: 79 Csatlakozás dátuma: 2012.04.14. Legújabb bejegyzésekWillem Vermeer:
Hi Pina,
Did you ever find a solution? I'm facing the exact same issue. I've tried reindexing the organisation after creating it, but still the site remains inactive.
Thanks,
Willem
Nope, sorry. As I was trying to figure this out, higher ups™ decided that it wasn't really necessary to use these organizations and the whole development was shelved. There's been talks recently to reconsider it though, so it would be great if a solution is found in the meantime. I unfortunately don't have the time to check on it right now, but I'll have another look at it probably later this month. I won't be able to help if you are in a hurry though.
Willem Vermeer, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Junior Member Bejegyzések: 32 Csatlakozás dátuma: 2012.03.30. Legújabb bejegyzések
Hi Pina and Jan,
Thanks so much for taking the time to look into this problem. I dug some deeper and found out that the problem has to do with the LayoutSet associated to the newly created site (=Group)
When I programmatically add the organization + site I see in the database a LayoutSet entry with pagecount = 0 and, interestingly, also a reference to the layoutsetprototypeuuid
Then when I go to the control panel and look up the organization and click on Manage Site (which is enough to activate the site) a second entry in the LayoutSet table is created, with pagecount =1 and a correct layoutsetprototypeuuid. My previously created entry has now an empty layoutsetprototypeuuid.
So the question is why this is happening and what I need to do to create the correct entry in the LayoutSet table.
The issue has nothing to do with the site template being too large - err come to think of it, maybe the issue is that the site template has no pages.....oops brb
Willem
Thanks so much for taking the time to look into this problem. I dug some deeper and found out that the problem has to do with the LayoutSet associated to the newly created site (=Group)
When I programmatically add the organization + site I see in the database a LayoutSet entry with pagecount = 0 and, interestingly, also a reference to the layoutsetprototypeuuid
Then when I go to the control panel and look up the organization and click on Manage Site (which is enough to activate the site) a second entry in the LayoutSet table is created, with pagecount =1 and a correct layoutsetprototypeuuid. My previously created entry has now an empty layoutsetprototypeuuid.
So the question is why this is happening and what I need to do to create the correct entry in the LayoutSet table.
The issue has nothing to do with the site template being too large - err come to think of it, maybe the issue is that the site template has no pages.....oops brb
Willem
Jan Geißler, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Liferay Master Bejegyzések: 735 Csatlakozás dátuma: 2011.07.05. Legújabb bejegyzések
How do you evaluate the id of your site template if I may ask?
I do smell a constant here, but on every installation the id's will differ...
I do smell a constant here, but on every installation the id's will differ...
Willem Vermeer, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Junior Member Bejegyzések: 32 Csatlakozás dátuma: 2012.03.30. Legújabb bejegyzések
I lookup the site template by its name. I'm on one single environment with just this site template. I can see in my logs that it's correctly found.
Jan Geißler, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Liferay Master Bejegyzések: 735 Csatlakozás dátuma: 2011.07.05. Legújabb bejegyzések
Dammit. Thought I got on the right track. And you can confirm, that the correct LayoutSetPrototypeUUID is set on the LayoutSet entity?
Willem Vermeer, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Junior Member Bejegyzések: 32 Csatlakozás dátuma: 2012.03.30. Legújabb bejegyzések
Found a solution!! After some more searching I first stumbled upon this open bug report:
https://issues.liferay.com/browse/LPS-48987
confirming we are not completely missing something obvious and then later I found a solution overhere:
http://livewithliferay.blogspot.nl/2014/12/create-site-programmatically-in-liferay.html
The following code is now working for me (haven't tested whether setting the threadlocal is really necessary as I'm already logged on as admin when I execute my code)
PrincipalThreadLocal.setName(getAdminUser().getUserId());
PermissionChecker adminPermissionChecker = PermissionCheckerFactoryUtil.create(getAdminUser());
PermissionThreadLocal.setPermissionChecker(adminPermissionChecker);
MethodKey methodKey = new MethodKey(SitesUtil.class, "updateLayoutSetPrototypesLinks", Group.class, long.class, long.class, boolean.class, boolean.class);
PortalClassInvoker.invoke(false, methodKey, organizationGroup, -1, template.getLayoutSetPrototypeId(), false, true);
LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(organizationGroup.getGroupId(), true);
MethodKey _mergeLayoutSetPrototypeLayoutsMethodKey = new MethodKey(SitesUtil.class, "mergeLayoutSetPrototypeLayouts", Group.class, LayoutSet.class);
PortalClassInvoker.invoke(true, _mergeLayoutSetPrototypeLayoutsMethodKey, organizationGroup, layoutSet);
https://issues.liferay.com/browse/LPS-48987
confirming we are not completely missing something obvious and then later I found a solution overhere:
http://livewithliferay.blogspot.nl/2014/12/create-site-programmatically-in-liferay.html
The following code is now working for me (haven't tested whether setting the threadlocal is really necessary as I'm already logged on as admin when I execute my code)
PrincipalThreadLocal.setName(getAdminUser().getUserId());
PermissionChecker adminPermissionChecker = PermissionCheckerFactoryUtil.create(getAdminUser());
PermissionThreadLocal.setPermissionChecker(adminPermissionChecker);
MethodKey methodKey = new MethodKey(SitesUtil.class, "updateLayoutSetPrototypesLinks", Group.class, long.class, long.class, boolean.class, boolean.class);
PortalClassInvoker.invoke(false, methodKey, organizationGroup, -1, template.getLayoutSetPrototypeId(), false, true);
LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(organizationGroup.getGroupId(), true);
MethodKey _mergeLayoutSetPrototypeLayoutsMethodKey = new MethodKey(SitesUtil.class, "mergeLayoutSetPrototypeLayouts", Group.class, LayoutSet.class);
PortalClassInvoker.invoke(true, _mergeLayoutSetPrototypeLayoutsMethodKey, organizationGroup, layoutSet);
Willem Vermeer, módosítva 8 év-val korábban
RE: "Activating" programatically created organization sites
Junior Member Bejegyzések: 32 Csatlakozás dátuma: 2012.03.30. Legújabb bejegyzések
When logged on as admin the following suffices:
SitesUtil.updateLayoutSetPrototypesLinks(organizationGroup, -1, template.getLayoutSetPrototypeId(), false, true);
LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(organizationGroup.getGroupId(), true);
SitesUtil.mergeLayoutSetPrototypeLayouts(organizationGroup, layoutSet);
SitesUtil.updateLayoutSetPrototypesLinks(organizationGroup, -1, template.getLayoutSetPrototypeId(), false, true);
LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(organizationGroup.getGroupId(), true);
SitesUtil.mergeLayoutSetPrototypeLayouts(organizationGroup, layoutSet);