private static SearchKoodisCriteriaType buildCriteria(String uri, Integer version) { return (version != null ? KoodiServiceSearchCriteriaBuilder.koodiByUriAndVersion(uri, version) : KoodiServiceSearchCriteriaBuilder.latestValidAcceptedKoodiByUri(uri)); }
/** * Get koodi metadata by locale with language fallback to FI * * @param koodiType * @param locale * @return */ public KoodiMetadataType getKoodiMetadataForLanguage(KoodiType koodiType, KieliType kieli) { KoodiMetadataType kmdt = KoodistoHelper.getKoodiMetadataForLanguage(koodiType, kieli); return kmdt; }
@Bean(name = "cachingKoodistoClient") public KoodistoClient getCachingKoodistoClient() { return new CachingKoodistoClient(); }
/** * Get koodi metadata by locale with language fallback to FI * * @param koodiType * @param locale * @return */ public KoodiMetadataType getKoodiMetadataForLanguage(KoodiType koodiType, Locale locale) { KoodiMetadataType kmdt = KoodistoHelper.getKoodiMetadataForLanguage(koodiType, KoodistoHelper.getKieliForLocale(locale)); if (kmdt == null || (kmdt.getNimi() == null || kmdt.getNimi().length() == 0)) { // Try finnish if current locale is not found kmdt = KoodistoHelper.getKoodiMetadataForLanguage(koodiType, KieliType.FI); } return kmdt; }
public static KoodiType getKoodiByUriWithVersion(String uriWithVersion, KoodiService koodiService) { SearchKoodisCriteriaType searchCriteria; String[] koodiUriAndVersion = splitKoodiURI(uriWithVersion); int version = Integer.parseInt(koodiUriAndVersion[1]); String uri = koodiUriAndVersion[0]; if (version < 0) { searchCriteria = KoodiServiceSearchCriteriaBuilder.latestKoodisByUris(uri); } else { searchCriteria = KoodiServiceSearchCriteriaBuilder.koodiByUriAndVersion(uri, version); } List<KoodiType> queryResult = koodiService.searchKoodis(searchCriteria); return queryResult.isEmpty() ? null : queryResult.get(0); }
public List<KoodiType> getKoodisByArvoAndKoodisto(String arvo, String koodistoUri) { try { SearchKoodistosCriteriaType koodistoSearchCriteria = KoodistoServiceSearchCriteriaBuilder.latestKoodistoByUri(koodistoUri); List<KoodistoType> koodistoResult = koodistoService.searchKoodistos(koodistoSearchCriteria); if(koodistoResult.size() != 1) { // FIXME: Throw something other than RuntimeException? throw new RuntimeException("No koodisto found for koodisto URI " + koodistoUri); } KoodistoType koodisto = koodistoResult.get(0); SearchKoodisByKoodistoCriteriaType koodiSearchCriteria = KoodiServiceSearchCriteriaBuilder.koodisByArvoAndKoodistoUriAndKoodistoVersio(arvo, koodistoUri, koodisto.getVersio()); return koodiService.searchKoodisByKoodisto(koodiSearchCriteria); } catch (Exception exp) { return null; } } /*
@Override public List<Code> getYliopistokoulutukset() { List<KoodiType> tutkintotyypit = getKoodiTypes(CODE_TUTKINTOTYYPPI); List<KoodiType> yliopistoKoulutukset = new ArrayList<KoodiType>(); for (KoodiType koodi : tutkintotyypit) { if (koodi.getKoodiArvo().equals(TOHTORIN_TUTKINTO) || koodi.getKoodiArvo().equals(LISENSIAATIN_TUTKINTO) || koodi.getKoodiArvo().equals(YLEMPI_KORKEAKOULUTUTKINTO) || koodi.getKoodiArvo().equals(ALEMPI_KORKEAKOULUTUTKINTO)) { List<KoodiType> ylakoodit = koodiService.getYlakoodis(koodi.getKoodiUri()); yliopistoKoulutukset.addAll(ylakoodit); } } return Lists.transform(yliopistoKoulutukset, new KoodiTypeToCodeFunction()); }
@Override public List<Option> getOpintoalat(String koulutusala) { return Lists.transform( koodiService.getAlakoodis(CODE_KOULUTUSALA + "_" + koulutusala), new KoodiTypeToOptionFunction()); }
private List<KoodiType> getKoodiTypes(final String koodistoUri, final Integer version) { List<KoodiType> koodiTypes = new ArrayList<KoodiType>(); try { koodiTypes = koodiService.getKoodisForKoodisto(koodistoUri, version, true); } catch (Exception t) { LOGGER.warn("Error calling koodisto", t); } return ImmutableList.copyOf(koodiTypes); } }
public void cacheKoodisto(String koodisto, Integer version) { List<KoodiType> koodiTypes = cachingKoodistoClient.getKoodisForKoodisto(koodisto, version); for (KoodiType koodi : koodiTypes) { koodiMap.put(koodi.getKoodiUri() + "#" + koodi.getVersio(), koodi); // Also direct access without version (use latest code version) if (version == null) { koodiMap.put(koodi.getKoodiUri(), koodi); } } }
@Override public Map<String, String> getCachedKoodistoLanguageCodes() { if (cachedlanguages == null) { cachedlanguages = new HashMap<String, String>(); List<KoodiType> searchKoodisByKoodisto = koodiService.searchKoodisByKoodisto(KoodiServiceSearchCriteriaBuilder.koodisByKoodistoUri(KOODISTO_LANGUAGE_URI)); for (KoodiType koodi : searchKoodisByKoodisto) { cachedlanguages.put(koodi.getKoodiUri(), koodi.getKoodiArvo()); } } return cachedlanguages; }
/** * Get koodi metadata by locale with language fallback to FI * * @param koodiType * @param locale * @return */ public static KoodiMetadataType getKoodiMetadataForLanguage(KoodiType koodiType, Locale locale) { KoodiMetadataType kmdt = KoodistoHelper.getKoodiMetadataForLanguage(koodiType, KoodistoHelper.getKieliForLocale(locale)); if (kmdt == null || (kmdt.getNimi() == null || kmdt.getNimi().length() == 0)) { // Try finnish if current locale is not found kmdt = KoodistoHelper.getKoodiMetadataForLanguage(koodiType, KieliType.FI); } return kmdt; }
searchCriteria = KoodiServiceSearchCriteriaBuilder.latestKoodisByUris(uri); } else { searchCriteria = KoodiServiceSearchCriteriaBuilder.koodiByUriAndVersion(uri, version);
public KoodiMetadataType getAvailableKoodiMetadata(KoodiType koodi) { KoodiMetadataType kmdt = KoodistoHelper.getKoodiMetadataForLanguage(koodi, KieliType.FI); if (kmdt == null && !koodi.getMetadata().isEmpty()) { kmdt = koodi.getMetadata().get(0); } return kmdt; }
@Autowired public KoodistoProactiveCaching(UrlConfiguration urlConfiguration) { this.cachingKoodistoClient = new CachingKoodistoClient(urlConfiguration.url("koodisto-service.base")); this.clearCache(); }
@Override public List<Code> getAMKkoulutukset() { List<KoodiType> tutkintotyypit = getKoodiTypes(CODE_TUTKINTOTYYPPI); List<KoodiType> koulutukset = new ArrayList<KoodiType>(); for (KoodiType koodi : tutkintotyypit) { if (koodi.getKoodiArvo().equals(YLEMPI_AMMATTIKORKEAKOULUTUTKINTO) || koodi.getKoodiArvo().equals(AMMATTIKORKEAKOULUJEN_ERIKOISTUMISOPINNOT) || koodi.getKoodiArvo().equals(AMMATTIKORKEAKOULUTUS)) { List<KoodiType> ylakoodit = koodiService.getYlakoodis(koodi.getKoodiUri()); koulutukset.addAll(ylakoodit); } } return Lists.transform(koulutukset, new KoodiTypeToCodeFunction()); }
@Override public SubjectRow apply(final KoodiType koodiType) { Map<String, String> translationsMap = TranslationsUtil.createTranslationsMap(koodiType); String koodiArvo = koodiType.getKoodiArvo(); boolean optional = false; boolean highSchool = false; boolean comprehensiveSchool = false; boolean language = false; KoodiUriAndVersioType koodi = new KoodiUriAndVersioType(); koodi.setKoodiUri(koodiType.getKoodiUri()); koodi.setVersio(koodiType.getVersio()); if (koodiService != null) { List<KoodiType> koodiTypes = koodiService.getAlakoodis(koodi.getKoodiUri()); for (KoodiType type : koodiTypes) { String koodistoUri = type.getKoodisto().getKoodistoUri(); if (CODE_OPPIAINEENVALINNAISUUS.equals(koodistoUri)) { optional = isTrue(type); } else if (CODE_ONLUKIONOPPIAINE.equals(koodistoUri)) { highSchool = isTrue(type); } else if (CODE_ONPERUSASTEENOPPIAINE.equals(koodistoUri)) { comprehensiveSchool = isTrue(type); } else if (CODE_OPPIAINEENKIELISYYS.equals(koodistoUri)) { language = isTrue(type); } } } SubjectRow subjectRow = new SubjectRow(koodiArvo, new I18nText(translationsMap), optional, highSchool, comprehensiveSchool, language); subjectRow.toString(); return subjectRow; }
break; List<KoodiType> ylakoodit = koodiService.getYlakoodis(koodi.getKoodiUri()); LOGGER.debug("Getting lukiokoodit. Koulukoodi: {}", koodi.getKoodiArvo()); LOGGER.debug("Ylakoodeja: {}", ylakoodit.size());
break; List<KoodiType> ylakoodit = koodiService.getYlakoodis(koodi.getKoodiUri()); LOGGER.debug("Getting korkeakoulukoodit. Koulukoodi: {}", koodi.getKoodiArvo()); LOGGER.debug("Ylakoodeja: {}", ylakoodit.size());