Last active
May 2, 2022 02:40
-
-
Save gustavopinto/10e995bc13915c72619d4fbd55c4a8f7 to your computer and use it in GitHub Desktop.
Exemplos refatorações CDD
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
public void method() { | |
final EarlyAlert saved = getDao().save(earlyAlert); | |
sendMessageToAdvisorService.sendMessageToAdvisor( | |
saved, earlyAlert.getEmailCC(), LOGGER); | |
} |
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
public void method() { | |
final EarlyAlert saved = getDao().save(earlyAlert); | |
try { | |
sendMessageToAdvisor(saved, earlyAlert.getEmailCC()); | |
} catch (final SendFailedException e) { | |
LOGGER.warn("Could not send Early Alert message to advisor.", e); | |
throw new ValidationException("Early Alert was NOT created.", e); | |
} | |
} |
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
public List<String> variables() { | |
List<String> variables = new ArrayList<>(); | |
variables.addAll(this.queriesTemplate.getAllValues()); | |
variables.addAll(this.headersTemplate.getAllValues()); | |
if (this.bodyTemplate != null) { | |
variables.addAll(this.bodyTemplate.getVariables()); | |
} | |
return variables; | |
} |
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
public List<String> variables() { | |
List<String> variables = new ArrayList<>(); | |
for (QueryTemplate queryTemplate : this.queries.values()) { | |
variables.addAll(queryTemplate.getVariables()); | |
} | |
for (HeaderTemplate headerTemplate : this.headers.values()) { | |
variables.addAll(headerTemplate.getVariables()); | |
} | |
if (this.bodyTemplate != null) { | |
variables.addAll(this.bodyTemplate.getVariables()); | |
} | |
return variables; | |
} |
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
public Map<String, Object> fillTemplateParameters( | |
@NotNull final EarlyAlert earlyAlert) { | |
EarlyAlertValidation.checkIsNull(earlyAlert); | |
EarlyAlertValidation.checkCreatedBy(earlyAlert); | |
EarlyAlertValidation.checkCampus(earlyAlert); | |
} |
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
public EarlyAlert create(@NotNull final EarlyAlert earlyAlert) { | |
if (earlyAlert.getPerson() == null) { | |
throw new ValidationException("Person is missing."); | |
} | |
if (earlyAlert.getCreatedBy() == null) { | |
throw new ValidationException("CreeatedBy is missing."); | |
} | |
if (earlyAlert.getCampus() == null) { | |
throw new ValidationException("Campus is missing."); | |
} | |
} |
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
public void method() { | |
for (BaseStudentReportTO person:persons) { | |
if (!map.containsKey(person.getSchoolId()) | |
&& StringUtils.isNotBlank(person.getCoachSchoolId()) | |
&& personSearchForm.getJournalSourceIds() == null | |
&& getDao().getJournalCountForPersonForJournalSourceIds(person.getId(), personSearchForm.getJournalSourceIds()) != 0) { | |
final JournalCaseNotesStudentReportTO entry = new JournalCaseNotesStudentReportTO(person); | |
personsWithJournalEntries.add(entry); | |
map.put(entry.getSchoolId(), entry); | |
} | |
} | |
} |
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
public void method() { | |
for (BaseStudentReportTO person:persons) { | |
if (!map.containsKey(person.getSchoolId()) && StringUtils.isNotBlank(person.getCoachSchoolId())) { | |
boolean addStudent = true; | |
if (personSearchForm.getJournalSourceIds()!=null) { | |
if (getDao().getJournalCountForPersonForJournalSourceIds(person.getId(), personSearchForm.getJournalSourceIds()) == 0) { | |
addStudent = false; | |
} | |
} | |
if (addStudent) { | |
final JournalCaseNotesStudentReportTO entry = new JournalCaseNotesStudentReportTO(person); | |
personsWithJournalEntries.add(entry); | |
map.put(entry.getSchoolId(), entry); | |
} | |
} | |
} | |
} |
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
public void method() { | |
for(UUID coachId: easByCoach.keySet()){ | |
Map<String,Object> messageParams = new HashMap<>(); | |
easByCoach.get(coachId).sort(MessageParamsComparator::compareParams); | |
} | |
} | |
public class MessageParamsComparator { | |
public int compare(EarlyAlertTO p1, EarlyAlertTO p2) { | |
Date p1Date = p1.getLastResponseDate(); | |
if (p1Date == null) | |
p1Date = p1.getCreatedDate(); | |
Date p2Date = p2.getLastResponseDate(); | |
if (p2Date == null) | |
p2Date = p2.getCreatedDate(); | |
return p1Date.compareTo(p2Date); | |
} | |
} |
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
public void method() { | |
for(UUID coachId: easByCoach.keySet()){ | |
Map<String,Object> messageParams = new HashMap<String,Object>(); | |
Collections.sort(easByCoach.get(coachId), new Comparator<EarlyAlertTO>() { | |
@Override | |
public int compare(EarlyAlertTO p1, EarlyAlertTO p2) { | |
Date p1Date = p1.getLastResponseDate(); | |
if (p1Date == null) | |
p1Date = p1.getCreatedDate(); | |
Date p2Date = p2.getLastResponseDate(); | |
if (p2Date == null) | |
p2Date = p2.getCreatedDate(); | |
return p1Date.compareTo(p2Date); | |
} | |
}); | |
} | |
} |
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
import java.io.Serializable; | |
import java.net.URI; | |
import java.nio.charset.Charset; | |
import feign.Request.HttpMethod; | |
import feign.template.BodyTemplate; | |
import feign.template.HeaderTemplate; | |
import feign.template.TemplateChunk; | |
import feign.template.UriTemplate; | |
import feign.template.UriUtils; | |
import static feign.Util.CONTENT_LENGTH; | |
import static feign.Util.checkNotNull; |
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
import java.io.Serializable; | |
import java.net.URI; | |
import java.nio.charset.Charset; | |
import feign.Request.HttpMethod; | |
import feign.template.*; | |
import static feign.Util.*; |
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
public static RequestTemplate from(RequestTemplate requestTemplate) { | |
RequestTemplate template = new RequestTemplate(...); | |
template.queriesTemplate.putIfEmpty(requestTemplate.queriesTemplate); | |
template.headersTemplate.putIfEmpty(requestTemplate.headersTemplate); | |
return template; | |
} |
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
public static RequestTemplate from(RequestTemplate requestTemplate) { | |
RequestTemplate template = new RequestTemplate(...); | |
if (!requestTemplate.queries().isEmpty()) { | |
template.queries.putAll(requestTemplate.queries); | |
} | |
if (!requestTemplate.headers().isEmpty()) { | |
template.headers.putAll(requestTemplate.headers); | |
} | |
return template; | |
} |
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
public Request request() { | |
Asserts.booleanStateMustBeTrue(this.resolved, "template has not been resolved."); | |
return Request.create(method, url(), headers(), body, this); | |
} |
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
public Request request() { | |
if (!this.resolved) { | |
throw new IllegalStateException("template has not been resolved."); | |
} | |
return Request.create(method, url(), headers(), body, this); | |
} |
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
public String method() { | |
return Optional.ofNullable(method).map(HttpMethod::name).orElse(null); | |
} |
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
public String method() { | |
return (method != null) ? method.name() : null; | |
} |
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
public String url() { | |
return PathBuilder.withAllQueryParameters(this); | |
} | |
public class PathBuilder { | |
public static String withAllQueryParameters (RequestTemplate requestTemplate) { ... } | |
} |
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
public String url() { | |
StringBuilder url = new StringBuilder(this.path()); | |
if (!this.queries.isEmpty()) { | |
url.append(this.queryLine()); | |
} | |
if (fragment != null) { | |
url.append(fragment); | |
} | |
return url.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment