private List<Map<String,Object>> globFiles(final Draft3Job job,final File workingDir,HashAlgorithm hashAlgorithm,final Draft3OutputPort outputPort,Object outputBinding) throws Draft3GlobException {
  if (outputPort.getOutputBinding() != null) {
    outputBinding=outputPort.getOutputBinding();
  }
  if (outputBinding == null) {
    logger.debug("Output binding is empty. Skip output extraction.");
    return null;
  }
  Object glob=Draft3BindingHelper.getGlob(outputBinding);
  if (glob == null) {
    logger.debug("GLOB does not exist. Skip output extraction.");
    return null;
  }
  Set<File> paths=globService.glob(job,workingDir,glob);
  if (paths == null) {
    logger.info("Glob service didn't find any files.");
    return null;
  }
  logger.debug("Glob service returned result {}",paths);
  final List<Map<String,Object>> result=new ArrayList<>();
  for (  File path : paths) {
    try {
      logger.info("Processing {}.",path);
      File file=path;
      Map<String,Object> fileData=new HashMap<>();
      Draft3FileValueHelper.setFileType(fileData);
      if (hashAlgorithm != null) {
        Draft3FileValueHelper.setChecksum(file,fileData,hashAlgorithm);
      }
      Draft3FileValueHelper.setSize(file.length(),fileData);
      Draft3FileValueHelper.setName(file.getName(),fileData);
      Draft3FileValueHelper.setPath(file.getAbsolutePath(),fileData);
      List<?> secondaryFiles=getSecondaryFiles(job,hashAlgorithm,fileData,file.getAbsolutePath(),outputPort.getSecondaryFiles());
      if (secondaryFiles != null && !secondaryFiles.isEmpty()) {
        Draft3FileValueHelper.setSecondaryFiles(secondaryFiles,fileData);
      }
      Object metadata=Draft3BindingHelper.getMetadata(outputBinding);
      metadata=metadataService.evaluateMetadataExpressions(job,fileData,metadata);
      logger.info("Metadata expressions evaluated. Metadata is {}.",metadata);
      if (metadata != null) {
        Draft3FileValueHelper.setMetadata(metadata,fileData);
      }
      metadata=metadataService.processMetadata(job,fileData,outputPort,outputBinding);
      if (metadata != null) {
        logger.info("Metadata for {} resolved. Metadata is {}",outputPort.getId(),metadata);
        Draft3FileValueHelper.setMetadata(metadata,fileData);
      }
 else {
        logger.info("Metadata for {} output is empty.",outputPort.getId());
      }
      result.add(fileData);
      boolean loadContents=Draft3BindingHelper.loadContents(outputBinding);
      if (loadContents) {
        Draft3FileValueHelper.setContents(fileData);
      }
    }
 catch (    Exception e) {
      logger.error("Failed to extract outputs",e);
      throw new Draft3GlobException("Failed to extract outputs.",e);
    }
  }
  return result;
}

private List < Map < String , Object > > globFiles ( final Draft3Job job , final File workingDir , HashAlgorithm hashAlgorithm , final Draft3OutputPort outputPort , Object outputBinding ) throws Draft3GlobException { if ( outputPort . getOutputBinding ( ) != null ) { outputBinding = outputPort . getOutputBinding ( ) ; } if ( outputBinding == null ) { logger . debug ( "Output binding is empty. Skip output extraction." ) ; return null ; } Object glob = Draft3BindingHelper . getGlob ( outputBinding ) ; if ( glob == null ) { logger . debug ( "GLOB does not exist. Skip output extraction." ) ; return null ; } Set < File > paths = globService . glob ( job , workingDir , glob ) ; if ( paths == null ) { logger . info ( "Glob service didn't find any files." ) ; return null ; } logger . debug ( "Glob service returned result {}" , paths ) ; final List < Map < String , Object > > result = new ArrayList < > ( ) ; for ( File path : paths ) { try { logger . info ( "Processing {}." , path ) ; File file = path ; Map < String , Object > fileData = new HashMap < > ( ) ; Draft3FileValueHelper . setFileType ( fileData ) ; if ( hashAlgorithm != null ) { Draft3FileValueHelper . setChecksum ( file , fileData , hashAlgorithm ) ; } Draft3FileValueHelper . setSize ( file . length ( ) , fileData ) ; Draft3FileValueHelper . setName ( file . getName ( ) , fileData ) ; Draft3FileValueHelper . setPath ( file . getAbsolutePath ( ) , fileData ) ; List < ? > secondaryFiles = getSecondaryFiles ( job , hashAlgorithm , fileData , file . getAbsolutePath ( ) , outputPort . getSecondaryFiles ( ) ) ; if ( secondaryFiles != null && ! secondaryFiles . isEmpty ( ) ) { Draft3FileValueHelper . setSecondaryFiles ( secondaryFiles , fileData ) ; } Object metadata = Draft3BindingHelper . getMetadata ( outputBinding ) ; metadata = metadataService . evaluateMetadataExpressions ( job , fileData , metadata ) ; logger . info ( "Metadata expressions evaluated. Metadata is {}." , metadata ) ; if ( metadata != null ) { Draft3FileValueHelper . setMetadata ( metadata , fileData ) ; } metadata = metadataService . processMetadata ( job , fileData , outputPort , outputBinding ) ; if ( metadata != null ) { logger . info ( "Metadata for {} resolved. Metadata is {}" , outputPort . getId ( ) , metadata ) ; Draft3FileValueHelper . setMetadata ( metadata , fileData ) ; } else { logger . info ( "Metadata for {} output is empty." , outputPort . getId ( ) ) ; } result . add ( fileData ) ; boolean loadContents = Draft3BindingHelper . loadContents ( outputBinding ) ; if ( loadContents ) { Draft3FileValueHelper . setContents ( fileData ) ; } } catch ( Exception e ) { logger . error ( "Failed to extract outputs" , e ) ; throw new Draft3GlobException ( "Failed to extract outputs." , e ) ; } } return result ; }
extracts files from a directory based on glob expression
