Jean-Francois Leveque

Ajour d'IndexingException à l'indexation de Publisher.

1 +package org.legrog.entities;
2 +
3 +import javax.ejb.ApplicationException;
4 +
5 +/*
6 + Exception when indexing fails, whatever the reason. Has to be dealt with at service level.
7 + */
8 +@ApplicationException(rollback = true)
9 +public class IndexingException extends Exception {
10 + Throwable rootCause;
11 +
12 + IndexingException(Throwable rootCause) {
13 + this.rootCause = rootCause;
14 + }
15 +
16 + public Throwable getRootCause() {
17 + return rootCause;
18 + }
19 +}
...@@ -15,5 +15,5 @@ public interface PublisherSearchRepository /*extends SolrCrudRepository<IndexedP ...@@ -15,5 +15,5 @@ public interface PublisherSearchRepository /*extends SolrCrudRepository<IndexedP
15 15
16 Indexe la version simplifiée de Publisher, IndexedPublisher. 16 Indexe la version simplifiée de Publisher, IndexedPublisher.
17 */ 17 */
18 - public IndexedPublisher save(IndexedPublisher indexedPublisher); 18 + public IndexedPublisher save(IndexedPublisher indexedPublisher) throws IndexingException;
19 } 19 }
......
...@@ -27,14 +27,14 @@ public class PublisherSearchRepositorySolrj implements PublisherSearchRepository ...@@ -27,14 +27,14 @@ public class PublisherSearchRepositorySolrj implements PublisherSearchRepository
27 } 27 }
28 28
29 @Override 29 @Override
30 - public IndexedPublisher save(IndexedPublisher indexedPublisher) { 30 + public IndexedPublisher save(IndexedPublisher indexedPublisher) throws IndexingException {
31 try { 31 try {
32 UpdateResponse updateResponse = solrClient.addBean(indexedPublisher, 1); 32 UpdateResponse updateResponse = solrClient.addBean(indexedPublisher, 1);
33 logger.trace("validatePublisherVersion SolrJ UpdateResponse {}", updateResponse); 33 logger.trace("validatePublisherVersion SolrJ UpdateResponse {}", updateResponse);
34 } catch (IOException ioe) { 34 } catch (IOException ioe) {
35 - logger.error("validatePublisherVersion IOException {}", ioe.getMessage()); 35 + throw new IndexingException(ioe);
36 } catch (SolrServerException sse) { 36 } catch (SolrServerException sse) {
37 - logger.error("validatePublisherVersion SolrServerException {}", sse.getMessage()); 37 + throw new IndexingException(sse.getRootCause());
38 } 38 }
39 39
40 return indexedPublisher; 40 return indexedPublisher;
......
...@@ -83,7 +83,11 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -83,7 +83,11 @@ public class PublisherServiceSpring implements PublisherService {
83 publisherAction.setPublisher(publisher); 83 publisherAction.setPublisher(publisher);
84 this.savePublisher(publisher); 84 this.savePublisher(publisher);
85 IndexedPublisher indexedPublisher = new IndexedPublisher(publisher); 85 IndexedPublisher indexedPublisher = new IndexedPublisher(publisher);
86 - publisherSearchRepository.save(indexedPublisher); 86 + try {
87 + publisherSearchRepository.save(indexedPublisher);
88 + } catch (IndexingException e) {
89 +
90 + }
87 publisherActionRepository.save(publisherAction); 91 publisherActionRepository.save(publisherAction);
88 return publisherAction; 92 return publisherAction;
89 } 93 }
......
...@@ -109,7 +109,11 @@ public class PublisherServiceSpringTest { ...@@ -109,7 +109,11 @@ public class PublisherServiceSpringTest {
109 when(publisherVersionMock.getPublisherName()).thenReturn("nom"); 109 when(publisherVersionMock.getPublisherName()).thenReturn("nom");
110 when(publisherVersionMock.getPublisherHistory()).thenReturn("histoire"); 110 when(publisherVersionMock.getPublisherHistory()).thenReturn("histoire");
111 publisherServiceSpring.validatePublisherVersion(publisherVersionMock); 111 publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
112 - Mockito.verify(publisherSearchRepository).save(indexedPublisherArgumentCaptor.capture()); 112 + try {
113 + Mockito.verify(publisherSearchRepository).save(indexedPublisherArgumentCaptor.capture());
114 + } catch (IndexingException e) {
115 + e.printStackTrace();
116 + }
113 IndexedPublisher indexedPublisher = indexedPublisherArgumentCaptor.getValue(); 117 IndexedPublisher indexedPublisher = indexedPublisherArgumentCaptor.getValue();
114 assertThat(indexedPublisher.getPublisherId()).isEqualTo(111); 118 assertThat(indexedPublisher.getPublisherId()).isEqualTo(111);
115 assertThat(indexedPublisher.getPublisherName()).isEqualTo("nom"); 119 assertThat(indexedPublisher.getPublisherName()).isEqualTo("nom");
......