Validating variables/fields from a schema object





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1












$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();
}
}









share|improve this question









New contributor




Krishna K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



















    1












    $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();
    }
    }









    share|improve this question









    New contributor




    Krishna K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      1












      1








      1





      $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();
      }
      }









      share|improve this question









      New contributor




      Krishna K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $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






      share|improve this question









      New contributor




      Krishna K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Krishna K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 16 mins ago









      Jamal

      30.6k11121227




      30.6k11121227






      New contributor




      Krishna K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      Krishna KKrishna K

      62




      62




      New contributor




      Krishna K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Krishna K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Krishna K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $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.






          share|improve this answer








          New contributor




          user3624390 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          $endgroup$














            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.










            draft saved

            draft discarded


















            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









            0












            $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.






            share|improve this answer








            New contributor




            user3624390 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            $endgroup$


















              0












              $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.






              share|improve this answer








              New contributor




              user3624390 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              $endgroup$
















                0












                0








                0





                $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.






                share|improve this answer








                New contributor




                user3624390 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                $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.







                share|improve this answer








                New contributor




                user3624390 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer






                New contributor




                user3624390 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered 1 hour ago









                user3624390user3624390

                82




                82




                New contributor




                user3624390 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                user3624390 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                user3624390 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






















                    Krishna K is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Список кардиналов, возведённых папой римским Каликстом III

                    Deduzione

                    Mysql.sock missing - “Can't connect to local MySQL server through socket”