use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class DefaultProjectWriter method updateRelativeResourcePaths.
private void updateRelativeResourcePaths(Iterable<IOConfiguration> resources, URI previousTarget, URI newTarget) {
// if the previous target is null, there cannot be relative paths
if (previousTarget == null)
return;
for (IOConfiguration resource : resources) {
Map<String, Value> providerConfig = resource.getProviderConfiguration();
URI pathUri = URI.create(providerConfig.get(ImportProvider.PARAM_SOURCE).as(String.class));
// update relative URIs
if (!pathUri.isAbsolute()) {
// resolve the resource's URI
pathUri = previousTarget.resolve(pathUri);
// try to get a relative path from the new project to the
// resource
URI relative = IOUtils.getRelativePath(pathUri, newTarget);
providerConfig.put(ImportProvider.PARAM_SOURCE, Value.of(relative.toString()));
}
}
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class JaxbToProject method toIOConfiguration.
/**
* Convert a JAXB representation to an {@link IOConfiguration}.
*
* @param config the JAXB representation
* @return the I/O configuration
*/
public static IOConfiguration toIOConfiguration(IOConfigurationType config) {
if (config == null) {
return null;
}
IOConfiguration result = new IOConfiguration();
result.setActionId(config.getActionId());
result.setProviderId(config.getProviderId());
for (JAXBElement<?> setting : config.getAbstractSetting()) {
Object value = setting.getValue();
if (value instanceof PropertyType) {
addProperty(result.getProviderConfiguration(), (PropertyType) value);
} else if (value instanceof ComplexPropertyType) {
addProperty(result.getProviderConfiguration(), (ComplexPropertyType) value);
}
}
// cache
ValueType cache = config.getCache();
if (cache != null) {
Value value = Value.NULL;
if (cache.getAny() != null) {
value = new ElementValue(cache.getAny(), null);
} else if (cache.getValue() != null) {
value = Value.of(cache.getValue());
}
result.setCache(value);
}
return result;
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class LocationUpdater method updateProject.
/**
* Update locations in the given project.
*
* @param keepRelative whether to keep working relative URIs as is or make
* them absolute
*/
public void updateProject(boolean keepRelative) {
if (project == null || getOldLocation() == null || getNewLocation() == null)
return;
IOConfiguration saveconfig = project.getSaveConfiguration();
// actually cannot be null here because then old location would be null
if (saveconfig == null)
return;
if (!getOldLocation().equals(getNewLocation()) || !keepRelative) {
// update save configuration
saveconfig.getProviderConfiguration().put(ExportProvider.PARAM_TARGET, Value.of(getNewLocation().toString()));
// update I/O configurations
List<IOConfiguration> configuration = project.getResources();
for (IOConfiguration providerconf : configuration) {
final Map<String, Value> conf = providerconf.getProviderConfiguration();
final URI uri = URI.create(conf.get(ImportProvider.PARAM_SOURCE).as(String.class));
URI resolved = findLocation(uri, true, true, keepRelative);
if (resolved != null)
conf.put(ImportProvider.PARAM_SOURCE, Value.of(resolved.toString()));
}
// update project file infos
for (ProjectFileInfo fileInfo : project.getProjectFiles()) {
URI location = fileInfo.getLocation();
/*
* Project files should always be next to the project file.
*
* Fallback wouldn't have an effect here because as it is used
* currently in the project service, project files are already
* loaded in the DefaultProjectReader.
*/
URI resolved = findLocation(location, false, false, keepRelative);
if (resolved != null)
fileInfo.setLocation(resolved);
}
}
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class ClassificationMappingUtil method getClassificationLookup.
/**
* Get the classification lookup table from the transformation parameters.
*
* @param parameters the transformation parameters
* @param serviceProvider service provider in case a lookup table has to be
* retrieved through a service
* @return the classification lookup table
*/
public static LookupTable getClassificationLookup(Multimap<String, ? extends Value> parameters, ServiceProvider serviceProvider) {
try {
if (!(parameters.get(PARAMETER_LOOKUPTABLE).isEmpty())) {
Collection<? extends Value> tmpMap = parameters.get(PARAMETER_LOOKUPTABLE);
return tmpMap.iterator().next().as(LookupTable.class);
}
if (!(parameters.get(PARAMETER_LOOKUPTABLE_ID).isEmpty())) {
LookupService lookupServiceImpl = serviceProvider.getService(LookupService.class);
Collection<? extends Value> tmpMap = parameters.get(PARAMETER_LOOKUPTABLE_ID);
LookupTableInfo lookupTableInfo = lookupServiceImpl.getTable(tmpMap.iterator().next().as(String.class));
return lookupTableInfo.getTable();
}
} catch (NullPointerException e) {
log.error("Service provider not accessible for retrieving lookup table", e);
}
// For reason of compatibility we need the following code
// lookup table in strangely encoded string parameter
Collection<? extends Value> mappings = parameters.get(PARAMETER_CLASSIFICATIONS);
try {
Map<Value, Value> lookupMap = new HashMap<Value, Value>();
for (Value mapping : mappings) {
String[] parts = mapping.as(String.class).split(" ");
if (parts.length > 0) {
Value target = Value.of(URLDecoder.decode(parts[0], "UTF-8"));
for (int i = 1; i < parts.length; i++) {
lookupMap.put(Value.of(URLDecoder.decode(parts[i], "UTF-8")), target);
}
}
}
return new LookupTableImpl(lookupMap);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("Failed to decode classification mapping.");
}
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class ClassificationMappingExplanation method getExplanation.
@Override
public String getExplanation(Cell cell, ServiceProvider provider, Locale locale) {
Entity target = CellUtil.getFirstEntity(cell.getTarget());
Entity source = CellUtil.getFirstEntity(cell.getSource());
LookupTable lookup = ClassificationMappingUtil.getClassificationLookup(cell.getTransformationParameters(), provider);
ListMultimap<Value, Value> revLookup = lookup.reverse();
String notClassifiedAction = CellUtil.getFirstParameter(cell, PARAMETER_NOT_CLASSIFIED_ACTION).as(String.class);
if (target != null && source != null) {
StringBuilder mappingString = new StringBuilder();
for (Value targetValue : revLookup.keySet()) {
mappingString.append(quoteValue(targetValue.as(String.class), false));
mappingString.append(' ');
mappingString.append(getMessage("oneOf", locale));
mappingString.append(' ');
int i = 1;
for (Value sourceValue : revLookup.get(targetValue)) {
if (i != 1) {
mappingString.append(", ");
}
mappingString.append(quoteValue(sourceValue.as(String.class), false));
i++;
}
mappingString.append(".\n");
}
String notClassifiedResult = "null";
if (USE_SOURCE_ACTION.equals(notClassifiedAction)) {
notClassifiedResult = getMessage("useSource", locale);
} else if (notClassifiedAction != null && notClassifiedAction.startsWith(USE_FIXED_VALUE_ACTION_PREFIX)) {
notClassifiedResult = quoteText(notClassifiedAction.substring(notClassifiedAction.indexOf(':') + 1), false);
}
return MessageFormat.format(getMessage("main", locale), formatEntity(target, false, true, locale), formatEntity(source, false, true, locale), mappingString.toString(), notClassifiedResult);
}
return null;
}
Aggregations