-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from shipping7/estimativa-api#77
Cria modelo para usar o serviço de estimativa do Correios
- Loading branch information
Showing
75 changed files
with
6,022 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=0.0.16-BETA | ||
version=0.0.17-BETA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package br.com.correios; | ||
|
||
import org.apache.commons.lang3.BooleanUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class BooleanStringfier { | ||
|
||
private TipoBooleanStringfier booleanToStringType; | ||
|
||
public BooleanStringfier(TipoBooleanStringfier booleanToStringType) { | ||
this.booleanToStringType = booleanToStringType; | ||
} | ||
|
||
public enum TipoBooleanStringfier { | ||
S_OU_N("S", "N"); | ||
|
||
private final String trueString; | ||
private final String falseString; | ||
|
||
private TipoBooleanStringfier(String trueString, String falseString) { | ||
this.trueString = trueString; | ||
this.falseString = falseString; | ||
} | ||
|
||
private boolean convertToBoolean(String text) { | ||
return BooleanUtils.toBoolean(text, trueString, falseString); | ||
} | ||
|
||
private String convertToString(boolean flag) { | ||
return BooleanUtils.toString(flag, trueString, falseString); | ||
} | ||
} | ||
|
||
public String convertToString(boolean flag) { | ||
return booleanToStringType.convertToString(flag); | ||
} | ||
|
||
public boolean convertToBoolean(String text) { | ||
return booleanToStringType.convertToBoolean(StringUtils.defaultIfBlank(text, booleanToStringType.falseString)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package br.com.correios; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Classe que representa o <b>CEP</b><br> | ||
* Sua formatacao deve ser de apenas 8 numeros. Ex: 99999999 | ||
* | ||
* @since 0.0.17-BETA | ||
*/ | ||
public class Cep { | ||
|
||
private final String value; | ||
|
||
public Cep(String value) { | ||
if (!Pattern.matches("\\d{8}", value)) { | ||
throw new IllegalArgumentException("O cep deve estar formatado somente com 8 numeros"); | ||
} | ||
|
||
this.value = value; | ||
} | ||
|
||
public String value() { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/br/com/correios/api/estimativa/CorreiosEstimativaAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package br.com.correios.api.estimativa; | ||
|
||
import br.com.correios.credentials.CorreiosCredenciais; | ||
import br.com.correios.estimativa.CResultadoToEstimativasConverter; | ||
import br.com.correios.estimativa.CServicoToEstimativaComPrazoConverter; | ||
import br.com.correios.estimativa.CServicoToEstimativaComPrecoEPrazoConverter; | ||
import br.com.correios.estimativa.EstimativaComPrazo; | ||
import br.com.correios.estimativa.EstimativaComPrecoEPrazo; | ||
import br.com.correios.webservice.estimativa.CalcPrecoPrazoWS; | ||
|
||
/** | ||
* Responsavel por chamar a API de estimativa do Correios para calcular | ||
* precos e prazos | ||
* | ||
* @since 0.0.17-BETA | ||
*/ | ||
public class CorreiosEstimativaAPI { | ||
|
||
private CorreiosServicoEstimativaAPI correiosServicoEstimativaAPI; | ||
|
||
public CorreiosEstimativaAPI(CorreiosCredenciais correiosCredenciais) { | ||
CResultadoToEstimativasConverter<EstimativaComPrecoEPrazo> precoEPrazoConverter = new CResultadoToEstimativasConverter<>(new CServicoToEstimativaComPrecoEPrazoConverter()); | ||
CResultadoToEstimativasConverter<EstimativaComPrazo> prazoConverter = new CResultadoToEstimativasConverter<>(new CServicoToEstimativaComPrazoConverter()); | ||
|
||
this.correiosServicoEstimativaAPI = new SoapCorreiosServicoEstimativaAPI(new CalcPrecoPrazoWS(), correiosCredenciais, precoEPrazoConverter, prazoConverter); | ||
} | ||
|
||
/** | ||
* @return Um builder para montar a requisicao para calcular preco e prazo | ||
*/ | ||
public RequisicaoEstimativaDePrecoEPrazoBuilder estimaPrecoEPrazo() { | ||
return new RequisicaoEstimativaDePrecoEPrazoBuilder(correiosServicoEstimativaAPI); | ||
} | ||
|
||
/** | ||
* @return Um builder para montar a requisicao para calcular somente prazo | ||
*/ | ||
public RequisicaoEstimativaDePrazoBuilder estimaPrazo() { | ||
return new RequisicaoEstimativaDePrazoBuilder(correiosServicoEstimativaAPI); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/br/com/correios/api/estimativa/CorreiosServicoEstimativaAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package br.com.correios.api.estimativa; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import br.com.correios.Cep; | ||
import br.com.correios.estimativa.DimensoesPacoteEstimado; | ||
import br.com.correios.estimativa.EstimativaComPrazo; | ||
import br.com.correios.estimativa.EstimativaComPrecoEPrazo; | ||
|
||
/** | ||
* Servico responsavel por acessar o servico do Correios | ||
* | ||
* @since 0.0.17-BETA | ||
*/ | ||
public interface CorreiosServicoEstimativaAPI { | ||
|
||
/** | ||
* @return estimativas com preco e prazo | ||
*/ | ||
List<EstimativaComPrecoEPrazo> calculaPrecoEPrazo(Set<String> codigosServico, Cep cepOrigem, Cep cepDestino, DimensoesPacoteEstimado dimensoesPacoteEstimado, BigDecimal valorDeclarado, boolean adicionaServicoMaoPropria, boolean adicionaServicoAvisoRecebimento); | ||
|
||
/** | ||
* @return estimativas somente com prazo | ||
*/ | ||
List<EstimativaComPrazo> calculaPrazo(Set<String> codigosServico, Cep cepOrigem, Cep cepDestino); | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/br/com/correios/api/estimativa/RequisicaoEstimativaDePrazoBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package br.com.correios.api.estimativa; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import com.google.common.collect.Sets; | ||
|
||
import br.com.correios.Cep; | ||
import br.com.correios.estimativa.EstimativaComPrazo; | ||
|
||
/** | ||
* Builder para construir a requisicao para estimativa de prazo. | ||
* | ||
* @since 0.0.17-BETA | ||
*/ | ||
public class RequisicaoEstimativaDePrazoBuilder { | ||
|
||
private CorreiosServicoEstimativaAPI correiosServicoEstimativaAPI; | ||
private Set<String> codigosServico; | ||
private Cep cepOrigem; | ||
private Cep cepDestino; | ||
|
||
RequisicaoEstimativaDePrazoBuilder(CorreiosServicoEstimativaAPI correiosServicoEstimativaAPI) { | ||
this.correiosServicoEstimativaAPI = correiosServicoEstimativaAPI; | ||
} | ||
|
||
/** | ||
* Informa o CEP de origem | ||
*/ | ||
public RequisicaoEstimativaDePrazoComCepOrigem de(Cep cepOrigem) { | ||
this.cepOrigem = cepOrigem; | ||
return new RequisicaoEstimativaDePrazoComCepOrigem(this); | ||
} | ||
|
||
public class RequisicaoEstimativaDePrazoComCepOrigem { | ||
|
||
private RequisicaoEstimativaDePrazoBuilder requisicaoEstimativaDePrazoBuilder; | ||
|
||
private RequisicaoEstimativaDePrazoComCepOrigem(RequisicaoEstimativaDePrazoBuilder requisicaoEstimativaDePrazoBuilder) { | ||
this.requisicaoEstimativaDePrazoBuilder = requisicaoEstimativaDePrazoBuilder; | ||
} | ||
|
||
/** | ||
* Informa o CEP de destino | ||
*/ | ||
public RequisicaoEstimativaDePrazoComCepDestino para(Cep cepDestino) { | ||
requisicaoEstimativaDePrazoBuilder.cepDestino = cepDestino; | ||
return new RequisicaoEstimativaDePrazoComCepDestino(requisicaoEstimativaDePrazoBuilder); | ||
} | ||
} | ||
|
||
public class RequisicaoEstimativaDePrazoComCepDestino { | ||
|
||
private RequisicaoEstimativaDePrazoBuilder requisicaoEstimativaDePrazoBuilder; | ||
|
||
private RequisicaoEstimativaDePrazoComCepDestino(RequisicaoEstimativaDePrazoBuilder requisicaoEstimativaDePrazoBuilder) { | ||
this.requisicaoEstimativaDePrazoBuilder = requisicaoEstimativaDePrazoBuilder; | ||
} | ||
|
||
/** | ||
* Informa os codigos dos servicos que serao calculados | ||
*/ | ||
public RequisicaoEstimativaDePrazoComServico comServicos(String...codigosServico) { | ||
requisicaoEstimativaDePrazoBuilder.codigosServico = Sets.newHashSet(codigosServico); | ||
return new RequisicaoEstimativaDePrazoComServico(); | ||
} | ||
} | ||
|
||
public class RequisicaoEstimativaDePrazoComServico { | ||
|
||
/** | ||
* @return as estimativas calculadas somente com prazo | ||
*/ | ||
public List<EstimativaComPrazo> calcula() { | ||
return correiosServicoEstimativaAPI.calculaPrazo(codigosServico, cepOrigem, cepDestino); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.