Skip to content

Commit

Permalink
address code quality issues #EA-3720
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergiu committed Feb 21, 2024
1 parent bb3c3db commit dbf681f
Show file tree
Hide file tree
Showing 4 changed files with 718 additions and 633 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -175,9 +176,9 @@ public class EntityManagementConfiguration implements InitializingBean {
@Value("${europeana.role.vocabulary:role_vocabulary.xml}")
private String roleVocabularyFilename;

Map<String, ZohoLabelUriMapping> countryMappings = new HashMap<>();
Map<String, String> wikidataCountryMappings = new HashMap<>();
Map<String, String> roleMappings = new HashMap<>();
private Map<String, ZohoLabelUriMapping> countryMappings = new ConcurrentHashMap<>();
private Map<String, String> wikidataCountryMappings = new ConcurrentHashMap<>();
private Map<String, String> roleMappings = new ConcurrentHashMap<>();

@Autowired
@Qualifier(BEAN_JSON_MAPPER)
Expand Down Expand Up @@ -236,14 +237,18 @@ private void initCountryMappings() throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String contents = reader.lines().collect(Collectors.joining(System.lineSeparator()));
List<ZohoLabelUriMapping> countryMappingList = emJsonMapper.readValue(contents, new TypeReference<List<ZohoLabelUriMapping>>(){});
for (ZohoLabelUriMapping countryMapping : countryMappingList) {
//init zoho country mapping
countryMappings.put(countryMapping.getZohoLabel(), countryMapping);
//init wikidata country mapping
if(StringUtils.isNotEmpty(countryMapping.getWikidataUri())){
wikidataCountryMappings.put(countryMapping.getWikidataUri(), countryMapping.getEntityUri());
}
}
addToCountryMappings(countryMappingList);
}
}
}

void addToCountryMappings(List<ZohoLabelUriMapping> countryMappingList) {
for (ZohoLabelUriMapping countryMapping : countryMappingList) {
//init zoho country mapping
countryMappings.put(countryMapping.getZohoLabel(), countryMapping);
//init wikidata country mapping
if(StringUtils.isNotEmpty(countryMapping.getWikidataUri())){
wikidataCountryMappings.put(countryMapping.getWikidataUri(), countryMapping.getEntityUri());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public static void main(String[] args) {
//failed tasks will not complete, therefore not all scheduled tasks are marked as completed in the database
//untill we have a better mechanism to reschedule failed tasks we wait for the next executions to mark them as complete
if (currentRunningTasks == 0 || currentRunningTasks == notCompletedTasks){
//if the open tasks is the same after waiting interval, than the processing is considered complete
//if the open tasks is the same after waiting interval, than the processing is considered complete
//reseting currentRunningTasks is not needed anymore
processingComplete = true;
currentRunningTasks = 0;
} else {
processingComplete = false;
notCompletedTasks = currentRunningTasks;
Expand All @@ -97,7 +97,7 @@ public static void main(String[] args) {
SpringApplication.exit(context);
System.exit(-2);
}
} while (notCompletedTasks > 0);
} while (!processingComplete);

// failed application execution should be indicated with negative codes
LOG.info("Stoping application after processing all Schdeduled Tasks!");
Expand Down
Loading

0 comments on commit dbf681f

Please sign in to comment.