1 package eu.ehri.project.cypher; 2 3 import eu.ehri.project.utils.LanguageHelpers; 4 import org.neo4j.procedure.Name; 5 import org.neo4j.procedure.Procedure; 6 7 import java.util.Arrays; 8 import java.util.Collections; 9 import java.util.List; 10 import java.util.stream.Stream; 11 12 13 public class Procedures { 14 15 public class Output { 16 public final String value; 17 18 Output(String value) { 19 this.value = value; 20 } 21 } 22 23 public class ListOutput { 24 public final List<Object> value; 25 26 ListOutput(List<Object> value) { 27 this.value = value; 28 } 29 } 30 31 @Procedure("eu.ehri.project.cypher.countryCodeToName") 32 public Stream<Output> countryCodeToName(@Name("code") String code) { 33 return Stream.of(new Output(LanguageHelpers.iso3166dashOneCodeToName(code))); 34 } 35 36 @Procedure("eu.ehri.project.cypher.languageCodeToName") 37 public Stream<Output> languageCodeToName(@Name("code") String code) { 38 return Stream.of(new Output(LanguageHelpers.codeToName(code))); 39 } 40 41 @Procedure("coerceList") 42 public Stream<ListOutput> toList(@Name("data") Object data) { 43 if (data == null) { 44 return Stream.of(new ListOutput(Collections.emptyList())); 45 } else if (data instanceof List) { 46 @SuppressWarnings("unchecked") List<Object> out = (List<Object>) data; 47 return Stream.of(new ListOutput(out)); 48 } else if (data instanceof Object[]) { 49 return Stream.of(new ListOutput(Arrays.asList(((Object[]) data)))); 50 } 51 return Stream.of(new ListOutput(Collections.singletonList(data))); 52 } 53 }