I am writing some JUnits for my hibernate search implementation.
I use a HSSQL in memory database. I use DBUnit to populate this DB (an XML file). It definitely works as other non-search tests work with the same data. The search code definitely works as I've tried it in the web-app and it returns the correct records.
I assume that Hibernate Search will only index database entries that have been inserted using Hibernate. I tried to index the db manually using : -
fullTextEntityManager.createIndexer().startAndWait();
I have put this in a bean that runs after Spring initialises
public class SearchIndexer {
#Autowired
private EntityManagerFactory entityManagerFactory;
public SearchIndexer(){
}
#PostConstruct
public void doIndexing(){
EntityManager em = entityManagerFactory.createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
try {
fullTextEntityManager.createIndexer().startAndWait();
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
I also Autowired it into my JUnit class and ran the doIndexing method manually (to be sure it was being picked up correctly AFTER the data was loaded).
#Before
public void setup() throws Exception{
dbUnitAdapter.setup("ClubDaoTest.xml");
searchIndexer.doIndexing();
super.before();
}
The dbUnitAdapter simply takes an XML file and inserts it in the db using DBUnit.
The entity is annotated like so: -
#Field
private String name;
#NotBlank
private String type;
#Field
private String address1;
#Field
private String county;
#Field
private String address2;
#Field
private String town;
#Field
private String country;
#Field
private String postcode;
private String telephone;
private String mobile;
private String fax;
#Field
private String email;
#Field
#NumericField
private long lft;
#Field
#NumericField
private long rgt;
I tried also tried inserting the data using hibernate (creating a Club entity), this didn't work either confusingly. I changed the the search index location from RAM to filesystem and used luke to read it. I could see the data that I'd tried inserting using hibernate, but no other data that I could see, although it was my first time using Luke, so I may have made a mistake.
Related
So I'm trying to fix Fortify Vulnerability Issue for content-sniffing, and this needs to use StringEscapeUtils.escapeHtml4 for all attributes of the DTO.
My problem is that the DTO is not a simple object, but rather having nested objects as its attributes:
Root DTO:
public class ServiceOrderListDTO implements Serializable {
private String count;
private String next;
private String previous;
private List<ServiceOrderDetailDTO> results;
}
public class ServiceOrderDetailDTO implements Serializable {
private static final long serialVersionUID = -819641011600662396L;
#JsonProperty("order_code")
private String orderCode;
#JsonProperty("service_number")
private String serviceNumber;
#JsonProperty("customer_name")
private String customerName;
#JsonProperty("customer_brn")
private String customerBrn;
private CustomerDTO[] customer;
#JsonProperty("order_details")
private OrderDetailsDTO orderDetails;
#JsonProperty("site_a_address")
private String siteAAddress;
#JsonProperty("site_b_address")
private String siteBAddress;
#JsonProperty("dff_service_order_id")
private String dffServiceOrderID;
#JsonProperty("dff_response")
private DffResponse dffResponse;
private MilestonesDTO milestones;
private AppointmentsDTO appointments;
}
So I need to Iterate through all the child objects and apply the escapehtml4 function one by one.
However I got feedback that this may lead to performance issue. Is there a way that the escapeHtml4 be applied in the DTO as a whole?
I've been going through SO also but no viable solution so far.
Cross-Site Scripting/Content Sniffing vulnerability detected through static scan for API while returning response
In the spring boot application let the entity is as follows
public class Employee{
private String location;
private String name;
private String lastName;
}
In my service, I am using #Cachable to find all
#Cacheable(value="employees")
public List<Employee> findAll() {
return employeeDAO.findAll();
}
How search from the cache using
findAllByLocationEqualsAndNameEquals(String location, String name)
without making a DB call?Please suggest.
I use Spring Boot and I'd like to save these objects in redis:
#RedisHash("Myobj")
public class Trace implements Serializable {
#Id
#JsonProperty
private final String id;
#JsonProperty
private final TraceType type;
#JsonProperty
private final String clientId;
#JsonProperty
private final String topicId;
#JsonProperty
private final String url;
#JsonProperty
private final String payload;
#JsonProperty
private final Date date;
How can I store these objects and later get some values using the following query:
get all objects for the particular clientId from date date1 to date2.
I use
#Repository
public interface TraceRepository extends CrudRepository<Trace, String> {
to save data this way:
traceRepository.save(trace);
THANK YOU VERY MUCH IN ADVANCE! It's very important for me. Thank you.
I started using spring data redis in my project for temporary storing some data. Redis is new for me, I've never worked something similar to redis before (Key-Value).
So, traditionally I created repository via extending CrudRepository and my #RedisHash is:
#Data
#NoArgsConstructor
#AllArgsConstructor
#RedisHash(value = "employee", timeToLive = 100)
public class RedisEmployee implements Serializable {
#Id
private String id;
#Indexed
private Long employeeId;
private String fullName;
#Indexed
private String date;
#Indexed
private String companyName;
private String phone;
}
So it works fine but I noticed something strange for me, it's result when
I watch GUI.
This is all data when I save with CrudRepository only one "entity"
So, Look how much rows, I just save 1 #RedisHash value, it could be because of #Indexed annotation but anyway it looks very strange for me.
P.S.
I noticed that without #Indexed it's impossible to find anything, for example:
#Repository
public interface RedisEmployeeRepository extends CrudRepository<RedisEmployee, String> {
RedisEmployee findByDateAndCompanyNameAndEmployeeId(String date, String companyName, Long employeeId);
}
so, findByDateAndCompanyNameAndEmployeeId will not return result if I don't have all fields #Indexed. Can't understand it is proper or not.
I am trying to use Jersey to get JSON request from the user to create vendor
#POST
#Produces({APPLICATION_JSON})
#Consumes({APPLICATION_JSON})
#Path("create")
public Response create(VendorTO vendorTO) throws Exception {
But before it converts in vendorTO object I want to validate it with javax.validation
I have added constraints in my pojo like this
{#JsonSerialize(include=Inclusion.NON_NULL)
public class VendorTO {
#NotNull
private Integer userId;
#Size(min = 2)
private String vendorName;
private String address1;
private String address2;
private String city;
private String state;
private String country;
private String email;
private String phone;
}
but it doesnt seems to be working. Can anyone help ?
You need to tell the framework that the parameter should be #Validated:
#POST
#Produces({APPLICATION_JSON})
#Consumes({APPLICATION_JSON})
#Path("create")
public Response create(#Valid VendorTO vendorTO) {
// ...
}
At this point, it appears Jersey does not support JSR 303 natively. You might have to write some ResourceFilters and handle the validation manually.