use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class ClassificationMappingTranslator method getNewParameters.
/**
* @see eu.esdihumboldt.hale.io.oml.helper.FunctionTranslator#getNewParameters(java.util.List,
* eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean,
* eu.esdihumboldt.hale.common.core.io.report.IOReporter,
* eu.esdihumboldt.hale.io.oml.internal.model.align.ICell)
*/
@Override
public List<ParameterValueBean> getNewParameters(List<ParameterValueBean> params, CellBean cellBean, IOReporter reporter, ICell cell) {
List<ParameterValueBean> newList = new ArrayList<ParameterValueBean>();
List<Restriction> sourceRest = new ArrayList<Restriction>();
List<Restriction> tarRest = new ArrayList<Restriction>();
sourceRest = ((Property) cell.getEntity1()).getValueCondition();
tarRest = ((Property) cell.getEntity2()).getValueCondition();
for (int i = 0; i < sourceRest.size(); i++) {
Restriction r1 = sourceRest.get(i);
Restriction r2 = tarRest.get(i);
Joiner joiner = Joiner.on(" ").skipNulls();
List<String> encodedParams = new ArrayList<String>();
// first encode and add the associated value to the string list ...
for (IValueExpression ival : r2.getValue()) {
String temp = null;
try {
temp = URLEncoder.encode(ival.getLiteral(), "UTF-8");
} catch (UnsupportedEncodingException e) {
reporter.error(new IOMessageImpl("Parameter could not be encoded.", null));
e.printStackTrace();
}
encodedParams.add(temp);
}
// then encode and add the value expressions to the string list
for (IValueExpression ival : r1.getValue()) {
String temp = null;
try {
temp = URLEncoder.encode(ival.getLiteral(), "UTF-8");
} catch (UnsupportedEncodingException e) {
reporter.error(new IOMessageImpl("Parameter could not be encoded.", null));
e.printStackTrace();
}
encodedParams.add(temp);
}
String encodedParameter = joiner.join(encodedParams);
newList.add(new ParameterValueBean(PARAMETER_CLASSIFICATIONS, encodedParameter));
}
return newList;
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class NotSupportedTranslator method getNewParameters.
/**
* @see eu.esdihumboldt.hale.io.oml.helper.FunctionTranslator#getNewParameters(java.util.List,
* eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean,
* eu.esdihumboldt.hale.common.core.io.report.IOReporter,
* eu.esdihumboldt.hale.io.oml.internal.model.align.ICell)
*/
@Override
public List<ParameterValueBean> getNewParameters(List<ParameterValueBean> params, CellBean cellBean, IOReporter reporter, ICell cell) {
IEntity entity1 = cell.getEntity1();
IEntity entity2 = cell.getEntity2();
String id = null;
if (entity1.getTransformation() != null || entity2.getTransformation() != null) {
if (entity1.getTransformation() != null) {
id = entity1.getTransformation().getService().getLocation();
} else {
id = entity2.getTransformation().getService().getLocation();
}
}
reporter.error(new IOMessageImpl("The function '" + id + "' is not supported in this hale studio version", null));
return params;
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class XsltGenerator method writeContainerFragment.
/**
* Write the container fragment.
*
* @param templateFile the file to write to
* @param groupedResults the result variable names grouped by associated
* target type
* @param targetElements an empty map that is populated with variable names
* mapped to target element names
* @throws IOException if an error occurs writing the template
* @throws XMLStreamException if an error occurs writing XML content to the
* template
*/
private void writeContainerFragment(File templateFile, Multimap<TypeDefinition, String> groupedResults, Map<String, QName> targetElements) throws XMLStreamException, IOException {
XMLStreamWriter writer = XslTransformationUtil.setupXMLWriter(new BufferedOutputStream(new FileOutputStream(templateFile)), prefixes);
try {
// write container
GmlWriterUtil.writeStartElement(writer, targetContainer.getName());
// generate an eventual required identifier on the container
GmlWriterUtil.writeRequiredID(writer, targetContainer.getType(), null, false);
writeContainerIntro(writer, context);
// cache definition paths
Map<TypeDefinition, DefinitionPath> paths = new HashMap<TypeDefinition, DefinitionPath>();
Descent lastDescent = null;
for (Entry<TypeDefinition, String> entry : groupedResults.entries()) {
TypeDefinition type = entry.getKey();
// get stored definition path for the type
DefinitionPath defPath;
if (paths.containsKey(type)) {
// get the stored path, may be null
defPath = paths.get(type);
} else {
// determine a valid definition path in the container
defPath = findMemberAttribute(targetContainer, type);
// store path (may be null)
paths.put(type, defPath);
}
if (defPath != null) {
// insert xsl:for-each at the appropriate position in
// the path
defPath = pathInsertForEach(defPath, entry.getValue(), targetElements);
lastDescent = Descent.descend(writer, defPath, lastDescent, false, true);
// write single target instance from variable
GmlWriterUtil.writeEmptyElement(writer, new QName(NS_URI_XSL, "copy-of"));
writer.writeAttribute("select", ".");
} else {
reporter.warn(new IOMessageImpl(MessageFormat.format("No compatible member attribute for type {0} found in root element {1}, one instance was skipped", type.getDisplayName(), targetContainer.getName().getLocalPart()), null));
}
}
if (lastDescent != null) {
lastDescent.close();
}
// end container
writer.writeEndElement();
} finally {
writer.close();
}
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class WorkspaceConfigurationPage method updateWorkspaceTable.
private void updateWorkspaceTable() {
AbstractAppSchemaConfigurator configurator = getWizard().getProvider();
DefaultIOReporter reporter = new DefaultIOReporter(configurator.getTarget(), "Generate Temporary App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, true);
AppSchemaMappingGenerator generator;
try {
configurator.generateMapping(reporter);
generator = configurator.getMappingGenerator();
AppSchemaDataAccessType appSchemaMapping = generator.getGeneratedMapping().getAppSchemaMapping();
List<FeatureTypeMapping> typeMappings = appSchemaMapping.getTypeMappings().getFeatureTypeMapping();
for (FeatureTypeMapping typeMapping : typeMappings) {
String[] workspaceAndType = typeMapping.getTargetElement().split(":");
String workspaceName = workspaceAndType[0];
String typeName = workspaceAndType[1];
List<Namespace> namespaces = appSchemaMapping.getNamespaces().getNamespace();
for (Namespace namespace : namespaces) {
if (workspaceName.equals(namespace.getPrefix())) {
String uri = namespace.getUri();
if (workspaceConf.hasWorkspace(uri)) {
workspaceConf.getWorkspace(uri).getFeatureTypes().add(typeName);
} else {
WorkspaceMetadata workspace = new WorkspaceMetadata(workspaceName, uri);
workspace.getFeatureTypes().add(typeName);
workspaceConf.addWorkspace(workspace);
}
}
}
}
// remove workspaces that contain no features
workspaceConf.getWorkspaces().forEach((ws) -> {
if (ws.getFeatureTypes().isEmpty()) {
workspaceConf.removeWorkspace(ws.getNamespaceUri());
}
});
workspaceTableViewer.setInput(workspaceConf.getWorkspaces());
reporter.setSuccess(true);
} catch (Exception e) {
reporter.error(new IOMessageImpl(e.getMessage(), e));
reporter.setSuccess(false);
}
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class AbstractAppSchemaConfigurator method updateTargetSchemaResources.
// TODO: code adapted from ArchiveProjectWriter: how to avoid duplication?
private Map<URI, String> updateTargetSchemaResources(File targetDirectory, ProgressIndicator progress, IOReporter reporter) throws IOException {
progress.begin("Copy resources", ProgressIndicator.UNKNOWN);
Project project = (Project) getProjectInfo();
// resource locations mapped to new resource path
Map<URI, String> handledResources = new HashMap<>();
try {
List<IOConfiguration> resources = project.getResources();
// every resource needs his own directory
int count = 0;
Iterator<IOConfiguration> iter = resources.iterator();
while (iter.hasNext()) {
IOConfiguration resource = iter.next();
if (resource.getActionId().equals(SchemaIO.ACTION_LOAD_TARGET_SCHEMA)) {
// get resource path
Map<String, Value> providerConfig = resource.getProviderConfiguration();
String path = providerConfig.get(ImportProvider.PARAM_SOURCE).toString();
URI pathUri;
try {
pathUri = new URI(path);
} catch (URISyntaxException e1) {
reporter.error(new IOMessageImpl("Skipped resource because of invalid URI: " + path, e1));
continue;
}
// check if path was already handled
if (handledResources.containsKey(pathUri)) {
// skip copying the resource
continue;
}
String scheme = pathUri.getScheme();
LocatableInputSupplier<? extends InputStream> input = null;
if (scheme != null) {
if (scheme.equals("http") || scheme.equals("https") || scheme.equals("file") || scheme.equals("platform") || scheme.equals("bundle") || scheme.equals("jar")) {
input = new DefaultInputSupplier(pathUri);
} else {
continue;
}
} else {
// now can't open that, can we?
reporter.error(new IOMessageImpl("Skipped resource because it cannot be loaded from " + pathUri.toString(), null));
continue;
}
progress.setCurrentTask("Copying resource at " + path);
// every resource file is copied into an own resource
// directory in the target directory
String resourceFolder = "_schemas";
if (count > 0) {
resourceFolder += count;
}
File newDirectory = new File(targetDirectory, resourceFolder);
try {
newDirectory.mkdir();
} catch (SecurityException e) {
throw new IOException("Can not create directory " + newDirectory.toString(), e);
}
// the filename
String name = path.toString().substring(path.lastIndexOf("/") + 1, path.length());
// remove any query string from the filename
int queryIndex = name.indexOf('?');
if (queryIndex >= 0) {
name = name.substring(0, queryIndex);
}
if (name.isEmpty()) {
name = "file";
}
File newFile = new File(newDirectory, name);
Path target = newFile.toPath();
// retrieve the resource advisor
Value ct = providerConfig.get(ImportProvider.PARAM_CONTENT_TYPE);
IContentType contentType = null;
if (ct != null) {
contentType = HalePlatform.getContentTypeManager().getContentType(ct.as(String.class));
}
ResourceAdvisor ra = ResourceAdvisorExtension.getInstance().getAdvisor(contentType);
// copy the resource
progress.setCurrentTask("Copying resource at " + path);
ra.copyResource(input, target, contentType, true, reporter);
// store new path for resource
String newPath = resourceFolder + "/" + name;
handledResources.put(pathUri, newPath);
count++;
}
}
} finally {
progress.end();
}
return handledResources;
}
Aggregations