Skip to content

Commit

Permalink
Merge pull request #318 from europeana/EA-3788_index_created_modified
Browse files Browse the repository at this point in the history
Ea 3788 index created modified
  • Loading branch information
gsergiu authored Mar 28, 2024
2 parents 1446106 + 13c4215 commit 6643fcc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
public class EntityRecordUtils {

public static final String ENTITY_ID_REMOVED_MSG = "Entity '%s' has been removed";
public static final String MULTIPLE_CHOICES_FOR_REDIRECTION_MSG = "There are multiple choices for redirecting the entity id: '%s'. They include: '%s'.";
public static final String MULTIPLE_CHOICES_FOR_REDIRECTION_MSG =
"There are multiple choices for redirecting the entity id: '%s'. They include: '%s'.";

private EntityRecordUtils() {
// private constructor to prevent instantiation
}

/**
* Utility method to build Entity Id URLs
* @param type of the entity
*
* @param type of the entity
* @param identifier of the entity
* @return EntityId url
*/
Expand All @@ -31,13 +33,13 @@ public static String buildEntityIdUri(EntityTypes type, String identifier) {
private static String buildEntityIdUri(@NotNull String type, @NotNull String identifier) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(WebEntityFields.BASE_DATA_EUROPEANA_URI)
.append(type.toLowerCase(Locale.ENGLISH)).append('/')
.append(identifier);
.append(type.toLowerCase(Locale.ENGLISH)).append('/').append(identifier);
return stringBuilder.toString();
}

/**
* Extract entity part from the EntityId Url
*
* @param entityId as URL
* @return the entity path including {type}/{identifier}
*/
Expand All @@ -63,6 +65,7 @@ public static String getEuropeanaProxyId(String entityId) {

/**
* extract the identifier part from the URL
*
* @param url
* @return
*/
Expand All @@ -76,6 +79,7 @@ public static String getIdentifierFromUrl(String url) {

/**
* Gets the "{type}/{identifier}" from an EntityId string
*
* @param entityId as url
* @return the request path "{type}/{identifier}"
*/
Expand All @@ -89,6 +93,7 @@ public static String getEntityRequestPath(String entityId) {

/**
* Gets the "{type}/base/{identifier}" from an EntityId string
*
* @param entityId as url
* @return the request path "{type}/base/{identifier}"
*/
Expand All @@ -98,46 +103,50 @@ public static String getEntityRequestPathWithBase(String entityId) {

return parts[parts.length - 2] + "/base/" + parts[parts.length - 1];
}

/**
* Utility method to extract the entity ids from the list of entity records
*
* @param entities the list of entity records
* @return the list of extracted entity ids
*/
public static List<String> getEntityIds(List<EntityRecord> entities) {
if(entities== null ||entities.isEmpty()) {
if (entities == null || entities.isEmpty()) {
return Collections.emptyList();
}
return entities.stream().map(e -> e.getEntityId()).toList();
}


/**
* Checks if the entity with the given id is a Europeana entity (data.europeana.eu)
*
* @param id entity id
* @return true if given entity is a Europeana entity, false otherwise
*/
public static boolean isEuropeanaEntity(String id) {
return id!=null && id.startsWith(WebEntityFields.BASE_DATA_EUROPEANA_URI);

return id != null && id.startsWith(WebEntityFields.BASE_DATA_EUROPEANA_URI);
}

/**
* Build redirection relative Location by replacing the identifier of requested entity with the identifier extracted from redirectionEntityId, the query string is appended if non null
* Build redirection relative Location by replacing the identifier of requested entity with the
* identifier extracted from redirectionEntityId, the query string is appended if non null
*
* @param identifier the identifier of the URL from the original request
* @param redirectionEntityId the full entityId of the entity to redirect to
* @param requestUri the URI of the original request
* @param queryString the queryString from the original request
* @return the constructed Location for redirection
*/
public static String buildRedirectionLocation(String identifier, String redirectionEntityId, String requestUri, String queryString) {
//get entity identifier
public static String buildRedirectionLocation(String identifier, String redirectionEntityId,
String requestUri, String queryString) {
// get entity identifier
String redirectionIdentifier = getIdentifierFromUrl(redirectionEntityId);
//replace identifier in original request URI
// replace identifier in original request URI
String redirectLocation = requestUri.replaceFirst(identifier, redirectionIdentifier);
//append queryString if exists
if(queryString != null) {
// append queryString if exists
if (queryString != null) {
redirectLocation += ('?' + queryString);
}
return redirectLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,18 @@ public void setLabelEnrich(Map<String, List<String>> labelEnrich) {
}

public Date getCreated() {
return created;
return (Date)created.clone();
}

public void setCreated(Date created) {
this.created = created;
}

public Date getModified() {
return (Date)modified.clone();
}

public void setModified(Date modified) {
this.modified = modified;
}
}
3 changes: 2 additions & 1 deletion entity-management-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<id>coverage</id>
<build>
<plugins>
<!-- plugins that need to be executed only on this module -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand All @@ -153,7 +154,7 @@
<goals>
<goal>report-aggregate</goal>
</goals>
<!-- include the reports from all modules -->
<!-- include the reports from all modules into the aggegated report (only in this module)-->
<configuration>
<dataFileIncludes>
<dataFileInclude>**/jacoco.exec</dataFileInclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import eu.europeana.api.commons.web.http.HttpHeaders;
Expand All @@ -19,10 +20,19 @@ public EMErrorController(ErrorAttributes errorAttributes) {
super(errorAttributes);
}

@RequestMapping(value = "/error", produces = {HttpHeaders.CONTENT_TYPE_JSON_UTF8, HttpHeaders.CONTENT_TYPE_JSONLD})
@GetMapping(value = "/error", produces = {HttpHeaders.CONTENT_TYPE_JSON_UTF8, HttpHeaders.CONTENT_TYPE_JSONLD})
@ResponseBody
public Map<String, Object> error(final HttpServletRequest request) {
return this.getErrorAttributes(request, ErrorAttributeOptions.defaults());
public Map<String, Object> errorGetMethod(final HttpServletRequest request) {
return getErrorAttributes(request);
}

@PostMapping(value = "/error", produces = {HttpHeaders.CONTENT_TYPE_JSON_UTF8, HttpHeaders.CONTENT_TYPE_JSONLD})
@ResponseBody
public Map<String, Object> errorPostMethod(final HttpServletRequest request) {
return getErrorAttributes(request);
}

Map<String, Object> getErrorAttributes(final HttpServletRequest request) {
return this.getErrorAttributes(request, ErrorAttributeOptions.defaults());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ public String getRedirectUriWhenNotFound(EntityTypes type, String identifier,
* Redirection in case of deprecated entities
*
* @param deprecatedEntity for which enabled entites are searched
* @param identifier - entity identifier extracted from the original request
* @param request - the web request
* @return the entity id to redirect to
* @throws EntityRemovedException if no entity is found to redirect to
* @throws MultipleChoicesException if multiple candidates are found for redirection, typically
Expand Down
12 changes: 2 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@
<id>coverage</id>
<build>
<plugins>
<!-- plugins that need to be executed for all modules -->
<plugin>
<!-- jacoco agent needs to be prepared when building the parent pom -->
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-plugin.version}</version>
Expand All @@ -342,16 +344,6 @@
<goal>prepare-agent</goal>
</goals>
</execution>

<!--
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
-->
</executions>
</plugin>
<plugin>
Expand Down

0 comments on commit 6643fcc

Please sign in to comment.