Jean-Francois Leveque

Indexation éditeur avec couche abstraction.

......@@ -81,26 +81,32 @@
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>${solr.version}</version>
</dependency>
<dependency>
<artifactId>solr-solrj</artifactId>
<groupId>org.apache.solr</groupId>
<version>${solr.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>${spring-data-solr.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>${solr.version}</version>
</dependency>
<dependency>
<artifactId>solr-solrj</artifactId>
<groupId>org.apache.solr</groupId>
<version>${solr.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>${spring-data-solr.version}</version>
</dependency>
-->
<!-- **** FRAMEWORK : JSF + CDI **** -->
<dependency>
......
package org.legrog.configuration;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import javax.enterprise.inject.Produces;
public class SolrJConfiguration {
@Produces
public SolrClient createSolrClient() {
return new HttpSolrClient.Builder("http://localhost:8983/solr/publishers").build();
}
}
package org.legrog.entities;
/*
import org.apache.solr.client.solrj.beans.Field;
/*
import org.springframework.data.solr.core.mapping.SolrDocument;
*/
import javax.persistence.Id;
......@@ -9,12 +9,12 @@ import javax.persistence.Lob;
//@SolrDocument(solrCoreName = "publishers")
public class IndexedPublisher {
@Id
// @Field
@Field
private int publisherId;
// @Field
@Field
private String publisherName;
@Lob
// @Field
@Field
private String publisherHistory;
public IndexedPublisher(Publisher publisher) {
......
package org.legrog.entities;
import org.springframework.data.jpa.repository.Query;
//import org.springframework.data.solr.repository.SolrCrudRepository;
//import org.springframework.data.solr.repository.Query;
import java.util.List;
public interface PublisherSearchRepository /*extends SolrCrudRepository<IndexedPublisher, Integer>*/ {
@Query("?0")
List<IndexedPublisher> search(String search);
// @Query("?0")
// List<IndexedPublisher> search(String search);
public IndexedPublisher save(IndexedPublisher indexedPublisher);
}
......
package org.legrog.entities;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.io.IOException;
public class PublisherSearchRepositorySolrj implements PublisherSearchRepository {
Logger logger = LoggerFactory.getLogger(getClass());
SolrClient solrClient;
@Inject
PublisherSearchRepositorySolrj(SolrClient solrClient) {
this.solrClient = solrClient;
}
//no args constructor to make it proxyable
PublisherSearchRepositorySolrj() {
}
@Override
public IndexedPublisher save(IndexedPublisher indexedPublisher) {
try {
UpdateResponse updateResponse = solrClient.addBean(indexedPublisher, 1);
logger.trace("validatePublisherVersion SolrJ UpdateResponse {}", updateResponse);
} catch (IOException ioe) {
logger.error("validatePublisherVersion IOException {}", ioe.getMessage());
} catch (SolrServerException sse) {
logger.error("validatePublisherVersion SolrServerException {}", sse.getMessage());
}
return indexedPublisher;
}
}
......@@ -8,7 +8,6 @@ import org.slf4j.LoggerFactory;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashSet;
......@@ -73,7 +72,6 @@ public class PublisherServiceSpring implements PublisherService {
return publisherVersion;
}
@Transactional
public PublisherAction validatePublisherVersion(PublisherVersion publisherVersion) {
Publisher publisher = publisherVersion.getPublisher();
publisher.setValidatedVersion(publisherVersion);
......@@ -85,7 +83,7 @@ public class PublisherServiceSpring implements PublisherService {
publisherAction.setPublisher(publisher);
this.savePublisher(publisher);
IndexedPublisher indexedPublisher = new IndexedPublisher(publisher);
// publisherSearchRepository.save(indexedPublisher);
publisherSearchRepository.save(indexedPublisher);
publisherActionRepository.save(publisherAction);
return publisherAction;
}
......@@ -108,7 +106,7 @@ public class PublisherServiceSpring implements PublisherService {
}
public PublisherAction getLastValidate(Publisher publisher) {
return publisherActionRepository.findFirstByActionTypeAndPublisherOrderByPublisherActionDatetime(ActionType.VALIDATE, publisher);
return publisherActionRepository.findFirstByActionTypeAndPublisherOrderByPublisherActionDatetimeDesc(ActionType.VALIDATE, publisher);
}
public List<PublisherAction> getAllPublisherActions() {
......