@BeforeTest
  public void createEntity() {
    entityType = when(mock(EntityType.class).getName()).thenReturn("Source").getMock();
    Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn("Identifier").getMock();

    when(idAttr.getDataType()).thenReturn(INT);
    Attribute intAttr = when(mock(Attribute.class).getName()).thenReturn("Int").getMock();
    when(intAttr.getDataType()).thenReturn(INT);
    Attribute stringAttr = when(mock(Attribute.class).getName()).thenReturn("String").getMock();
    when(stringAttr.getDataType()).thenReturn(STRING);
    Attribute nonNumericStringAttr =
        when(mock(Attribute.class).getName()).thenReturn("NonNumericString").getMock();
    when(nonNumericStringAttr.getDataType()).thenReturn(STRING);
    Attribute longAttr = when(mock(Attribute.class).getName()).thenReturn("Long").getMock();
    when(longAttr.getDataType()).thenReturn(LONG);
    when(entityType.getIdAttribute()).thenReturn(idAttr);
    when(entityType.getAttribute("Identifier")).thenReturn(idAttr);
    when(entityType.getAttribute("Int")).thenReturn(intAttr);
    when(entityType.getAttribute("String")).thenReturn(stringAttr);
    when(entityType.getAttribute("NonNumericString")).thenReturn(nonNumericStringAttr);
    when(entityType.getAttribute("Long")).thenReturn(longAttr);

    entity = new DynamicEntity(entityType);
    entity.set("Int", 1);
    entity.set("String", "12");
    entity.set("Long", 10L);
    entity.set("NonNumericString", "Hello World!");
  }
Beispiel #2
0
 @Test
 public void checkRangeMaxOnly() {
   Entity entity = new DynamicEntity(intRangeMaxMeta);
   entity.set("id", "123");
   entity.set("intrangemin", 0);
   Set<ConstraintViolation> constraints =
       entityAttributesValidator.validate(entity, intRangeMaxMeta);
   assertTrue(constraints.isEmpty());
 }
Beispiel #3
0
 @Test
 public void checkRangeMaxOnlyInvalid() {
   Entity entity = new DynamicEntity(intRangeMaxMeta);
   entity.set("id", "123");
   entity.set("intrangemin", 2);
   Set<ConstraintViolation> constraints =
       entityAttributesValidator.validate(entity, intRangeMaxMeta);
   assertEquals(constraints.size(), 1);
 }
 private Entity toEntityMappingEntity(
     EntityMapping entityMapping, List<Entity> attributeMappingEntities) {
   Entity entityMappingEntity = new DynamicEntity(entityMappingMetaData);
   entityMappingEntity.set(EntityMappingMetaData.IDENTIFIER, entityMapping.getIdentifier());
   entityMappingEntity.set(EntityMappingMetaData.SOURCE_ENTITY_TYPE, entityMapping.getName());
   entityMappingEntity.set(
       EntityMappingMetaData.TARGET_ENTITY_TYPE,
       entityMapping.getTargetEntityType() != null
           ? entityMapping.getTargetEntityType().getName()
           : null);
   entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, attributeMappingEntities);
   return entityMappingEntity;
 }
 private Entity toEntityMappingEntity(
     EntityMapping entityMapping, List<Entity> attributeMappingEntities) {
   Entity entityMappingEntity = new MapEntity(META_DATA);
   entityMappingEntity.set(EntityMappingMetaData.IDENTIFIER, entityMapping.getIdentifier());
   entityMappingEntity.set(EntityMappingMetaData.SOURCEENTITYMETADATA, entityMapping.getName());
   entityMappingEntity.set(
       EntityMappingMetaData.TARGETENTITYMETADATA,
       entityMapping.getTargetEntityMetaData() != null
           ? entityMapping.getTargetEntityMetaData().getName()
           : null);
   entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTEMAPPINGS, attributeMappingEntities);
   return entityMappingEntity;
 }
  @BeforeMethod
  public void beforeMethod() {
    owner = new MolgenisUser();
    owner.setUsername("flup");
    owner.setPassword("geheim");
    owner.setId("12345");
    owner.setActive(true);
    owner.setEmail("*****@*****.**");
    owner.setFirstName("Flup");
    owner.setLastName("de Flap");

    DefaultEntityMetaData target1 = new DefaultEntityMetaData("target1");
    target1.addAttribute("id", ROLE_ID);
    DefaultEntityMetaData target2 = new DefaultEntityMetaData("target2");
    target2.addAttribute("id", ROLE_ID);

    mappingProject = new MappingProject("My first mapping project", owner);
    mappingTarget1 = mappingProject.addTarget(target1);
    mappingTarget2 = mappingProject.addTarget(target2);

    Entity mappingTargetEntity = new MapEntity(MappingTargetRepositoryImpl.META_DATA);
    mappingTargetEntity.set(MappingTargetMetaData.TARGET, "target1");
    mappingTargetEntity.set(MappingTargetMetaData.IDENTIFIER, "mappingTargetID1");
    Entity mappingTargetEntity2 = new MapEntity(MappingTargetRepositoryImpl.META_DATA);
    mappingTargetEntity2.set(MappingTargetMetaData.TARGET, "target2");
    mappingTargetEntity2.set(MappingTargetMetaData.IDENTIFIER, "mappingTargetID2");
    mappingTargetEntities = asList(mappingTargetEntity, mappingTargetEntity2);

    mappingProjectEntity = new MapEntity(META_DATA);
    mappingProjectEntity.set(IDENTIFIER, "mappingProjectID");
    mappingProjectEntity.set(MAPPINGTARGETS, mappingTargetEntities);
    mappingProjectEntity.set(OWNER, owner);
    mappingProjectEntity.set(NAME, "My first mapping project");
  }
 @Override
 public void populateTestEntity(Entity entity) throws Exception {
   entity.set("col1", sdf.parse("2012-03-13 23:59:33"));
   entity.set("col2", sdf.parse("2013-02-09 13:12:11"));
   assertEquals(entity.getUtilDate("col1"), sdf.parse("2012-03-13 23:59:33"));
   assertEquals(entity.getUtilDate("col2"), sdf.parse("2013-02-09 13:12:11"));
 }
 @Override
 public Entity createTestEntity() {
   Entity e = new MapEntity();
   e.set("col1", "lorem");
   e.set("col2", "ipsum");
   return e;
 }
  /**
   * @param entityName The name of the entity to update
   * @param attributeName The name of the attribute to update
   * @param request EntityCollectionBatchRequestV2
   * @param response HttpServletResponse
   * @throws Exception
   */
  @RequestMapping(value = "/{entityName}/{attributeName}", method = PUT)
  @ResponseStatus(OK)
  public synchronized void updateAttribute(
      @PathVariable("entityName") String entityName,
      @PathVariable("attributeName") String attributeName,
      @RequestBody @Valid EntityCollectionBatchRequestV2 request,
      HttpServletResponse response)
      throws Exception {
    final EntityMetaData meta = dataService.getEntityMetaData(entityName);
    if (meta == null) {
      throw createUnknownEntityException(entityName);
    }

    try {
      AttributeMetaData attr = meta.getAttribute(attributeName);
      if (attr == null) {
        throw createUnknownAttributeException(entityName, attributeName);
      }

      if (attr.isReadonly()) {
        throw createMolgenisDataAccessExceptionReadOnlyAttribute(entityName, attributeName);
      }

      final List<Entity> entities =
          request
              .getEntities()
              .stream()
              .filter(e -> e.size() == 2)
              .map(e -> this.restService.toEntity(meta, e))
              .collect(Collectors.toList());
      if (entities.size() != request.getEntities().size()) {
        throw createMolgenisDataExceptionIdentifierAndValue();
      }

      final List<Entity> updatedEntities = new ArrayList<Entity>();
      int count = 0;
      for (Entity entity : entities) {
        String id = checkForEntityId(entity, count);

        Entity originalEntity = dataService.findOne(entityName, id);
        if (originalEntity == null) {
          throw createUnknownEntityExceptionNotValidId(id);
        }

        Object value = this.restService.toEntityValue(attr, entity.get(attributeName));
        originalEntity.set(attributeName, value);
        updatedEntities.add(originalEntity);
        count++;
      }

      // update all entities
      this.dataService.update(entityName, updatedEntities.stream());
      response.setStatus(HttpServletResponse.SC_OK);
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_NO_CONTENT);
      throw e;
    }
  }
  private void toEntity(
      EntityMetaData emd, Map<String, Entity> entities, Map<String, Entity> attributes) {
    // TODO prevent duplicates
    Entity e = new MapEntity();
    e.set("name", emd.getName());
    entities.put(emd.getName(), e);

    logger.debug("entity: " + e);

    for (AttributeMetaData amd : emd.getAttributes()) {
      Entity a = new MapEntity();
      a.set("name", amd.getName());
      a.set("entity", emd.getName());
      if (amd.getDataType() != null && amd.getDataType() != MolgenisFieldTypes.STRING)
        a.set("dataType", amd.getDataType());
      if (amd.getDefaultValue() != null) a.set("defaultValue", amd.getDefaultValue());
      if (amd.getRefEntity() != null) a.set("refEntity", amd.getRefEntity().getName());

      logger.debug("attribute: " + a);

      attributes.put(emd.getName() + "." + amd.getName(), a);

      // compound
      if (amd.getDataType() == MolgenisFieldTypes.COMPOUND
          && entities.get(amd.getRefEntity().getName()) == null) {
        this.toEntity(amd.getRefEntity(), entities, attributes);
      }
    }
  }
 Entity getDefaultSettings() {
   Entity defaultSettingsEntity = new DynamicEntity(this);
   for (Attribute attr : this.getAtomicAttributes()) {
     // default values are stored/retrieved as strings, so we convert them to the required type
     // here.
     String defaultValue = attr.getDefaultValue();
     if (defaultValue != null) {
       Object typedDefaultValue = getTypedValue(defaultValue, attr, entityManager);
       defaultSettingsEntity.set(attr.getName(), typedDefaultValue);
     }
   }
   return defaultSettingsEntity;
 }
  @BeforeMethod
  public void setUp() {
    fileStoreDownloadMock = mock(FileStoreDownload.class);
    fileRepositoryCollectionFactoryMock = mock(FileRepositoryCollectionFactory.class);
    fileRepositoryCollectionMock = mock(FileRepositoryCollection.class);
    importServiceFactoryMock = mock(ImportServiceFactory.class);
    importServiceMock = mock(ImportService.class);
    dataService = mock(DataService.class);
    progress = mock(Progress.class);

    fileIngester =
        new FileIngester(
            fileStoreDownloadMock,
            importServiceFactoryMock,
            fileRepositoryCollectionFactoryMock,
            dataService);

    entityMetaData = new MapEntity(EntityMetaDataMetaData.FULL_NAME, entityName);
    fileIngest = new MapEntity();
    fileIngest.set(FileIngestMetaData.ENTITY_META_DATA, entityMetaData);
    fileIngest.set(FileIngestMetaData.URL, url);
    fileIngest.set(FileIngestMetaData.LOADER, "CSV");
  }
  @Test
  public void testReaderFiltersRows() throws IOException {
    Mockito.when(tabixReader.query("13:12-12")).thenReturn(iterator);
    Mockito.when(iterator.next())
        .thenReturn(
            "id1\t13\t11\tnope", "id2\t13\t12\tyup", "id3\t13\t12\tyup", "id3\t13\t13\tnope", null);

    Iterable<Entity> actual =
        tabixRepository.findAll(tabixRepository.query().eq(CHROM, "13").and().eq(POS, 12));

    Entity e1 = new MapEntity(entityMetaData);
    e1.set("ID", "id2");
    e1.set("#CHROM", "13");
    e1.set("POS", 12l);
    e1.set("Description", "yup");

    Entity e2 = new MapEntity(entityMetaData);
    e2.set("ID", "id3");
    e2.set("#CHROM", "13");
    e2.set("POS", 12l);
    e2.set("Description", "yup");
    assertEquals(Lists.newArrayList(actual), Arrays.asList(e1, e2));
  }
  /**
   * Uses the map containing the parsed OMIM map to create a list of {@link Entity}
   *
   * @param omimEntriesByGeneSymbol
   * @param geneSymbol
   */
  private void addEntityToGeneEntityList(
      Map<String, List<List<String>>> omimEntriesByGeneSymbol, String geneSymbol) {
    Entity entity = new MapEntity(getEntityMetaData());
    entity.set(OMIM_GENE_SYMBOLS_COL_NAME, geneSymbol);
    entity.set(OMIM_PHENOTYPE_COL_NAME, join(omimEntriesByGeneSymbol.get(geneSymbol).get(0), ","));
    entity.set(OMIM_MIM_NUMBER_COL_NAME, join(omimEntriesByGeneSymbol.get(geneSymbol).get(1), ","));
    entity.set(
        OMIM_CYTO_LOCATION_COL_NAME, join(omimEntriesByGeneSymbol.get(geneSymbol).get(2), ","));
    entity.set(OMIM_TYPE_COL_NAME, join(omimEntriesByGeneSymbol.get(geneSymbol).get(3), ","));
    entity.set(OMIM_ENTRY_COL_NAME, join(omimEntriesByGeneSymbol.get(geneSymbol).get(4), ","));

    List<Entity> entities = entitiesByGeneSymbol.get(geneSymbol);
    if (entities == null) {
      entities = new ArrayList<>();
      entitiesByGeneSymbol.put(geneSymbol, entities);
    }
    entities.add(entity);
  }
 @Override
 public void set(String attributeName, Object value) {
   decoratedEntity.set(attributeName, value);
 }
  @Test
  public void resolveSelfReferences() {
    DefaultEntityMetaData emd = new DefaultEntityMetaData("Person");
    emd.addAttribute("name").setIdAttribute(true).setNillable(false);
    emd.addAttribute("father")
        .setDataType(MolgenisFieldTypes.XREF)
        .setNillable(true)
        .setRefEntity(emd);
    emd.addAttribute("mother")
        .setDataType(MolgenisFieldTypes.XREF)
        .setNillable(true)
        .setRefEntity(emd);

    Entity piet = new MapEntity("name");
    piet.set("name", "Piet");

    Entity klaas = new MapEntity("name");
    klaas.set("name", "Klaas");
    klaas.set("father", "Piet");
    klaas.set("mother", "Katrijn");

    Entity jan = new MapEntity("name");
    jan.set("name", "Jan");
    jan.set("father", "Piet");
    jan.set("mother", "Marie");

    Entity katrijn = new MapEntity("name");
    katrijn.set("name", "Katrijn");
    katrijn.set("father", "Jan");
    katrijn.set("mother", "Marie");

    Entity marie = new MapEntity("name");
    marie.set("name", "Marie");

    Repository repo = mock(Repository.class);
    when(repo.getName()).thenReturn("Person");
    when(repo.findOne("Piet")).thenReturn(piet);
    when(repo.findOne("Jan")).thenReturn(jan);
    when(repo.findOne("Marie")).thenReturn(marie);
    when(repo.findOne("Katrijn")).thenReturn(katrijn);

    DataServiceImpl ds = new DataServiceImpl();
    ds.addRepository(repo);

    Iterable<Entity> entities =
        Arrays.<Entity>asList(
            new DefaultEntity(emd, ds, piet),
            new DefaultEntity(emd, ds, klaas),
            new DefaultEntity(emd, ds, jan),
            new DefaultEntity(emd, ds, katrijn),
            new DefaultEntity(emd, ds, marie));

    Iterable<Entity> sorted = new DependencyResolver().resolveSelfReferences(entities, emd);
    List<Entity> sortedList = Lists.newArrayList(sorted);
    assertEquals(sortedList.size(), 5);
    assertEquals(sortedList.get(0).getIdValue(), "Marie");
    assertEquals(sortedList.get(1).getIdValue(), "Piet");
    assertEquals(sortedList.get(2).getIdValue(), "Jan");
    assertEquals(sortedList.get(3).getIdValue(), "Katrijn");
    assertEquals(sortedList.get(4).getIdValue(), "Klaas");
  }
 @Override
 public void updateTestEntity(Entity entity) throws Exception {
   entity.set("col2", sdf.parse("2013-02-09 13:00:00"));
 }
 @Override
 public void set(Entity values) {
   decoratedEntity.set(values);
 }
  @RequestMapping(
      value = "/verify",
      method = RequestMethod.POST,
      headers = "Content-Type=multipart/form-data")
  public void verify(
      @RequestParam(value = "selectedDataSet", required = false) String selectedDataSetId,
      @RequestParam Part file,
      HttpServletResponse response,
      Model model)
      throws IOException {
    EntitySource reader = null;
    ExcelWriter<Entity> excelWriterRanks = null;

    try {
      if (selectedDataSetId != null) {
        String origFileName = FileUploadUtils.getOriginalFileName(file);
        File uploadFile = fileStore.store(file.getInputStream(), origFileName);
        response.setContentType("application/vnd.ms-excel");
        response.addHeader(
            "Content-Disposition",
            "attachment; filename=" + getCsvFileName(file.getName() + "-ranks"));
        excelWriterRanks = new ExcelWriter<Entity>(response.getOutputStream());
        excelWriterRanks.addCellProcessor(new LowerCaseProcessor(true, false));

        Writable<Entity> sheetWriterRank = null;
        Writable<Entity> sheetWriterRankStatistics = null;
        Writable<Entity> sheetWriteBiobankRanks = null;
        Writable<Entity> sheetWriteSpssInput = null;

        reader = new ExcelEntitySourceFactory().create(uploadFile);
        Repository<? extends Entity> inputSheet = reader.getRepositoryByEntityName("Sheet1");

        List<String> biobankNames = new ArrayList<String>();
        for (AttributeMetaData attr : inputSheet.getAttributes()) {
          biobankNames.add(attr.getName());
        }
        String firstColumn = biobankNames.get(0);
        biobankNames.remove(0);

        // First column has to correspond to the selected dataset
        DataSet ds = dataService.findOne(DataSet.ENTITY_NAME, Integer.parseInt(selectedDataSetId));

        if (ds.getName().equalsIgnoreCase(firstColumn)) {
          Map<String, Map<String, List<String>>> maunalMappings =
              new HashMap<String, Map<String, List<String>>>();
          for (Entity row : inputSheet) {
            String variableName = row.getString(firstColumn);
            if (!maunalMappings.containsKey(variableName))
              maunalMappings.put(variableName, new HashMap<String, List<String>>());
            for (String biobank : biobankNames) {
              if (row.get(biobank) != null) {
                String mappingString = row.get(biobank).toString();
                if (!maunalMappings.containsKey(variableName)) {
                  maunalMappings.put(variableName, new HashMap<String, List<String>>());
                }
                if (!maunalMappings.get(variableName).containsKey(biobank.toLowerCase())) {
                  maunalMappings
                      .get(variableName)
                      .put(biobank.toLowerCase(), new ArrayList<String>());
                }
                maunalMappings
                    .get(variableName)
                    .get(biobank.toLowerCase())
                    .addAll(Arrays.asList(mappingString.split(",")));
              }
            }
          }

          List<String> lowerCaseBiobankNames = new ArrayList<String>();
          for (String element : biobankNames) {
            lowerCaseBiobankNames.add(element.toLowerCase());
          }

          List<DataSet> dataSets =
              dataService.findAllAsList(
                  DataSet.ENTITY_NAME, new QueryImpl().in(DataSet.NAME, lowerCaseBiobankNames));

          lowerCaseBiobankNames.add(0, firstColumn.toLowerCase());
          sheetWriterRank = excelWriterRanks.createWritable("result", lowerCaseBiobankNames);

          Map<String, Map<String, List<Integer>>> rankCollection =
              new HashMap<String, Map<String, List<Integer>>>();
          List<Object> allRanks = new ArrayList<Object>();

          for (Entry<String, Map<String, List<String>>> entry : maunalMappings.entrySet()) {
            String variableName = entry.getKey();
            List<String> ranks = new ArrayList<String>();
            ranks.add(variableName);
            Map<String, List<String>> mappingDetail = entry.getValue();
            List<ObservableFeature> features =
                dataService.findAllAsList(
                    ObservableFeature.ENTITY_NAME,
                    new QueryImpl().eq(ObservableFeature.NAME, variableName));
            String description = features.get(0).getDescription();
            if (!rankCollection.containsKey(description))
              rankCollection.put(description, new HashMap<String, List<Integer>>());

            if (!features.isEmpty()) {
              Entity row = new MapEntity();
              row.set(firstColumn.toLowerCase(), description);

              for (DataSet dataSet : dataSets) {
                List<Integer> ranksBiobank = new ArrayList<Integer>();
                if (mappingDetail.containsKey(dataSet.getName().toLowerCase())) {
                  Map<String, Hit> mappedFeatureIds =
                      findFeaturesFromIndex(
                          "name",
                          mappingDetail.get(dataSet.getName().toLowerCase()),
                          dataSet.getId());

                  String mappingDataSetIdentifier =
                      SecurityUtils.getCurrentUsername()
                          + "-"
                          + selectedDataSetId
                          + "-"
                          + dataSet.getId();

                  Query q =
                      new QueryImpl()
                          .eq("store_mapping_feature", features.get(0).getId())
                          .pageSize(50)
                          .sort(new Sort(Direction.DESC, "store_mapping_score"));

                  SearchRequest searchRequest =
                      new SearchRequest(mappingDataSetIdentifier, q, null);

                  SearchResult result = searchService.search(searchRequest);

                  if (mappedFeatureIds.size() == 0) {
                    row.set(dataSet.getName().toLowerCase(), "N/A2");
                    continue;
                  }

                  List<String> ids = new ArrayList<String>();
                  for (Hit hit : result.getSearchHits()) {
                    Map<String, Object> columnValueMap = hit.getColumnValueMap();
                    ids.add(columnValueMap.get("store_mapping_mapped_feature").toString());
                  }
                  Map<String, Hit> featureInfos = findFeaturesFromIndex("id", ids, dataSet.getId());

                  String previousDescription = null;
                  int rank = 0;
                  for (Hit hit : result.getSearchHits()) {
                    Map<String, Object> columnValueMap = hit.getColumnValueMap();
                    String mappedFeatureId =
                        columnValueMap.get("store_mapping_mapped_feature").toString();
                    String mappedFeatureDescription =
                        featureInfos
                            .get(mappedFeatureId)
                            .getColumnValueMap()
                            .get("description")
                            .toString()
                            .replaceAll("[^0-9a-zA-Z ]", " ");

                    rank++;
                    if (previousDescription != null
                        && previousDescription.equalsIgnoreCase(mappedFeatureDescription)) rank--;

                    if (mappedFeatureIds.containsKey(mappedFeatureId)) {
                      ranksBiobank.add(rank);
                      allRanks.add(rank);
                      mappedFeatureIds.remove(mappedFeatureId);
                    }
                    previousDescription = mappedFeatureDescription;
                  }
                  if (mappedFeatureIds.size() == 0) {
                    String output = StringUtils.join(ranksBiobank, ',');
                    if (ranksBiobank.size() > 1) {
                      output += " (" + averageRank(ranksBiobank) + ")";
                    }
                    row.set(dataSet.getName().toLowerCase(), output);
                  } else {
                    for (int i = 0; i < mappedFeatureIds.size(); i++) allRanks.add("Not mapped");
                    row.set(dataSet.getName().toLowerCase(), "Not mapped");
                    ranksBiobank.clear();
                  }
                } else row.set(dataSet.getName().toLowerCase(), "N/A1");

                rankCollection.get(description).put(dataSet.getName().toLowerCase(), ranksBiobank);
              }
              sheetWriterRank.add(row);
            }
          }

          Map<String, List<Integer>> rankCollectionPerBiobank =
              new HashMap<String, List<Integer>>();
          {
            sheetWriterRankStatistics =
                excelWriterRanks.createWritable(
                    "rank statistics",
                    Arrays.asList(
                        firstColumn.toLowerCase(),
                        "average rank",
                        "round-up rank",
                        "median rank",
                        "minium",
                        "maximum"));

            for (Entry<String, Map<String, List<Integer>>> entry : rankCollection.entrySet()) {
              String variableName = entry.getKey();
              Entity row = new MapEntity();
              row.set(firstColumn.toLowerCase(), variableName);
              List<Integer> rankAllBiobanks = new ArrayList<Integer>();
              for (Entry<String, List<Integer>> rankBiobanks : entry.getValue().entrySet()) {
                if (!rankCollectionPerBiobank.containsKey(rankBiobanks.getKey()))
                  rankCollectionPerBiobank.put(rankBiobanks.getKey(), new ArrayList<Integer>());
                rankCollectionPerBiobank.get(rankBiobanks.getKey()).addAll(rankBiobanks.getValue());
                rankAllBiobanks.addAll(rankBiobanks.getValue());
              }

              row.set("average rank", averageRank(rankAllBiobanks));
              row.set("round-up rank", Math.ceil(averageRank(rankAllBiobanks)));
              Collections.sort(rankAllBiobanks);
              if (!rankAllBiobanks.isEmpty()) {
                row.set("minium", rankAllBiobanks.get(0));
                row.set("maximum", rankAllBiobanks.get(rankAllBiobanks.size() - 1));

                double medianRank = 0;
                if (rankAllBiobanks.size() % 2 == 0) {
                  medianRank =
                      (double)
                              (rankAllBiobanks.get(rankAllBiobanks.size() / 2 - 1)
                                  + rankAllBiobanks.get(rankAllBiobanks.size() / 2))
                          / 2;
                } else {
                  medianRank = rankAllBiobanks.get(rankAllBiobanks.size() / 2);
                }
                row.set("median rank", medianRank);
              }

              sheetWriterRankStatistics.add(row);
            }
          }

          {
            lowerCaseBiobankNames.remove(0);
            sheetWriteBiobankRanks =
                excelWriterRanks.createWritable("biobank average ranks", lowerCaseBiobankNames);
            Entity entity = new MapEntity();
            for (Entry<String, List<Integer>> entry : rankCollectionPerBiobank.entrySet()) {
              entity.set(entry.getKey(), averageRank(entry.getValue()));
            }
            sheetWriteBiobankRanks.add(entity);
          }

          {
            sheetWriteSpssInput =
                excelWriterRanks.createWritable("spss ranks", Arrays.asList("rank"));
            for (Object rank : allRanks) {
              Entity entity = new MapEntity("rank", rank);
              sheetWriteSpssInput.add(entity);
            }
          }
        }
      }
    } finally {
      if (reader != null) reader.close();
      if (excelWriterRanks != null) IOUtils.closeQuietly(excelWriterRanks);
    }
  }
 @Override
 public void updateTestEntity(Entity entity) throws Exception {
   entity.set("col1", "ONE");
 }
 @Override
 public void populateTestEntity(Entity entity) throws Exception {
   entity.set("identifier", "ONE");
   entity.set("col1", "TWO");
 }