use of eu.europeana.metis.transformation.service.EuropeanaGeneratedIdsMap in project Europeana-Cloud by europeana.
the class IdentifierSupplier method prepareIdentifiers.
public void prepareIdentifiers(StormTaskTuple tuple) throws EuropeanaIdException {
final boolean useDefaultIdentifiers = useDefaultIdentifier(tuple);
String metisDatasetId = null;
if (!useDefaultIdentifiers) {
metisDatasetId = tuple.getParameter(PluginParameterKeys.METIS_DATASET_ID);
if (StringUtils.isEmpty(metisDatasetId)) {
throw new EuropeanaIdException("Could not create identifier - parameter " + PluginParameterKeys.METIS_DATASET_ID + " is empty!");
}
}
String localId;
if (useDefaultIdentifiers) {
localId = formulateLocalId(evaluateFileRelativePath(tuple));
} else {
EuropeanaGeneratedIdsMap europeanaIdentifier = getEuropeanaIdentifier(tuple, metisDatasetId);
localId = europeanaIdentifier.getEuropeanaGeneratedId();
tuple.addParameter(PluginParameterKeys.ADDITIONAL_LOCAL_IDENTIFIER, europeanaIdentifier.getSourceProvidedChoAbout());
}
tuple.addParameter(PluginParameterKeys.CLOUD_LOCAL_IDENTIFIER, localId);
}
use of eu.europeana.metis.transformation.service.EuropeanaGeneratedIdsMap in project metis-framework by europeana.
the class DatasetService method transformRecords.
private List<Record> transformRecords(Dataset dataset, Collection<Record> records, String xsltUrl) throws XsltSetupException {
// Set up transformer.
final XsltTransformer transformer;
final EuropeanaIdCreator europeanIdCreator;
try {
final TransformationParameters transformationParameters = new TransformationParameters(dataset);
transformer = new XsltTransformer(xsltUrl, transformationParameters.getDatasetName(), transformationParameters.getEdmCountry(), transformationParameters.getEdmLanguage());
europeanIdCreator = new EuropeanaIdCreator();
} catch (TransformationException e) {
throw new XsltSetupException("Could not setup XSL transformation.", e);
} catch (EuropeanaIdException e) {
throw new XsltSetupException(CommonStringValues.EUROPEANA_ID_CREATOR_INITIALIZATION_FAILED, e);
}
// Transform the records.
return records.stream().map(record -> {
try {
EuropeanaGeneratedIdsMap europeanaGeneratedIdsMap = europeanIdCreator.constructEuropeanaId(record.getXmlRecord(), dataset.getDatasetId());
return new Record(record.getEcloudId(), transformer.transform(record.getXmlRecord().getBytes(StandardCharsets.UTF_8), europeanaGeneratedIdsMap).toString());
} catch (TransformationException e) {
LOGGER.info("Record from list failed transformation", e);
return new Record(record.getEcloudId(), e.getMessage());
} catch (EuropeanaIdException e) {
LOGGER.info(CommonStringValues.EUROPEANA_ID_CREATOR_INITIALIZATION_FAILED, e);
return new Record(record.getEcloudId(), e.getMessage());
}
}).collect(Collectors.toList());
}
use of eu.europeana.metis.transformation.service.EuropeanaGeneratedIdsMap in project metis-sandbox by europeana.
the class TransformationServiceImpl method transformToEdmInternal.
@Override
public RecordInfo transformToEdmInternal(Record record) {
requireNonNull(record, "Record must not be null");
final byte[] recordTransformed;
try {
final EuropeanaGeneratedIdsMap europeanaGeneratedIdsMap = new EuropeanaIdCreator().constructEuropeanaId(record.getContentInputStream(), record.getDatasetId());
XsltTransformer transformer = getTransformer(getJoinDatasetIdDatasetName(record), record.getCountry().xmlValue(), record.getLanguage().name().toLowerCase());
recordTransformed = transformer.transformToBytes(record.getContent(), europeanaGeneratedIdsMap);
} catch (TransformationException | EuropeanaIdException e) {
throw new RecordProcessingException(record.getProviderId(), e);
}
return new RecordInfo(Record.from(record, recordTransformed));
}
Aggregations