Validating variables/fields from a schema object The 2019 Stack Overflow Developer Survey...
Falsification in Math vs Science
How to type this arrow in math mode?
Return to UK after being refused entry years previously
If a Druid sees an animal’s corpse, can they wild shape into that animal?
Does a dangling wire really electrocute me if I'm standing in water?
Why hard-Brexiteers don't insist on a hard border to prevent illegal immigration after Brexit?
Are there any other methods to apply to solving simultaneous equations?
Can someone be penalized for an "unlawful" act if no penalty is specified?
Is there any way to tell whether the shot is going to hit you or not?
Lightning Grid - Columns and Rows?
What does ひと匙 mean in this manga and has it been used colloquially?
A poker game description that does not feel gimmicky
How come people say “Would of”?
The difference between dialogue marks
What tool would a Roman-age civilization have for the breaking of silver and other metals into dust?
Why isn't airport relocation done gradually?
Why didn't the Event Horizon Telescope team mention Sagittarius A*?
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
What is the motivation for a law requiring 2 parties to consent for recording a conversation
How are circuits which use complex ICs normally simulated?
Why do UK politicians seemingly ignore opinion polls on Brexit?
Do these rules for Critical Successes and Critical Failures seem Fair?
Are spiders unable to hurt humans, especially very small spiders?
Why do we hear so much about the Trump administration deciding to impose and then remove tariffs?
Validating variables/fields from a schema object
The 2019 Stack Overflow Developer Survey Results Are InNull Object pattern with simple class hierarchyMax heap in JavaEfficient way of sorting a List based on multiple properties using Google GuavaListening to modifications on variablesJava class for creating HeadPhone class and Test classChecking for existence of object by id, name, display name, or web idDeserializing a customly formatted stringData processing programThread-safe Java class for managing XML files <> domain modelsCombine data from a list and map based on criteria
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
Can someone help me to create a generic method that validates common fields/variables comes from multiple objects, if that is possible?
The below code validates some bunch of variables/fields from a schema object, so here the requirement is I have two different schema objects which has common Fields/variables, Is it possible to validate these variables in more generic way. In below code there is two events FI & Profile (Note: Future can be more events like these) these are two different schema objects but has same fields/variables of same Object "Types".
public class RequestValidation {
public void validateRequest(EventRequest eventRequest) {
//FI Event
FIEventProcessorImpl fiEventProcessor = new FIEventProcessorImpl();
FIEventSchema fiEvent = fiEventProcessor.getFiEventSchema(eventRequest);
//Party data Validation
String partyFName = null;
String partyLName = null;
String partyEmail = null;
String partyId = null;
if (null != fiEvent.getParty()) {
partyId = fiEvent.getParty().getPartyId();
if (null != fiEvent.getParty().getPartyName()
&& null != fiEvent.getParty().getPartyName().getName()) {
partyFName = fiEvent.getParty().getPartyName().getName().getGivenName();
partyLName = fiEvent.getParty().getPartyName().getName().getSurname();
if (null == partyFName && null == partyLName) {
Map<String, Object> nameMap = fiEvent.getParty().getPartyName().getName()
.getAdditionalProperties();
if (!nameMap.isEmpty()) {
partyFName = getAdditionalProperty(nameMap, "first_name");
partyLName = getAdditionalProperty(nameMap, "last_name");
}
}
}
if (null != fiEvent.getParty().getPartyEmail()) {
partyEmail = fiEvent.getParty().getPartyEmail().getEmailAddress();
if(null == partyEmail || partyEmail.isEmpty()){
//Logging missing field value logic
}
}
}
if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty()
|| null == partyId || partyId.isEmpty()) {
//Logging missing field value logic
}
//Application Context data Validation
String score = null;
String clientId = null;
if(null != fiEvent.getApplicationContext() && null != fiEvent.getApplicationContext().getContextItems()){
List<ContextItem> contextItems = fiEvent.getApplicationContext().getContextItems();
if(null != contextItems && !contextItems.isEmpty()){
socialScore = getContextValue(contextItems, "SCORE");
clientFp = getContextValue(contextItems, "CLIENT_ID");
}
}
if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) {
//Logging missing field value logic
}
//ProfileChange Event
ProfileProcessorImpl eventProcessor = new ProfileProcessorImpl();
ProfileEventSchema profileevent = eventProcessor.getProfileEventSchema(eventRequest);
//Party data Validation
if (null != profileevent.getParty()) {
partyId = profileevent.getParty().getPartyId();
if (null != profileevent.getParty().getPartyName()
&& null != profileevent.getParty().getPartyName().getName()) {
partyFName = profileevent.getParty().getPartyName().getName().getGivenName();
partyLName = profileevent.getParty().getPartyName().getName().getSurname();
if (null == partyFName && null == partyLName) {
Map<String, Object> nameMap = profileevent.getParty().getPartyName().getName()
.getAdditionalProperties();
if (!nameMap.isEmpty()) {
partyFName = getAdditionalProperty(nameMap, "first_name");
partyLName = getAdditionalProperty(nameMap, "last_name");
}
}
}
if (null != profileevent.getParty().getPartyEmail()) {
partyEmail = profileevent.getParty().getPartyEmail().getEmailAddress();
if(null == partyEmail || partyEmail.isEmpty()){
//Logging missing field value logic
}
}
}
if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty()
|| null == partyId || partyId.isEmpty()) {
//Logging missing field value logic
}
//Application Context data Validation
if(null != profileevent.getApplicationContext() && null != profileevent.getApplicationContext().getContextItems()){
List<ContextItem> contextItems = profileevent.getApplicationContext().getContextItems();
if(null != contextItems && !contextItems.isEmpty()){
socialScore = getContextValue(contextItems, "SCORE");
clientFp = getContextValue(contextItems, "CLIENT_ID");
}
}
if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) {
//Logging missing field value logic
}
}
private String getContextValue(List<ContextItem> contextItems, String key) {
String value = null;
for(ContextItem contextItem : contextItems){
if(contextItem.getKey().equalsIgnoreCase(key)){
value = contextItem.getValue();
}
}
return value.toString();
}
private String getAdditionalProperty(Map<String, ?> map, String key) {
Object value = map.get(key);
return value == null ? null : value.toString();
}
}
java
New contributor
$endgroup$
add a comment |
$begingroup$
Can someone help me to create a generic method that validates common fields/variables comes from multiple objects, if that is possible?
The below code validates some bunch of variables/fields from a schema object, so here the requirement is I have two different schema objects which has common Fields/variables, Is it possible to validate these variables in more generic way. In below code there is two events FI & Profile (Note: Future can be more events like these) these are two different schema objects but has same fields/variables of same Object "Types".
public class RequestValidation {
public void validateRequest(EventRequest eventRequest) {
//FI Event
FIEventProcessorImpl fiEventProcessor = new FIEventProcessorImpl();
FIEventSchema fiEvent = fiEventProcessor.getFiEventSchema(eventRequest);
//Party data Validation
String partyFName = null;
String partyLName = null;
String partyEmail = null;
String partyId = null;
if (null != fiEvent.getParty()) {
partyId = fiEvent.getParty().getPartyId();
if (null != fiEvent.getParty().getPartyName()
&& null != fiEvent.getParty().getPartyName().getName()) {
partyFName = fiEvent.getParty().getPartyName().getName().getGivenName();
partyLName = fiEvent.getParty().getPartyName().getName().getSurname();
if (null == partyFName && null == partyLName) {
Map<String, Object> nameMap = fiEvent.getParty().getPartyName().getName()
.getAdditionalProperties();
if (!nameMap.isEmpty()) {
partyFName = getAdditionalProperty(nameMap, "first_name");
partyLName = getAdditionalProperty(nameMap, "last_name");
}
}
}
if (null != fiEvent.getParty().getPartyEmail()) {
partyEmail = fiEvent.getParty().getPartyEmail().getEmailAddress();
if(null == partyEmail || partyEmail.isEmpty()){
//Logging missing field value logic
}
}
}
if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty()
|| null == partyId || partyId.isEmpty()) {
//Logging missing field value logic
}
//Application Context data Validation
String score = null;
String clientId = null;
if(null != fiEvent.getApplicationContext() && null != fiEvent.getApplicationContext().getContextItems()){
List<ContextItem> contextItems = fiEvent.getApplicationContext().getContextItems();
if(null != contextItems && !contextItems.isEmpty()){
socialScore = getContextValue(contextItems, "SCORE");
clientFp = getContextValue(contextItems, "CLIENT_ID");
}
}
if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) {
//Logging missing field value logic
}
//ProfileChange Event
ProfileProcessorImpl eventProcessor = new ProfileProcessorImpl();
ProfileEventSchema profileevent = eventProcessor.getProfileEventSchema(eventRequest);
//Party data Validation
if (null != profileevent.getParty()) {
partyId = profileevent.getParty().getPartyId();
if (null != profileevent.getParty().getPartyName()
&& null != profileevent.getParty().getPartyName().getName()) {
partyFName = profileevent.getParty().getPartyName().getName().getGivenName();
partyLName = profileevent.getParty().getPartyName().getName().getSurname();
if (null == partyFName && null == partyLName) {
Map<String, Object> nameMap = profileevent.getParty().getPartyName().getName()
.getAdditionalProperties();
if (!nameMap.isEmpty()) {
partyFName = getAdditionalProperty(nameMap, "first_name");
partyLName = getAdditionalProperty(nameMap, "last_name");
}
}
}
if (null != profileevent.getParty().getPartyEmail()) {
partyEmail = profileevent.getParty().getPartyEmail().getEmailAddress();
if(null == partyEmail || partyEmail.isEmpty()){
//Logging missing field value logic
}
}
}
if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty()
|| null == partyId || partyId.isEmpty()) {
//Logging missing field value logic
}
//Application Context data Validation
if(null != profileevent.getApplicationContext() && null != profileevent.getApplicationContext().getContextItems()){
List<ContextItem> contextItems = profileevent.getApplicationContext().getContextItems();
if(null != contextItems && !contextItems.isEmpty()){
socialScore = getContextValue(contextItems, "SCORE");
clientFp = getContextValue(contextItems, "CLIENT_ID");
}
}
if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) {
//Logging missing field value logic
}
}
private String getContextValue(List<ContextItem> contextItems, String key) {
String value = null;
for(ContextItem contextItem : contextItems){
if(contextItem.getKey().equalsIgnoreCase(key)){
value = contextItem.getValue();
}
}
return value.toString();
}
private String getAdditionalProperty(Map<String, ?> map, String key) {
Object value = map.get(key);
return value == null ? null : value.toString();
}
}
java
New contributor
$endgroup$
add a comment |
$begingroup$
Can someone help me to create a generic method that validates common fields/variables comes from multiple objects, if that is possible?
The below code validates some bunch of variables/fields from a schema object, so here the requirement is I have two different schema objects which has common Fields/variables, Is it possible to validate these variables in more generic way. In below code there is two events FI & Profile (Note: Future can be more events like these) these are two different schema objects but has same fields/variables of same Object "Types".
public class RequestValidation {
public void validateRequest(EventRequest eventRequest) {
//FI Event
FIEventProcessorImpl fiEventProcessor = new FIEventProcessorImpl();
FIEventSchema fiEvent = fiEventProcessor.getFiEventSchema(eventRequest);
//Party data Validation
String partyFName = null;
String partyLName = null;
String partyEmail = null;
String partyId = null;
if (null != fiEvent.getParty()) {
partyId = fiEvent.getParty().getPartyId();
if (null != fiEvent.getParty().getPartyName()
&& null != fiEvent.getParty().getPartyName().getName()) {
partyFName = fiEvent.getParty().getPartyName().getName().getGivenName();
partyLName = fiEvent.getParty().getPartyName().getName().getSurname();
if (null == partyFName && null == partyLName) {
Map<String, Object> nameMap = fiEvent.getParty().getPartyName().getName()
.getAdditionalProperties();
if (!nameMap.isEmpty()) {
partyFName = getAdditionalProperty(nameMap, "first_name");
partyLName = getAdditionalProperty(nameMap, "last_name");
}
}
}
if (null != fiEvent.getParty().getPartyEmail()) {
partyEmail = fiEvent.getParty().getPartyEmail().getEmailAddress();
if(null == partyEmail || partyEmail.isEmpty()){
//Logging missing field value logic
}
}
}
if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty()
|| null == partyId || partyId.isEmpty()) {
//Logging missing field value logic
}
//Application Context data Validation
String score = null;
String clientId = null;
if(null != fiEvent.getApplicationContext() && null != fiEvent.getApplicationContext().getContextItems()){
List<ContextItem> contextItems = fiEvent.getApplicationContext().getContextItems();
if(null != contextItems && !contextItems.isEmpty()){
socialScore = getContextValue(contextItems, "SCORE");
clientFp = getContextValue(contextItems, "CLIENT_ID");
}
}
if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) {
//Logging missing field value logic
}
//ProfileChange Event
ProfileProcessorImpl eventProcessor = new ProfileProcessorImpl();
ProfileEventSchema profileevent = eventProcessor.getProfileEventSchema(eventRequest);
//Party data Validation
if (null != profileevent.getParty()) {
partyId = profileevent.getParty().getPartyId();
if (null != profileevent.getParty().getPartyName()
&& null != profileevent.getParty().getPartyName().getName()) {
partyFName = profileevent.getParty().getPartyName().getName().getGivenName();
partyLName = profileevent.getParty().getPartyName().getName().getSurname();
if (null == partyFName && null == partyLName) {
Map<String, Object> nameMap = profileevent.getParty().getPartyName().getName()
.getAdditionalProperties();
if (!nameMap.isEmpty()) {
partyFName = getAdditionalProperty(nameMap, "first_name");
partyLName = getAdditionalProperty(nameMap, "last_name");
}
}
}
if (null != profileevent.getParty().getPartyEmail()) {
partyEmail = profileevent.getParty().getPartyEmail().getEmailAddress();
if(null == partyEmail || partyEmail.isEmpty()){
//Logging missing field value logic
}
}
}
if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty()
|| null == partyId || partyId.isEmpty()) {
//Logging missing field value logic
}
//Application Context data Validation
if(null != profileevent.getApplicationContext() && null != profileevent.getApplicationContext().getContextItems()){
List<ContextItem> contextItems = profileevent.getApplicationContext().getContextItems();
if(null != contextItems && !contextItems.isEmpty()){
socialScore = getContextValue(contextItems, "SCORE");
clientFp = getContextValue(contextItems, "CLIENT_ID");
}
}
if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) {
//Logging missing field value logic
}
}
private String getContextValue(List<ContextItem> contextItems, String key) {
String value = null;
for(ContextItem contextItem : contextItems){
if(contextItem.getKey().equalsIgnoreCase(key)){
value = contextItem.getValue();
}
}
return value.toString();
}
private String getAdditionalProperty(Map<String, ?> map, String key) {
Object value = map.get(key);
return value == null ? null : value.toString();
}
}
java
New contributor
$endgroup$
Can someone help me to create a generic method that validates common fields/variables comes from multiple objects, if that is possible?
The below code validates some bunch of variables/fields from a schema object, so here the requirement is I have two different schema objects which has common Fields/variables, Is it possible to validate these variables in more generic way. In below code there is two events FI & Profile (Note: Future can be more events like these) these are two different schema objects but has same fields/variables of same Object "Types".
public class RequestValidation {
public void validateRequest(EventRequest eventRequest) {
//FI Event
FIEventProcessorImpl fiEventProcessor = new FIEventProcessorImpl();
FIEventSchema fiEvent = fiEventProcessor.getFiEventSchema(eventRequest);
//Party data Validation
String partyFName = null;
String partyLName = null;
String partyEmail = null;
String partyId = null;
if (null != fiEvent.getParty()) {
partyId = fiEvent.getParty().getPartyId();
if (null != fiEvent.getParty().getPartyName()
&& null != fiEvent.getParty().getPartyName().getName()) {
partyFName = fiEvent.getParty().getPartyName().getName().getGivenName();
partyLName = fiEvent.getParty().getPartyName().getName().getSurname();
if (null == partyFName && null == partyLName) {
Map<String, Object> nameMap = fiEvent.getParty().getPartyName().getName()
.getAdditionalProperties();
if (!nameMap.isEmpty()) {
partyFName = getAdditionalProperty(nameMap, "first_name");
partyLName = getAdditionalProperty(nameMap, "last_name");
}
}
}
if (null != fiEvent.getParty().getPartyEmail()) {
partyEmail = fiEvent.getParty().getPartyEmail().getEmailAddress();
if(null == partyEmail || partyEmail.isEmpty()){
//Logging missing field value logic
}
}
}
if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty()
|| null == partyId || partyId.isEmpty()) {
//Logging missing field value logic
}
//Application Context data Validation
String score = null;
String clientId = null;
if(null != fiEvent.getApplicationContext() && null != fiEvent.getApplicationContext().getContextItems()){
List<ContextItem> contextItems = fiEvent.getApplicationContext().getContextItems();
if(null != contextItems && !contextItems.isEmpty()){
socialScore = getContextValue(contextItems, "SCORE");
clientFp = getContextValue(contextItems, "CLIENT_ID");
}
}
if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) {
//Logging missing field value logic
}
//ProfileChange Event
ProfileProcessorImpl eventProcessor = new ProfileProcessorImpl();
ProfileEventSchema profileevent = eventProcessor.getProfileEventSchema(eventRequest);
//Party data Validation
if (null != profileevent.getParty()) {
partyId = profileevent.getParty().getPartyId();
if (null != profileevent.getParty().getPartyName()
&& null != profileevent.getParty().getPartyName().getName()) {
partyFName = profileevent.getParty().getPartyName().getName().getGivenName();
partyLName = profileevent.getParty().getPartyName().getName().getSurname();
if (null == partyFName && null == partyLName) {
Map<String, Object> nameMap = profileevent.getParty().getPartyName().getName()
.getAdditionalProperties();
if (!nameMap.isEmpty()) {
partyFName = getAdditionalProperty(nameMap, "first_name");
partyLName = getAdditionalProperty(nameMap, "last_name");
}
}
}
if (null != profileevent.getParty().getPartyEmail()) {
partyEmail = profileevent.getParty().getPartyEmail().getEmailAddress();
if(null == partyEmail || partyEmail.isEmpty()){
//Logging missing field value logic
}
}
}
if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty()
|| null == partyId || partyId.isEmpty()) {
//Logging missing field value logic
}
//Application Context data Validation
if(null != profileevent.getApplicationContext() && null != profileevent.getApplicationContext().getContextItems()){
List<ContextItem> contextItems = profileevent.getApplicationContext().getContextItems();
if(null != contextItems && !contextItems.isEmpty()){
socialScore = getContextValue(contextItems, "SCORE");
clientFp = getContextValue(contextItems, "CLIENT_ID");
}
}
if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) {
//Logging missing field value logic
}
}
private String getContextValue(List<ContextItem> contextItems, String key) {
String value = null;
for(ContextItem contextItem : contextItems){
if(contextItem.getKey().equalsIgnoreCase(key)){
value = contextItem.getValue();
}
}
return value.toString();
}
private String getAdditionalProperty(Map<String, ?> map, String key) {
Object value = map.get(key);
return value == null ? null : value.toString();
}
}
java
java
New contributor
New contributor
edited 2 mins ago
Jamal♦
30.6k11121227
30.6k11121227
New contributor
asked 3 hours ago
Krishna KKrishna K
62
62
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
It looks like both of the events are validating the same party and context objects. If those are the same type you could make a method to validate the profile, and a method to validate the context object. If the objects are different but you have control over the classes you could make both party objects implement an interface with getters for all of the fields being retrieved. If the objects being retrieved are different you can continue with the same pattern. In my opinion this method would be much easier to read if it was broken up to smaller methods that validate one thing, such as the name of the party.
New contributor
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Krishna K is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217233%2fvalidating-variables-fields-from-a-schema-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
It looks like both of the events are validating the same party and context objects. If those are the same type you could make a method to validate the profile, and a method to validate the context object. If the objects are different but you have control over the classes you could make both party objects implement an interface with getters for all of the fields being retrieved. If the objects being retrieved are different you can continue with the same pattern. In my opinion this method would be much easier to read if it was broken up to smaller methods that validate one thing, such as the name of the party.
New contributor
$endgroup$
add a comment |
$begingroup$
It looks like both of the events are validating the same party and context objects. If those are the same type you could make a method to validate the profile, and a method to validate the context object. If the objects are different but you have control over the classes you could make both party objects implement an interface with getters for all of the fields being retrieved. If the objects being retrieved are different you can continue with the same pattern. In my opinion this method would be much easier to read if it was broken up to smaller methods that validate one thing, such as the name of the party.
New contributor
$endgroup$
add a comment |
$begingroup$
It looks like both of the events are validating the same party and context objects. If those are the same type you could make a method to validate the profile, and a method to validate the context object. If the objects are different but you have control over the classes you could make both party objects implement an interface with getters for all of the fields being retrieved. If the objects being retrieved are different you can continue with the same pattern. In my opinion this method would be much easier to read if it was broken up to smaller methods that validate one thing, such as the name of the party.
New contributor
$endgroup$
It looks like both of the events are validating the same party and context objects. If those are the same type you could make a method to validate the profile, and a method to validate the context object. If the objects are different but you have control over the classes you could make both party objects implement an interface with getters for all of the fields being retrieved. If the objects being retrieved are different you can continue with the same pattern. In my opinion this method would be much easier to read if it was broken up to smaller methods that validate one thing, such as the name of the party.
New contributor
New contributor
answered 52 mins ago
user3624390user3624390
82
82
New contributor
New contributor
add a comment |
add a comment |
Krishna K is a new contributor. Be nice, and check out our Code of Conduct.
Krishna K is a new contributor. Be nice, and check out our Code of Conduct.
Krishna K is a new contributor. Be nice, and check out our Code of Conduct.
Krishna K is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217233%2fvalidating-variables-fields-from-a-schema-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown