Search in sources :

Example 11 with HaleConnectService

use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.

the class HaleConnectSourceProvider method getCurrentState.

/**
 * @see org.eclipse.ui.ISourceProvider#getCurrentState()
 */
@Override
public Map<String, Object> getCurrentState() {
    final Map<String, Object> result = new HashMap<String, Object>();
    final HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
    result.put(LOGIN_STATUS, hcs.isLoggedIn());
    return result;
}
Also used : HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService) HashMap(java.util.HashMap)

Example 12 with HaleConnectService

use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.

the class HaleConnectUIPlugin method start.

/**
 * @see AbstractUIPlugin#start(BundleContext)
 */
@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
    try {
        HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
        boolean useDefaults;
        if (!HaleConnectUIPlugin.getDefault().getPreferenceStore().contains(PreferenceConstants.HALE_CONNECT_BASEPATH_USE_DEFAULTS)) {
            useDefaults = true;
            HaleConnectUIPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.HALE_CONNECT_BASEPATH_USE_DEFAULTS, true);
        } else {
            useDefaults = HaleConnectUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.HALE_CONNECT_BASEPATH_USE_DEFAULTS);
        }
        if (useDefaults) {
            // Force default values
            hcs.getBasePathManager().setBasePath(HaleConnectServices.USER_SERVICE, PreferenceInitializer.HALE_CONNECT_BASEPATH_USERS_DEFAULT);
            hcs.getBasePathManager().setBasePath(HaleConnectServices.BUCKET_SERVICE, PreferenceInitializer.HALE_CONNECT_BASEPATH_DATA_DEFAULT);
            hcs.getBasePathManager().setBasePath(HaleConnectServices.PROJECT_STORE, PreferenceInitializer.HALE_CONNECT_BASEPATH_PROJECTS_DEFAULT);
            hcs.getBasePathManager().setBasePath(HaleConnectServices.WEB_CLIENT, PreferenceInitializer.HALE_CONNECT_BASEPATH_CLIENT_DEFAULT);
        } else {
            hcs.getBasePathManager().setBasePath(HaleConnectServices.USER_SERVICE, getPreference(PreferenceConstants.HALE_CONNECT_BASEPATH_USERS));
            hcs.getBasePathManager().setBasePath(HaleConnectServices.BUCKET_SERVICE, getPreference(PreferenceConstants.HALE_CONNECT_BASEPATH_DATA));
            hcs.getBasePathManager().setBasePath(HaleConnectServices.PROJECT_STORE, getPreference(PreferenceConstants.HALE_CONNECT_BASEPATH_PROJECTS));
            hcs.getBasePathManager().setBasePath(HaleConnectServices.WEB_CLIENT, getPreference(PreferenceConstants.HALE_CONNECT_BASEPATH_CLIENT));
        }
    } catch (Throwable t) {
        log.error("Error initializing HaleConnectService", t);
    }
}
Also used : HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService)

Example 13 with HaleConnectService

use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectService in project hale by halestudio.

the class HaleConnectTarget method updateLoginStatus.

private void updateLoginStatus() {
    HaleConnectService hcs = HaleUI.getServiceProvider().getService(HaleConnectService.class);
    boolean loggedIn = hcs.isLoggedIn();
    ownershipGroup.setEnabled(loggedIn);
    enableVersioning.setEnabled(loggedIn);
    publicAccess.setEnabled(loggedIn);
    ownerUser.setEnabled(loggedIn);
    includeWebResources.setEnabled(loggedIn);
    excludeData.setEnabled(loggedIn);
    excludeCachedResources.setEnabled(loggedIn);
    selectProjectButton.setEnabled(loggedIn);
    newProject.setEnabled(loggedIn);
    updateProject.setEnabled(loggedIn);
    if (loggedIn) {
        loginStatusLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN));
        loginStatusLabel.setText(MessageFormat.format("Logged in as {0}", hcs.getSession().getUsername()));
        boolean orgAllowed;
        if (hcs.getSession().getOrganisationIds().isEmpty()) {
            orgAllowed = false;
        } else {
            try {
                orgAllowed = hcs.testUserPermission(RESOURCE_TRANSFORMATION_PROJECT, hcs.getSession().getOrganisationIds().iterator().next(), PERMISSION_CREATE);
            } catch (Throwable t) {
                log.userError("A problem occurred while contacting hale connect. Functionality may be limited.", t);
                orgAllowed = false;
            }
        }
        ownerOrg.setEnabled(false);
        orgSelector.getCombo().setEnabled(false);
        if (orgAllowed) {
            final SettableFuture<List<HaleConnectOrganisationInfo>> orgsFuture = SettableFuture.create();
            Futures.addCallback(orgsFuture, new FutureCallback<List<HaleConnectOrganisationInfo>>() {

                @Override
                public void onSuccess(List<HaleConnectOrganisationInfo> result) {
                    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            ownerOrg.setEnabled(true);
                            orgSelector.getCombo().setEnabled(true);
                            orgSelector.setInput(result);
                            if (!result.isEmpty()) {
                                orgSelector.setSelection(new StructuredSelection(result.get(0)));
                            }
                        }
                    });
                }

                @Override
                public void onFailure(Throwable t) {
                    log.userError("A problem occurred while contacting hale connect. Functionality may be limited.", t);
                }
            });
            Thread fetchOrgInfoThread = new Thread(new Runnable() {

                @Override
                public void run() {
                    boolean hadException = false;
                    List<HaleConnectOrganisationInfo> organisations = new ArrayList<>();
                    List<HaleConnectException> exceptions = new ArrayList<>();
                    for (String orgId : hcs.getSession().getOrganisationIds()) {
                        try {
                            HaleConnectOrganisationInfo orgInfo = hcs.getOrganisationInfo(orgId);
                            if (orgInfo != null) {
                                organisations.add(orgInfo);
                            }
                        } catch (HaleConnectException e) {
                            hadException = true;
                            log.error("Error fetching organization details from hale connect.", e);
                            exceptions.add(e);
                            // As a fallback, display dummy value that
                            // contains the
                            // orgId
                            organisations.add(new HaleConnectOrganisationInfo(orgId, MessageFormat.format("<Organisation {0}>", orgId)));
                        }
                    }
                    orgsFuture.set(organisations);
                    if (hadException) {
                        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                log.userError("A problem occurred while contacting hale connect. Functionality may be limited.");
                            }
                        });
                    }
                }
            });
            fetchOrgInfoThread.start();
        }
        boolean userAllowed;
        try {
            userAllowed = hcs.testUserPermission(RESOURCE_TRANSFORMATION_PROJECT, OwnerType.USER.getJsonValue(), PERMISSION_CREATE);
        } catch (Throwable t) {
            log.userError("A problem occurred while contacting hale connect. Functionality may be limited.", t);
            userAllowed = false;
        }
        ownerUser.setEnabled(userAllowed);
        ownerUser.setSelection(userAllowed);
        if (!userAllowed || !orgAllowed) {
            ownerOrg.setSelection(orgAllowed);
        }
        if (!userAllowed && !orgAllowed) {
            loginStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
            loginStatusLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
            loginStatusLabel.setText("You do not have sufficient permissions to upload transformation projects to hale connect.");
        }
    } else {
        loginStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
        loginStatusLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
        loginStatusLabel.setText("You are not logged in to hale connect. Please login before sharing a project.");
        ownerOrg.setEnabled(false);
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) HaleConnectOrganisationInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo) HaleConnectService(eu.esdihumboldt.hale.io.haleconnect.HaleConnectService) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

HaleConnectService (eu.esdihumboldt.hale.io.haleconnect.HaleConnectService)13 StorageException (org.eclipse.equinox.security.storage.StorageException)6 HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)5 GridData (org.eclipse.swt.layout.GridData)4 StringFieldEditor (org.eclipse.jface.preference.StringFieldEditor)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Button (org.eclipse.swt.widgets.Button)2 Label (org.eclipse.swt.widgets.Label)2 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 HaleConnectOrganisationInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo)1 HaleConnectLoginDialog (eu.esdihumboldt.hale.io.haleconnect.ui.HaleConnectLoginDialog)1 PasswordFieldEditor (eu.esdihumboldt.hale.ui.util.components.PasswordFieldEditor)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 VelocityContext (org.apache.velocity.VelocityContext)1 VelocityEngine (org.apache.velocity.app.VelocityEngine)1