View Javadoc

1   package ecar.dao;
2   
3   import java.util.Iterator;
4   import java.util.List;
5   
6   import javax.servlet.http.HttpServletRequest;
7   
8   import org.apache.commons.fileupload.FileItem;
9   
10  import comum.database.Dao;
11  import comum.util.FileUpload;
12  
13  import ecar.exception.ECARException;
14  import ecar.pojo.Cor;
15  import ecar.pojo.CorTipoFuncAcompCtfa;
16  import ecar.pojo.CorTipoFuncAcompCtfaPK;
17  import ecar.pojo.TipoFuncAcompTpfa;
18  
19  /**
20   * @author rogerio
21   * @since 28/02/2007
22   */
23  public class CorTipoFuncAcompDao extends Dao {
24  
25    /**
26     * Construtor. Chama o Session factory do Hibernate.
27     * @param request
28     */
29    public CorTipoFuncAcompDao(HttpServletRequest request) {
30      super();
31      this.request = request;
32    } // fim construtor
33  
34    /**
35     * Salva o objeto CorTipoFuncAcompCtfa.
36     * @author rogerio
37     * @since 0.1, 28/02/2007
38     * @version 0.1, 28/02/2007
39     * @param ctfa
40     * @throws ECARException
41     */
42    public void salvar(CorTipoFuncAcompCtfa ctfa) throws ECARException {
43      super.salvar(ctfa);
44    } // fim salvar
45  
46    /**
47     * Cria a lista das imagens da cor do tipo função de acompanhamento (ctfa) no
48     * banco de dados.<br>
49     * @author rogerio
50     * @since 0.1, 28/02/2007
51     * @version 0.1, 28/02/2007
52     * @param posicao
53     * @param listFuncao
54     * @param listCampo
55     * @return List
56     * @throws ECARException
57     */
58    public List criarListaCorTipoFuncAcomp(String posicao, List listFuncao, List listCampo, Cor cor, List currentList) throws ECARException {
59      Iterator itf = listFuncao.iterator();
60      Iterator itc = null;
61  
62      while (itf.hasNext()) {
63        TipoFuncAcompTpfa tfa = (TipoFuncAcompTpfa) itf.next();
64  
65        CorTipoFuncAcompCtfaPK ctfapk = new CorTipoFuncAcompCtfaPK();
66        ctfapk.setCodCor(cor.getCodCor());
67        ctfapk.setCodTpfa(tfa.getCodTpfa());
68        ctfapk.setPosicaoCtfa(posicao);
69        CorTipoFuncAcompCtfa ctfa = null;
70  
71        /*
72         * -- Foi necessário tratar com try/ catch pois ao pesquisar e não
73         * encontrar, o método retorna uma exception. --
74         */
75        try {
76          ctfa = (CorTipoFuncAcompCtfa) this.buscar(CorTipoFuncAcompCtfa.class, ctfapk);
77        } catch (ECARException e) {
78          ctfa = new CorTipoFuncAcompCtfa();
79          ctfa.setComp_id(ctfapk);
80          ctfa.setCor(cor);
81          ctfa.setTipoFuncAcompTpfa(tfa);
82          ctfa.setPosicaoCtfa(posicao);
83        }
84  
85        itc = listCampo.iterator();
86        while (itc.hasNext()) {
87          FileItem file = (FileItem) itc.next();
88          String fieldName = posicao + "-" + tfa.getCodTpfa();
89  
90          // registra no banco
91          if (fieldName.equals(file.getFieldName()) && (file.getName() != null && !"".equals(file.getName().trim()))) {
92            ctfa.setCaminhoImagemCtfa(FileUpload.getNomeArquivo(file));
93            currentList.add(ctfa);
94          }
95        }
96      }
97  
98      return currentList;
99    } // fim salvarImagemCorTipoFuncAcomp()
100 } // fim class