use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class JacksonMapper method skipChoice.
/**
* Handles skipping choice groups.
*
* @param propertyName the start property name
* @param obj the object to inspect
* @param reporter the reporter
* @return a pair of property name and value to use
*/
private Pair<String, Object> skipChoice(String propertyName, Object obj, IOReporter reporter) {
if (obj instanceof Group) {
Group group = (Group) obj;
// For choices search for the (only!) child and skip the choice.
if (group.getDefinition() instanceof GroupPropertyDefinition) {
if (((GroupPropertyDefinition) group.getDefinition()).getConstraint(ChoiceFlag.class).isEnabled()) {
Iterator<QName> childPropertyNames = group.getPropertyNames().iterator();
if (!childPropertyNames.hasNext()) {
reporter.warn(new IOMessageImpl("Found an empty choice.", null));
return null;
}
QName childPropertyName = childPropertyNames.next();
Object[] values = group.getProperty(childPropertyName);
Object value = values[0];
if (childPropertyNames.hasNext() || values.length > 1)
reporter.warn(new IOMessageImpl("Found a choice with multiple children. Using first.", null));
// delegate to only value
return skipChoice(childPropertyName.getLocalPart(), value, reporter);
}
}
}
return new Pair<>(propertyName, obj);
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class OrdinatesToPointTranslator 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) {
reporter.warn(new IOMessageImpl("Behavior of this function has changed.", null));
List<NamedEntityBean> src = cellBean.getSource();
for (int i = 0; i < src.size(); i++) {
NamedEntityBean bean = src.get(i);
if (i == 0) {
bean.setName("X");
}
if (i == 1) {
bean.setName("Y");
}
if (i == 2) {
bean.setName("Z");
}
}
return params;
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class ProjectParser method load.
private void load(URI source, String actionId, String msgCT, String msgIO, @SuppressWarnings("rawtypes") Class clazz) {
// create IOConfiguration for source data
IOConfiguration conf = new IOConfiguration();
// populate IOConfiguration
// set action ID
conf.setActionId(actionId);
// find provider
File file;
try {
file = new File(source);
} catch (IllegalArgumentException e) {
file = null;
}
@SuppressWarnings("unchecked") IContentType ct = HaleIO.findContentType(clazz, new DefaultInputSupplier(source), (file == null) ? (null) : (file.getAbsolutePath()));
if (ct == null) {
report.error(new IOMessageImpl(msgCT, null, -1, -1, source));
return;
}
@SuppressWarnings("unchecked") IOProviderDescriptor srf = HaleIO.findIOProviderFactory(clazz, ct, null);
if (srf == null) {
report.error(new IOMessageImpl(msgIO, null, -1, -1, source));
return;
}
conf.setProviderId(srf.getIdentifier());
// provider configuration
// source
conf.getProviderConfiguration().put(AbstractImportProvider.PARAM_SOURCE, Value.of(source.toString()));
// content type
conf.getProviderConfiguration().put(AbstractImportProvider.PARAM_CONTENT_TYPE, Value.of(ct.getId()));
// no dependencies needed
// add configuration to project
project.getResources().add(conf);
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class ShapeInstanceReader method execute.
/**
* @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
// $NON-NLS-1$
progress.begin(Messages.getString("ShapeSchemaProvider.1"), ProgressIndicator.UNKNOWN);
// DataStore store = new ShapefileDataStoreFactory().createDataStore(location.toURL());
// DataStore store = FileDataStoreFinder.getDataStore(getSource().getLocation().toURL());
ShapefileDataStore store = new ShapefileDataStore(getSource().getLocation().toURL());
store.setCharset(getCharset());
progress.setCurrentTask("Extracting shape instances");
String typename = getParameter(PARAM_TYPENAME).as(String.class);
TypeDefinition defaultType = null;
if (typename != null && !typename.isEmpty()) {
try {
defaultType = getSourceSchema().getType(QName.valueOf(typename));
} catch (Exception e) {
// ignore
}
}
if (defaultType == null) {
// check if typename was supplied w/o namespace
try {
defaultType = getSourceSchema().getType(new QName(ShapefileConstants.SHAPEFILE_NS, typename));
} catch (Exception e) {
// ignore
// TODO report?
}
}
if (defaultType == null) {
reporter.info(new IOMessageImpl("No type name supplied as parameter, trying to auto-detect the schema type.", null));
TypeDefinition dataType = ShapeSchemaReader.readShapeType(getSource());
if (dataType == null) {
throw new IOException("Could not read shapefile structure information");
}
String preferredName = null;
Name name = store.getNames().iterator().next();
if (name != null) {
preferredName = name.getLocalPart();
}
Pair<TypeDefinition, Integer> tp = getMostCompatibleShapeType(getSourceSchema(), dataType, preferredName);
if (tp == null) {
throw new IOProviderConfigurationException("No schema type specified and auto-detection failed");
}
defaultType = tp.getFirst();
reporter.info(new IOMessageImpl(MessageFormat.format("Auto-deteted {0} as schema type, with a {1}% compatibility rating.", defaultType.getName(), tp.getSecond()), null));
}
Map<TypeDefinition, InstanceCollection> collections = new HashMap<>();
// create a collection for each type
for (Name name : store.getNames()) {
SimpleFeatureSource features = store.getFeatureSource(name);
TypeDefinition type = defaultType;
if (type == null) {
QName typeName = new QName(ShapefileConstants.SHAPEFILE_NS, name.getLocalPart());
type = getSourceSchema().getType(typeName);
}
collections.put(type, new ShapesInstanceCollection(features, type, getCrsProvider(), name.getLocalPart()));
}
instances = new PerTypeInstanceCollection(collections);
reporter.setSuccess(true);
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class AbstractWFSWriter method execute.
@Override
public IOReport execute(ProgressIndicator progress) throws IOProviderConfigurationException, IOException {
progress.begin("WFS Transaction", ProgressIndicator.UNKNOWN);
// configure internal provider
internalProvider.setDocumentWrapper(createTransaction());
final PipedInputStream pIn = new PipedInputStream();
PipedOutputStream pOut = new PipedOutputStream(pIn);
currentExecuteStream = pOut;
Future<Response> futureResponse = null;
IOReporter reporter = createReporter();
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
// read the stream (in another thread)
futureResponse = executor.submit(new Callable<Response>() {
@Override
public Response call() throws Exception {
Proxy proxy = ProxyUtil.findProxy(targetWfs.getLocation());
Request request = Request.Post(targetWfs.getLocation()).bodyStream(pIn, ContentType.APPLICATION_XML);
Executor executor = FluentProxyUtil.setProxy(request, proxy);
// authentication
String user = getParameter(PARAM_USER).as(String.class);
String password = getParameter(PARAM_PASSWORD).as(String.class);
if (user != null) {
// target host
int port = targetWfs.getLocation().getPort();
String hostName = targetWfs.getLocation().getHost();
String scheme = targetWfs.getLocation().getScheme();
HttpHost host = new HttpHost(hostName, port, scheme);
// add credentials
Credentials cred = ClientProxyUtil.createCredentials(user, password);
executor.auth(new AuthScope(host), cred);
executor.authPreemptive(host);
}
try {
return executor.execute(request);
} finally {
pIn.close();
}
}
});
// write the stream
SubtaskProgressIndicator subprogress = new SubtaskProgressIndicator(progress);
reporter = (IOReporter) super.execute(subprogress);
} finally {
executor.shutdown();
}
try {
Response response = futureResponse.get();
HttpResponse res = response.returnResponse();
int statusCode = res.getStatusLine().getStatusCode();
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
if (statusCode >= 200 && statusCode < 300) {
// success
reporter.setSuccess(reporter.isSuccess());
// construct summary from response
try {
Document responseDoc = parseResponse(res.getEntity());
// totalInserted
String inserted = xpath.compile("//TransactionSummary/totalInserted").evaluate(responseDoc);
// XXX totalUpdated
// XXX totalReplaced
// XXX totalDeleted
reporter.setSummary("Inserted " + inserted + " features.");
} catch (XPathExpressionException e) {
log.error("Error in XPath used to evaluate service response");
} catch (ParserConfigurationException | SAXException e) {
reporter.error(new IOMessageImpl(MessageFormat.format("Server returned status code {0}, but could not parse server response", statusCode), e));
reporter.setSuccess(false);
}
} else {
// failure
reporter.error(new IOMessageImpl("Server reported failure with code " + res.getStatusLine().getStatusCode() + ": " + res.getStatusLine().getReasonPhrase(), null));
reporter.setSuccess(false);
try {
Document responseDoc = parseResponse(res.getEntity());
String errorText = xpath.compile("//ExceptionText/text()").evaluate(responseDoc);
reporter.setSummary("Request failed: " + errorText);
} catch (XPathExpressionException e) {
log.error("Error in XPath used to evaluate service response");
} catch (ParserConfigurationException | SAXException e) {
reporter.error(new IOMessageImpl("Could not parse server response", e));
reporter.setSuccess(false);
}
}
} catch (ExecutionException | InterruptedException e) {
reporter.error(new IOMessageImpl("Failed to execute WFS-T request", e));
reporter.setSuccess(false);
}
progress.end();
return reporter;
}
Aggregations