From e3a17848c210cdfb970af5d55113418ea0185c4a Mon Sep 17 00:00:00 2001 From: Mirco Date: Thu, 5 Oct 2017 17:26:50 +0200 Subject: [PATCH] Docker fixes --- .../controller/DocumentController.java | 5 ++++- .../docmgmt/extraction/ListPreparation.java | 20 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/service/src/main/java/ml/anon/docmgmt/controller/DocumentController.java b/service/src/main/java/ml/anon/docmgmt/controller/DocumentController.java index ac6ea23..84c5648 100644 --- a/service/src/main/java/ml/anon/docmgmt/controller/DocumentController.java +++ b/service/src/main/java/ml/anon/docmgmt/controller/DocumentController.java @@ -41,6 +41,9 @@ public class DocumentController { @Autowired private EntityLinks links; + @Autowired + private ListPreparation listPreparation = new ListPreparation(); + @Autowired private TokenizerService tokenizerService; @@ -64,7 +67,7 @@ public ResponseEntity bulkUpload(@RequestParam("doc") String file, @RequestMapping(value = "/document/{id}", method = RequestMethod.PUT) public ResponseEntity update(@PathVariable String id, @RequestBody Document doc) throws OutdatedException { log.info("update id " + id); - ListPreparation listPreparation = new ListPreparation(); + Document one = repo.findOne(id); checkVersion(doc); one.setState(doc.getState()); diff --git a/service/src/main/java/ml/anon/docmgmt/extraction/ListPreparation.java b/service/src/main/java/ml/anon/docmgmt/extraction/ListPreparation.java index a8a1725..88add3f 100644 --- a/service/src/main/java/ml/anon/docmgmt/extraction/ListPreparation.java +++ b/service/src/main/java/ml/anon/docmgmt/extraction/ListPreparation.java @@ -7,6 +7,7 @@ import ml.anon.anonymization.model.Anonymization; import ml.anon.docmgmt.service.TokenizerService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import java.lang.reflect.Array; import java.util.*; @@ -15,13 +16,15 @@ * Compares the originals of the anonymizations and dismisses duplicates * Created by matthias on 20.08.2017 */ +@Component public class ListPreparation { @Autowired - TokenizerService tokenizerService = new TokenizerService(); + private TokenizerService tokenizerService; /** * Removes the duplicates by looking at the original value of the anonymization objects + * * @param anonymizations list of anonymizations from ml and rulebased approaches * @return the list of anonymizations without duplicates */ @@ -29,16 +32,17 @@ private ArrayList removeDuplicates(List anonymizat ArrayList noDuplicate = new ArrayList(); ObjectMapper mapper = new ObjectMapper(); - anonymizations = mapper.convertValue(anonymizations, new TypeReference>(){}); + anonymizations = mapper.convertValue(anonymizations, new TypeReference>() { + }); boolean contained = false; for (Anonymization anon1 : anonymizations) { for (Anonymization anon2 : noDuplicate) { - if(anon1.getData().getOriginal().equals(anon2.getData().getOriginal())){ + if (anon1.getData().getOriginal().equals(anon2.getData().getOriginal())) { contained = true; break; } } - if(!contained){ + if (!contained) { noDuplicate.add(anon1); } contained = false; @@ -49,6 +53,7 @@ private ArrayList removeDuplicates(List anonymizat /** * Sorts the Anonymization list by the number of tokens the original holds, to cope with encapsulated * anonymizations. + * * @param anonymizations list to sort by token number * @return the sorted list of {@link Anonymization}s */ @@ -56,8 +61,8 @@ private List sortByTokenNumber(List anonymizations HashMap anonymizationTokenNumber = new HashMap<>(); anonymizations.forEach(anonymization -> - anonymizationTokenNumber.put(anonymization, tokenizerService - .tokenize(anonymization.getData().getOriginal()).size()) + anonymizationTokenNumber.put(anonymization, tokenizerService + .tokenize(anonymization.getData().getOriginal()).size()) ); Collections.sort(anonymizations, @@ -70,10 +75,11 @@ private List sortByTokenNumber(List anonymizations /** * Applies the duplicate removal and sort by number of tokens + * * @param anonymizations list to apply operations on * @return sorted {@link Anonymization} list without duplicates */ - public List prepareAnonymizationList(List anonymizations){ + public List prepareAnonymizationList(List anonymizations) { anonymizations = this.removeDuplicates(anonymizations); anonymizations = this.sortByTokenNumber(anonymizations);