package sg.ncl.service.experiment;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import sg.ncl.service.experiment.data.jpa.ExperimentEntity;
import sg.ncl.service.experiment.data.jpa.ExperimentRepository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Desmond.
 */
public class Util {

    public static ExperimentEntity getExperimentsEntity() {
        final ExperimentEntity entity = new ExperimentEntity();
        entity.setId(Long.parseLong(RandomStringUtils.randomNumeric(10)));
        entity.setUserId(RandomStringUtils.randomAlphanumeric(20));
        entity.setTeamId(RandomStringUtils.randomAlphanumeric(20));
        entity.setName(RandomStringUtils.randomAlphanumeric(20));
        entity.setDescription(RandomStringUtils.randomAlphanumeric(20));
        entity.setNsFile(RandomStringUtils.randomAlphanumeric(20));
        entity.setIdleSwap(Integer.parseInt(RandomStringUtils.randomNumeric(5)));
        entity.setMaxDuration(Integer.parseInt(RandomStringUtils.randomNumeric(5)));
        return entity;
    }

    public static boolean isListEqual(List<ExperimentEntity> one, List<ExperimentEntity> two) {
        ArrayList<ExperimentEntity> cp = new ArrayList<>(one);
        for (ExperimentEntity twoIterator : two) {
            if (!cp.remove(twoIterator)) {
                return false;
            }
        }
        return cp.isEmpty();
    }

    public static void addExperiments(int numEntries, String userId, ExperimentRepository experimentRepository) {
        for (int i = 0; i < numEntries; i++) {
            ExperimentEntity experimentEntity = Util.getExperimentsEntity();

            if (i % 2 == 0) {
                experimentEntity.setUserId(userId);
            }

            experimentRepository.save(experimentEntity);
        }
    }
}

@@ -249,16 +249,97 @@
 sitory;%0A
+import sg.ncl.service.experiment.web.ExperimentInfo;%0A%0Aimport java.io.PrintWriter;
 %0Aimport 
@@ -1166,32 +1166,782 @@
  entity;%0A    %7D%0A%0A
+    public static ExperimentInfo getExperimentsInfo() %7B%0A        String nsFileContents = createNsFileContents();%0A%0A        final ExperimentInfo experimentInfo = new ExperimentInfo(%0A                Long.parseLong(RandomStringUtils.randomNumeric(10)),%0A                RandomStringUtils.randomAlphanumeric(20),%0A                RandomStringUtils.randomAlphanumeric(20),%0A                RandomStringUtils.randomAlphanumeric(20),%0A                RandomStringUtils.randomAlphanumeric(20),%0A                RandomStringUtils.randomAlphanumeric(20),%0A                Integer.parseInt(RandomStringUtils.randomNumeric(5)),%0A                Integer.parseInt(RandomStringUtils.randomNumeric(5)),%0A                nsFileContents);%0A%0A        return experimentInfo;%0A    %7D%0A%0A
     public stati
@@ -2675,11 +2675,372 @@
  %7D%0A    %7D
+%0A%0A    public static String createNsFileContents() %7B%0A        StringBuilder sb = new StringBuilder();%0A        sb.append(%22set ns %5Bnew Simulator%5D%5Cn%22);%0A        sb.append(%22source tb_compat.tcl%5Cn%22);%0A        sb.append(%22set n0 %5B$ns node%5D%5Cn%22);%0A        sb.append(%22%5Cn%22);%0A        sb.append(%22$ns Static%5Cn%22);%0A        sb.append(%22$ns run%5Cn%22);%0A        return sb.toString();%0A    %7D
 %0A%7D%0A

Add getExperimentInfo method