Jean-Francois Leveque

Indexation éditeur avec couche abstraction.

...@@ -81,26 +81,32 @@ ...@@ -81,26 +81,32 @@
81 </dependency> 81 </dependency>
82 </dependencies> 82 </dependencies>
83 </dependencyManagement> 83 </dependencyManagement>
84 -
85 <dependencies> 84 <dependencies>
85 +
86 <dependency> 86 <dependency>
87 <groupId>org.apache.solr</groupId> 87 <groupId>org.apache.solr</groupId>
88 - <artifactId>solr-core</artifactId>
89 - <version>${solr.version}</version>
90 - </dependency>
91 - <dependency>
92 <artifactId>solr-solrj</artifactId> 88 <artifactId>solr-solrj</artifactId>
93 - <groupId>org.apache.solr</groupId>
94 <version>${solr.version}</version> 89 <version>${solr.version}</version>
95 - <type>jar</type>
96 - <scope>compile</scope>
97 - </dependency>
98 - <dependency>
99 - <groupId>org.springframework.data</groupId>
100 - <artifactId>spring-data-solr</artifactId>
101 - <version>${spring-data-solr.version}</version>
102 </dependency> 90 </dependency>
103 - 91 + <!--
92 + <dependency>
93 + <groupId>org.apache.solr</groupId>
94 + <artifactId>solr-core</artifactId>
95 + <version>${solr.version}</version>
96 + </dependency>
97 + <dependency>
98 + <artifactId>solr-solrj</artifactId>
99 + <groupId>org.apache.solr</groupId>
100 + <version>${solr.version}</version>
101 + <type>jar</type>
102 + <scope>compile</scope>
103 + </dependency>
104 + <dependency>
105 + <groupId>org.springframework.data</groupId>
106 + <artifactId>spring-data-solr</artifactId>
107 + <version>${spring-data-solr.version}</version>
108 + </dependency>
109 + -->
104 <!-- **** FRAMEWORK : JSF + CDI **** --> 110 <!-- **** FRAMEWORK : JSF + CDI **** -->
105 111
106 <dependency> 112 <dependency>
......
1 +package org.legrog.configuration;
2 +
3 +import org.apache.solr.client.solrj.SolrClient;
4 +import org.apache.solr.client.solrj.impl.HttpSolrClient;
5 +
6 +import javax.enterprise.inject.Produces;
7 +
8 +public class SolrJConfiguration {
9 +
10 + @Produces
11 + public SolrClient createSolrClient() {
12 + return new HttpSolrClient.Builder("http://localhost:8983/solr/publishers").build();
13 + }
14 +
15 +}
1 package org.legrog.entities; 1 package org.legrog.entities;
2 -/*
3 import org.apache.solr.client.solrj.beans.Field; 2 import org.apache.solr.client.solrj.beans.Field;
3 +/*
4 import org.springframework.data.solr.core.mapping.SolrDocument; 4 import org.springframework.data.solr.core.mapping.SolrDocument;
5 */ 5 */
6 import javax.persistence.Id; 6 import javax.persistence.Id;
...@@ -9,12 +9,12 @@ import javax.persistence.Lob; ...@@ -9,12 +9,12 @@ import javax.persistence.Lob;
9 //@SolrDocument(solrCoreName = "publishers") 9 //@SolrDocument(solrCoreName = "publishers")
10 public class IndexedPublisher { 10 public class IndexedPublisher {
11 @Id 11 @Id
12 -// @Field 12 + @Field
13 private int publisherId; 13 private int publisherId;
14 -// @Field 14 + @Field
15 private String publisherName; 15 private String publisherName;
16 @Lob 16 @Lob
17 -// @Field 17 + @Field
18 private String publisherHistory; 18 private String publisherHistory;
19 19
20 public IndexedPublisher(Publisher publisher) { 20 public IndexedPublisher(Publisher publisher) {
......
1 package org.legrog.entities; 1 package org.legrog.entities;
2 2
3 -import org.springframework.data.jpa.repository.Query;
4 //import org.springframework.data.solr.repository.SolrCrudRepository; 3 //import org.springframework.data.solr.repository.SolrCrudRepository;
4 +//import org.springframework.data.solr.repository.Query;
5 5
6 import java.util.List; 6 import java.util.List;
7 7
8 public interface PublisherSearchRepository /*extends SolrCrudRepository<IndexedPublisher, Integer>*/ { 8 public interface PublisherSearchRepository /*extends SolrCrudRepository<IndexedPublisher, Integer>*/ {
9 - @Query("?0") 9 +// @Query("?0")
10 - List<IndexedPublisher> search(String search); 10 +// List<IndexedPublisher> search(String search);
11 +
12 + public IndexedPublisher save(IndexedPublisher indexedPublisher);
11 } 13 }
......
1 +package org.legrog.entities;
2 +
3 +import org.apache.solr.client.solrj.SolrClient;
4 +import org.apache.solr.client.solrj.SolrServerException;
5 +import org.apache.solr.client.solrj.response.UpdateResponse;
6 +import org.slf4j.Logger;
7 +import org.slf4j.LoggerFactory;
8 +
9 +import javax.inject.Inject;
10 +import java.io.IOException;
11 +
12 +public class PublisherSearchRepositorySolrj implements PublisherSearchRepository {
13 + Logger logger = LoggerFactory.getLogger(getClass());
14 +
15 + SolrClient solrClient;
16 +
17 + @Inject
18 + PublisherSearchRepositorySolrj(SolrClient solrClient) {
19 + this.solrClient = solrClient;
20 + }
21 +
22 + //no args constructor to make it proxyable
23 + PublisherSearchRepositorySolrj() {
24 + }
25 +
26 + @Override
27 + public IndexedPublisher save(IndexedPublisher indexedPublisher) {
28 + try {
29 + UpdateResponse updateResponse = solrClient.addBean(indexedPublisher, 1);
30 + logger.trace("validatePublisherVersion SolrJ UpdateResponse {}", updateResponse);
31 + } catch (IOException ioe) {
32 + logger.error("validatePublisherVersion IOException {}", ioe.getMessage());
33 + } catch (SolrServerException sse) {
34 + logger.error("validatePublisherVersion SolrServerException {}", sse.getMessage());
35 + }
36 +
37 + return indexedPublisher;
38 + }
39 +}
...@@ -8,7 +8,6 @@ import org.slf4j.LoggerFactory; ...@@ -8,7 +8,6 @@ import org.slf4j.LoggerFactory;
8 8
9 import javax.ejb.Stateless; 9 import javax.ejb.Stateless;
10 import javax.inject.Inject; 10 import javax.inject.Inject;
11 -import javax.transaction.Transactional;
12 import java.sql.Timestamp; 11 import java.sql.Timestamp;
13 import java.util.Date; 12 import java.util.Date;
14 import java.util.HashSet; 13 import java.util.HashSet;
...@@ -73,7 +72,6 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -73,7 +72,6 @@ public class PublisherServiceSpring implements PublisherService {
73 return publisherVersion; 72 return publisherVersion;
74 } 73 }
75 74
76 - @Transactional
77 public PublisherAction validatePublisherVersion(PublisherVersion publisherVersion) { 75 public PublisherAction validatePublisherVersion(PublisherVersion publisherVersion) {
78 Publisher publisher = publisherVersion.getPublisher(); 76 Publisher publisher = publisherVersion.getPublisher();
79 publisher.setValidatedVersion(publisherVersion); 77 publisher.setValidatedVersion(publisherVersion);
...@@ -85,7 +83,7 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -85,7 +83,7 @@ public class PublisherServiceSpring implements PublisherService {
85 publisherAction.setPublisher(publisher); 83 publisherAction.setPublisher(publisher);
86 this.savePublisher(publisher); 84 this.savePublisher(publisher);
87 IndexedPublisher indexedPublisher = new IndexedPublisher(publisher); 85 IndexedPublisher indexedPublisher = new IndexedPublisher(publisher);
88 -// publisherSearchRepository.save(indexedPublisher); 86 + publisherSearchRepository.save(indexedPublisher);
89 publisherActionRepository.save(publisherAction); 87 publisherActionRepository.save(publisherAction);
90 return publisherAction; 88 return publisherAction;
91 } 89 }
...@@ -108,7 +106,7 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -108,7 +106,7 @@ public class PublisherServiceSpring implements PublisherService {
108 } 106 }
109 107
110 public PublisherAction getLastValidate(Publisher publisher) { 108 public PublisherAction getLastValidate(Publisher publisher) {
111 - return publisherActionRepository.findFirstByActionTypeAndPublisherOrderByPublisherActionDatetime(ActionType.VALIDATE, publisher); 109 + return publisherActionRepository.findFirstByActionTypeAndPublisherOrderByPublisherActionDatetimeDesc(ActionType.VALIDATE, publisher);
112 } 110 }
113 111
114 public List<PublisherAction> getAllPublisherActions() { 112 public List<PublisherAction> getAllPublisherActions() {
......