Skip to content

Commit

Permalink
Merge pull request #11 from europeana/EA-3669_AddFewConfigs
Browse files Browse the repository at this point in the history
EA-3669 added info endpoint and swagger
  • Loading branch information
nshweta90 authored Apr 11, 2024
2 parents cb29a65 + 93561cc commit 7b9d1a4
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 35 deletions.
31 changes: 18 additions & 13 deletions k8s/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ spec:
image: europeana/record-api-v3
ports:
- containerPort: 8080
## Need to add actuator or swagger configuration
# livenessProbe:
# httpGet:
# port: 8080
# path: /actuator/info
# initialDelaySeconds: 30
# periodSeconds: 30
# readinessProbe:
# httpGet:
# port: 8080
# path: /actuator/info
# initialDelaySeconds: 30
# periodSeconds: 30
livenessProbe:
httpGet:
port: 8080
path: /actuator/health/liveness
httpHeaders:
- name: Accept
value: application/json
initialDelaySeconds: 90
periodSeconds: 60
readinessProbe:
httpGet:
port: 8080
path: /actuator/health/readiness
httpHeaders:
- name: Accept
value: application/json
initialDelaySeconds: 60
periodSeconds: 60
volumeMounts:
- name: secret
mountPath: "/opt/app/config/record-api.user.properties"
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<!-- Spring Boot 3 is based on Spring Framework 6.0 and Jakarta EE 9. A-->
<spring-boot.version>3.1.2</spring-boot.version>
<spring-framework.version>6.0.11</spring-framework.version>
<springdoc.version>2.3.0</springdoc.version>

<surefire.version>3.1.2</surefire.version>
<swagger.version>3.0.0</swagger.version>
Expand Down Expand Up @@ -129,6 +130,7 @@
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
<includeOnlyProperty>git.branch</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import dev.morphia.mapping.codec.MorphiaCodecProvider;
import eu.europeana.api.config.AppConfigConstants;
import eu.europeana.api.record.db.codec.*;
import eu.europeana.api.record.model.internal.LanguageMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down
8 changes: 8 additions & 0 deletions record-api-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

<!-- spring doc dependencies -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>


<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package eu.europeana.api.record.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
* Makes build information and the application name and description from the project's pom.xml available.
* While generating a war file this data is written automatically to the build.properties file which is read here.
* Note that the same information is also available in the Spring-Boot /actuator/info endpoint
* @author Sristhti Singh
* @since 26 Feb 2024
*/
@Configuration
@PropertySource("classpath:build.properties")
public class BuildInfo {

@Value("${info.app.name}")
private String appName;

@Value("${info.app.version}")
private String appVersion;

@Value("${info.app.description}")
private String appDescription;

@Value("${info.build.number}")
private String buildNumber;

public String getAppName() {
return appName;
}

public String getAppDescription() {
return appDescription;
}

public String getAppVersion() {
return appVersion;
}

public String getBuildNumber() {
return buildNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package eu.europeana.api.record.config;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Initialises Spring doc configurations
* @author Sristhti Singh
* @since 26 Feb 2024
*/
@Configuration
public class SpringDocConfig {

private final BuildInfo buildInfo;

/**
* Initialize SpringDoc with API build information
* @param buildInfo object for retrieving build information
*/
public SpringDocConfig(BuildInfo buildInfo) {
this.buildInfo = buildInfo;
}

@Bean
public OpenAPI userServiceOpenAPI() {
return new OpenAPI().info(new Info().title(buildInfo.getAppName())
.description(buildInfo.getAppDescription())
.version(buildInfo.getAppVersion() + " (build " + buildInfo.getBuildNumber() + ")")
.contact(new Contact().name("API team").url("https://api.europeana.eu").email("[email protected]"))
.termsOfService("https://www.europeana.eu/en/rights/api-terms-of-use")
.license(new License().name("EUPL 1.2").url("https://www.eupl.eu")))
.externalDocs(new ExternalDocumentation()
.description("Documentation")
.url("https://pro.europeana.eu/page/intro#general"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
*Setup CORS for all requests and setup default Content-type
* @author Sristhti Singh
* @since 23 October 2023
*/
@Configuration
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {

registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "OPTIONS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public class RecordConstants {
public static final String MEDIA_TYPE_TURTLE = "application/turtle";
public static final String MEDIA_TYPE_TURTLE_X = "application/x-turtle";

// N3 headers
public static final String MEDIA_TYPE_N3_TEXT = "text/n3";
public static final String MEDIA_TYPE_N3_RDF = "text/rdf+n3";
public static final String MEDIA_TYPE_N3 = "application/n3";

// NT headers
public static final String MEDIA_TYPE_NT_TEXT = "text/nt";
public static final String MEDIA_TYPE_NT_TRIPLES = "application/n-triples";
public static final String MEDIA_TYPE_NT = "application/ntriples";

// Accept Headers for retrieval endpoint
public static final String ACCEPT_HEADER_JSONLD = ACCEPT + HttpHeaders.CONTENT_TYPE_JSONLD;
public static final String ACCEPT_HEADER_JSON = ACCEPT + MediaType.APPLICATION_JSON_VALUE;
Expand All @@ -30,4 +40,14 @@ public class RecordConstants {
public static final String ACCEPT_HEADER_APPLICATION_TURTLE_TEXT = ACCEPT + MEDIA_TYPE_TURTLE_TEXT;
public static final String ACCEPT_HEADER_APPLICATION_TURTLE = ACCEPT + MEDIA_TYPE_TURTLE;
public static final String ACCEPT_HEADER_APPLICATION_TURTLE_X = ACCEPT + MEDIA_TYPE_TURTLE_X;


public static final String ACCEPT_HEADER_APPLICATION_N3_TEXT = ACCEPT + MEDIA_TYPE_N3_TEXT;
public static final String ACCEPT_HEADER_APPLICATION_N3_RDF = ACCEPT + MEDIA_TYPE_N3_RDF;
public static final String ACCEPT_HEADER_APPLICATION_N3 = ACCEPT + MEDIA_TYPE_N3;

public static final String ACCEPT_HEADER_APPLICATION_NT_TEXT = ACCEPT + MEDIA_TYPE_NT_TEXT;
public static final String ACCEPT_HEADER_APPLICATION_NT_TRIPLES = ACCEPT + MEDIA_TYPE_NT_TRIPLES;
public static final String ACCEPT_HEADER_APPLICATION_NT = ACCEPT + MEDIA_TYPE_NT;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import eu.europeana.api.record.service.RecordService;
import eu.europeana.api.record.utils.RecordUtils;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -19,14 +21,26 @@
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;


import java.io.*;
import java.util.*;

import static eu.europeana.api.record.utils.RecordConstants.*;

@Tag(
name = "Record API rest endpoints"
// description = "Record API retrieval in different formats"

)
@RestController
@Validated
public class RecordController {
Expand All @@ -43,10 +57,9 @@ public RecordController(RecordService recordService, FormatHandlerRegistry forma
this.formatHandlerRegistry = formatHandlerRegistry;
}


/**
* Retrieves the Record in the format requested
* Format is requested two way - either as an extension in the localID or the Accept Header
* Format is requested two-way - either as an extension in the localID or the Accept Header
* If present in localId : example - UEDIN_214.xml or UEDIN_214.json Or a valid Accept header.
* Extensions are given preference over Accept header values
* If both are provided then default format is set to JSONLD
Expand All @@ -56,20 +69,29 @@ public RecordController(RecordService recordService, FormatHandlerRegistry forma
* @return Response Entity with StreamingResponseBody
* @throws EuropeanaApiException throws generic EuropeanaApiException
*/
@ApiOperation(
value = "Retrieve a record",
nickname = "retrieveRecord",
response = StreamingResponseBody.class)

@Operation(
summary = "retrieveRecord",
description = "Retrieve record in json/json-ld, XML, Turtle, N3, NT "
)
@ApiResponse(
responseCode = "200",
description = "HTTP Status 200 OK"
)
@GetMapping(
value = {
"/record/v3/{datasetId}/{localId}",
},
headers = { ACCEPT_HEADER_JSONLD, ACCEPT_HEADER_JSON,
ACCEPT_HEADER_APPLICATION_TEXT_XML, ACCEPT_HEADER_RDF_XML, ACCEPT_HEADER_APPLICATION_RDF_XML, ACCEPT_HEADER_APPLICATION_XML,
ACCEPT_HEADER_APPLICATION_TURTLE_TEXT, ACCEPT_HEADER_APPLICATION_TURTLE, ACCEPT_HEADER_APPLICATION_TURTLE_X
ACCEPT_HEADER_APPLICATION_TURTLE_TEXT, ACCEPT_HEADER_APPLICATION_TURTLE, ACCEPT_HEADER_APPLICATION_TURTLE_X,
ACCEPT_HEADER_APPLICATION_N3, ACCEPT_HEADER_APPLICATION_N3_RDF, ACCEPT_HEADER_APPLICATION_N3_TEXT,
ACCEPT_HEADER_APPLICATION_NT, ACCEPT_HEADER_APPLICATION_NT_TEXT, ACCEPT_HEADER_APPLICATION_NT_TRIPLES
},
produces = {HttpHeaders.CONTENT_TYPE_JSONLD_UTF8, HttpHeaders.CONTENT_TYPE_JSON_UTF8,
produces = {HttpHeaders.CONTENT_TYPE_JSONLD, MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_XML_VALUE, HttpHeaders.CONTENT_TYPE_RDF_XML, HttpHeaders.CONTENT_TYPE_APPLICATION_RDF_XML, MediaType.APPLICATION_XML_VALUE,
MEDIA_TYPE_TURTLE_TEXT, MEDIA_TYPE_TURTLE, MEDIA_TYPE_TURTLE_X,
MEDIA_TYPE_N3_TEXT, MEDIA_TYPE_N3_RDF, MEDIA_TYPE_N3,
MEDIA_TYPE_TURTLE_TEXT, MEDIA_TYPE_TURTLE, MEDIA_TYPE_TURTLE_X})
public ResponseEntity<StreamingResponseBody> retrieveRecord(
@PathVariable String datasetId,
Expand Down
37 changes: 37 additions & 0 deletions record-api-web/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#debug=true

#Spring configs
spring.application.name=Record API
spring.main.allow-bean-definition-overriding=false
info.app.name=${spring.application.name}
info.app.version=${project.version}
info.app.description=Europeana Record API retrieves record in different formats.

#switch Spring boot logging to log4j (see https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.logging)
org.springframework.boot.logging.LoggingSystem= org.springframework.boot.logging.log4j2.Log4J2LoggingSystem

## management / actuator / swagger
#springfox.documentation.swagger-ui.enabled=true
management.security.enabled=false

management.endpoints.web.exposure.include=health,info
# for debugging conditioonal annotations locally the following configuration can be used
management.info.build.enabled=true
management.info.git.enabled=true
management.health.probes.enabled=true

### Configurations for swagger console
#springdoc.paths-to-exclude=/error
#springdoc.show-actuator=true

## server configurations
server.port = 8080
server.error.include-message=always
server.error.include-stacktrace=on_param
server.error.include-exception=false
server.error.see-also=https://pro.europeana.eu/page/apis

# compression:
# enabled: true
# min-response-size: 4096
# mime-types: application/json, application/ld+json, application/xml, text/html, text/xml, text/plain
11 changes: 0 additions & 11 deletions record-api-web/src/main/resources/application.yml

This file was deleted.

21 changes: 21 additions & 0 deletions record-api-web/src/main/resources/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Template for application build and version information. If you use the Europeana Parent POM then all Maven properties
# will be filled during a build by the Maven War plugin.
# Properties that start with 'info.' will be displayed by Spring Actuator in the /actuator/info endpoint and can be
# reused in the BuildInfo class

info.app.name = ${project.name}
info.app.version = ${project.version}
info.app.description = ${project.description}

info.build.branch = ${scmBranch}
info.build.number = ${buildNumber}
info.build.date = ${timestamp}


## Default values for local testing. Will be ignored in war builds
project.name = MyApi
project.version = n/a
project.description = No description available
scmBranch = n/a
buildNumber = local-build
timestamp = n/a
6 changes: 5 additions & 1 deletion record-api-web/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<AppenderRef ref="Console"/>
</Root>
<Logger name="org.apache.http" level="INFO"/>
<Logger name="eu.europeana.api.record" level="DEBUG"/>
<Logger name="eu.europeana.api.record.web.RecordController" level="DEBUG"/>

<!-- Log only error. suppress warn messages - specially "Found more than one class mapped to collection"-->
<Logger name="dev.morphia.mapping.Mapper" level="ERROR"/>

</Loggers>
</Configuration>
Loading

0 comments on commit 7b9d1a4

Please sign in to comment.