Search in sources :

Example 6 with IOConfiguration

use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration in project hale by halestudio.

the class TransformDataWizardSourcePage method createControl.

/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createControl(Composite parent) {
    Composite content = new Composite(parent, SWT.NONE);
    content.setLayout(GridLayoutFactory.swtDefaults().create());
    final ListViewer listViewer = new ListViewer(content);
    listViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    if (!useProjectData) {
        Button addButton = new Button(content, SWT.PUSH);
        addButton.setText("Add source file");
        addButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
        addButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                InstanceImportWizard importWizard = new InstanceImportWizard();
                TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
                // specifying null as actionId results in no call to
                // ProjectService.rememberIO
                importWizard.setAdvisor(advisor, null);
                if (new HaleWizardDialog(getShell(), importWizard).open() == Dialog.OK) {
                    if (advisor.getInstances() != null) {
                        sourceCollections.add(advisor.getInstances());
                        listViewer.add(advisor.getLocation());
                        getContainer().updateButtons();
                    }
                }
            }
        });
    } else {
        // initialize project source data
        IRunnableWithProgress op = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Prepare data sources", IProgressMonitor.UNKNOWN);
                ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
                final List<URI> locations = new ArrayList<>();
                for (Resource resource : ps.getResources()) {
                    if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(resource.getActionId())) {
                        // resource is source data
                        IOConfiguration conf = resource.copyConfiguration(true);
                        TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
                        ProjectResourcesUtil.executeConfiguration(conf, advisor, false, null);
                        if (advisor.getInstances() != null) {
                            sourceCollections.add(advisor.getInstances());
                            locations.add(advisor.getLocation());
                        }
                    }
                }
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        for (URI location : locations) {
                            listViewer.add(location);
                        }
                    }
                });
                monitor.done();
            }
        };
        try {
            ThreadProgressMonitor.runWithProgressDialog(op, false);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    setControl(content);
}
Also used : InstanceImportWizard(eu.esdihumboldt.hale.ui.io.instance.InstanceImportWizard) ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 7 with IOConfiguration

use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration 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;
}
Also used : Path(java.nio.file.Path) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) HashMap(java.util.HashMap) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IContentType(org.eclipse.core.runtime.content.IContentType) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) ResourceAdvisor(eu.esdihumboldt.hale.common.core.io.ResourceAdvisor) Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) Value(eu.esdihumboldt.hale.common.core.io.Value) File(java.io.File)

Example 8 with IOConfiguration

use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration in project hale by halestudio.

the class ProjectToJaxb method convert.

/**
 * Convert the given project to the corresponding JAXB type.
 *
 * @param project the project to convert
 * @return the converted project
 */
public static ProjectType convert(Project project) {
    ProjectType result = new ProjectType();
    result.setAuthor(project.getAuthor());
    result.setCreated(toXMLCalendar(project.getCreated()));
    result.setDescription(project.getDescription());
    result.setModified(toXMLCalendar(project.getModified()));
    result.setName(project.getName());
    result.setSaveConfig(toIOConfigurationType(project.getSaveConfiguration()));
    if (project.getHaleVersion() != null) {
        result.setVersion(project.getHaleVersion().toString());
    }
    // resources
    for (IOConfiguration resource : project.getResources()) {
        result.getResource().add(toIOConfigurationType(resource));
    }
    // export configs
    for (Entry<String, IOConfiguration> confEntry : project.getExportConfigurations().entrySet()) {
        IOConfigurationType conf = toIOConfigurationType(confEntry.getValue());
        ExportConfigurationType exportConf = new ExportConfigurationType();
        exportConf.setConfiguration(conf);
        exportConf.setName(confEntry.getKey());
        result.getExportConfig().add(exportConf);
    }
    // project files
    for (ProjectFileInfo file : project.getProjectFiles()) {
        result.getFile().add(toProjectFileType(file));
    }
    // properties
    for (Entry<String, Value> property : project.getProperties().entrySet()) {
        Object p = createProperty(property.getKey(), property.getValue());
        if (p instanceof PropertyType) {
            result.getAbstractProperty().add(of.createProperty((PropertyType) p));
        } else if (p instanceof ComplexPropertyType) {
            result.getAbstractProperty().add(of.createComplexProperty((ComplexPropertyType) p));
        }
    }
    return result;
}
Also used : IOConfigurationType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.IOConfigurationType) ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType) ExportConfigurationType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ExportConfigurationType) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) Value(eu.esdihumboldt.hale.common.core.io.Value) PropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.PropertyType) ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType)

Example 9 with IOConfiguration

use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration in project hale by halestudio.

the class HaleConnectProjectReader method execute.

/**
 * @see eu.esdihumboldt.hale.common.core.io.project.impl.ArchiveProjectReader#execute(eu.esdihumboldt.hale.common.core.io.ProgressIndicator,
 *      eu.esdihumboldt.hale.common.core.io.report.IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    IOReport result = super.execute(progress, reporter);
    if (getSource() instanceof HaleConnectInputSupplier) {
        HaleConnectInputSupplier source = (HaleConnectInputSupplier) getSource();
        getProject().getProperties().put(HALECONNECT_LAST_MODIFIED_PROPERTY, Value.of(source.getLastModified()));
        getProject().getProperties().put(HALECONNECT_URN_PROPERTY, Value.of(source.getLocation()));
        IOConfiguration saveConfig = getProject().getSaveConfiguration();
        saveConfig.setProviderId(HaleConnectProjectWriter.ID);
        saveConfig.getProviderConfiguration().put(ExportProvider.PARAM_CONTENT_TYPE, Value.of(HaleConnectProjectWriter.HALECONNECT_CONTENT_TYPE_ID));
        /*
			 * Don't overwrite the target of the save configuration which is, at
			 * this point, set to the temporary location of the extracted
			 * project archive. The reason for this is to make sure that
			 * PathUpdate can correctly resolve all relative resource paths.
			 * (https://github.com/halestudio/hale/issues/506)
			 */
        // saveConfig.getProviderConfiguration().put(ExportProvider.PARAM_TARGET,
        // Value.of(source.getLocation()));
        getProject().setSaveConfiguration(saveConfig);
    }
    return result;
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) HaleConnectInputSupplier(eu.esdihumboldt.hale.io.haleconnect.HaleConnectInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 10 with IOConfiguration

use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration 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);
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IContentType(org.eclipse.core.runtime.content.IContentType) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) File(java.io.File)

Aggregations

IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)31 Value (eu.esdihumboldt.hale.common.core.io.Value)10 URI (java.net.URI)9 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)8 File (java.io.File)8 IOException (java.io.IOException)6 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)5 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)5 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)5 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ArrayList (java.util.ArrayList)5 IOConfigurationResource (eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)4 Project (eu.esdihumboldt.hale.common.core.io.project.model.Project)4 ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)3 ProjectFile (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile)3 LocationUpdater (eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater)3