Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.22 KB | None | 0 0
  1. package webService;
  2.  
  3. import java.io.StringWriter;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.Statement;
  8. import java.util.ArrayList;
  9. import javax.xml.parsers.DocumentBuilder;
  10. import javax.xml.parsers.DocumentBuilderFactory;
  11. import javax.xml.parsers.ParserConfigurationException;
  12. import javax.xml.transform.Result;
  13. import javax.xml.transform.Source;
  14. import javax.xml.transform.Transformer;
  15. import javax.xml.transform.TransformerConfigurationException;
  16. import javax.xml.transform.TransformerException;
  17. import javax.xml.transform.TransformerFactory;
  18. import javax.xml.transform.dom.DOMSource;
  19. import javax.xml.transform.stream.StreamResult;
  20.  
  21. import org.w3c.dom.Document;
  22. import org.w3c.dom.Element;
  23.  
  24. import com.pindarset.myclipper.common.Util;
  25. import com.pindarset.myclipper.common.exception.MyClipperApplicationException;
  26. import com.pindarset.myclipper.common.exception.MyClipperException;
  27. import com.pindarset.myclipper.common.exception.MyClipperSystemException;
  28. import com.pindarset.myclipper.job.common.JobDelegator;
  29. import com.pindarset.myclipper.job.specvisual.model.Advertiser;
  30. import com.pindarset.myclipper.job.specvisual.model.SpecVisual;
  31.  
  32. public class EdicionImpl implements Edicion {
  33.  
  34. public Document getXMLMassiveSpecVisualResponse(
  35. ArrayList<AdvertSearchForMassiveSpecVisualCreationInfo> lstAdvertSearchForMassiveSpecVisualCreationInfo,
  36. int totalOK) throws ParserConfigurationException {
  37. Document document = null;
  38. DocumentBuilderFactory documentBuilderFactory =
  39.  
  40. DocumentBuilderFactory.newInstance();
  41. DocumentBuilder documentBuilder = null;
  42.  
  43. documentBuilder = documentBuilderFactory.newDocumentBuilder();
  44.  
  45. document = documentBuilder.newDocument();
  46.  
  47. Element rootElement = document.createElement("response");
  48. document.appendChild(rootElement);
  49.  
  50. Element ok = document.createElement("ok");
  51.  
  52. Element total = document.createElement("total");
  53. total.appendChild(document.createTextNode(String.valueOf(totalOK)));
  54.  
  55. ok.appendChild(total);
  56.  
  57. Element fail = document.createElement("fail");
  58. int i = 0;
  59. while (i < lstAdvertSearchForMassiveSpecVisualCreationInfo.size()) {
  60.  
  61. AdvertSearchForMassiveSpecVisualCreationInfo tmpAdvertSearchForMassiveSpecVisualCreationInfo = (AdvertSearchForMassiveSpecVisualCreationInfo) lstAdvertSearchForMassiveSpecVisualCreationInfo
  62. .get(i);
  63.  
  64. // while (i <= specVisual.size()) {
  65. Element boceto = document.createElement("boceto");
  66.  
  67. Element id = document.createElement("id");
  68. id.appendChild(document
  69. .createTextNode(tmpAdvertSearchForMassiveSpecVisualCreationInfo
  70. .getClipper_wi_ref()));
  71.  
  72. Element guia = document.createElement("guia");
  73. guia.appendChild(document
  74. .createTextNode(tmpAdvertSearchForMassiveSpecVisualCreationInfo
  75. .getEdition_name()));
  76.  
  77. Element edicion = document.createElement("edicion");
  78. edicion.appendChild(document
  79. .createTextNode(tmpAdvertSearchForMassiveSpecVisualCreationInfo
  80. .getBook_edition()));
  81.  
  82. Element tamano = document.createElement("tamano");
  83. tamano.appendChild(document
  84. .createTextNode(tmpAdvertSearchForMassiveSpecVisualCreationInfo
  85. .getUdac_desc()));
  86.  
  87. Element producto = document.createElement("producto");
  88. producto.appendChild(document
  89. .createTextNode(tmpAdvertSearchForMassiveSpecVisualCreationInfo
  90. .getPub_product_desc()));
  91.  
  92. Element estado = document.createElement("estado");
  93. estado.appendChild(document
  94. .createTextNode(tmpAdvertSearchForMassiveSpecVisualCreationInfo
  95. .getCurrent_status()));
  96.  
  97. boceto.appendChild(id);
  98. boceto.appendChild(guia);
  99. boceto.appendChild(edicion);
  100. boceto.appendChild(tamano);
  101. boceto.appendChild(producto);
  102. boceto.appendChild(estado);
  103.  
  104. fail.appendChild(boceto);
  105.  
  106. i++;
  107.  
  108. }
  109.  
  110. rootElement.appendChild(ok);
  111. rootElement.appendChild(fail);
  112.  
  113. return document;
  114. }
  115.  
  116. public static void main(String args[]) {
  117.  
  118. String array[] = new String[4];
  119. array[0] = "1-S00001030001";
  120. array[1] = "1-S00626023001";
  121. array[2] = "1-S00605935001";
  122. array[3] = "1-S00001030001";
  123. EdicionImpl edicion = new EdicionImpl();
  124. try {
  125. edicion.Insertar(array);
  126. } catch (MyClipperException e) {
  127. e.printStackTrace();
  128. }
  129.  
  130. }
  131.  
  132. public ArrayList<SpecVisual> Insertar_bocetos(String[] anuncios) {
  133.  
  134. String driver = "org.postgresql.Driver";
  135. String connectString = "jdbc:postgresql://db1.medellin.intrayell.com:5432/clipper";
  136. String user = "clipper";
  137. String password = "clipper";
  138.  
  139. SpecVisual specVisual = new SpecVisual();
  140. Advertiser advertiser = new Advertiser();
  141. ArrayList<SpecVisual> arrbocetos = new ArrayList<SpecVisual>();
  142.  
  143. try {
  144. Class.forName(driver);
  145. Connection con = DriverManager.getConnection(connectString, user,
  146. password);
  147. Statement stmt = con.createStatement();
  148. for (int i = 0; i < anuncios.length; i++) {
  149.  
  150. ResultSet rs = stmt
  151. .executeQuery("Select sp.clipper_Book_Id,sp.Book_Edition,"
  152. + "sp.creativity_id,sp.Awaiting_ref_flag,sp.type_Id,sp.pub_ad_code,sp.heading_name,"
  153. + "sp.Login_Id,sp.sales_rep_code,ad.advertiser_name,ad.clipper_advertiser_ref,sp.language_id,sp.multi_page_flag "
  154. + "from advertiser ad,Spec_visual sp "
  155. + "where sp.clipper_advertiser_ref= ad.clipper_advertiser_ref and sp.clipper_wi_ref='"
  156. + anuncios[i] + "'");
  157.  
  158. while (rs.next()) {
  159.  
  160. specVisual
  161. .setClipperBookId(rs.getString("clipper_Book_Id"));
  162. specVisual.setBookEditionId(Long.parseLong(rs
  163. .getString("Book_Edition")));
  164. specVisual.setCreativityId(Integer.parseInt(rs
  165. .getString("creativity_id")));
  166. specVisual.setAwaitRefFlag(Integer.parseInt(rs
  167. .getString("Awaiting_ref_flag")));
  168. specVisual.setTypeId(Integer.parseInt(rs
  169. .getString("type_Id")));
  170. specVisual.setPubAdCode(rs.getString("pub_ad_code"));
  171. specVisual.setHeadingName(rs.getString("heading_name"));
  172. specVisual.setLoginId(rs.getString("Login_Id"));
  173. specVisual.setSalesRepCode(rs.getString("sales_rep_code"));
  174.  
  175. advertiser.setAdvertiserName(rs
  176. .getString("advertiser_name"));
  177. advertiser.setClipperAdvertiserRef(rs
  178. .getString("clipper_advertiser_ref"));
  179.  
  180. specVisual.setAdvertiser(advertiser);
  181. specVisual.setLanguageId(Integer.parseInt(rs
  182. .getString("language_id")));
  183. specVisual.setMultiPageFlag(Integer.parseInt(rs
  184. .getString("multi_page_flag")));
  185. // specVisual.setTypeInstructionsText("specVisualFB.getInstructions()");
  186. arrbocetos.add(specVisual);
  187.  
  188. }
  189. }
  190. stmt.close();
  191. con.close();
  192.  
  193.  
  194. } catch (Exception e) {
  195. System.out.println(e.getMessage());
  196. }
  197. return arrbocetos;
  198. }
  199.  
  200. public String Insertar(String[] anuncios) throws MyClipperException,
  201. MyClipperApplicationException {
  202.  
  203. String textXMLDoc = "";
  204. ArrayList<SpecVisual> arrbocetos = null;
  205. arrbocetos = new ArrayList<SpecVisual>();
  206. ArrayList<SpecVisual> arrbocetosEnviar = null;
  207. arrbocetosEnviar = new ArrayList<SpecVisual>();
  208. ArrayList<SpecVisual> arrbocetosFallidos = null;
  209. arrbocetosFallidos = new ArrayList<SpecVisual>();
  210. ArrayList<AdvertSearchForMassiveSpecVisualCreationInfo> arrbocetosFallidosadvert = null;
  211. arrbocetosFallidosadvert = new ArrayList<AdvertSearchForMassiveSpecVisualCreationInfo>();
  212.  
  213. arrbocetos = Insertar_bocetos(anuncios);
  214.  
  215. for (SpecVisual spec : arrbocetos) {
  216. arrbocetosEnviar.add(spec);
  217. try {
  218. arrbocetosEnviar.clear();
  219. JobDelegator.createSpecVisuals(arrbocetosEnviar);
  220. arrbocetosEnviar.clear();
  221. }
  222.  
  223. catch (MyClipperException exe) {
  224. arrbocetosFallidos.add(spec);
  225. arrbocetosEnviar.clear();
  226. for (SpecVisual specFall : arrbocetosFallidos) {
  227. AdvertSearchForMassiveSpecVisualCreationInfo adverFall = new AdvertSearchForMassiveSpecVisualCreationInfo();
  228.  
  229. try {
  230.  
  231. adverFall.setClipper_wi_ref(specFall.getClipperWiRef());
  232. // adverFall.setEdition_name(specFall.get);
  233. adverFall.setBook_edition(specFall.getBookEdition()
  234. .toString());// ?
  235. adverFall.setUdac_desc(specFall.getPubAdCode());
  236. // adverFall.setPub_product_desc(specFall.getPubAdCode());
  237. adverFall
  238. .setCurrent_status(specFall.getCurrentStatus());
  239. arrbocetosFallidosadvert.add(adverFall);
  240. }
  241.  
  242. catch (Exception e) {
  243.  
  244. }
  245. }
  246.  
  247. }
  248. }
  249.  
  250. try {
  251. Document doc = getXMLMassiveSpecVisualResponse(
  252. arrbocetosFallidosadvert, arrbocetosFallidos.size());
  253. try {
  254.  
  255. Source source = new DOMSource(doc);
  256. StringWriter stringWriter = new StringWriter();
  257. Result result = new StreamResult(stringWriter);
  258. TransformerFactory factory = TransformerFactory.newInstance();
  259. Transformer transformer = factory.newTransformer();
  260. transformer.transform(source, result);
  261. textXMLDoc = stringWriter.getBuffer().toString();
  262. } catch (TransformerConfigurationException e) {
  263. throw new MyClipperException(
  264. "Error while creating Massive SpecVisuals");
  265.  
  266. } catch (TransformerException e) {
  267. throw new MyClipperException(
  268. "Error while creating Massive SpecVisuals");
  269. }
  270. } catch (ParserConfigurationException e) {
  271.  
  272. e.printStackTrace();
  273. }
  274.  
  275. return textXMLDoc;
  276. }
  277.  
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement