private StreamDefinition validateAndGetStreamDefinition(String name, String version)
     throws AnalyticsWebServiceException {
   StreamDefinition streamDefinition;
   try {
     if (name != null && version != null) {
       streamDefinition = eventStreamService.getStreamDefinition(name, version);
     } else if (name != null) {
       streamDefinition = eventStreamService.getStreamDefinition(name);
     } else {
       throw new AnalyticsWebServiceException("The stream name is not provided");
     }
   } catch (Exception e) {
     logger.error("Unable to get the stream definition: " + e.getMessage(), e);
     throw new AnalyticsWebServiceException(
         "Unable to get the stream definition: " + e.getMessage(), e);
   }
   return streamDefinition;
 }
 private static boolean validateSiddhiStreamWithDatabridgeStream(
     String streamName,
     String streamVersion,
     org.wso2.siddhi.query.api.definition.StreamDefinition siddhiStreamDefinition)
     throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
   if (siddhiStreamDefinition == null) {
     throw new ExecutionPlanDependencyValidationException(
         streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion,
         "Cannot validate null Siddhi stream for the stream: "
             + streamName
             + EventProcessorConstants.STREAM_SEPARATOR
             + streamVersion
             + " ");
   }
   EventStreamService eventStreamService = EventProcessorValueHolder.getEventStreamService();
   try {
     StreamDefinition streamDefinition =
         eventStreamService.getStreamDefinition(streamName, streamVersion);
     if (streamDefinition != null) {
       String siddhiAttributeName;
       int attributeCount = 0;
       int streamSize =
           (streamDefinition.getMetaData() == null ? 0 : streamDefinition.getMetaData().size())
               + (streamDefinition.getCorrelationData() == null
                   ? 0
                   : streamDefinition.getCorrelationData().size())
               + (streamDefinition.getPayloadData() == null
                   ? 0
                   : streamDefinition.getPayloadData().size());
       if (siddhiStreamDefinition.getAttributeList().size() != streamSize) {
         throw new ExecutionPlanDependencyValidationException(
             streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion,
             "No of attributes in stream "
                 + streamName
                 + EventProcessorConstants.STREAM_SEPARATOR
                 + streamVersion
                 + " do not match the no of attributes in Siddhi stream");
       }
       if (streamDefinition.getMetaData() != null) {
         for (Attribute attribute : streamDefinition.getMetaData()) {
           siddhiAttributeName = EventProcessorConstants.META_PREFIX + attribute.getName();
           org.wso2.siddhi.query.api.definition.Attribute.Type type =
               siddhiStreamDefinition.getAttributeType(siddhiAttributeName);
           // null check for type not required since an exception is thrown by Siddhi
           // StreamDefinition.getAttributeType() method for non-existent attributes
           if (siddhiStreamDefinition.getAttributePosition(siddhiAttributeName)
               != attributeCount++) {
             throw new ExecutionPlanDependencyValidationException(
                 streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion,
                 "Stream "
                     + streamName
                     + EventProcessorConstants.STREAM_SEPARATOR
                     + streamVersion
                     + "; Attribute positions do not match for attribute: "
                     + attribute.getName());
           }
           if (!isMatchingType(type, attribute.getType())) {
             throw new ExecutionPlanDependencyValidationException(
                 streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion,
                 "Stream "
                     + streamName
                     + EventProcessorConstants.STREAM_SEPARATOR
                     + streamVersion
                     + "; Type mismatch for attribute: "
                     + attribute.getName());
           }
         }
       }
       if (streamDefinition.getCorrelationData() != null) {
         for (Attribute attribute : streamDefinition.getCorrelationData()) {
           siddhiAttributeName = EventProcessorConstants.CORRELATION_PREFIX + attribute.getName();
           org.wso2.siddhi.query.api.definition.Attribute.Type type =
               siddhiStreamDefinition.getAttributeType(siddhiAttributeName);
           // null check for type not required since an exception is thrown by Siddhi
           // StreamDefinition.getAttributeType() method for non-existent attributes
           if (siddhiStreamDefinition.getAttributePosition(siddhiAttributeName)
               != attributeCount++) {
             throw new ExecutionPlanDependencyValidationException(
                 streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion,
                 "Stream "
                     + streamName
                     + EventProcessorConstants.STREAM_SEPARATOR
                     + streamVersion
                     + "; Attribute positions do not match for attribute: "
                     + attribute.getName());
           }
           if (!isMatchingType(type, attribute.getType())) {
             throw new ExecutionPlanDependencyValidationException(
                 streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion,
                 "Stream "
                     + streamName
                     + EventProcessorConstants.STREAM_SEPARATOR
                     + streamVersion
                     + "; Type mismatch for attribute: "
                     + attribute.getName());
           }
         }
       }
       if (streamDefinition.getPayloadData() != null) {
         for (Attribute attribute : streamDefinition.getPayloadData()) {
           siddhiAttributeName = attribute.getName();
           org.wso2.siddhi.query.api.definition.Attribute.Type type =
               siddhiStreamDefinition.getAttributeType(siddhiAttributeName);
           // null check for type not required since an exception is thrown by Siddhi
           // StreamDefinition.getAttributeType() method for non-existent attributes
           if (siddhiStreamDefinition.getAttributePosition(siddhiAttributeName)
               != attributeCount++) {
             throw new ExecutionPlanDependencyValidationException(
                 streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion,
                 "Stream "
                     + streamName
                     + EventProcessorConstants.STREAM_SEPARATOR
                     + streamVersion
                     + "; Attribute positions do not match for attribute: "
                     + attribute.getName());
           }
           if (!isMatchingType(type, attribute.getType())) {
             throw new ExecutionPlanDependencyValidationException(
                 streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion,
                 "Stream "
                     + streamName
                     + EventProcessorConstants.STREAM_SEPARATOR
                     + streamVersion
                     + "; Type mismatch for attribute: "
                     + attribute.getName());
           }
         }
       }
       return true;
     }
   } catch (EventStreamConfigurationException e) {
     throw new ExecutionPlanConfigurationException(
         "Error while validating stream definition with store : " + e.getMessage(), e);
   } catch (AttributeNotExistException e) {
     throw new ExecutionPlanDependencyValidationException(
         streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion, e.getMessage());
   }
   throw new ExecutionPlanDependencyValidationException(
       streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion,
       "Stream "
           + streamName
           + EventProcessorConstants.STREAM_SEPARATOR
           + streamVersion
           + " does not exist");
 }