Liferay: get PortletID and companyID from init() - java

Maybe trough PortletConfig in init(PortletConfig)
The thing is that using
((PortletConfigImpl) portletConfig).getPortletId();
is not allowed anymore because adding portal-impl.jar in package.properties gives throws an exception when trying to execute build ant target, saying that this is not allowed anymore
For companyID I directly have no idea where to start. I am using currently
long companyId = CompanyLocalServiceUtil.getCompanies().get(0).getCompanyId();
but as soon as I got more than one company it will fail
If only I could get Portlet object somehow, I think it would be enough to get both portletId and companyId

I'm not one 100% sure what you need, but if you have just one company, you can use the following code to get the company id:
PortalUtil.getDefaultCompanyId()

Adding portal-impl.jar to plugins has always been a source of problems and has never been the correct way to do. With that I'm quite happy to see that it actually seems to be actively prohibited now by the build scripts. As discussed in this question you should not do this and the portlet API does not support what you want. You strictly don't have the context necessary for knowing which company a portlet instance has been added to.
Keep in mind: There might (and typically is) only one instance of your portlet class ever, no matter if a portlet instance is placed on any page - and independent of how many portlet instances are around in the whole portal, across all companies and sites.
You should not follow this path, instead explain what you're trying to achieve with it. We might help you with that, but cannot help you learning how to implement something that is impossible, or, if you find a loophole, will be unmaintainable and randomly break with the next update because it's far outside the specification.

You can get the Portlet from PortletConfig through the portletId got from the method Portletconfig.getPortletName() and then using PortletLocalServiceUtil.getPortletById(String):
// I have not tried this but I think it should work
String portletName = Portletconfig.getPortletName();
Portlet portlet = PortletLocalServiceUtil.getPortletById(portletName);
long companyId = portlet.getCompanyId();
And then from the Portlet you can easily get the companyId.
A word of caution as stated by Olaf Kock in his answer, hence here is another answer which gives you some alternative to fetch the companyId if you know some aspect of the company. This approach does not fetch the companyId from the portlet instance for the reasons as explained by Olaf Kock.
Try this approach and see if this helps.

Related

Best way of adding id's to html elements in GWT

I'm rather unexperienced in GWT, and I have large codebase with working project in this technology. My task refers to assigning id's to html elements witch will be used in automatic testing. We can't use some dynamically assigned id's because in automatic test we have to specify exact values of id's. My way for now was to use method ensureDebug(id), written by hand in code for specific elements.
I think that doing it this way mean that code will be more spaghetti-like, with mixed ensureDebug(id) methods usages there and here. I was thinking if there is any way of doing it that will be more manageable and cleaner than current. Is is maybe possible to use AOP? (I have never used AOP, so I don't know if it is any good idea, or possible in GWT) Or maybe other way than using ensureDebug?
You also can set the IDs for HTML elements like
element.setId("myId");
But this is as much spaghetti like as your approach adding the IDs in the code.
Another possibility would be to use an UiBinder and set the id there. With this approach you have all your ui elements of one view, which should have an id, at one place. With bootstrap for example it would look like this:
<b:TextBox ui:field="searchTextBox" b:id="search-text-box"/>
Like this you can access the field in your view-class via searchTextBox and the id search-text-boxis added to the HTML element (which you could also use for styling etc.)
We have faced same issue for our project while adding test automation. As per my knowledge unfortunately GWT doesn't support anything like AOP yet. So we have to follow any of the spaghetti-like approach only from one mentioned above by #mxlse or the one you are already following.
Based on my experience I can recommend you to create separate constant/property at client or server end. Use this file to save all your id's which you can share latter on with test team as well.

Configuring ServiceNow through a program

I need a custom definition of ServiceNow for my business. For which, I'll have to configure many tables like Incident, CIs to name a few, then the views, forms etc. I am aware that it can be done through UI provided at our instance. But doing it through a program which can configure our definition on a fresh instance in one go will be a challenge.
But I think it should be possible, to give you a scenario here's what I might be doing..
-- I need to create new views on a table, new fields on that view, adding dependent fields, new choices in the choice list for a choice field and the list goes on...
Is there any way to do it in Java? maybe using JSON Web services provided by ServiceNow?
Or is there any API in java which can simplify the work, like the one for BMC Remedy?
I understand that it is a big task, please let me know if there is any other way to do it.
PS: I am familiar with the JSON web service API available for ServiceNow.
I agree with Joey. It sounds like a vanilla use case for Update Sets.

Is there any other alternative to template specific exclusion of pages from search

I have restricted some pages like admin pages from not getting visible in search results.Using the below code
map.put("group.1_group.1_property","**jcr:content/cq:template**");
map.put("group.1_group.1_property.1_value","**/apps/MyApp/templates/SampleTemplate**");
map.put("group.1_group.1_property.and","true");
map.put("group.1_group.1_property.operation","unequals");
final Query finalQuery = builder.createQuery(PredicateGroup.create(map),
session);
which means it is template specific search filtration,means that Im telling the query builder not to display those pages having the above specified template .However the drawback is that, in future if we want to restrict more pages, those pages also must be mapped to the above template. So instead of specifying the template in the map, can we put any other property in the map, so that search restriction is not template specific.
Thanks,
Balaji
What other properties do your pages have available (specifically, the admin pages)? For example, if you have a specific property that you add to your admin pages, or other pages that you could sort on, that could work. On one site I worked on, we had a property we put into certain content items called hideInNav. So along those lines, this is how I would do it:
map.put("group.1_group.1_property","jcr:content/hideInNav");
map.put("group.1_group.1_property.1_value","/content/somepath/you/want");
map.put("group.1_group.1_property.and","true");
map.put("group.1_group.1_property.operation","unequals");
I hope that helps to make sense of it. Am I understanding it correctly? If not, please clarify and I'll try to help more.
---------------EDIT-----------------------
If you don't have a custom property, but you know the path these pages are located, and maybe a default property they all have in common (like a jcr:title), you could try doing that instead. Like this:
map.put(1_group.0_path","/content/yoursite");
map.put(2_group.0_type","cq:Page");
map.put(3_group.fulltext","test text");
map.put(3_group.fulltext.relPath","jcr:content/#jcr:title");
You can see how this would run on a local query debugger when you have CQ running:
http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&query=http%3A%2F%2Flocalhost%3A4502%2Fcontent%2Fsalesportal%2Fen%2Fmobile%2Fresources.assets.get.json%3Fp.limit%3D7%0D%0A1_group.0_path%3D%2Fcontent%2Fyoursite%0D%0A2_group.0_type%3Dcq%3APage%0D%0A3_group.fulltext%3Dtest+text%0D%0A3_group.fulltext.relPath%3Djcr%3Acontent%2F%40jcr%3Atitle
Hopefully that's more helpful.
EDIT #2
This is a summary of both my answers, and will hopefully answer your last comment as well.
In order to more fully answer your question (since you're still not quite getting what you want), I dug a little deeper to find the information you need. Just as a reference, any time you're doing XPath querying, this is a great tool to look at: JCR Query Usecases - jboss
Anyway, you said that you were getting results that didn't include items that were missing the 'hideInNav' property. Here is how you can get those results, specifically:
map.put("1_group.0_path","/content/yoursite");
map.put("2_group.0_type","cq:Page");
map.put("3_group.1_property","jcr:content/hideInNav");
map.put("3_group.1_property.1_value","not");
map.put("3_group.1_property.operation","not");
This way, you're searching in the path you want, getting the type of result you want (cq:Page, if that is what you're actually looking for), and you're getting the results that DO NOT HAVE the property 'hideInNav'.

Passing session information with WebObjects

My team's lead developer is trying to figure out a way to pass session information in some other way than via the URL when using WebObjects.
Our site was built using web objects, but the problem we're now having is that when bloggers blog about us and post links from our site in their blog posts, the URL typically includes session information it and isn't valid for anyone other than the person who copied the link in the first place, Bloggers trying to point people to www.example-dot-com are instead blogging links such as
www.example-dot-com/cgi-bin/WebObjects/example.woa/wo/0.11.3.8
Anyone have any suggestions? Thanks!
There are a couple of issues here. Firstly, if you want to remove the session ID from the URL (which is the default), you override WOSession.setStoresIDsInCookies() to return true and WOSession.setStoresIDsInURLs() to return false.
However, your example URL doesn't have a session ID, so presumably you've figured that out. There are then a number of ways to get friendlier URLs, the easiest of which is probably to use direct actions. You could then have a URL more like www.example-dot-com/cgi-bin/WebObjects/example.woa/wa/someTarget.
Finally, Project Wonder provides full support for URL re-writing, to the extent that you could have something more like www.example-dot-com/someTarget.

Spring - multiple command class with AbstractWizardFormController

Can i have a AbstractWizardFormController controller with different command class for each page ?
Sounds like a hack to me, but sure --the formBackingObject() method is called for each page, so you can override that method and add code to determine which command object to return (based on which page view is being requested).
On the other hand, that's going to add complications when you handle each pages submission -- will you have to figure out which type of object you're getting and cast? I'd rethink -- maybe this isn't really a wizard-type situation and you should have separate controllers? Or perhaps you should look at Web Flow? My experience is that the Wizard controller is useful if you're using it as envisioned, but when you start trying to squeeze it into a scenario it's not meant for, it becomes more complicated than helpful.

Categories