001    package org.findata.blpwrapper;
002    
003    import com.bloomberglp.blpapi.*;
004    
005    import java.util.logging.Logger;
006    
007    public abstract class DataResult {
008      public abstract void processResponse(Element response, Logger logger, boolean throwInvalidSecurityError) throws WrapperException;
009      public abstract String[][] getData() throws WrapperException;
010      public abstract String[] getColumnNames() throws WrapperException;
011      public abstract String[] getDataTypes() throws WrapperException;
012    
013      public void processSecurityError(Element securityData, Logger logger, boolean throwError) throws WrapperException {
014        if (securityData.hasElement("securityError")) {
015          logger.info("securityError info\n" + securityData.getElement("security") + "\n" + securityData.getElement("securityError"));
016          
017          if (throwError) {
018            // Note this will only show the first invalid security.
019            throw new WrapperException("invalid security " + securityData.getElementAsString("security"));
020          }
021        }
022      }
023    
024      public void processFieldExceptions(Element securityData, Logger logger) throws WrapperException {
025        Element field_exceptions = securityData.getElement("fieldExceptions");
026        if (field_exceptions.numValues() > 0) {
027          for (int k = 0; k < field_exceptions.numValues(); k++) {
028            Element exception = field_exceptions.getValueAsElement(k);
029            logger.info("fieldError info\n" + securityData.getElement("security") + "\n" + exception.getElement("fieldId"));
030    
031            Element errorInfo = exception.getElement("errorInfo");
032            logger.info("" + errorInfo);
033            String errorType = errorInfo.getElementAsString("subcategory");
034            if (errorType.equals("INVALID_FIELD")) {
035              throw new WrapperException("invalid field " + exception.getElementAsString("fieldId"));
036            } else if (errorType.equals("NOT_APPLICABLE_TO_REF_DATA")) {
037              // Not a fatal error. Just return null value.
038            } else if (errorType.equals("NOT_APPLICABLE_TO_HIST_DATA")) {
039              // Not a fatal error. Just return null value.
040            } else {
041              throw new WrapperException("unknown field error type " + errorType);
042            }
043          }
044        }
045      }
046    }