Search in sources :

Example 1 with ProjectInfoService

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

the class HaleConnectTarget method prefillTargetProject.

/**
 */
private void prefillTargetProject() {
    if (!haleConnect.isLoggedIn()) {
        return;
    }
    ProjectInfoService pis = HaleUI.getServiceProvider().getService(ProjectInfoService.class);
    String projectUrnProperty = pis.getProperty(HaleConnectProjectReader.HALECONNECT_URN_PROPERTY).getStringRepresentation();
    if (projectUrnProperty != null) {
        // If project was loaded from hale connect, prefill project name
        URI projectUrn = URI.create(projectUrnProperty);
        if (HaleConnectUrnBuilder.isValidProjectUrn(projectUrn)) {
            String projectId = HaleConnectUrnBuilder.extractProjectId(projectUrn);
            Owner owner = HaleConnectUrnBuilder.extractProjectOwner(projectUrn);
            try {
                if (!haleConnect.testProjectPermission(HaleConnectService.PERMISSION_EDIT, owner, projectId)) {
                    return;
                }
                HaleConnectProjectInfo projectInfo = haleConnect.getProject(owner, projectId);
                if (projectInfo != null) {
                    targetProject = new HaleConnectProjectConfig();
                    targetProject.setOwner(owner);
                    targetProject.setProjectId(projectId);
                    targetProject.setProjectName(projectInfo.getName());
                    targetProject.setLastModified(projectInfo.getLastModified());
                    newProject.setSelection(false);
                    updateProject.setSelection(true);
                    projectName.setStringValue(projectInfo.getName());
                }
            } catch (Throwable t) {
                // Non-fatal
                log.warn(MessageFormat.format("Unable to prefill target project: {0}", t.getMessage()), t);
            }
        }
    }
}
Also used : Owner(eu.esdihumboldt.hale.io.haleconnect.Owner) ProjectInfoService(eu.esdihumboldt.hale.common.core.io.project.ProjectInfoService) HaleConnectProjectInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectProjectInfo) URI(java.net.URI)

Example 2 with ProjectInfoService

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

the class JDBCUtil method replaceVariables.

/**
 * Replace variables in an SQL query.
 *
 * @param query the query
 * @param services the service provider
 * @return the query with variables replaced
 */
public static String replaceVariables(String query, ServiceProvider services) {
    if (services != null) {
        ProjectInfoService projectInfo = services.getService(ProjectInfoService.class);
        ProjectVariableReplacer replacer = new ProjectVariableReplacer(projectInfo);
        return replacer.replaceVariables(query, true);
    }
    return query;
}
Also used : ProjectInfoService(eu.esdihumboldt.hale.common.core.io.project.ProjectInfoService) ProjectVariableReplacer(eu.esdihumboldt.hale.common.core.io.project.ProjectVariableReplacer)

Example 3 with ProjectInfoService

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

the class HaleConnectTarget method updateOverwriteWarning.

private void updateOverwriteWarning() {
    if (createNewProject || targetProject == null) {
        upstreamModifiedWarning.setVisible(false);
        return;
    }
    ProjectInfoService pis = HaleUI.getServiceProvider().getService(ProjectInfoService.class);
    String lastModifiedProperty = pis.getProperty(HaleConnectProjectReader.HALECONNECT_LAST_MODIFIED_PROPERTY).getStringRepresentation();
    if (lastModifiedProperty != null && targetProject != null && targetProject.getLastModified() != null) {
        Long lastModified = Long.parseLong(lastModifiedProperty);
        boolean hasNewerVersion = lastModified < targetProject.getLastModified();
        if (hasNewerVersion) {
            upstreamModifiedWarning.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
            upstreamModifiedWarning.setText("The project on hale connect has been updated since it was last imported.\nChanges may be lost if you continue with this export.");
            upstreamModifiedWarning.setVisible(true);
        } else {
            upstreamModifiedWarning.setVisible(false);
        }
    } else {
        upstreamModifiedWarning.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
        upstreamModifiedWarning.setText("The current project to be exported was not originally imported from hale connect.\nThe project to update on hale connect will be replaced by this project if you continue with this export.");
        upstreamModifiedWarning.setVisible(true);
    }
    updateProjectControls.layout();
}
Also used : ProjectInfoService(eu.esdihumboldt.hale.common.core.io.project.ProjectInfoService)

Example 4 with ProjectInfoService

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

the class DefaultIOAdvisor method prepareProvider.

/**
 * @see AbstractIOAdvisor#prepareProvider(IOProvider)
 */
@Override
public void prepareProvider(T provider) {
    super.prepareProvider(provider);
    if (provider instanceof ProjectInfoAware) {
        ProjectInfoService ps = getService(ProjectInfoService.class);
        if (ps != null) {
            ProjectInfoAware pia = (ProjectInfoAware) provider;
            pia.setProjectInfo(ps.getProjectInfo());
            URI projectFile = ps.getLoadLocation();
            if (projectFile == null) {
                pia.setProjectLocation(null);
            } else {
                pia.setProjectLocation(projectFile);
            }
        }
    }
}
Also used : ProjectInfoService(eu.esdihumboldt.hale.common.core.io.project.ProjectInfoService) ProjectInfoAware(eu.esdihumboldt.hale.common.core.io.project.ProjectInfoAware) URI(java.net.URI)

Aggregations

ProjectInfoService (eu.esdihumboldt.hale.common.core.io.project.ProjectInfoService)4 URI (java.net.URI)2 ProjectInfoAware (eu.esdihumboldt.hale.common.core.io.project.ProjectInfoAware)1 ProjectVariableReplacer (eu.esdihumboldt.hale.common.core.io.project.ProjectVariableReplacer)1 HaleConnectProjectInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectProjectInfo)1 Owner (eu.esdihumboldt.hale.io.haleconnect.Owner)1