Search in sources :

Example 11 with Locatable

use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.

the class JaxbAlignmentIO method printCell.

/**
 * Print a cell to an output stream (intended for tests/debugging).
 *
 * @param cell the cell to print
 * @param out the output stream
 * @throws Exception if an error occurs trying to print the cell
 */
public static void printCell(MutableCell cell, OutputStream out) throws Exception {
    DefaultAlignment alignment = new DefaultAlignment();
    alignment.addCell(cell);
    IOReporter reporter = new DefaultIOReporter(new Locatable() {

        @Override
        public URI getLocation() {
            return null;
        }
    }, "Print cell", null, false);
    PathUpdate pathUpdate = new PathUpdate(null, null);
    AlignmentType at = convert(alignment, reporter, pathUpdate);
    CellType ct = (CellType) at.getCellOrModifier().get(0);
    JAXBContext jc = JAXBContext.newInstance(ALIGNMENT_CONTEXT, ObjectFactory.class.getClassLoader());
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    ObjectFactory of = new ObjectFactory();
    try {
        m.marshal(of.createCell(ct), out);
    } finally {
        out.flush();
        out.close();
    }
}
Also used : AlignmentType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) Marshaller(javax.xml.bind.Marshaller) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) ObjectFactory(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory) CellType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) JAXBContext(javax.xml.bind.JAXBContext) URI(java.net.URI) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 12 with Locatable

use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.

the class FileValidateTarget method createControls.

@Override
public void createControls(Composite parent) {
    super.createControls(parent);
    // page has a 3-column grid layout
    Group validatorGroup = new Group(parent, SWT.NONE);
    validatorGroup.setText("Validation");
    validatorGroup.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).span(3, 1).indent(8, 10).create());
    validatorGroup.setLayout(GridLayoutFactory.swtDefaults().numColumns(3).margins(10, 8).create());
    // Add project validator by default
    IOProviderDescriptor pvDescriptor = HaleIO.findIOProviderFactory(IOProvider.class, getWizard().getContentType(), ProjectValidator.PROVIDER_ID);
    if (pvDescriptor != null) {
        ProjectValidator projectValidator = new ProjectValidator();
        List<? extends Locatable> schemas = getWizard().getProvider().getValidationSchemas();
        projectValidator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
        ValidatorEntry entry = new ValidatorEntry(projectValidator, pvDescriptor);
        validators.add(entry);
        getWizard().addValidator(projectValidator);
    }
    // viewer with validator list
    Composite tableContainer = new Composite(validatorGroup, SWT.NONE);
    tableContainer.setLayoutData(GridDataFactory.swtDefaults().span(3, 1).minSize(100, 100).align(SWT.FILL, SWT.FILL).grab(true, true).create());
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    validatorsTableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    validatorsTableViewer.getTable().setLinesVisible(true);
    validatorsTableViewer.getTable().setHeaderVisible(true);
    validatorsTableViewer.setContentProvider(ArrayContentProvider.getInstance());
    validatorsTableViewer.setInput(validators);
    TableViewerColumn typeColumn = new TableViewerColumn(validatorsTableViewer, SWT.NONE);
    layout.setColumnData(typeColumn.getColumn(), new ColumnWeightData(4));
    typeColumn.getColumn().setText("Validator");
    typeColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ValidatorEntry validator = (ValidatorEntry) element;
            return validator.getDescriptor().getDisplayName();
        }

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
         */
        @Override
        public Image getImage(Object element) {
            ValidatorEntry validator = (ValidatorEntry) element;
            if (validator.getStatusMessage() != null && !validator.getStatusMessage().isEmpty()) {
                return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEC_FIELD_ERROR);
            }
            return null;
        }
    });
    TableViewerColumn errorColumn = new TableViewerColumn(validatorsTableViewer, SWT.NONE);
    layout.setColumnData(errorColumn.getColumn(), new ColumnWeightData(3));
    errorColumn.getColumn().setText("Status");
    errorColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ValidatorEntry validator = (ValidatorEntry) element;
            String message = validator.getStatusMessage();
            if (message == null || message.trim().isEmpty()) {
                message = "OK";
            }
            return message;
        }
    });
    validatorsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateWizard(getSelectedValidator(event.getSelection()));
        }
    });
    // Selection dialog for adding validators to the list
    final ValidatorSelectionDialog validatorSelectionDialog = new ValidatorSelectionDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
    addValidatorButton = new Button(validatorGroup, SWT.PUSH);
    addValidatorButton.setText("Add validator...");
    addValidatorButton.setEnabled(false);
    addValidatorButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            validatorSelectionDialog.create();
            validatorSelectionDialog.setContentType(getWizard().getContentType());
            if (validatorSelectionDialog.open() == Dialog.OK) {
                IOProviderDescriptor selection = validatorSelectionDialog.getSelection();
                addValidator(selection);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    // Remove button
    removeValidatorButton = new Button(validatorGroup, SWT.PUSH);
    removeValidatorButton.setText("Remove validator...");
    removeValidatorButton.setEnabled(false);
    removeValidatorButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ValidatorEntry selection = getSelectedValidator();
            getWizard().removeValidator(selection.getValidator());
            validators.remove(selection);
            updateWizard(getSelectedValidator());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    // Configure button
    configureValidatorButton = new Button(validatorGroup, SWT.PUSH);
    configureValidatorButton.setText("Configure validator...");
    configureValidatorButton.setEnabled(false);
    getWizard().addIOWizardListener(this);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Group(org.eclipse.swt.widgets.Group) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ProjectValidator(eu.esdihumboldt.hale.io.validation.ProjectValidator) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 13 with Locatable

use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.

the class InstanceExportWizard method performValidation.

/**
 * Run the configured validators on the exported instance. May be overriden
 * to customize validation process.
 *
 * @return true if all validations were successful
 */
protected boolean performValidation() {
    boolean success = true;
    for (InstanceValidator validator : validators) {
        // set schemas
        List<? extends Locatable> schemas = getProvider().getValidationSchemas();
        validator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
        // set service provider
        validator.setServiceProvider(HaleUI.getServiceProvider());
        ExportTarget<?> exportTarget = getSelectTargetPage().getExportTarget();
        if (exportTarget instanceof FileTarget) {
            LocatableOutputSupplier<? extends OutputStream> target = getProvider().getTarget();
            List<String> fileNames = new ArrayList<>();
            if (target instanceof MultiLocationOutputSupplier) {
                for (URI location : ((MultiLocationOutputSupplier) target).getLocations()) {
                    if (!"file".equals(location.getScheme())) {
                        continue;
                    }
                    File targetFile = new File(location);
                    fileNames.add(targetFile.getAbsolutePath());
                }
            } else {
                fileNames.add(((FileTarget<?>) exportTarget).getTargetFileName());
            }
            for (String fileName : fileNames) {
                LocatableInputSupplier<? extends InputStream> source = new FileIOSupplier(new File(fileName));
                validator.setSource(source);
                validator.setContentType(getContentType());
                IOReporter defReport = validator.createReporter();
                // validate and execute provider
                try {
                    // validate configuration
                    validator.validate();
                    IOReport report = execute(validator, defReport);
                    if (report != null) {
                        // add report to report server
                        ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
                        repService.addReport(report);
                        if (report.isSuccess()) {
                            log.info(report.getSummary());
                        } else {
                            log.error(report.getSummary());
                            success = false;
                        }
                    }
                } catch (IOProviderConfigurationException e) {
                    log.error(MessageFormat.format("The validator '{0}' could not be executed", validator.getClass().getCanonicalName()), e);
                    success = false;
                }
            }
        } else {
            log.error("No input can be provided for validation (no file target)");
            success = false;
        }
    }
    if (success) {
        log.userInfo("All validations completed successfully.");
    } else {
        log.userError("There were validation failures. Please check the report for more details.");
    }
    return success;
}
Also used : InstanceValidator(eu.esdihumboldt.hale.common.instance.io.InstanceValidator) ArrayList(java.util.ArrayList) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) URI(java.net.URI) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) FileTarget(eu.esdihumboldt.hale.ui.io.target.FileTarget) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) MultiLocationOutputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.MultiLocationOutputSupplier) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) File(java.io.File) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Aggregations

Locatable (eu.esdihumboldt.hale.common.core.io.supplier.Locatable)13 URI (java.net.URI)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)4 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)4 InstanceValidator (eu.esdihumboldt.hale.common.instance.io.InstanceValidator)4 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)3 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)3 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)3 ArrayList (java.util.ArrayList)3 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)2 LocatableURI (eu.esdihumboldt.hale.common.core.io.supplier.LocatableURI)2 BasePathResolver (eu.esdihumboldt.hale.io.haleconnect.BasePathResolver)2 IOException (java.io.IOException)2 ATransaction (de.fhg.igd.slf4jplus.ATransaction)1 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)1 CellType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType)1 ObjectFactory (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory)1 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)1