commit 22d88044386b28b8e83eaf4af8efb7760b3e9be5 Author: konstantina.galouni Date: Fri Dec 1 10:33:31 2023 +0200 [master | WIP | ADDED] First implementation of irish-monitor-service using uoa-monitor-service as library (library classifier). diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1af4ce4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea +target +*.iml +make.sh diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6f0f8cb --- /dev/null +++ b/pom.xml @@ -0,0 +1,83 @@ + + +4.0.0 +irish-monitor-service +1.0.0-SNAPSHOT +war +irish-monitor-service + + + + + eu.dnetlib + uoa-spring-boot-parent + 1.0.0 + + + UTF-8 + UTF-8 + ${maven.build.timestamp} + E MMM dd HH:mm:ss z yyyy + + + + + eu.dnetlib + uoa-monitor-service + 1.0.4-SNAPSHOT + library + + + + + io.springfox + springfox-swagger2 + ${swagger-version} + + + + io.springfox + springfox-swagger-ui + ${swagger-version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-version} + + eu.dnetlib.irishmonitorservice.IrishMonitorServiceApplication + true + + + + + repackage + + + + + + org.apache.maven.plugins + maven-war-plugin + 2.6 + + false + + + + irish-monitor-service + + + src/main/resources + true + + + + + diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/IrishMonitorServiceApplication.java b/src/main/java/eu/dnetlib/irishmonitorservice/IrishMonitorServiceApplication.java new file mode 100644 index 0000000..d89f5db --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/IrishMonitorServiceApplication.java @@ -0,0 +1,28 @@ +package eu.dnetlib.irishmonitorservice; + +import eu.dnetlib.irishmonitorservice.configuration.GlobalVars; +import eu.dnetlib.irishmonitorservice.configuration.properties.APIProperties; +import eu.dnetlib.uoamonitorservice.UoaMonitorServiceConfiguration; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.PropertySource; +import org.springframework.context.annotation.PropertySources; +//uoahelptexts +@SpringBootApplication(scanBasePackages = {"eu.dnetlib.irishmonitorservice"}) +@PropertySources({ + @PropertySource("classpath:authorization.properties"), + @PropertySource("classpath:admintoolslibrary.properties"), +// @PropertySource("classpath:notification.properties"), + @PropertySource("classpath:monitorservice.properties"), + @PropertySource("classpath:irishmonitorservice.properties"), + @PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true) +}) +@EnableConfigurationProperties({ GlobalVars.class, APIProperties.class}) +@Import({UoaMonitorServiceConfiguration.class}) +public class IrishMonitorServiceApplication { + public static void main(String[] args) { + SpringApplication.run(IrishMonitorServiceApplication.class, args); + } +} diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/ServletInitializer.java b/src/main/java/eu/dnetlib/irishmonitorservice/ServletInitializer.java new file mode 100644 index 0000000..f0c2994 --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/ServletInitializer.java @@ -0,0 +1,14 @@ +package eu.dnetlib.irishmonitorservice; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.support.SpringBootServletInitializer; +//import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +public class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(IrishMonitorServiceApplication.class); + } + +} diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/configuration/GlobalVars.java b/src/main/java/eu/dnetlib/irishmonitorservice/configuration/GlobalVars.java new file mode 100644 index 0000000..b3fadbf --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/configuration/GlobalVars.java @@ -0,0 +1,31 @@ +package eu.dnetlib.irishmonitorservice.configuration; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.Date; + +@ConfigurationProperties("irishservice.globalVars") +public class GlobalVars { + public static Date date = new Date(); + private Date buildDate; + private String version; + + public String getBuildDate() { + if(buildDate == null) { + return null; + } + return buildDate.toString(); + } + + public void setBuildDate(Date buildDate) { + this.buildDate = buildDate; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/configuration/SwaggerConfig.java b/src/main/java/eu/dnetlib/irishmonitorservice/configuration/SwaggerConfig.java new file mode 100644 index 0000000..774229e --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/configuration/SwaggerConfig.java @@ -0,0 +1,120 @@ +package eu.dnetlib.irishmonitorservice.configuration; + +import eu.dnetlib.irishmonitorservice.configuration.properties.APIProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.schema.ModelRef; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Parameter; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.Collections; +import java.util.List; + +/** + * Swagger configuration class + */ +@Configuration +@Profile({"swagger"}) +@EnableSwagger2 +public class SwaggerConfig extends WebMvcConfigurerAdapter { + + private final APIProperties apiProperties; + + @Autowired + public SwaggerConfig(APIProperties apiProperties) { + this.apiProperties = apiProperties; + } + + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) +// .globalOperationParameters(globalParameterList()) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("eu.dnetlib.irishmonitorservice.controllers")) + .paths(PathSelectors.any()) + .build(); + } + + @Bean + public Docket createRestApiMonitorLibrary() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .groupName("Monitor Library") + .select() + .apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoamonitorservice.controllers")) + .paths(PathSelectors.any()) + .build(); + } + + + @Bean + public Docket createRestApiLibrary() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .groupName("Library") + .select() + .apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoaadmintoolslibrary.controllers")) + .paths(PathSelectors.any()) + .build(); + } + + @Bean + public Docket createRestApiAuthorizationLibrary() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .groupName("Authorization Library") + .select() + .apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoaauthorizationlibrary.controllers")) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title(this.apiProperties.getTitle()) + .description(this.apiProperties.getDescription()) + .version(this.apiProperties.getVersion()) + .build(); + } + + private List globalParameterList() { + Parameter authTokenHeader = new ParameterBuilder() + .name("Session") // name of the header + .modelRef(new ModelRef("string")) // data-type of the header + .required(false) + .parameterType("header") + .description("Session ID") + .build(); + return Collections.singletonList(authTokenHeader); + } + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addRedirectViewController("/v2/api-docs", "/v2/api-docs"); + registry.addRedirectViewController("/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui"); + registry.addRedirectViewController("/swagger-resources/configuration/security", "/swagger-resources/configuration/security"); + registry.addRedirectViewController("/swagger-resources", "/swagger-resources"); + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/swagger-ui.html**").addResourceLocations("classpath:/META-INF/resources/swagger-ui.html"); + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + +} + diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/configuration/properties/APIProperties.java b/src/main/java/eu/dnetlib/irishmonitorservice/configuration/properties/APIProperties.java new file mode 100644 index 0000000..230f412 --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/configuration/properties/APIProperties.java @@ -0,0 +1,38 @@ +package eu.dnetlib.irishmonitorservice.configuration.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("api") +public class APIProperties { + + private String title; + private String description; + private String version; + + public APIProperties() { + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} diff --git a/src/main/java/eu/dnetlib/irishmonitorservice/controllers/IrishServiceCheckDeployController.java b/src/main/java/eu/dnetlib/irishmonitorservice/controllers/IrishServiceCheckDeployController.java new file mode 100644 index 0000000..6217fcb --- /dev/null +++ b/src/main/java/eu/dnetlib/irishmonitorservice/controllers/IrishServiceCheckDeployController.java @@ -0,0 +1,46 @@ +package eu.dnetlib.irishmonitorservice.controllers; + +import eu.dnetlib.irishmonitorservice.configuration.GlobalVars; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.Map; + +@RestController +@CrossOrigin(origins = "*") +public class IrishServiceCheckDeployController { + private final Logger log = LogManager.getLogger(this.getClass()); + + @Autowired + private GlobalVars globalVars; + + @RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET) + public String hello() { + log.debug("Hello from irish-monitor-service!"); + return "Hello from irish-monitor-service!"; + } + +// @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") + @RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET) + public Map checkEverything() { + Map response = new HashMap<>(); + + if(globalVars.date != null) { + response.put("Date of deploy", globalVars.date.toString()); + } + if(globalVars.getBuildDate() != null) { + response.put("Date of build", globalVars.getBuildDate()); + } + if(globalVars.getVersion() != null) { + response.put("Version", globalVars.getVersion()); + } + + return response; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..deef270 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#static properties +api.title = Irish Monitor Service Documentation Swagger +api.description = Irish Monitor Service is a service which ... +api.version = ${project.version} \ No newline at end of file diff --git a/src/main/resources/irishmonitorservice.properties b/src/main/resources/irishmonitorservice.properties new file mode 100644 index 0000000..299af37 --- /dev/null +++ b/src/main/resources/irishmonitorservice.properties @@ -0,0 +1,2 @@ +irishmonitorservice.globalVars.buildDate=@timestamp@ +irishmonitorservice.globalVars.version=@version@ \ No newline at end of file diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..1949895 --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,39 @@ + + + + + %d %p %t [%c] - %m%n + + + + + + + ${LOG_PATTERN} + + + + + + + + + ${LOG_PATTERN} + + + + + + + + + + + + + + + + \ No newline at end of file