package org.rabix.bindings.draft3;

import java.util.Map;

import org.rabix.bindings.BindingException;
import org.rabix.bindings.ProtocolFilePathMapper;
import org.rabix.bindings.draft3.bean.Draft3Job;
import org.rabix.bindings.draft3.helper.Draft3JobHelper;
import org.rabix.bindings.draft3.processor.Draft3PortProcessor;
import org.rabix.bindings.draft3.processor.Draft3PortProcessorException;
import org.rabix.bindings.draft3.processor.callback.Draft3FilePathMapProcessorCallback;
import org.rabix.bindings.mapper.FilePathMapper;
import org.rabix.bindings.model.Job;

public class Draft3FilePathMapper implements ProtocolFilePathMapper {

  @Override
  public Job mapInputFilePaths(final Job job, final FilePathMapper fileMapper) throws BindingException {
    Draft3Job draft2Job = Draft3JobHelper.getDraft3Job(job);
    
    Draft3PortProcessor draft2PortProcessor = new Draft3PortProcessor(draft2Job);
    try {
      Map<String, Object> config = job.getConfig();
      Map<String, Object> inputs = draft2PortProcessor.processInputs(job.getInputs(), new Draft3FilePathMapProcessorCallback(fileMapper, config));
      return Job.cloneWithInputs(job, inputs);
    } catch (Draft3PortProcessorException e) {
      throw new BindingException(e);
    }
  }

  @Override
  public Job mapOutputFilePaths(final Job job, final FilePathMapper fileMapper) throws BindingException {
    Draft3Job draft2Job = Draft3JobHelper.getDraft3Job(job);
    
    Draft3PortProcessor draft2PortProcessor = new Draft3PortProcessor(draft2Job);
    try {
      Map<String, Object> config = job.getConfig();
      Map<String, Object> outputs = draft2PortProcessor.processOutputs(job.getOutputs(), new Draft3FilePathMapProcessorCallback(fileMapper, config));
      return Job.cloneWithOutputs(job, outputs);
    } catch (Draft3PortProcessorException e) {
      throw new BindingException(e);
    }
  }

}

@@ -763,33 +763,33 @@
  Draft3Job draft
-2
+3
 Job = Draft3JobH
@@ -839,33 +839,33 @@
 tProcessor draft
-2
+3
 PortProcessor = 
@@ -885,33 +885,33 @@
 tProcessor(draft
-2
+3
 Job);%0A    try %7B%0A
@@ -994,33 +994,33 @@
 %3E inputs = draft
-2
+3
 PortProcessor.pr
@@ -1388,17 +1388,17 @@
 ob draft
-2
+3
 Job = Dr
@@ -1460,25 +1460,25 @@
 cessor draft
-2
+3
 PortProcesso
@@ -1510,17 +1510,17 @@
 or(draft
-2
+3
 Job);%0A  
@@ -1624,9 +1624,9 @@
 raft
-2
+3
 Port

rename draft-2 to draft-3