can we map multiple annoter to props.setProperty("tokensregex.matchedExpressionsAnnotationKey",com.demo.UcpAnnoter$CreditAvailableByAnnotation"); - stanford-nlp

Can we mapped two/multiple annotation to tokensregex.matchedExpressionsAnnotationKey
Sample code:
props.setProperty("tokensregex.matchedExpressionsAnnotationKey","com.demo.SampleAnnoter$MyMatchedExpressionAnnotation");

No you can only provide one class for that field.

Related

Is is possible to get multiple pojo class with different fields using one #postmapping in one controller class

I have 3 POJO classes with different fields and three repositories related to that POJO classes and I have one controller class that has one #postmapping. so can I get those three pooja classes field by using one postmapping. Is this possible?
You can return a map of string and Object. String will be
simpleClassName and value will be your pojos. Think that is the simplest solution.

How to Use sorting in Spring Data Rest GET method

When I create any repository in spring framework like following it gives method by default to get all records of the entity using this API
GET : http://localhost:3000/api/addresses
It sends data from ascending order But If I want my data in descending order than How can I specify this ?
Address Repository
public interface AddressRepository extends JpaRepository<Address, Long>
{
}
Perhaps,you can :
localhost:3000/api/addresses?sort={property},desc
this will help you sort by property desc
You can also specify this as part of your request, take a look at documentation here Sorting.
Also please take a look at similar answer here.
Try inside the AddressRepository class something like:
public List<Address> findAllByOrderByIdDesc();
of course you can change the "ById" part with any other field you want to use for sorting.

Assign ArrayList from the data in propeties file

this is my property file.
REDCA_IF_00001=com.sds.redca.biz.svc.RedCAIF00001SVC
REDCA_IF_00002=com.sds.redca.biz.svc.RedCAIF00002SVC
REDCA_IF_00003=com.sds.redca.biz.svc.RedCAIF00003SVC
REDCA_IF_00004=com.sds.redca.biz.svc.RedCAIF00004SVC
and I want to these values into hashmap in my spring context file.
How can I achieve this?
Does it have to be a HashMap or any kind of Map would be fine?
Because you can define that as a java.util.Properties instance (Spring has great support for properties loading), which already implements Map (it actually extends from Hashtable).

How can I use a CustomConverter with Dozer to convert multiple entities into one entity with a list field?

I have a list of entities which in turn have a field of another (Embeddable) type.
All these entities shall be converted into a single bean which holds a list of these embeddable types.
Prior to using Dozer I have written a conversion method. I have put this into the dozerBeanMapping.xml:
<custom-converters>
<converter type="com.foo.bar.helper.ChargingPoiEntityToPoiConverter" >
<class-a>com.foo.bar.services.charging.repository.ChargingPoiEntity</class-a>
<class-b>com.foo.bar.beans.ChargingPoi</class-b>
</converter>
</custom-converters>
I instantiate Dozer this way:
final Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();
Which map method do I have to invoke?
Using
mapper.map(cpEntities, Cp.class);
my custom converter is not invoked.
Trying to invoke
mapper.map(cpEntities.get(0), Cp.class);
works well, but I have to convert a List<ChargingPoiEntity> instead of a single ChargingPoiEntity.
how can I achieve this?
mapper.map(cpEntities, Cp.class); is not matching your custom converter because the generic type information in List<ChargingPoiEntity> is lost. Dozer sees the class of cpEntities as java.util.ArrayList, which does not match com.foo.bar.services.charging.repository.ChargingPoiEntity. My understanding is that this is a limitation of Java generics, not an issue in Dozer.
One workaround is to define a custom converter between a ChargingPoiEntity array and a ChargingPoi:
<custom-converters>
<converter type="com.foo.bar.helper.ChargingPoiEntityToPoiConverter" >
<class-a>[Lcom.foo.bar.services.charging.repository.ChargingPoiEntity;</class-a>
<class-b>com.foo.bar.beans.ChargingPoi</class-b>
</converter>
</custom-converters>
When mapping, you can convert the cpEntities list to an array:
ChargingPoiEntity[] entityArray = cpEntities.toArray(
new ChargingPoiEntity[cpEntities.size()]);
ChargingPoi convertedList = mapper.map(entityArray, ChargingPoi.class);
Note that in this case, the custom converter will not be invoked when you do
mapper.map(cpEntities.get(0), ChargingPoi.class);
This problem should only apply when attempting to map generic collections directly via mapper.map(...); entities containing generic collections as fields should map fine.

Spring Data Neo4j - Indexing and Inheritance

Lets say i have the following data model:
public class A {
#Indexed(indexType = IndexType.FULLTEXT, indexName = "property1")
String property1;
}
public class B extends A {
#Indexed(indexType = IndexType.FULLTEXT, indexName = "property2")
String property2;
}
Can i tell the Spring framework to index property1 of class B under a different index name?
If not, what would you do in such case? I mean, what would you do if you have few classes that all extends the same base class, but in the same time, all the properties that those classes inherit form the base class should be indexed. I can annotate those properties for indexing only in the base class, and it is very limiting. What can i do?
Thanks.
The level attribute in the index definition annotation can be set to Level.INSTANCE. For more help please refer spring-data-neo4j documentation here
Here is an excerpt from the doc :
If a field is declared in a superclass but different indexes for
subclasses are needed, the level attribute declares what will be used
as index. Level.CLASS uses the class where the field was declared and
Level.INSTANCE uses the class that is provided or of the actual entity
instance.
I don't think that's possible. Your property1 will always be indexed in index property1. Being able to specify multiple indexes on a single field would probably fix your issue, but it's currently not possible. A while ago, I've raised an issue for this, but it's not yet implemented.
If you really want a domain (entity) object approach, you could also opt for the domain entity approach. It's not related to Spring or Spring Data Neo4j, but it also does the trick. By manually handling your entities this way, you could also manage the indexes yourself, thus gaining all the flexibility you want.
Just a question, why would you want to specify a different index per subclass?

Resources