how to get a search box using jhipster:import-jdl? - java

Lets say that we have a book and author entities in JDL-Studio like this:
entity Book {
name String required minlength(2)
}
entity Author {
name String required minlength(2)
}
relationship ManyToMany {
Book{author(name)} to Author{book}
}
When we run the show, we can login and create a new book, but we need to choose between the list of authors in the dropdown list that we have already created in the author entity, right?
How can we do this 2 things using jhipster:import-jdl:
1) tell Jhipster-JDL to create a search box to look in a list of authors (let's say we have a 1000 author entries) and
2) have a text box where we can add a new text creating a new author entry in the database (or think about a tag for the book: adventures, science-fiction,... but not using the already created from the list).
Is it posible to do that when creating de JDL-Studio Entities? Is there any place with more advanced use cases besides https://www.jhipster.tech/jdl/
Would it be possible with jhipster-uml? Is UML, more powerful? https://www.jhipster.tech/jhipster-uml/

Related

How to compare below tokenized text useing open NLP with Database column values?

In my java web application (Jsp + Servlet + hibernate) users can request books. The request goes to the database as a text. After that I tokenize the text using Apache Open NLP. Then I need to compare these tokenized text with books table (the books table has book ID , Book Name , Author , Description) and give most related suggestions to the user. Mostly I need to compare this with book name column and book description column. Is this possible?
import opennlp.tools.tokenize.SimpleTokenizer;
public class SimpleTokenizerExample {
public static void main(String args[]){
String sentence = "Hello Guys , I like to read horror stories. If you have any horror story books please share with us. Also my favorite author is Stephen King";
//Instantiating SimpleTokenizer class
SimpleTokenizer simpleTokenizer = SimpleTokenizer.INSTANCE;
//Tokenizing the given sentence
String tokens[] = simpleTokenizer.tokenize(sentence);
//Printing the tokens
for(String token : tokens) {
System.out.println(token);
}
}
}
Apache OpenNLP can do Natural Language Processing, but the task you describe is Information Retrieval. Take a look at http://lucene.apache.org/solr/.
If you really need to use DB only, you can try to make a query for each token using the LIKE sql keyword:
SELECT DISTINCT FROM mytable WHERE token IN description;
and rank the lines with higher match.
How OpenNLP can help you?
You can use the OpenNLP Stemmer. In that case you can get the stem of the book description and title before adding it to the columns to the database. You also need to stem the query. This will help you with inflections: "car" will match "cars", "car".
You can accomplish the same with the OpenNLP Lemmatizer, but you need a trained model, which is not available today for that module.
just to add to what #wcolen says, some out of the box stemmers exist for various languages in Lucene as well.
Another thing OpenNLP could help with is recognizing book authors names (e.g. Stephen King) via the NameFinderTool so that you could adjust the query so that your code creates a phrase query for such entities instead of a plain keyword based query (with the result that you won't get results containing Stephen or King but only results containing Stephen King).

Java - (JSON) What is this called?

Guide I'm working with: http://crunchify.com/how-to-write-json-object-to-file-in-java/
I've currently created an application which downloads a big JSON file and parses the data which list items into it, but unfortunately all items are named as it's ID so basically it means that I have to fetch all of the item ID's from separate files, because their JSON doesn't support querying a many items once i.e "item=1983,1093,984,2847" so I have do it for EVERY item individually.
That means I have to make many query connections to remote service in order to find names of up to 35,000 items which isn't very good choice since my query limit will reach to maximum in a seconds.
I want to create a custom JSON file that the item ids and names are fetched into it so it won't use anyone's bandwidth in order to gain item name.
So I'm thinking about 2D array, it's like [int][int] so what is this called for and how do I make my Java JSON (json-simple-1.1.1) understand that the item id will be the (object?) and rest info that relates to that id will be (key?)
{
"1094" // Item ID
{
"name": "item name",
"info": "item info"
}
}
In PHP there was something similar like this:
foreach($whatever as $something => $key) {
}
Item ID must be the identifier that I can parse rest of the details from it.
Edit: So "item id" should be JSONArray which is placed to object so I can add "keys" to it? I'm not sure about the terms.

Object modification inconsistency on Play framework 2.2.X

Here's the deal:
public static List<Survey> getFilteredSurveys(Municipality municipality, Company company) {
String sql = "SELECT DISTINCT id FROM survey INNER JOIN " +
"(SELECT SURVEY_ID FROM publicity INNER JOIN brand "+
"ON publicity.brand_id=brand.id WHERE brand.company_id="+company.getId()+") "+
"ON survey_id=survey.id WHERE survey.municipality_id="+municipality.getId();
RawSql rawSql = RawSqlBuilder.parse(sql).create();
List<Survey> surveys = Ebean.find(Survey.class).setRawSql(rawSql).findList();
for (Survey survey : surveys) {
List<Publicity> publicities = new ArrayList<>();
for (Publicity publicity : survey.publicities) {
if(publicity.getBrand().getCompany() == company){
publicities.add(publicity);
}
}
survey.setPublicities(publicities);
}
return surveys;
}
This app is meant for measuring Publicities in a given place,
So people upload a 'Survey' of a place containing all the 'Publicity' that place has.
That function is supposed to return a List,
Each Survey has a List,
And each Publicity has a Brand, which is associated to a Company (ex. Coke -> Coca Cola Co.)
What I'm trying to do is this:
Given a Company, show all the surveys that contain a 'Coca Cola Co.' publicity, but showing only the publicities that belong to 'Coca Cola Co.'
I have a 'Surveys' controller which receives a form with a Municipality and a Company, calls this method, and it renders a view with its result.
This is part of the view template:
#(surveys: java.util.List[Survey])
#for(survey <- surveys){
#for(publicity <- survey.getPublicities){
<tr>
<td>#publicity.getBrand.getName</td>
<td>#publicity.getType.getName</td>
<td>#publicity.getSquareMeters</td>
</tr>
}
}
Problem: even though I removed some publicities from each Survey, all the publicities show up in the view. Why is this happening?
I know I'm not persisting the changes, and I don't want to, I just want to temporarily obfuscate the data so the user only sees the publicities that belong to a given company.
Why isn't this view using the surveys as they are given to it, modified?
Actually I'll put this in an answer ...
You should look at the SQL executed in the log (because I suspect you are getting N+1) here and you could fairly easily avoid that.
You should probably look to change your raw sql to include the publicities columns in the select clause (name, type, squareMeters) to avoid the extra queries.
Alternatively you could add fetch("publicities") to the query (so that they are fetched eagerly via a query join 100 at a time).
Also refer to:
https://github.com/ebean-orm/avaje-ebeanorm/issues/223
... RawSql that includes a OneToMany not working
https://github.com/ebean-orm/avaje-ebeanorm/issues/224
... Enhancement adding RawSqlBuilder.tableAliasMapping()
Ideally you'd be able to use 4.5.2 and take advantage of that fix and that enhancement.
So, I found a fix,
My fix was:
for (Survey survey : surveys) {
survey.getAddress(); //This line fixes the issue
List<Publicity> publicities = new ArrayList<>();
for (Publicity publicity : survey.publicities) {
if(publicity.getBrand().getCompany() != null){
if(publicity.getBrand().getCompany().getId().equals(company.getId())){
publicities.add(publicity);
}
}
}
survey.setPublicities(publicities);
}
My guess is that the problem resides in the way ebean lazily instantiates objects, despite setting Publicities to FetchType.EAGER, and the fact that the output from this function was the expected one, also inspecting surveys in the controller seemed to be ok, and also a #println(surveys) in the view showed only the publicities corresponding to the company I had selected.

Lotus getting field from database

I am new to lotus. I need to get some info from Lotus database with Java. I have database:
Session session = NotesFactory.createSession(host, user, pwd);
Database database = session.getDatabase(server, database);
I have that info:
field - fldContractorCode;
form - form="formAgreement";
For example field is "abcde";
So how I can get info from that database? I need to use seatch formula? Or what methods I need to use? Thanx for help.
UPD
Now I am using such way:
DocumentCollection collection = DATABASE.search("form=\"formAgreement\"");
Document doc = collection.getFirstDocument();
while(doc != null) {
doc.getItemValueString("fldContractorCode");
doc = collection.getNextDocument();
}
And it works fine for me, but I think that way is not very comfortable because to find some document for example with field="abcd" I need to itearte over collection every time...
So that why I am asking for some way to find document by the field value. And I dont understand what is VIEW in database and where to get this VIEW name.
In your existing code, you can just change one line:
DocumentCollection collection = DATABASE.search("form=\"formAgreement\ & "fldContractorCode=\"abcd\"");
However, this will be slow if the database contains many documents. For best performance, you should consider using Domino Designer to add a new view to your database and using the getDocumentByKey() method suggested in the other answers. If that is not an option, Simon's suggestion of using the FTSearch() method is faster than the Search() method, but only if a full text index exists for the database. It also has a slightly different syntax for the search string.
There are a number of ways to get the document.
1. Search for the document from a view, where the first column of the view contains a sorted value of the fldContractorCode.
For example:
String key = "abide";
View view = db.getView("viewName");
Document doc = view.getDocumentByKey(key, true);
2. You can use the Database FTSearch Method to do a full text search to find the document. You will need the database to have a full text index created.
3. If you know the UNID or notes ID of the document you can use getDocumentByUNID() or getDocumentByID().
Your question is quite broad, so I recommend reading the Infocenter as it details sample code for each method.
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.designer.domino.main.doc/H_NOTESDATABASE_CLASS_JAVA.html
You will have to drill down to the DOCUMENT (not Form) you want to retrieve the field from.
Lotus Notes has a very easy to understand hierarchical way to get to where you want. You will need to instantiate objects in this sequence:
Session
Database
View
Document
Let's say you have a view called $(sysAgreements) that list all forms "formAgreement".
Its selection formula would be something like this:
SELECT Form="formAgreement"
To get to the document or documents you want you will do something like this:
Session session = NotesFactory.createSession(host, user, pwd);
Database database = session.getDatabase(server, database);
View view = database.getView("$(sysAgreements)");
Document doc = view.getDocumentByKey(VIEW_KEY);
String fieldContent = doc.getItemValueString("fldContractorCode");
There are several ways to retrieve info from a Notes database. This is one of them. Bear in mind that they key used by Notes to search a view with getDocumentByKey is the 1st sorted column.
If you want to get multiple documents you can use:
DocumentCollection docCol = view.getAllDocumentsByKey(VIEW_KEY);
and then iterate over it.
Avoid doing ftsearch because it's slow and a bit painful to Notes. Prefere looking up in the views.
Also another powerful source of help is the Notes help. Get the help database from a computer that has the Notes Development Client installed. But pay attention to the name of the help you're picking, there are 3 helps in Notes: the client, development and administration. Development is what you want.

Dynamic Textfields in Struts2

All -
New to struts2 here.. I've been reading some tutorials, and even picked up a book so I understand some, but please forgive me if I use the wrong terms.
I'm looking for an example or an explanation on how to create a dynamic list of text fields based on a collection, have the user enter some input and then assign that input back to the object.
Example:
I have a dynamic set of products, I'd like to be able to display a table of product names and textfields where the user can enter a price for that product.
Product1 ....... [ textfield_price1 ]
Product2 ....... [ textfield_price2 ]
...
ProductN
[submit_button ]
How do I then map those textfield values back to each product, most of the examples I have seen are standard forms with static information.
Can anyone point me to the right place ?
Thanks in advance.
Typically you'd use map-based syntax, usually with an ID as the key, and a domain object as the value. This is covered in the type conversion docs.
Nutshell: the action has a map of { ID => Product } for the form data:
public Map<Long, Product> getProductMap() { ... }
// and setter, and private property
Use [] in the JSP with an ID as thename` attribute value:
<s:textfield name="productMap[%{id}]" ... />
You could iterate over a collection of products, a pre-filled map, etc.

Categories

Resources