This file contains hidden or 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
public SomeClass(StateParameter parameter) { | |
/* se você criou essa classe e espera que o construtor seja chamado de outra determinada classe, pq não deixar isso claro | |
* e ajudar a próxima pessoa? | |
*/ | |
//inclusive a linguagem podia abraçar e garantir o acoplamento em compilação | |
ForceSiteCall.from(Other.class); | |
//como você sabe o ponto de chamada, fica mais aberto você mexer no estado alheio. A ideia é ficar mais claro que essa classe só foi criada para ser usada naquele outro lugar. | |
parameter.chanceState(); |
This file contains hidden or 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
public class CaracteristicaRequest implements CriadorCaracteristica{ | |
new Produto(...., caracteristicasRequest) | |
} | |
public Produto(@NotNull Usuario usuario, | |
@NotNull Categoria categoria, | |
@NotEmpty String nome, | |
@Min(value = 1) BigDecimal valor, | |
@Min(value = 0) int quantidade, | |
@NotEmpty @Length(max = 1000) String descricao, |
This file contains hidden or 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
public CustomValidtor implements Validator { | |
public void validate(Object currentForm, Errors validationErrors) { | |
//O spring já espera que você mexa na referência de Errors passada com argumento e isso muda tudo. | |
if(...) { | |
validationErrors.rejectValue("fieldName","customKey", "defaultMessage"); | |
} | |
} | |
} | |
///// simulando o spring validator |
This file contains hidden or 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
//exemplo mexendo nas referências que não deveria | |
public class PagamentoController { | |
@Post("/pagamento/usuario/{usuarioId}") | |
public void aceita(@PathVariable("usuarioId") Long usuarioId,@Valid NovoPagamentoForm dadosPagamento) { | |
Usuario novoCliente = usuarioRepository.findyId(usuarioId); | |
//novoCliente.getPagamento() => Optional.empty aqui | |
novoPagamentoService.executa(novoCliente,dadosPagamento); | |
//novoCliente.getPagamento() => Optional(pagamento) | |
//como você ia saber que o estado foi alterado? |
This file contains hidden or 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
@RestController | |
public class TeamController { | |
@Autowired | |
private FormFlow formFlow; | |
@PostMapping(...) | |
public void save(@Valid NewTeamForm newTeamForm){ | |
formFlow.transform(newTeamForm).save().andThen(savedObject -> { |
This file contains hidden or 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
public class DataView<T> { | |
private T proxy; | |
private Trace trace; | |
private T original; | |
private Map<String, Object> complexValues = new HashMap<>(); | |
private DataView(T instance) { | |
Enhancer enhancer = new Enhancer(); | |
enhancer.setSuperclass(instance.getClass()); |
This file contains hidden or 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
public static void main(String[] args) { | |
Team team = new Team("instrutores"); | |
Cycle cycle = new Cycle("novo ciclo", LocalDate.now().minusDays(60), LocalDate.now()); | |
ArrayList<SupportStrategy> strategies = new ArrayList<>(); | |
strategies.add(new SupportStrategy("descricao")); | |
TeamCycle teamCycle = new TeamCycle(cycle, team, strategies); | |
System.out.println(DataView.of(teamCycle) | |
.add(TeamCycle :: getId) |
This file contains hidden or 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
<Form onSubmit={handleSubmit} subscription={{ submitting: true }} validate={validate}> | |
{({ handleSubmit2, submitting }) => ( | |
<form onSubmit={handleSubmit2} className={classes.form} noValidate> | |
<Field | |
autoComplete="email" | |
autoFocus | |
component={RFTextField} | |
disabled={submitting || sent} | |
fullWidth | |
label="Email" |
This file contains hidden or 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
<form action="/connect/facebook" method="POST"> | |
<input type="hidden" name="scope" value="email" /> | |
<p> | |
<button type="submit">Connect to Facebook</button> | |
</p> | |
</form> |
This file contains hidden or 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
@Controller | |
@Transactional | |
public class FacebookLoginController { | |
@Autowired | |
private Facebook facebook; | |
@RequestMapping(value = "/facebook/login", method = RequestMethod.GET) | |
public ModelAndView handleFacebookLogin(HttpServletResponse response) { | |
User profile = facebook.fetchObject("me", User.class, "id", "name", "link", "email"); |
NewerOlder