@@ -84,42 +84,33 @@ public class Debatcher {
8484 private String segment = null ;
8585 private String outputLocation ;
8686 private Map <String , Long > claimIdMap = new HashMap <String , Long >();
87- private boolean transactionIdUpdate = true ;
87+ private boolean updateTransactionId = true ;
8888
8989 public Debatcher () {
90- this .config = new ConfigDefault ();
91- this .ediValidator = new EdiValidatorDefault (false );
92- this .metadataLogger = new MetadataLoggerDefault ();
90+ this (new ConfigDefault (), new EdiValidatorDefault (false ), new MetadataLoggerDefault ());
9391 }
9492
9593 public Debatcher (Config config , EdiValidator ediValidator , MetadataLogger metadataLogger ) {
9694 this .config = config ;
9795 this .ediValidator = ediValidator ;
9896 this .metadataLogger = metadataLogger ;
99- }
100-
101- public void debatch (String transactionId , InputStream is ) throws Exception {
102- logger .info ("debatching started..." + transactionId );
103- this .transactionId = transactionId ;
104- this .inputStream = is ;
10597 this .outputLocation = this .config .getOutputDirectory ().toString ();
106- this .batchIdMetadata = metadataLogger .logBatchSubmissionData (transactionId );
98+ this .updateTransactionId = this .config .willUpdateTransactionId ();
99+ }
107100
108- readInterchangeControls ();
109- is . close ( );
101+ public void debatch ( String transactionId , InputStream inputStream ) throws Exception {
102+ debatch ( transactionId , - 1 , inputStream );
110103 }
111104
112- public Map <String , Long > debatch (String transactionId , long batchIdMetadata , InputStream is , String outputLocation , boolean transactionIdUpdate ) throws Exception {
105+ public Map <String , Long > debatch (String transactionId , long batchIdMetadata , InputStream inputStream ) throws Exception {
113106 logger .info ("debatching started..." + transactionId );
114107 this .transactionId = transactionId ;
115- this .inputStream = is ;
116- this .batchIdMetadata = batchIdMetadata ;
117- this .outputLocation = outputLocation ;
118- this .transactionIdUpdate = transactionIdUpdate ;
119-
108+ this .inputStream = inputStream ;
109+ this .batchIdMetadata = batchIdMetadata < 0 ? this .metadataLogger .logBatchSubmissionData (transactionId ) : batchIdMetadata ;
110+
120111 readInterchangeControls ();
121- is . close ();
122-
112+
113+ inputStream . close (); // TODO: Why are we closing a stream we do not own? Shouldn't that be the responsibility of the caller that passed it in?
123114 return claimIdMap ;
124115 }
125116
@@ -130,9 +121,7 @@ private void readInterchangeControls() throws Exception {
130121 continue ;
131122 }
132123 if (segment == null || segment .equals ("\r \n " )) {
133- throw new DebatcherException ("Invalid Control Structure" ,
134- EdiValidatorDefault .TA1_ERROR_ISAIEA ,
135- ERROR .TYPE_TA1 , ERROR_LEVEL .Batch , batchIdMetadata );
124+ throw new DebatcherException ("Invalid Control Structure" , EdiValidatorDefault .TA1_ERROR_ISAIEA , ERROR .TYPE_TA1 , ERROR_LEVEL .Batch , batchIdMetadata );
136125 }
137126 isaSegment = segment .replaceAll ("\\ r|\\ n" , "" );
138127 ediValidator .validate (batchIdMetadata , X12_ELEMENT .DATA_SEPARATOR , fieldDlm , null );
@@ -141,9 +130,9 @@ private void readInterchangeControls() throws Exception {
141130
142131 isaIdMetadata = metadataLogger .logIsaData (batchIdMetadata , isa13 , isaSegment );
143132 String isa06 = readField (segment , 6 );
144- if (transactionIdUpdate ) {
133+ if (updateTransactionId ) {
145134 transactionId = isa06 .trim () + transactionId ;
146- transactionIdUpdate = false ;
135+ updateTransactionId = false ;
147136 }
148137 ediValidator .validate (batchIdMetadata , X12_ELEMENT .ISA06 , isa06 , null );
149138 ediValidator .validate (batchIdMetadata , X12_ELEMENT .ISA07 , readField (segment , 7 ), null );
0 commit comments