1111import lombok .extern .slf4j .Slf4j ;
1212import org .springframework .stereotype .Service ;
1313
14+ import java .io .BufferedReader ;
1415import java .io .IOException ;
1516import java .io .Reader ;
1617import java .sql .Clob ;
1718import java .sql .SQLException ;
1819import java .util .*;
20+ import java .util .stream .Collectors ;
1921
2022@ Service
2123@ Slf4j
@@ -38,30 +40,27 @@ public NoticeXml getNoticeByPpn(String ppn) throws IllegalPpnException, IOExcept
3840 throw new IllegalPpnException ("Le PPN ne peut pas être null" );
3941 //Optional<NoticesBibio> noticeOpt = this.noticesBibioRepository.findByPpn(ppn);
4042 Optional <NoticesBibio > noticeOpt = baseXmlFunctionsCaller .findByPpn (ppn );
41- if (noticeOpt .isPresent ()) {
42- Clob clob = noticeOpt .get ().getDataXml ();
43-
44- try (Reader reader = clob .getCharacterStream ()){
45- return xmlMapper .readValue (reader , NoticeXml .class );
46- } catch (SQLException e ) {
47- log .error (e .getMessage ());
48- } finally {
49- try {
50- clob .free ();
51- } catch (SQLException e ) {
52- log .error (e .getMessage ());
53- }
54- }
43+ if (noticeOpt .isEmpty ()) {
44+ return null ;
5545 }
56-
57- /*if (noticeOpt.isPresent()) {
46+ Clob clob = noticeOpt .get ().getDataXml ();
47+ String xmlString = null ;
48+
49+ try (Reader reader = clob .getCharacterStream ()){
50+ xmlString = new BufferedReader (reader )
51+ .lines ()
52+ .collect (Collectors .joining ("\n " ));
53+ } catch (SQLException e ) {
54+ log .error (e .getMessage ());
55+ } finally {
5856 try {
59- return xmlMapper.readValue(noticeOpt.get().getDataXml().getCharacterStream(), NoticeXml.class );
57+ clob . free ( );
6058 } catch (SQLException e ) {
6159 log .error (e .getMessage ());
6260 }
63- }*/
64- return null ;
61+ }
62+
63+ return (xmlString != null ) ? xmlMapper .readValue (xmlString , NoticeXml .class ) : null ;
6564 }
6665
6766 public List <String > getEquivalentElectronique (NoticeXml notice ) throws IOException , IllegalPpnException , ZoneNotFoundException {
0 commit comments