Search in sources :

Example 1 with HaleConnectOrganisationInfo

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

the class HaleConnectServiceImpl method getOrganisationInfo.

/**
 * @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#getOrganisationInfo(java.lang.String)
 */
@Override
public HaleConnectOrganisationInfo getOrganisationInfo(String orgId) throws HaleConnectException {
    if (!this.isLoggedIn()) {
        return null;
    }
    if (!orgInfoCache.containsKey(orgId)) {
        OrganisationsApi api = UserServiceHelper.getOrganisationsApi(this, this.getSession().getToken());
        try {
            OrganisationInfo org = api.getOrganisation(orgId);
            orgInfoCache.put(org.getId(), new HaleConnectOrganisationInfo(org.getId(), org.getName()));
        } catch (ApiException e) {
            throw new HaleConnectException(e.getMessage(), e);
        }
    }
    return orgInfoCache.get(orgId);
}
Also used : HaleConnectOrganisationInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo) OrganisationInfo(com.haleconnect.api.user.v1.model.OrganisationInfo) HaleConnectOrganisationInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) OrganisationsApi(com.haleconnect.api.user.v1.api.OrganisationsApi) ApiException(com.haleconnect.api.user.v1.ApiException)

Example 2 with HaleConnectOrganisationInfo

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

the class HaleConnectTarget method createControls.

@Override
public void createControls(Composite parent) {
    getPage().setDescription("Please select a destination file for the export");
    parent.setLayout(new GridLayout(3, false));
    /*
		 * Login status label
		 */
    loginStatusLabel = new Label(parent, SWT.NONE);
    loginStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    loginButton = new Button(parent, SWT.PUSH);
    loginButton.setText("Login");
    loginButton.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            HaleConnectLoginDialog loginDialog = HaleConnectLoginHandler.createLoginDialog(Display.getCurrent().getActiveShell());
            if (loginDialog.open() == Dialog.OK) {
                HaleConnectLoginHandler.performLogin(loginDialog);
                updateState();
                prefillTargetProject();
            }
        }
    });
    updateOrNewGroup = new Group(parent, SWT.NONE);
    updateOrNewGroup.setText("Please choose whether you would like to...");
    updateOrNewGroup.setLayout(new GridLayout(3, true));
    updateOrNewGroup.setLayoutData(new GridData(SWT.LEAD, SWT.LEAD, true, false, 3, 1));
    newProject = new Button(updateOrNewGroup, SWT.RADIO);
    newProject.setText("create a new project on hale connect");
    newProject.setSelection(true);
    newProject.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateState();
        }
    });
    updateProject = new Button(updateOrNewGroup, SWT.RADIO);
    updateProject.setText("update an existing project");
    updateProject.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateState();
        }
    });
    controlsStackLayout = new StackLayout();
    controlsStack = new Composite(parent, SWT.NONE);
    controlsStack.setLayout(controlsStackLayout);
    newProjectControls = new Composite(controlsStack, SWT.NONE);
    newProjectControls.setLayout(new GridLayout(3, true));
    GridData grid = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    newProjectControls.setLayoutData(grid);
    ownershipGroup = new Composite(newProjectControls, SWT.NONE);
    ownershipGroup.setLayout(new GridLayout(4, false));
    ownershipGroup.setLayoutData(new GridData(SWT.LEAD, SWT.LEAD, false, false, 4, 1));
    Label ownerLabel = new Label(ownershipGroup, SWT.NONE);
    ownerLabel.setText("Who should own the uploaded project?");
    ownerUser = new Button(ownershipGroup, SWT.RADIO);
    ownerUser.setText("You");
    ownerOrg = new Button(ownershipGroup, SWT.RADIO);
    ownerOrg.setText("Your organisation");
    orgSelector = new ComboViewer(ownershipGroup);
    GridData orgSelectorGrid = new GridData(SWT.LEAD, SWT.LEAD, false, false);
    orgSelectorGrid.widthHint = 175;
    orgSelector.getCombo().setLayoutData(orgSelectorGrid);
    orgSelector.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // 
        }

        @Override
        public void dispose() {
        // 
        }

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof List<?>) {
                List<?> elements = (List<?>) inputElement;
                return elements.toArray();
            } else if (inputElement instanceof Object[]) {
                return (Object[]) inputElement;
            }
            return new Object[] {};
        }
    });
    orgSelector.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectOrganisationInfo) {
                return ((HaleConnectOrganisationInfo) element).getName();
            }
            return super.getText(element);
        }
    });
    enableVersioning = new Button(newProjectControls, SWT.CHECK);
    enableVersioning.setText("Enable versioning?");
    enableVersioning.setLayoutData(new GridData(SWT.LEAD, SWT.LEAD, true, false, 3, 1));
    publicAccess = new Button(newProjectControls, SWT.CHECK);
    publicAccess.setText("Allow public access?");
    publicAccess.setLayoutData(new GridData(SWT.LEAD, SWT.LEAD, true, false, 3, 1));
    updateProjectControls = new Composite(controlsStack, SWT.NONE);
    updateProjectControls.setVisible(false);
    updateProjectControls.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    /*
		 * Project name text field
		 */
    projectName = new StringFieldEditor("project", "Project to update", updateProjectControls) {

        // the following methods are overridden so the button
        // may appear on the same line
        @Override
        public int getNumberOfControls() {
            return super.getNumberOfControls() + 1;
        }

        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns - 1);
        }
    };
    projectName.setEmptyStringAllowed(false);
    projectName.setErrorMessage("Please select a project before continuing.");
    projectName.setPage(getPage());
    projectName.getTextControl(updateProjectControls).setEditable(false);
    projectName.getTextControl(updateProjectControls).addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            selectProject();
        }
    });
    projectName.setPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(FieldEditor.IS_VALID)) {
                getPage().setMessage(null);
                updateState();
            } else if (event.getProperty().equals(FieldEditor.VALUE)) {
                getPage().setMessage(null);
                updateState();
            }
        }
    });
    /*
		 * Select project button
		 */
    selectProjectButton = new Button(updateProjectControls, SWT.PUSH);
    selectProjectButton.setText("Select");
    selectProjectButton.setToolTipText("Select project");
    selectProjectButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    selectProjectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectProject();
        }
    });
    FontData currentFont = loginStatusLabel.getFont().getFontData()[0];
    upstreamModifiedWarning = new Label(updateProjectControls, SWT.WRAP);
    upstreamModifiedWarning.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 3, 1));
    upstreamModifiedWarning.setFont(new Font(upstreamModifiedWarning.getDisplay(), new FontData(currentFont.getName(), currentFont.getHeight(), SWT.BOLD)));
    upstreamModifiedWarning.setVisible(false);
    Composite writerOptions = new Composite(parent, SWT.NONE);
    writerOptions.setLayout(new RowLayout());
    writerOptions.setLayoutData(new GridData(SWT.LEAD, SWT.LEAD, true, true, 3, 2));
    includeWebResources = new Button(writerOptions, SWT.CHECK);
    includeWebResources.setText("Include web resources?");
    excludeData = new Button(writerOptions, SWT.CHECK);
    excludeData.setText("Exclude source data?");
    excludeData.setSelection(true);
    excludeCachedResources = new Button(writerOptions, SWT.CHECK);
    excludeCachedResources.setText("Use cached internal schema representation (required for big schema files)?");
    excludeCachedResources.setSelection(true);
    prefillTargetProject();
    updateState();
}
Also used : Group(org.eclipse.swt.widgets.Group) Label(org.eclipse.swt.widgets.Label) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StackLayout(org.eclipse.swt.custom.StackLayout) List(java.util.List) ArrayList(java.util.ArrayList) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FontData(org.eclipse.swt.graphics.FontData) MouseAdapter(org.eclipse.swt.events.MouseAdapter) HaleConnectLoginDialog(eu.esdihumboldt.hale.io.haleconnect.ui.HaleConnectLoginDialog) StringFieldEditor(org.eclipse.jface.preference.StringFieldEditor) HaleConnectOrganisationInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 3 with HaleConnectOrganisationInfo

use of eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo 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)

Example 4 with HaleConnectOrganisationInfo

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

the class HaleConnectServiceImpl method processBucketDetail.

@SuppressWarnings("unchecked")
private HaleConnectProjectInfo processBucketDetail(BucketDetail bucket) {
    String author = null;
    Long lastModified = bucket.getLastModified();
    if (bucket.getProperties() instanceof Map<?, ?>) {
        Map<Object, Object> properties = (Map<Object, Object>) bucket.getProperties();
        if (properties.containsKey("author")) {
            author = properties.get("author").toString();
        }
    }
    HaleConnectUserInfo user = null;
    HaleConnectOrganisationInfo org = null;
    try {
        if (!StringUtils.isEmpty(bucket.getId().getUserId())) {
            user = this.getUserInfo(bucket.getId().getUserId());
        }
        if (!StringUtils.isEmpty(bucket.getId().getOrgId())) {
            org = this.getOrganisationInfo(bucket.getId().getOrgId());
        }
    } catch (HaleConnectException e) {
        log.error(e.getMessage(), e);
    }
    return new HaleConnectProjectInfo(bucket.getId().getTransformationproject(), user, org, bucket.getName(), author, lastModified);
}
Also used : HaleConnectOrganisationInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) HaleConnectProjectInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectProjectInfo) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

HaleConnectOrganisationInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo)4 HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GridData (org.eclipse.swt.layout.GridData)2 ApiException (com.haleconnect.api.user.v1.ApiException)1 OrganisationsApi (com.haleconnect.api.user.v1.api.OrganisationsApi)1 OrganisationInfo (com.haleconnect.api.user.v1.model.OrganisationInfo)1 HaleConnectProjectInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectProjectInfo)1 HaleConnectService (eu.esdihumboldt.hale.io.haleconnect.HaleConnectService)1 HaleConnectUserInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo)1 HaleConnectLoginDialog (eu.esdihumboldt.hale.io.haleconnect.ui.HaleConnectLoginDialog)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 StringFieldEditor (org.eclipse.jface.preference.StringFieldEditor)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1