Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.34 KB | None | 0 0
  1.  
  2. package com.fitbank.person.sequence;
  3.  
  4. import com.fitbank.common.ApplicationDates;
  5. import com.fitbank.common.FileHelper;
  6. import com.fitbank.common.Helper;
  7. import com.fitbank.dto.management.Detail;
  8. import com.fitbank.dto.management.Record;
  9. import com.fitbank.dto.management.Table;
  10. import com.fitbank.processor.maintenance.MaintenanceCommand;
  11. import com.fitbank.dto.management.Field;
  12. import com.fitbank.hb.persistence.person.TlinkingpersonKey;
  13. import com.fitbank.hb.persistence.person.Tlinkingperson;
  14. import java.io.File;
  15.  
  16.  
  17. public class GenericImageSecuence extends MaintenanceCommand  {
  18.          /**
  19.      * Llama al m�todo que valida el RUC
  20.      */
  21.     @Override
  22.     public Detail executeNormal(Detail pDetail) throws Exception {
  23.  
  24.         Integer secuencia = Helper.nextValue("SIMAGEN");
  25.         Integer numero = 1;
  26.         Boolean setearValor=false;
  27.  
  28.         if (secuencia != null) {
  29.             numero = secuencia;
  30.         }
  31.  
  32.  
  33.         Table timage = pDetail.findTableByName("TIMAGENES");
  34.         if(timage !=null){
  35.             for (Record r : timage.getRecords()) {
  36.                 Field f = r.findFieldByName("IMAGEN");
  37.                 if (f != null && f.getValue() != null) {
  38.                     setearValor=true;
  39.                 }
  40.                 Field f2 = r.findFieldByName("CIMAGEN");
  41.                 if (f2 != null && f2.getValue() == null && setearValor) {
  42.                     f2.setValue(numero);
  43.                 }
  44.             }
  45.         }
  46.         if (setearValor){
  47.             setCimagen(pDetail,getParameter(),numero);
  48.         }
  49.         FileHelper.writeFile(new File("/home/efra/", "out.xml").toString(), pDetail.toXml());
  50.  
  51.         return pDetail;
  52.     }
  53.  
  54.     public void setCimagen(Detail pDetail,String nombre,Integer numero) throws Exception {
  55.         for (Table t : pDetail.getTables()) {
  56.             if (t.getName().toString().compareTo("TPERSONAVINCULACIONES")==0){
  57.              for (Record r : t.getRecords()) {
  58.                 Field f = r.findFieldByName(nombre);
  59.                 if (f != null && f.getValue() == null) {
  60.                     f.setValue(numero);
  61.                 }
  62.             }
  63.             }
  64.             else
  65.             {
  66.                 Integer cperson = pDetail.findFieldByName("CPERSONA").getIntegerValue();
  67.                 Integer clinkedPerson = pDetail.findFieldByName("CPERSONA_VINCULADA").getIntegerValue();
  68.                 String clinkingType = pDetail.findFieldByName("CTIPOVINCULACION").getStringValue();
  69.                 setLinkingPersonImg(cperson,clinkedPerson,clinkingType,(long)numero);
  70.             }
  71.         }
  72.     }
  73.  
  74.     public void setLinkingPersonImg(Integer cperson, Integer clinkedPerson, String clinkigType, Long cimage) throws Exception
  75.     {
  76.         TlinkingpersonKey tlinkedid = new TlinkingpersonKey(cperson,clinkedPerson,clinkigType,ApplicationDates.getDefaultExpiryTimestamp());
  77.         Tlinkingperson tt=(Tlinkingperson)Helper.getBean(Tlinkingperson.class, tlinkedid);
  78.         Tlinkingperson tlinked = new Tlinkingperson(tlinkedid,ApplicationDates.getInstance().getDataBaseTimestamp());
  79.         tlinked.setCimagen(cimage);
  80.         if(tlinked!=null){
  81.             if(tt!=null){
  82.                Helper.update(tlinked);
  83.  
  84.             }
  85.         }
  86.     }
  87.  
  88.     @Override
  89.     public Detail executeReverse(Detail detail) throws Exception {
  90.         return detail;
  91.     }
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement