Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.20 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-S00001030001";
  121. array[2] = "1-S00001030001";
  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.  
  148. for (int i = 0; i < anuncios.length; i++) {
  149. Statement stmt = con.createStatement();
  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[0] + "'");
  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. stmt.close();
  190. con.close();
  191.  
  192. }
  193. } catch (Exception e) {
  194. System.out.println(e.getMessage());
  195. }
  196. return arrbocetos;
  197. }
  198.  
  199. public String Insertar(String[] anuncios) throws MyClipperException,
  200. MyClipperApplicationException {
  201.  
  202. String textXMLDoc = "";
  203. ArrayList<SpecVisual> arrbocetos = null;
  204. arrbocetos = new ArrayList<SpecVisual>();
  205. ArrayList<SpecVisual> arrbocetosEnviar = null;
  206. arrbocetosEnviar = new ArrayList<SpecVisual>();
  207. ArrayList<SpecVisual> arrbocetosFallidos = null;
  208. arrbocetosFallidos = new ArrayList<SpecVisual>();
  209. ArrayList<AdvertSearchForMassiveSpecVisualCreationInfo> arrbocetosFallidosadvert = null;
  210. arrbocetosFallidosadvert = new ArrayList<AdvertSearchForMassiveSpecVisualCreationInfo>();
  211.  
  212. arrbocetos = Insertar_bocetos(anuncios);
  213.  
  214. for (SpecVisual spec : arrbocetos) {
  215. arrbocetosEnviar.add(spec);
  216. try {
  217. arrbocetosEnviar.clear();
  218. JobDelegator.createSpecVisuals(arrbocetosEnviar);
  219. arrbocetosEnviar.clear();
  220. }
  221.  
  222. catch (MyClipperException exe) {
  223. arrbocetosFallidos.add(spec);
  224. arrbocetosEnviar.clear();
  225. for (SpecVisual specFall : arrbocetosFallidos) {
  226. AdvertSearchForMassiveSpecVisualCreationInfo adverFall = new AdvertSearchForMassiveSpecVisualCreationInfo();
  227.  
  228. try {
  229.  
  230. adverFall.setClipper_wi_ref(specFall.getClipperWiRef());
  231.  
  232. adverFall.setBook_edition(specFall.getBookEdition()
  233. .toString());
  234.  
  235. adverFall
  236. .setCurrent_status(specFall.getCurrentStatus());
  237. // adverFall.setEdition_name(specFall.getBookEdition());
  238. adverFall.setPub_product_desc(specFall.getPubAdCode());
  239. // adverFall.setUdac_desc(specFall)
  240. arrbocetosFallidosadvert.add(adverFall);
  241. }
  242.  
  243. catch (Exception e) {
  244.  
  245. }
  246. }
  247.  
  248. }
  249. }
  250.  
  251. try {
  252. Document doc = getXMLMassiveSpecVisualResponse(
  253. arrbocetosFallidosadvert, arrbocetosFallidos.size());
  254. try {
  255.  
  256. Source source = new DOMSource(doc);
  257. StringWriter stringWriter = new StringWriter();
  258. Result result = new StreamResult(stringWriter);
  259. TransformerFactory factory = TransformerFactory.newInstance();
  260. Transformer transformer = factory.newTransformer();
  261. transformer.transform(source, result);
  262. textXMLDoc = stringWriter.getBuffer().toString();
  263. } catch (TransformerConfigurationException e) {
  264. throw new MyClipperException(
  265. "Error while creating Massive SpecVisuals");
  266.  
  267. } catch (TransformerException e) {
  268. throw new MyClipperException(
  269. "Error while creating Massive SpecVisuals");
  270. }
  271. } catch (ParserConfigurationException e) {
  272.  
  273. e.printStackTrace();
  274. }
  275.  
  276. return textXMLDoc;
  277. }
  278.  
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement