use of eu.europeana.metis.schema.jibx.Identifier in project metis-framework by europeana.
the class RecordRedirectsUtil method introduceRedirection.
/**
* Introduce a new redirect X -> Y. If X equals Y we do nothing. Otherwise, we do the following:
* <ol>
* <li>
* We delete all mappings Y -> ?. We can do this because we are indexing record Y and it should
* therefore not be redirected to any other link.
* </li>
* <li>
* We delete all mappings X -> ? except X -> Y. We can do this because X will be redirected to
* record Y only, and it should therefore not be redirected to any other record.
* </li>
* <li>
* Introduce new redirect from X -> Y if it doesn't already exist. This new redirect will get the
* record redirect date (passed to this method).
* </li>
* <li>
* We update all existing redirects ? -> X to point to Y instead (so becoming ? -> Y).
* </li>
* </ol>
* Note that after this method is called (and if X does not equal Y), X should only occur as
* source of a redirect, and then only as part of redirect X -> Y, whereas Y should occur only as
* destination of a redirect. Neither of them can therefore be part of a redirection cycle.
*
* @param recordRedirectDao The DAO object to manage redirects.
* @param newIdentifier The new identifier (value Y).
* @param oldIdentifier The old identifier (value X).
* @param recordRedirectDate The date (timestamp) for any new redirects.
*/
private static void introduceRedirection(RecordRedirectDao recordRedirectDao, String newIdentifier, String oldIdentifier, Date recordRedirectDate) {
// Sanity check: if old and new identifier are equal, do nothing.
if (oldIdentifier.equals(newIdentifier)) {
LOGGER.info("Encountered the request to create mappping from {} to itself. This will be ignored.", oldIdentifier);
return;
}
// Remove any redirects Y -> ?.
recordRedirectDao.getRecordRedirectsByOldId(newIdentifier).forEach(recordRedirectDao::delete);
// Remove any redirects X -> ? except X -> Y.
final List<RecordRedirect> existingRedirectsFromOldIdentifier = recordRedirectDao.getRecordRedirectsByOldId(oldIdentifier);
existingRedirectsFromOldIdentifier.stream().filter(redirect -> !redirect.getNewId().equals(newIdentifier)).forEach(recordRedirectDao::delete);
// Create the new redirect X -> Y if one doesn't already exist.
final boolean mappingAlreadyExists = existingRedirectsFromOldIdentifier.stream().map(RecordRedirect::getNewId).anyMatch(newIdentifier::equals);
if (!mappingAlreadyExists) {
recordRedirectDao.createUpdate(new RecordRedirect(newIdentifier, oldIdentifier, recordRedirectDate));
}
// Update the redirects ? -> X to point to Y instead, becoming ? -> Y.
recordRedirectDao.getRecordRedirectsByNewId(oldIdentifier).forEach(redirect -> {
redirect.setNewId(newIdentifier);
recordRedirectDao.createUpdate(redirect);
});
}
use of eu.europeana.metis.schema.jibx.Identifier in project metis-framework by europeana.
the class RecordRedirectsUtil method searchMatchingRecordForRedirection.
private static List<Pair<String, Date>> searchMatchingRecordForRedirection(RdfWrapper rdfWrapper, List<String> datasetIdsToRedirectFrom, ThrowingFunction<Map<String, String>, SolrDocumentList, IndexingException> solrDocumentRetriever) throws IndexingException {
// The incoming structure of the identifier is /datasetId/recordId
final String[] splitRecordIdentifier = rdfWrapper.getAbout().split("/");
String datasetId = splitRecordIdentifier[1];
String recordId = splitRecordIdentifier[2];
// Create combinations of all rules into one query
final Pair<String, List<String>> queryForDatasetIdsAndConcatenatedIds = generateQueryForDatasetIds(datasetIdsToRedirectFrom, recordId);
final Map<String, List<String>> firstMapOfLists = new HashMap<>();
final Map<String, List<String>> secondMapOfLists = new HashMap<>();
final Map<String, List<String>> thirdMapOfLists = new HashMap<>();
final String queryMatchingFields = generateQueryForMatchingFields(rdfWrapper, firstMapOfLists, secondMapOfLists, thirdMapOfLists);
final List<String> queriesToCombine = Arrays.asList(queryForDatasetIdsAndConcatenatedIds.getLeft(), queryMatchingFields);
final String combinedQueryOr = computeJoiningQuery(getFilteredItems(queriesToCombine), UnaryOperator.identity(), Collectors.joining(" OR ", "(", ")"));
// If combined query or is empty then we do not have a reason to search for a redirection match
if (StringUtils.isNotBlank(combinedQueryOr)) {
// Create query to restrict search on specific datasetId subsets
final List<String> datasetIds = new ArrayList<>();
datasetIds.add(datasetId);
if (!CollectionUtils.isEmpty(datasetIdsToRedirectFrom)) {
datasetIdsToRedirectFrom.stream().filter(StringUtils::isNotBlank).forEach(datasetIds::add);
}
final String datasetIdSubsets = generateQueryInDatasetSubsets(datasetIds);
// Query avoiding self-redirection. If the dataset already exists in the Solr it is likely that
// our query so far would return the very record we're indexing, which should be prevented.
final String queryPreventingFindingSameRecord = String.format("-%s:%s", EdmLabel.EUROPEANA_ID.toString(), ClientUtils.escapeQueryChars(rdfWrapper.getAbout()));
// Assemble final query.
final List<String> finalQueryParts = Arrays.asList(datasetIdSubsets, combinedQueryOr, queryPreventingFindingSameRecord);
final String finalQuery = computeJoiningQuery(getFilteredItems(finalQueryParts), UnaryOperator.identity(), Collectors.joining(" AND "));
// Apply solr query and execute
final Map<String, String> queryParamMap = new HashMap<>();
queryParamMap.put("q", finalQuery);
queryParamMap.put("fl", String.format("%s,%s,%s,%s,%s,%s", EdmLabel.EUROPEANA_ID, EdmLabel.TIMESTAMP_CREATED, EdmLabel.PROXY_DC_IDENTIFIER, EdmLabel.PROXY_DC_TITLE, EdmLabel.PROXY_DC_DESCRIPTION, EdmLabel.PROVIDER_AGGREGATION_EDM_IS_SHOWN_BY));
// Preprocess sub-query and replace documents based on the result
SolrDocumentList solrDocuments = solrDocumentRetriever.apply(queryParamMap);
// Check exact ids match first
modifyDocumentListIfMatchesFound(solrDocuments, queryForDatasetIdsAndConcatenatedIds.getRight(), firstMapOfLists, secondMapOfLists, thirdMapOfLists);
// Return all identifiers found and their creationDates
return solrDocuments.stream().map(document -> ImmutablePair.of((String) document.getFieldValue(EdmLabel.EUROPEANA_ID.toString()), (Date) document.getFieldValue(EdmLabel.TIMESTAMP_CREATED.toString()))).collect(Collectors.toList());
}
return new ArrayList<>();
}
use of eu.europeana.metis.schema.jibx.Identifier in project metis-framework by europeana.
the class ProxyFieldInputTest method createEuropeanaTermsList.
private List<EuropeanaType.Choice> createEuropeanaTermsList() {
List<EuropeanaType.Choice> dctermsList = new ArrayList<>();
EuropeanaType.Choice choiceAlternative = new EuropeanaType.Choice();
Alternative alternative = new Alternative();
alternative.setString("test alternative");
choiceAlternative.setAlternative(alternative);
dctermsList.add(choiceAlternative);
EuropeanaType.Choice choiceConformsTo = new EuropeanaType.Choice();
ConformsTo conformsTo = new ConformsTo();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource conformsResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
conformsResource.setResource("test conforms to");
conformsTo.setResource(conformsResource);
choiceConformsTo.setConformsTo(conformsTo);
dctermsList.add(choiceConformsTo);
EuropeanaType.Choice choiceCreated = new EuropeanaType.Choice();
Created created = new Created();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource createdResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
createdResource.setResource("test created");
created.setResource(createdResource);
choiceCreated.setCreated(created);
dctermsList.add(choiceCreated);
EuropeanaType.Choice choiceExtent = new EuropeanaType.Choice();
Extent extent = new Extent();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource extentResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
extentResource.setResource("test extent");
extent.setResource(extentResource);
choiceExtent.setExtent(extent);
dctermsList.add(choiceExtent);
EuropeanaType.Choice choiceHasFormat = new EuropeanaType.Choice();
HasFormat hasFormat = new HasFormat();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource choiceHasFormatResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
choiceHasFormatResource.setResource("test hasFormat");
hasFormat.setResource(choiceHasFormatResource);
choiceHasFormat.setHasFormat(hasFormat);
dctermsList.add(choiceHasFormat);
EuropeanaType.Choice choiceHasPart = new EuropeanaType.Choice();
HasPart hasPart = new HasPart();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource hasPartResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
hasPartResource.setResource("test hasPart");
hasPart.setResource(hasPartResource);
choiceHasPart.setHasPart(hasPart);
dctermsList.add(choiceHasPart);
EuropeanaType.Choice choiceHasVersion = new EuropeanaType.Choice();
HasVersion hasVersion = new HasVersion();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource hasVersionResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
hasVersionResource.setResource("test hasVersion");
hasVersion.setResource(hasVersionResource);
choiceHasVersion.setHasVersion(hasVersion);
dctermsList.add(choiceHasVersion);
EuropeanaType.Choice choiceIsFormatOf = new EuropeanaType.Choice();
IsFormatOf isFormatOf = new IsFormatOf();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource isFormatOfResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
isFormatOfResource.setResource("test isFormatOf");
isFormatOf.setResource(isFormatOfResource);
choiceIsFormatOf.setIsFormatOf(isFormatOf);
dctermsList.add(choiceIsFormatOf);
EuropeanaType.Choice choiceIsPartOf = new EuropeanaType.Choice();
IsPartOf isPartOf = new IsPartOf();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource isPartOfResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
isPartOfResource.setResource("test isPartOf");
isPartOf.setResource(isPartOfResource);
choiceIsPartOf.setIsPartOf(isPartOf);
dctermsList.add(choiceIsPartOf);
EuropeanaType.Choice choiceIsReferencedBy = new EuropeanaType.Choice();
IsReferencedBy isReferencedBy = new IsReferencedBy();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource isReferencedByResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
isReferencedByResource.setResource("test isReferencedBy");
isReferencedBy.setResource(isReferencedByResource);
choiceIsReferencedBy.setIsReferencedBy(isReferencedBy);
dctermsList.add(choiceIsReferencedBy);
EuropeanaType.Choice choiceIsReplacedBy = new EuropeanaType.Choice();
IsReplacedBy isReplacedBy = new IsReplacedBy();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource isReplacedByResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
isReplacedByResource.setResource("test isReplacedBy");
isReplacedBy.setResource(isReplacedByResource);
choiceIsReplacedBy.setIsReplacedBy(isReplacedBy);
dctermsList.add(choiceIsReplacedBy);
EuropeanaType.Choice choiceIsRequiredBy = new EuropeanaType.Choice();
IsRequiredBy isRequiredBy = new IsRequiredBy();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource isRequiredByResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
isRequiredByResource.setResource("test isRequiredBy");
isRequiredBy.setResource(isRequiredByResource);
choiceIsRequiredBy.setIsRequiredBy(isRequiredBy);
dctermsList.add(choiceIsRequiredBy);
EuropeanaType.Choice choiceIssued = new EuropeanaType.Choice();
Issued issued = new Issued();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource issuedResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
issuedResource.setResource("test issued");
issued.setResource(issuedResource);
choiceIssued.setIssued(issued);
dctermsList.add(choiceIssued);
EuropeanaType.Choice choiceIsVersionOf = new EuropeanaType.Choice();
IsVersionOf isVersionOf = new IsVersionOf();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource isVersionOfResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
isVersionOfResource.setResource("test isVersionOf");
isVersionOf.setResource(isVersionOfResource);
choiceIsVersionOf.setIsVersionOf(isVersionOf);
dctermsList.add(choiceIsVersionOf);
EuropeanaType.Choice choiceMedium = new EuropeanaType.Choice();
Medium medium = new Medium();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource mediumResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
mediumResource.setResource("test medium");
medium.setResource(mediumResource);
choiceMedium.setMedium(medium);
dctermsList.add(choiceMedium);
EuropeanaType.Choice choiceProvenance = new EuropeanaType.Choice();
Provenance provenance = new Provenance();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource provenanceResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
provenanceResource.setResource("test provenance");
provenance.setResource(provenanceResource);
choiceProvenance.setProvenance(provenance);
dctermsList.add(choiceProvenance);
EuropeanaType.Choice choiceReferences = new EuropeanaType.Choice();
References references = new References();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource referencesResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
referencesResource.setResource("test references");
references.setResource(referencesResource);
choiceReferences.setReferences(references);
dctermsList.add(choiceReferences);
EuropeanaType.Choice choiceReplaces = new EuropeanaType.Choice();
Replaces replaces = new Replaces();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource replacesResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
replacesResource.setResource("test replaces");
replaces.setResource(replacesResource);
choiceReplaces.setReplaces(replaces);
dctermsList.add(choiceReplaces);
EuropeanaType.Choice choiceRequires = new EuropeanaType.Choice();
Requires requires = new Requires();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource requiresResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
requiresResource.setResource("test requires");
requires.setResource(requiresResource);
choiceRequires.setRequires(requires);
dctermsList.add(choiceRequires);
EuropeanaType.Choice choiceSpatial = new EuropeanaType.Choice();
Spatial spatial = new Spatial();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource spatialResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
spatialResource.setResource("test spatial");
spatial.setResource(spatialResource);
choiceSpatial.setSpatial(spatial);
dctermsList.add(choiceSpatial);
EuropeanaType.Choice choiceTableOfContents = new EuropeanaType.Choice();
TableOfContents tableOfContents = new TableOfContents();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource tableOfContentsResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
tableOfContentsResource.setResource("test TOC");
tableOfContents.setResource(tableOfContentsResource);
choiceTableOfContents.setTableOfContents(tableOfContents);
dctermsList.add(choiceTableOfContents);
EuropeanaType.Choice choiceTemporal = new EuropeanaType.Choice();
Temporal temporal = new Temporal();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource temporalResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
temporalResource.setResource("temporal");
temporal.setResource(temporalResource);
choiceTemporal.setTemporal(temporal);
dctermsList.add(choiceTemporal);
EuropeanaType.Choice choiceContributor = new EuropeanaType.Choice();
Contributor contributor = new Contributor();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource contributorResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
contributorResource.setResource("test contributor");
contributor.setResource(contributorResource);
choiceContributor.setContributor(contributor);
dctermsList.add(choiceContributor);
EuropeanaType.Choice choiceCoverage = new EuropeanaType.Choice();
Coverage coverage = new Coverage();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource coverageResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
coverageResource.setResource("test coverage");
coverage.setResource(coverageResource);
choiceCoverage.setCoverage(coverage);
dctermsList.add(choiceCoverage);
EuropeanaType.Choice choiceCreator = new EuropeanaType.Choice();
Creator creator = new Creator();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource creatorResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
creatorResource.setResource("test creator");
creator.setResource(creatorResource);
choiceCreator.setCreator(creator);
dctermsList.add(choiceCreator);
EuropeanaType.Choice choiceDate = new EuropeanaType.Choice();
Date date = new Date();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource dateResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
dateResource.setResource("test date");
date.setResource(dateResource);
choiceDate.setDate(date);
dctermsList.add(choiceDate);
EuropeanaType.Choice choiceDescription = new EuropeanaType.Choice();
Description description = new Description();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource descriptionResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
descriptionResource.setResource("test description");
description.setResource(descriptionResource);
choiceDescription.setDescription(description);
dctermsList.add(choiceDescription);
EuropeanaType.Choice choiceFormat = new EuropeanaType.Choice();
Format format = new Format();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource formatResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
formatResource.setResource("test format");
format.setResource(formatResource);
choiceFormat.setFormat(format);
dctermsList.add(choiceFormat);
EuropeanaType.Choice choiceIdentifier = new EuropeanaType.Choice();
Identifier identifier = new Identifier();
identifier.setString("test identifier");
choiceIdentifier.setIdentifier(identifier);
dctermsList.add(choiceIdentifier);
EuropeanaType.Choice choiceLanguage = new EuropeanaType.Choice();
Language language = new Language();
language.setString("test language");
choiceLanguage.setLanguage(language);
dctermsList.add(choiceLanguage);
EuropeanaType.Choice choicePublisher = new EuropeanaType.Choice();
Publisher publisher = new Publisher();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource publisherResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
publisherResource.setResource("test publisher");
publisher.setResource(publisherResource);
choicePublisher.setPublisher(publisher);
dctermsList.add(choicePublisher);
EuropeanaType.Choice choiceRelation = new EuropeanaType.Choice();
Relation relation = new Relation();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource relationResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
relationResource.setResource("test relation");
relation.setResource(relationResource);
choiceRelation.setRelation(relation);
dctermsList.add(choiceRelation);
EuropeanaType.Choice choiceRights = new EuropeanaType.Choice();
Rights rights = new Rights();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource rightsResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
rightsResource.setResource("test rights");
rights.setResource(rightsResource);
choiceRights.setRights(rights);
dctermsList.add(choiceRights);
EuropeanaType.Choice choiceSource = new EuropeanaType.Choice();
Source source = new Source();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource sourceResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
sourceResource.setResource("test source");
source.setResource(sourceResource);
choiceSource.setSource(source);
dctermsList.add(choiceSource);
EuropeanaType.Choice choiceSubject = new EuropeanaType.Choice();
Subject subject = new Subject();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource subjectResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
subjectResource.setResource("test subject");
subject.setResource(subjectResource);
choiceSubject.setSubject(subject);
dctermsList.add(choiceSubject);
EuropeanaType.Choice choiceTitle = new EuropeanaType.Choice();
Title title = new Title();
title.setString("test title");
choiceTitle.setTitle(title);
dctermsList.add(choiceTitle);
EuropeanaType.Choice choiceType = new EuropeanaType.Choice();
Type type = new Type();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource typeResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
typeResource.setResource("test type");
type.setResource(typeResource);
choiceType.setType(type);
dctermsList.add(choiceType);
return dctermsList;
}
Aggregations