package mtsar.api;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import mtsar.processors.AnswerAggregator;
import mtsar.processors.TaskAllocator;
import mtsar.processors.WorkerRanker;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Map;
import java.util.logging.Logger;

@Singleton
@XmlRootElement
public class Process {
    public static Provider<Process> wrap(Process process) {
        return () -> process;
    }

    protected String id;
    protected Map<String, String> options;

    protected final WorkerRanker workerRanker;
    protected final TaskAllocator taskAllocator;
    protected final AnswerAggregator answerAggregator;

    @Inject
    public Process(@Named("id") String id, @Named("options") Map<String, String> options, WorkerRanker workerRanker, TaskAllocator taskAllocator, AnswerAggregator answerAggregator, Logger logger) {
        this.id = id;
        this.workerRanker = workerRanker;
        this.taskAllocator = taskAllocator;
        this.answerAggregator = answerAggregator;
        this.options = options;
        logger.info(String.format("Allocated a Process called \"%s\" with %d option(s)", id, options.size()));
    }

    @JsonProperty
    public String getId() {
        return id;
    }

    @JsonProperty
    public Map<String, String> getOptions() {
        return options;
    }

    @JsonIgnore
    public WorkerRanker getWorkerRanker() {
        return workerRanker;
    }

    @JsonIgnore
    public TaskAllocator getTaskAllocator() {
        return taskAllocator;
    }

    @JsonIgnore
    public AnswerAggregator getAnswerAggregator() {
        return answerAggregator;
    }

    @JsonProperty("workerRanker")
    public String getWorkerRankerName() {
        return workerRanker.getClass().getName();
    }

    @JsonProperty("taskAllocator")
    public String getTaskAllocatorName() {
        return taskAllocator.getClass().getName();
    }

    @JsonProperty("answerAggregator")
    public String getAnswerAggregatorName() {
        return answerAggregator.getClass().getName();
    }
}

@@ -404,16 +404,46 @@
 lement;%0A
+import java.util.Collections;%0A
 import j
@@ -703,16 +703,41 @@
  options
+ = Collections.emptyMap()
 ;%0A%0A    p
@@ -1953,32 +1953,62 @@
 %7B%0A        return
+ workerRanker == null ? null :
  workerRanker.ge
@@ -2019,32 +2019,32 @@
 ss().getName();%0A
-
     %7D%0A%0A    @Json
@@ -2118,32 +2118,63 @@
 %7B%0A        return
+ taskAllocator == null ? null :
  taskAllocator.g
@@ -2277,32 +2277,32 @@
 regatorName() %7B%0A
-
         return a
@@ -2291,32 +2291,66 @@
 %7B%0A        return
+ answerAggregator == null ? null :
  answerAggregato

Make the Process class more error-proof