Java tutorial
/* * Copyright (c) 2013 The Finnish National Board of Education - Opetushallitus * * This program is free software: Licensed under the EUPL, Version 1.1 or - as * soon as they will be approved by the European Commission - subsequent versions * of the EUPL (the "Licence"); * * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: http://www.osor.eu/eupl/ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * European Union Public Licence for more details. */ package fi.vm.sade.osoitepalvelu.kooste.mvc; import com.wordnik.swagger.annotations.Api; import com.wordnik.swagger.annotations.ApiOperation; import fi.vm.sade.osoitepalvelu.kooste.common.ObjectMapperProvider; import fi.vm.sade.osoitepalvelu.kooste.common.route.DefaultCamelRequestContext; import fi.vm.sade.osoitepalvelu.kooste.scheduled.ScheduledOrganisaatioCacheTask; import fi.vm.sade.osoitepalvelu.kooste.service.koodisto.KoodistoService; import fi.vm.sade.osoitepalvelu.kooste.service.organisaatio.OrganisaatioService; import fi.vm.sade.osoitepalvelu.kooste.service.settings.AppSettingsService; import fi.vm.sade.osoitepalvelu.kooste.service.settings.dto.AppSettingsDto; import com.fasterxml.jackson.databind.ObjectMapper; import fi.vm.sade.properties.OphProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.apache.http.HttpStatus; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.context.WebApplicationContext; import java.io.IOException; /** * User: ratamaa * Date: 3/18/14 * Time: 12:41 PM */ @Api(value = "app", description = "Tuottaa kyttliittym varten aikaisessa latausvaiheessa (mm. lokalisointipavlvelun sijainti) " + "tarvittavat asetukset ja tarjoaa kehityksen tueksi toimenpiteit vlimuistin hallintaan.") @Controller @Scope(value = WebApplicationContext.SCOPE_APPLICATION) @RequestMapping(value = "/app") public class AppSettingsController extends AbstractMvcController { @Autowired private AppSettingsService appSettingsService; @Autowired private ObjectMapperProvider objectMapperProvider; @Autowired private ScheduledOrganisaatioCacheTask organisaatioCacheTask; @Autowired private OrganisaatioService organisaatioService; @Autowired private KoodistoService koodistoService; private OphProperties ophProperties = new OphProperties(); @ApiOperation("Palauttaa sovelluksen polkuviittauksia sisltvt, aikaisessa kyttliittymn alustuksen " + "vaiheessa tarpeelliset asetukset kyttliittymlle JavaScriptin, joka tuottaa asetukset" + " window.CONFIG -olioon.") @RequestMapping(value = "/settings.js", method = RequestMethod.GET, produces = "text/javascript") @ResponseBody public String settingsJs() throws IOException { AppSettingsDto settings = appSettingsService.getUiSettings(); ObjectMapper mapper = objectMapperProvider.getContext(ObjectMapper.class); return "window.CONFIG = " + mapper.writeValueAsString(settings) + ";"; } @ApiOperation("Palauttaa URL-propertyt javascript-muodossa.") @RequestMapping(value = "/url-props.js", method = RequestMethod.GET, produces = "application/javascript") @ResponseBody public String urlProperties() throws IOException { return "window.urls.addOverrides(" + ophProperties.frontPropertiesToJson() + ")"; } @ApiOperation("Pivitt Organisaatiovlimuistin. Kytettviss vain paikallisena pyyntn kehityksen tukena. " + "Normaalisti tt ei ole tarpeen kutsua, sill pivitys suoritetaan automaattisesti erajona.") @PreAuthorize("hasIpAddress('127.0.0.1/24')") @RequestMapping(value = "/refereshOrganisaatioCache", method = RequestMethod.POST, produces = "text/plain") @ResponseBody public int buildOrganisaatioCache() { organisaatioCacheTask.refreshOrganisaatioCache(); return HttpStatus.SC_OK; } @ApiOperation("Pivitt Organisaatiovlimuistin silt osin kuin tarpeellista." + "Kytettviss vain paikallisena pyyntn kehityksen tukena. " + "Normaalisti tt ei ole tarpeen kutsua, sill operaatio suoritetaan sovelluksen kynnistymisen yhteydess.") @PreAuthorize("hasIpAddress('127.0.0.1/24')") @RequestMapping(value = "/ensureOrganisaatioCacheFresh", method = RequestMethod.POST, produces = "text/plain") @ResponseBody public int ensureOrganisaatioCacheFresh() { organisaatioCacheTask.ensureOrganisaatioCacheFresh(); return HttpStatus.SC_OK; } @ApiOperation("Poistaa Koodistoon liittyvt vlimuistit sovelluksen ajonaikaisesta muistista " + "sek vlimuistista MongoDB-tietokannasta. Kytettviss vain paikallisena pyyntn kehityksen tukena. " + "Normaalisti tt ei ole tarpeen kutsua, sill koodiston vlimuistissa on elinaika ja se pivitetn " + "automaattisesti.") @PreAuthorize("hasIpAddress('127.0.0.1/24')") @RequestMapping(value = "/purgeKoodistoCaches", method = RequestMethod.POST, produces = "text/plain") @ResponseBody public int purgeKoodistoCaches() { koodistoService.purgeCaches(); return HttpStatus.SC_OK; } @ApiOperation("Ky uudelleen Y-tunnustiedot organisaatioille hierarkiahaun kautta. " + "Kytettviss vain paikallisena pyyntn kehityksen tukena. Normaalisti tt ei ole tarpeen kutsua, sill " + "operaatio suoritetaan automaattisesti ajastettuna organisaatiovlimuistin pivittmisen yhteydess ja " + "sovelluksen kynnistymisen yhteydess.") @PreAuthorize("hasIpAddress('127.0.0.1/24')") @RequestMapping(value = "/updateOrganisaatioYtunnusDetails", method = RequestMethod.POST, produces = "text/plain") @ResponseBody public int updateYtunnusDetails() { organisaatioService.updateOrganisaatioYtunnusDetails(new DefaultCamelRequestContext()); return HttpStatus.SC_OK; } }