| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Arquivo | 
 | 
 | 1.5333333333333334;1,533 | 
| 1 |  /** | |
| 2 |   * Copyright 2008 WebPhotos | |
| 3 |   * | |
| 4 |   * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 |   * you may not use this file except in compliance with the License. | |
| 6 |   * You may obtain a copy of the License at | |
| 7 |   * | |
| 8 |   *      http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 |   * | |
| 10 |   * Unless required by applicable law or agreed to in writing, software | |
| 11 |   * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 |   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 |   * See the License for the specific language governing permissions and | |
| 14 |   * limitations under the License. | |
| 15 |   */ | |
| 16 |  package net.sf.webphotos.util.legacy; | |
| 17 | ||
| 18 |  import java.io.File; | |
| 19 |  import java.util.List; | |
| 20 |  import net.sf.webphotos.util.Util; | |
| 21 | ||
| 22 |  /** | |
| 23 |   * Objeto que contém os dados do arquivo usados na tabela FtpClient | |
| 24 |   * @author guilherme | |
| 25 |   */ | |
| 26 | public class Arquivo { | |
| 27 | ||
| 28 | 0 |      private String linhaComando = ""; | 
| 29 | 0 |      private int acao = -1; | 
| 30 | 0 |      private String nomeAcao = ""; | 
| 31 | 0 |      private int albumID = -1; | 
| 32 | 0 |      private int fotoID = -1; | 
| 33 | 0 |      private String nmArquivo = ""; | 
| 34 | 0 |      private long tamanho = 0; | 
| 35 | 0 |      private String status = ""; | 
| 36 |      private File arqFoto; | |
| 37 | ||
| 38 |      /** | |
| 39 |       * Cria uma nova instância para o Arquivo | |
| 40 |       */ | |
| 41 | 0 |      public Arquivo() { | 
| 42 | 0 |      } | 
| 43 | ||
| 44 |      /** | |
| 45 |       * Verifica qual operação deverá ser feita com o arquivo e caso seja Upload ele enviará o arquivo para o local especificado | |
| 46 |       * @param linha Linha de comando | |
| 47 |       * @param operacao Tipo de ação a ser seguida | |
| 48 |       * @param album Identificação do album | |
| 49 |       * @param foto Identificação da foto | |
| 50 |       * @param nomeArquivo Nome do arqvuio | |
| 51 |       */ | |
| 52 | 0 |      public Arquivo(String linha, int operacao, int album, int foto, String nomeArquivo) { | 
| 53 | 0 |          linhaComando = linha; | 
| 54 | 0 |          acao = operacao; | 
| 55 | 0 |          albumID = album; | 
| 56 | 0 |          fotoID = foto; | 
| 57 | 0 |          nmArquivo = nomeArquivo; | 
| 58 | 0 |          status = "??"; | 
| 59 | ||
| 60 | 0 |          if (operacao == CacheFTP.DELETE) { | 
| 61 | 0 |              nomeAcao = "apagar"; | 
| 62 | } | |
| 63 | 0 |          if (operacao == CacheFTP.DOWNLOAD) { | 
| 64 | 0 |              nomeAcao = "receber"; | 
| 65 | } | |
| 66 | ||
| 67 | 0 |          if (operacao == CacheFTP.UPLOAD) { | 
| 68 | 0 |              nomeAcao = "enviar"; | 
| 69 | 0 |              arqFoto = new File(Util.getAlbunsRoot(), albumID + File.separator + nmArquivo); | 
| 70 | 0 |              if (arqFoto.isFile() && arqFoto.canRead()) { | 
| 71 | 0 |                  tamanho = arqFoto.length(); | 
| 72 |              } else { | |
| 73 | 0 |                  tamanho = 0; | 
| 74 | } | |
| 75 |          } else { | |
| 76 | 0 |              tamanho = 0; | 
| 77 | } | |
| 78 | 0 |      } | 
| 79 | ||
| 80 |      /** | |
| 81 |       * Verifica qual operação deverá ser acionada para o arquivo | |
| 82 |       * @param linha Linha de comando | |
| 83 |       * @param operacao Tipo de ação a ser seguida | |
| 84 |       * @param album Identificação do album | |
| 85 |       * @param foto Identificação da foto | |
| 86 |       * @param nomeArquivo Nome do arqvuio | |
| 87 |       * @param tam Tamanho do arquivo do arqvuio | |
| 88 |       */ | |
| 89 | 0 |      public Arquivo(String linha, int operacao, int album, int foto, String nomeArquivo, long tam) { | 
| 90 | 0 |          linhaComando = linha; | 
| 91 | 0 |          acao = operacao; | 
| 92 | 0 |          albumID = album; | 
| 93 | 0 |          fotoID = foto; | 
| 94 | 0 |          nmArquivo = nomeArquivo; | 
| 95 | 0 |          status = "??"; | 
| 96 | 0 |          switch (operacao) { | 
| 97 |              case CacheFTP.DELETE: | |
| 98 | 0 |                  nomeAcao = "apagar"; | 
| 99 | 0 |                  break; | 
| 100 |              case CacheFTP.DOWNLOAD: | |
| 101 | 0 |                  nomeAcao = "receber"; | 
| 102 | 0 |                  break; | 
| 103 |              case CacheFTP.UPLOAD: | |
| 104 | 0 |                  nomeAcao = "enviar"; | 
| 105 |                  break; | |
| 106 | } | |
| 107 | 0 |          tamanho = tam; | 
| 108 | 0 |      } | 
| 109 | ||
| 110 |      /** | |
| 111 |       * <pre> | |
| 112 |       * Constructor thar loads the data from a {@link java.util.List List} | |
| 113 |       * List Data Format | |
| 114 |       * Position 0: Status | |
| 115 |       * Position 1: nomeAcao | |
| 116 |       * Position 2: albumID | |
| 117 |       * Position 3: fotoID | |
| 118 |       * Position 4: nmArquivo | |
| 119 |       * Position 5: tamanho | |
| 120 |       * </pre> | |
| 121 |       *  | |
| 122 |       * TODO: review | |
| 123 |       * @param _data photo data | |
| 124 |       */ | |
| 125 |      @SuppressWarnings("unchecked") | |
| 126 | 0 |      public Arquivo(final List<String> data) { | 
| 127 | 0 |          status = data.get(0).toString(); | 
| 128 | 0 |          nomeAcao = data.get(1).toString(); | 
| 129 | 0 |          albumID = Integer.parseInt(data.get(2).toString()); | 
| 130 | 0 |          fotoID = Integer.parseInt(data.get(3).toString()); | 
| 131 | 0 |          nmArquivo = data.get(4).toString(); | 
| 132 | 0 |          tamanho = Integer.parseInt(data.get(5).toString()); | 
| 133 | 0 |      } | 
| 134 | ||
| 135 |      /** | |
| 136 |       * Retorna a variável status | |
| 137 |       * @return status | |
| 138 |       */ | |
| 139 |      public String getStatus() { | |
| 140 | 0 |          return status; | 
| 141 | } | |
| 142 | ||
| 143 |      /** | |
| 144 |       * Retorna variável linhaComando | |
| 145 |       * @return Linha de comando | |
| 146 |       */ | |
| 147 |      public String getLinhaComando() { | |
| 148 | 0 |          return linhaComando; | 
| 149 | } | |
| 150 | ||
| 151 |      /** | |
| 152 |       * Passa a variável valor para a variável status | |
| 153 |       * @param valor valor usado | |
| 154 |       */ | |
| 155 | public void setStatus(String valor) { | |
| 156 | 0 |          status = valor; | 
| 157 | 0 |      } | 
| 158 | ||
| 159 |      /** | |
| 160 |       * Retorna a variável acao(indica qual operação deverá ser acionada) | |
| 161 |       * @return retorna acao | |
| 162 |       */ | |
| 163 | public int getAcao() { | |
| 164 | 0 |          return acao; | 
| 165 | } | |
| 166 | ||
| 167 |      /** | |
| 168 |       * Retorna variável  acao(indica qual operação deverá ser acionada) | |
| 169 |       * @return retorna nome da ação | |
| 170 |       */ | |
| 171 |      public String getNomeAcao() { | |
| 172 | 0 |          return nomeAcao; | 
| 173 | } | |
| 174 | ||
| 175 |      /** | |
| 176 |       * Retorna variável albumID(identificação do album) | |
| 177 |       * @return retorna id ao album | |
| 178 |       */ | |
| 179 | public int getAlbumID() { | |
| 180 | 0 |          return albumID; | 
| 181 | } | |
| 182 | ||
| 183 |      /** | |
| 184 |       * Retorna variável fotoID | |
| 185 |       * @return retorna id da foto | |
| 186 |       */ | |
| 187 | public int getFotoID() { | |
| 188 | 0 |          return fotoID; | 
| 189 | } | |
| 190 | ||
| 191 |      /** | |
| 192 |       * Retorna variável nmArquivo(Nome do arquivo) | |
| 193 |       * @return retorna nome do arquivo | |
| 194 |       */ | |
| 195 |      public String getNomeArquivo() { | |
| 196 | 0 |          return nmArquivo; | 
| 197 | } | |
| 198 | ||
| 199 |      /** | |
| 200 |       * Retorna variável tamanho(tamanho do arquivo no qual será utilizado) | |
| 201 |       * @return retorna tamanho do arquivo | |
| 202 |       */ | |
| 203 | public long getTamanho() { | |
| 204 | 0 |          return tamanho; | 
| 205 | } | |
| 206 | ||
| 207 |      /** | |
| 208 |       * Passa a variável valor para a variável tamanho | |
| 209 |       * @param valor valor a ser usado | |
| 210 |       */ | |
| 211 | public void setTamanho(long valor) { | |
| 212 | 0 |          tamanho = valor; | 
| 213 | 0 |      } | 
| 214 | ||
| 215 |      /** | |
| 216 |       * Concatena e retorna as variáveis acao,albumID,fotoID e tamanho | |
| 217 |       * @return Retorna as variáveis acao,albumID,fotoID e tamanho | |
| 218 |       */ | |
| 219 | @Override | |
| 220 |      public String toString() { | |
| 221 | 0 |          return status + " " + acao + " " + albumID + " " + fotoID + " " + tamanho; | 
| 222 | } | |
| 223 | } |