i18n in jHipster entities - jhipster

I am creating a blog like application using jHipster and want to support i18n in 2 languages (English and Chinese). The jHipster page on this (https://jhipster.github.io/installing-new-languages/) explains i18n on UI elements only.
But how to provide i18n support for values of entities? In this case I want Articles entity of blog to be in two languages.
One of the workaround would be to get the values in both languages from the user into separate entity fields and display accordingly. Is it a right approach?

JHipster does not provide any helper for content localization. This must be done at JPA/Hibernate level.
You can have a field per language or an entity per language where Article would have a one-to-many relationship with LocalizedArticle that would contain all localized fields using a Map<String, LocalizedArticle> using locale as map key.
There are other options which are presented in this good article.

Related

Indexing dynamic fields in azure search

I have used solr search engine which has a feature of dynamic fields. For example , if we define product_* field in the schema.xml, it will accept all the fields starting with product_ during the indexing.
Is there a feature like this in azure search where we can just define a wildcard for a field and it can accept the related fields in the indexing? As the fixed field thing reduces flexibility and one has to define a new schema every time for adding new fields.
Azure Cognitive Search does not support dynamic fields. Adding fields to the schema as you detect them during indexing is the suggested workaround.
Please consider creating an item on our User Voice page for this. While we haven't considered adding support for dynamic fields specifically, we have been looking at making schemas more flexible and extensible, and your input could help us prioritize this.

provide Custom Entities to Google NLP engine

I want the Google NLP engine to be able to recognize custom entities.
I have a company called Hint and I want it to tag it as an organization.
'I like hint'
or
'I like Hint'
does not tag Hint as a organization. It tags Hint as "Other" entity type.
Is there some key word to provide to Google NLP so I can talk to it. For example can I pre process my text such as
I like %CUSTOM_ENTITY%
We don't currently have a mechanism for adding custom entities.
I'd be interested to learn more about what you'd like to do. How many entities would you like to put in? What kinds of information would you like to include? Are you thinking of a list of entity names and types?

MVC 5 ViewBag security

I am coding an MVC internet application, and I have a question in regards to using the ViewBag.
In many of my controllers, I have SelectList objects, where the user can select an object. The object that is selected is a foreign key value for my model.
My question is this: Should I use ViewBag for this? How secure is the ViewBag? Should I use values in my ViewModel instead of the ViewBag?
Thanks in advance.
Use your view model.
When the ViewBag was implemented (MVC 3) dynamic typing was new (.NET 4.0) and it was put in just as a side-option to ViewData or to quickly generate a view without the need for additional classes.
Any serious MVC project will take advantage of a model/viewmodel with a strongly typed view.
There are no security concerns with either because both essentially only exist through the controllers lifespan.
There are no security concerns with ViewBag since it is disposed once rendered in the View.
I think the answer really should be "it depends". For example, if you have 6 collections required to populate dropdown lists aand you want to get the data posted back, you should definitely use a ViewModel for this. Since 6 collections will be hard to manage if they are stuffed in ViewBag with no strong typing in the view, especially if another developer comes along later needing to do maintenance to the view.
Generically everything should be done inside a view model. That's what a view model is. A class that you specifically define to meet the requirements of your view. Here is an image depecting when to Use TempData, ViewBag or ViewData

Can you explain Service-builder concept?

It's easier to generate tables and default classes with liferay's service builder.
But it is bit difficult for me to understand the hierarchy of classes generated by it.
Also the exact use of each class other than modifying LocalServiceImpl class as per our need by adding our own functionality.
I have gone through Service Builder doc. So I got some basic knowledge but would like to get more on this.
Even the link "Liferay Service Builder" was useful but outdated with current Liferay version. So Does anyone have update on above link or nice info explaining hierarchy with example/diagram?.
Any help is appreciated.
Thanks.
To implement the foreign key concept in liferay, you have to apply your own coding logic since the implementation of FK are not available in service builder. So I guess you need to put some code.
Read some forums related to service builder on liferay website. It will give you better exposure.
Read Liferay In Action. It is a good book
Here is What I obeserved In Liferay 6.1.
com.liferay.portlet.p_name.model:
This has interfaces and classes related to (table entity related to) this portlet.
For example com.liferay.portlet.announcements.model will have
Interfaces:
AnnouncementsEntry
AnnouncementsEntryModel
AnnouncementsDelivery
AnnouncementsDeliveryModel
AnnouncementsFlag
AnnouncementsFlagModel
Classes:
And In classes section, You will find wrapper classes and soap classes for each entity like:
AnnouncementEntryWrapper
AnnouncementEntrySoap
AnnouncementFlagWrapper
AnnouncementFlagSoap
AnnouncementDeliveryWrapper
AnnouncementDeliverySoap
Also for few Entity, you will find Classes for Constant entries like
AnnouncementsEntryConstants, AnnouncementsFlagConstants etc.
com.liferay.portlet.p_name.service:
This has classes and interfaces related to (table entity related to) this portlet.
For example com.liferay.portlet.announcements.service will have
Interfaces:
AnnouncementsEntryService
AnnouncementsEntryLocalService
AnnouncementsDeliveryService
AnnouncementsDeliveryLocalService
AnnouncementsFlagService
AnnouncementsFlagLocalService
Classes:
And In classes section you will have Util and Wrapper classes.
AnnouncementsEntryServiceUtil
AnnouncementsEntryServiceWrapper
AnnouncementsEntryLocalServiceUtil
AnnouncementsEntryLocalServiceWrapper
and so on.....
So In short following is the structure I observed in Liferay
[In Model, I:+Model,(ModelName), C:Soap, Wrapper and Constants]
[In Service, I:Service,LocalService ; C:ServiceUtil,ServiceWrapper,LocalServiceUtil and LocalServiceWrapper]
[In Persistence, I:Finder(BlogsEntryFinder),Persistence(BlogsEntryPersistence); C:Util(BlogsEntryUtil, BlogsEntryFinderUtil)]
Note:
I --> Interface
C --> Class

What about link tables in domain-driven-design?

In the book .NET Domain-Driven Design with C# from Tim McCarthy there's an example of a link table (two foreign keys + one boolean column) that gets it's own class in the domain. Is this common?
The example is a Contact table and a Project table. The link table is a ProjectContact. What are the pros and cons of using a class ProjectContact instead of having a List of Contacts property in the Project class and a List of Projects property in the Contact class?
I must say that having a ProjectContact class makes it easy to persist a new link between a Project and a Contact... but it seems overkill to me.
Pragmatically spoken (I'm not a DDD expert), I would say that a link table shouldn't pop up in the domain unless it is an entity on it's own (i.e. you need to attach behaviour to it, or it has properties other than the foreign keys).

Resources