PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/javaProject/src/comparacion/Comparador.java

https://bitbucket.org/ericson_cepeda/repbiblioteca
Java | 218 lines | 151 code | 35 blank | 32 comment | 14 complexity | 1cc77d254f963fd7bcceed009be75b43 MD5 | raw file
  1. package comparacion;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Set;
  5. import models.BasesConstantes;
  6. import models.Books;
  7. import seeds.ClientServicios;
  8. import world.BibliotecaTDO;
  9. import world.Cargador;
  10. import com.google.gson.Gson;
  11. import com.mongodb.DBObject;
  12. import com.mongodb.util.JSON;
  13. public class Comparador
  14. {
  15. private static String servicioUrl = "http://157.253.238.114:8080/serializationbiblio/views/index/";
  16. private static String servicioMetodo = "getBookByTitle.jsp?callback=jsonCallback&title=";
  17. private static String servicioMetodoDos = "&_=1351286739326";
  18. private static ArrayList<DtoRespuesta> rtaLibreria;
  19. private static Gson gson;
  20. private static Comparador INSTANCE;
  21. public Comparador( )
  22. {
  23. rtaLibreria= new ArrayList<DtoRespuesta>( );
  24. gson = new Gson( );
  25. }
  26. public static ArrayList<DtoRespuesta> getRtaLibreria( )
  27. {
  28. return rtaLibreria;
  29. }
  30. public static Comparador getInstance(){
  31. if (INSTANCE == null)
  32. INSTANCE = new Comparador( );
  33. return INSTANCE;
  34. }
  35. public List<Books> covertirAListaBooks( List<DBObject> listaDb )
  36. {
  37. Gson gson = new Gson( );
  38. List<Books> listaRespuesta = new ArrayList<Books>( );
  39. for( DBObject dbObject : listaDb )
  40. {
  41. Books libros = gson.fromJson( dbObject.toString( ), Books.class );
  42. listaRespuesta.add( libros );
  43. }
  44. return listaRespuesta;
  45. }
  46. public static void resultadoBusqueda( String titulo )
  47. {
  48. String servicio = servicioUrl + servicioMetodo + titulo + servicioMetodoDos;
  49. String entrada = "";
  50. try
  51. {
  52. entrada = ClientServicios.getHtml( servicio );
  53. if( entrada.equals( "-1" ) )
  54. {
  55. throw new Exception( "Error en llamada del servicio getBookByTitle" );
  56. }
  57. }
  58. catch( Exception e )
  59. {
  60. e.printStackTrace( );
  61. }
  62. DBObject dbObject = (DBObject) JSON.parse( entrada );
  63. Set<String> set = dbObject.keySet( );
  64. analizarLibros (set, dbObject);
  65. }
  66. public static void analizarLibros(Set<String> set, DBObject dbObject)
  67. {
  68. for( String setMongo : set )
  69. {
  70. DtoRespuesta prmAnalisisLibro = new DtoRespuesta( );
  71. prmAnalisisLibro.setIdHash( Integer.parseInt( setMongo ) );
  72. DBObject objetos = ( DBObject )dbObject.get( setMongo );
  73. DBObject deweyInfo = ( DBObject )objetos.get( "deweyInfo" );
  74. DBObject categories = ( DBObject )deweyInfo.get( "categories" );
  75. DBObject errors = ( DBObject )deweyInfo.get( "errors" );
  76. if( errors !=null )
  77. {
  78. Set<String> setErrors = errors.keySet( );
  79. ArrayList<String> erroresArray = new ArrayList<String>( );
  80. for( String errores : setErrors )
  81. {
  82. erroresArray.add( errors.get( errores).toString( ) );
  83. }
  84. prmAnalisisLibro.setErroresDewey( erroresArray );
  85. }
  86. if(categories == null )
  87. {
  88. prmAnalisisLibro.setVarStringDeweyRta( ConstantesRespuestas.ERROR_DEWEY );
  89. }
  90. else
  91. {
  92. analizarDewey( objetos , prmAnalisisLibro );
  93. }
  94. rtaLibreria.add( prmAnalisisLibro );
  95. }
  96. }
  97. private static void analizarDewey( DBObject objetos, DtoRespuesta prmAnalisisLibro )
  98. {
  99. DBObject libraryBook = ( DBObject )objetos.get( "libraryBook" );
  100. DBObject deweyInfo = ( DBObject )objetos.get( "deweyInfo" );
  101. DBObject categories = ( DBObject )deweyInfo.get( "categories" );
  102. Set<String> setErrors = categories.keySet( );
  103. ArrayList<String> categoriasArray = new ArrayList<String>( );
  104. for( String errores : setErrors )
  105. {
  106. categoriasArray.add( categories.get( errores).toString( ) );
  107. }
  108. prmAnalisisLibro.setCategoriaSugerias( categoriasArray );
  109. DBObject collectionBooks = ( DBObject )objetos.get( "collectionBooks" );
  110. if( collectionBooks != null )
  111. {
  112. Set<String> set = collectionBooks.keySet( );
  113. for( String books : set )
  114. {
  115. Books libro = gson.fromJson( books, Books.class );
  116. switch( Integer.parseInt( libro.getColeccion( ) ) )
  117. {
  118. case BasesConstantes.COREINT:
  119. break;
  120. case BasesConstantes.ARXIVINT:
  121. break;
  122. case BasesConstantes.GOOGLEBOOKSINT:
  123. break;
  124. case BasesConstantes.OPENLIBRARYINT:
  125. break;
  126. case BasesConstantes.ISBNDTOINT:
  127. break;
  128. default:
  129. break;
  130. }
  131. }
  132. }else
  133. {
  134. prmAnalisisLibro.setVarStringBusquedaRta( ConstantesRespuestas.ERROR_BUSQUEDA );
  135. try
  136. {
  137. Cargador cargador;
  138. cargador = new Cargador( );
  139. BibliotecaTDO libro = gson.fromJson( libraryBook.toString( ), BibliotecaTDO.class );
  140. for( String autor : libro.getAutorPersonal( ) )
  141. {
  142. cargador.llamarArxiv( autor );
  143. }
  144. }
  145. catch( Exception e )
  146. {
  147. e.printStackTrace();
  148. }
  149. }
  150. }
  151. // public void analizarBusqueda( List<Books> listaBooksMongo )
  152. // {
  153. // for( Books books : listaBooksMongo )
  154. // {
  155. // switch( Integer.parseInt( books.getColeccion( ) ) )
  156. // {
  157. // case BasesConstantes.COREINT:
  158. // varAnalizadorCore.inicializar( books, listaBooksMongo, varLibroBiblioteca );
  159. //
  160. // break;
  161. //
  162. // case BasesConstantes.ARXIVINT:
  163. // varAnalizadorArxiv.inicializar( books, listaBooksMongo, varLibroBiblioteca );
  164. // break;
  165. //
  166. // case BasesConstantes.GOOGLEBOOKSINT:
  167. //
  168. // break;
  169. //
  170. // case BasesConstantes.OPENLIBRARYINT:
  171. //
  172. // break;
  173. //
  174. // case BasesConstantes.ISBNDTOINT:
  175. //
  176. // break;
  177. //
  178. // default:
  179. // break;
  180. // }
  181. // }
  182. // }
  183. }