001    package org.findata.blpwrapper;
002    
003    import com.bloomberglp.blpapi.*;
004    
005    import java.util.logging.Logger;
006    
007    public class BulkDataResult extends DataResult {
008      private String[] requested_fields;
009      private String[] returned_fields;
010      private String[] securities;
011      private String[] data_types;
012      private String[][] result_data;
013    
014      public BulkDataResult(String[] argSecurities, String[] argFields) {
015        securities = argSecurities;
016        requested_fields = argFields;
017      }
018    
019      public String[][] getData() {
020        return(result_data);
021      }
022    
023      public String[] getDataTypes() {
024        return(data_types);
025      }
026    
027      public String[] getColumnNames() {
028        return(returned_fields);
029      }
030    
031      public void processResponse(Element response, Logger logger, boolean throwInvalidTickerError) throws WrapperException {
032        Element securityDataArray = response.getElement("securityData");
033        Element securityData = securityDataArray.getValueAsElement(0);
034        Element fieldData = securityData.getElement("fieldData");
035    
036        int seq = securityData.getElementAsInt32("sequenceNumber");
037        if (seq > 0) {
038          throw new WrapperException("do not expect seq " + seq + " to be greater than 0.");
039        }
040        
041        processSecurityError(securityData, logger, throwInvalidTickerError);
042        processFieldExceptions(securityData, logger);
043    
044        if (fieldData.numElements() > 1) {
045          throw new WrapperException("not expecting more than 1 element in fieldData, got " + fieldData.numElements());
046        }
047    
048        Element x = fieldData.getElement(0);
049    
050        if (x.datatype().intValue() != Schema.Datatype.Constants.SEQUENCE) {
051          throw new WrapperException("bulk data request can only handle SEQUENCE data in field " + x.name().toString());
052        }
053    
054        for (int i = 0; i < x.numValues(); i++) {
055          Element field = x.getValueAsElement(i);
056          
057          if (i == 0) {
058            returned_fields = new String[field.numElements()];
059            data_types = new String[field.numElements()];
060            result_data = new String[x.numValues()][field.numElements()];
061          }
062    
063          for (int j = 0; j < field.numElements(); j++) {
064            Element y = field.getElement(j);
065    
066            if (i == 0) {
067              returned_fields[j] = y.name().toString();
068              data_types[j] = y.datatype().toString();
069            }
070    
071            String value = y.getValueAsString();
072    
073            if (value.equals("-2.4245362661989844E-14")) {
074              logger.info("Numeric of -2.4245362661989844E-14 encountered. Not a real value. Will be left NULL.");
075            } else {
076              result_data[i][j] = value;
077            }
078          }
079        }
080      }
081    }