"InvalidMongoDbApiUsageException: - java

Criteria criteria = new Criteria();
if(StringUtils.isNotEmpty(payeeIdentifier)){
criteria.orOperator(Criteria.where(MAPPING + "." + NPI).is(payeeIdentifier),
Criteria.where(MAPPING + "." + GROUP_NAME).regex(CriteriaBuilder.toRegexAny(payeeIdentifier), CASE_INSENSITIVE),
Criteria.where(MAPPING + "." + PROVIDER_NAME).regex(CriteriaBuilder.toRegexAny(payeeIdentifier), CASE_INSENSITIVE),
Criteria.where(MAPPING + "." + LAST_NAME).regex(CriteriaBuilder.toRegexAny(payeeIdentifier), CASE_INSENSITIVE),
Criteria.where(MAPPING + "." + PROVIDER_FULL_NAME).regex(CriteriaBuilder.toRegexAny(payeeIdentifier), CASE_INSENSITIVE),
Criteria.where(MAPPING + "." + FEIN).is(payeeIdentifier));
}
if(isSNPI){
criteria.orOperator(
Criteria.where(REQUEST_TYPE).is(GROUP).andOperator(Criteria.where(MAPPING + "." + IS_SNPI_ALLOWED).is(true)),
Criteria.where(REQUEST_TYPE).ne(GROUP)
);
}
final Query query = new Query();
query.addCriteria(criteria);
If payeeIdentifier contains identifying data and isSNPI is also true getting this exception :
"InvalidMongoDbApiUsageException: Due to limitations of the com.mongodb.BasicDocument, you can't add a second '$or' expression specified as '$or : [Document{{requestType=group, $and=[Document{{mapping.isSNPIAllowed=true}}]}}, Document{{requestType=Document{{$ne=group}}}}]'. Criteria already contains '$or : [Document{{mapping.npi=g3}}, Document{{mapping.groupName=.\Qg3\E.}}, Document{{mapping.providerName=.\Qg3\E.}}, Document{{mapping.lastName=.\Qg3\E.}}, Document{{mapping.providerFullName=.\Qg3\E.}}, Document{{mapping.fein=g3}}]'."
}

Related

Unable to get value from redis using webflux

Currently I am storing some value in redis
And when I try to get the value I am getting MonoNext
This is the code
redisOps.opsForValue().set(sId + "_" + cId + "_" + sufix, true);
Mono<String> data = redisOps.opsForValue().get(sId + "_" + cId + "_" + sufix);
I am expecting it to be of Mono<String>.
Is there something wrong here?

How to print the tokens like with "-tokens" in the terminal?

In the terminal (or console), I can just do grun Exp eval -tokens, but how do I do that from Java? I found that, that do like -tree:
ParseTree tree = parser.eval();
System.out.println(tree.toStringTree(parser));
But I can't find anything similar for -tokens.
Edit 1: I found something with lexer.reset():
lexer.reset();
for (Token token: lexer.getAllTokens()) {
System.out.println(token);
}
But the token are only numbers like <4>, I would like to get the real name from it.
Edit 2: I got it:
Vocabulary vocabulary = lexer.getVocabulary();
lexer.reset();
for (Token token: lexer.getAllTokens()) {
System.out.println(token.getLine() + ":" + token.getCharPositionInLine() + " '" + token.getText() + "' " + vocabulary.getSymbolicName(token.getType()));
}
This isn't the exact same thing but the main infos still!
The answer is:
Vocabulary vocabulary = lexer.getVocabulary();
lexer.reset();
for (Token token: lexer.getAllTokens()) {
System.out.println(token.getLine() + ":" + token.getCharPositionInLine() + " '" + token.getText() + "' " + vocabulary.getSymbolicName(token.getType()));
}

Intellij toString multiline

When auto-generating the toString method in IntelliJ it is putting all text onto a single line. Some of these lines are massive - how can I get Intellij to split the toString onto multi lines, after each new variable?
This is what I have:
#Override
public String toString() {
return "Address{" + " line1='" + line1 + '\'' + ", line2='" + line2 + '\'' + ", town='" + town + '\'' + ", county='" + county + '\'' + ", postcode='" + postcode + '\'' + ", country='" + country + '\'' + '}';
}
And this is what I want:
#Override
public String toString() {
return "Address{"
+ " line1='" + line1 + '\''
+ ", line2='" + line2 + '\''
+ ", town='" + town + '\''
+ ", county='" + county + '\''
+ ", postcode='" + postcode + '\''
+ ", country='" + country + '\'' + '}';
}
I have tried creating a custom template but it just seems to ignore this.
IntelliJ's String concat (+) template produces output ~identical to the desired output shown in your question.
To engage this template ...
Code > Generate > toString
Choose Template: String concat (+)
If you need to tweak this template then click on Settings and choose the Templates tab and copy and create a copy of whichever existing template is closest to your needs, edit this copy and then it will appear in the Template dropdown for selection.
Here's a screenshot:
If - after using this template - the output is in a single long line then it's possible that your chosen Java code formatter is reformatting the output produced by the toString template.

Using JSON data as a String object in Java

I am using HTTP Client to send different kinds of requests (GET, PUT, POST, DELETE) where I am sending the JSON as a data to post with different requests.
I have a JSON data like:
{ "createdByID": "100000", "createdByName": "Admin", "modifiedByID": "100000", "modifiedByName": "Admin" }
Now, to store this JSON into a string, I have to add double quotes wherever necessary so that this can be stored as
String jsonData = "{" + "\"" + "createdByID" + "\"" + ":" + "\"" + "100000" + "\"" + "," + "\"" + "createdByName" + "\"" + ":" + "\"" + "Admin" + "\"" + "," + "\"" + "modifiedByID" + "\"" + ":" + "\"" + "100000" + "\"" + "," + "\"" + "modifiedByName" + "\"" + ":" + "\"" + "Admin" + "\"" + "}"
Does anyone use any tool/utility to convert the JSON data such that it can be stored in a string object?
Please share if anyone has already done this
Hey if you store the json as a sting in your code then only you need to add double codes.
Try to read json from a text file , then you don't need to add double quotes and other stuffs.
More over java does not consider double quotes after compiling your code.

criteria query is not getting data when adding or condition

I have a Java file that query data and I'm trying to add a filtering function. By using criteria builder and criteria query, I manage to get data that I want to filter.
As starter, this is the column to display my data:
Name Host
Fikrie ubuntu
Fikrie2 unix
Fikrie3 ulalala
Fikrie4 ugagaga
There are 3 variable used here. The Name column, is displaying data from name. For the Host column, it is a bit tricky. It will display the hostname, but if there is a logAsHost display, this data will overwrite the hostname.
So this is how my data really look like:
Name Host
Fikrie ubuntu <-- hostname = 1, logAsHost = ubuntu
Fikrie2 unix <-- hostname = 123, logAsHost = unix
Fikrie3 ulala <-- hostname = ulala, logAsHost = no value
Fikrie4 ugaga <-- hostname = ugaga, logAsHost = no value
When I try to filter just 1 variable, I manage to do so. (Eg. filter by Name). When I try to filter out 2 variable, then a problem happen. I didnt manage to get any data.
This is the code that I use:
public List<Connection> retrieveAll(String nameFilter, String hostFilter,
int start, int length) {
ServiceUtil.requireAdmin();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Connection> q = cb.createQuery(Connection.class);
Root<Connection> c = q.from(Connection.class);
q.select(c);
logger.info("nameFilter = [" + nameFilter + "]");
logger.info("hostFilter = [" + hostFilter + "]");
//This is the line that I use to query data.
//when I replace Connection_.hostname with Connection_.logAsHost, or Connection_.name
//It works just fine. So I use either one of these line to query.
//q.where(cb.like(c.get(Connection_.hostname), "%" + hostFilter + "%"));
//q.where(cb.like(c.get(Connection_.logAsHost), "%" + hostFilter + "%"));
//q.where(cb.like(c.get(Connection_.name), "%" + nameFilter + "%"));
//This is the problem part.
//When I add cb.or, it cannot get any data.
//From the documentation, it should just be q.where(cb.or(A, B))
//Where A is the first expression and B is the second.
// I have confirm both the expression are working by calling it separately
q.where(cb.or(cb.like(c.get(Connection_.hostname), "%" + hostFilter + "%")), cb.like(c.get(Connection_.logAsHost), "%" + hostFilter + "%"));
List<Connection> results = em.createQuery(q).setFirstResult(start)
.setMaxResults(length).getResultList();
for (Connection conn : results) {
logger.info("Name=" + conn.getName() + ", hostname=["
+ conn.getHostname() + "]" + ", logAsHost =["
+ conn.getLogAsHost() + "]");
}
return results;
}
This the log to show that the data is available or not:
I used c.get(Connection_.hostname), and passed u to hostFilter,
INFO nameFilter = []
INFO hostFilter = [u]
INFO Name=fikrie3, hostname=[ulala], logAsHost =[]
INFO Name=testt, hostname=[ugaga], logAsHost =[]
I used c.get(Connection_.logAsHost), and passed u to hostFilter,
INFO nameFilter = []
INFO hostFilter = [u]
INFO Name=fikrie, hostname=[192.168.56.90], logAsHost =[ubuntu]
INFO Name=fikrie2, hostname=[192.168.56.90], logAsHost =[unix]
I combine both and passed u to hostFilter,
INFO nameFilter = []
INFO hostFilter = [u]
I'm assuming the cb.or() is causing this error. If so, how do I use OR condition properly in criteriaquery? I'm following this part
or(Expression<java.lang.Boolean> x, Expression<java.lang.Boolean> y) from the documentation.
For me it looks like only a problem with your parenthesis. Your predicates are not parameter to the or method
you have
q.where(
cb.or(
cb.like(c.get(Connection_.hostname), "%" + hostFilter + "%")
),
cb.like(c.get(Connection_.logAsHost), "%" + hostFilter + "%")
);
Which lead to an AND of both predicates.
It should rather be
q.where(
cb.or(
cb.like(c.get(Connection_.hostname), "%" + hostFilter + "%"),
cb.like(c.get(Connection_.logAsHost), "%" + hostFilter + "%")
)
);

Categories