Search in sources :

Example 1 with HaleConnectUserInfo

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

the class ChooseHaleConnectProjectWizardPage method createContent.

/**
 * @see eu.esdihumboldt.hale.ui.util.wizard.ConfigurationWizardPage#createContent(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(4, false));
    keywordFilter = new Text(page, SWT.SEARCH | SWT.ICON_SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
    keywordFilter.setMessage("Enter search text here...");
    GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(keywordFilter);
    ownerFilter = new ComboViewer(page);
    GridDataFactory.fillDefaults().grab(false, false).applyTo(ownerFilter.getControl());
    ownerFilter.setContentProvider(new IStructuredContentProvider() {

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

        @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[] {};
        }
    });
    ownerFilter.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof OwnerFilterEntry) {
                return ((OwnerFilterEntry) element).getLabel();
            }
            return super.getText(element);
        }
    });
    List<OwnerFilterEntry> availableFilters = new ArrayList<>();
    availableFilters.add(NULL_FILTER);
    availableFilters.add(new OwnerFilterEntry(new Owner[] { new Owner(OwnerType.USER, haleConnect.getSession().getUserId()) }, "My projects"));
    List<Owner> orgs = new ArrayList<>();
    for (String orgId : haleConnect.getSession().getOrganisationIds()) {
        orgs.add(new Owner(OwnerType.ORGANISATION, orgId));
    }
    if (!orgs.isEmpty()) {
        availableFilters.add(new OwnerFilterEntry(orgs.toArray(new Owner[] {}), "My organisations' projects"));
    }
    ownerFilter.setInput(availableFilters);
    ownerFilter.setSelection(new StructuredSelection(NULL_FILTER));
    Composite tableComposite = new Composite(page, SWT.NONE);
    TableColumnLayout columnLayout = new TableColumnLayout();
    tableComposite.setLayout(columnLayout);
    projects = new TableViewer(tableComposite, SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    projects.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            update();
        }
    });
    TableViewerColumn nameColumn = new TableViewerColumn(projects, SWT.LEAD);
    nameColumn.getColumn().setText("Project name");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                return ((HaleConnectProjectInfo) element).getName();
            }
            return element.toString();
        }
    });
    columnLayout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(45, 200, true));
    TableViewerColumn authorColumn = new TableViewerColumn(projects, SWT.LEAD);
    authorColumn.getColumn().setText("Author");
    authorColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                return ((HaleConnectProjectInfo) element).getAuthor();
            }
            return element.toString();
        }
    });
    columnLayout.setColumnData(authorColumn.getColumn(), new ColumnWeightData(20, 50, true));
    TableViewerColumn ownerColumn = new TableViewerColumn(projects, SWT.LEAD);
    ownerColumn.getColumn().setText("Owner");
    ownerColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                Owner owner = ((HaleConnectProjectInfo) element).getOwner();
                if (owner.isUser()) {
                    try {
                        HaleConnectUserInfo user = haleConnect.getUserInfo(owner.getId());
                        if (!StringUtils.isEmpty(user.getFullName())) {
                            return user.getFullName();
                        } else if (!StringUtils.isEmpty(user.getScreenName())) {
                            return user.getScreenName();
                        } else {
                            return MessageFormat.format("<user {0}>", user.getUserId());
                        }
                    } catch (HaleConnectException e) {
                        log.error(e.getMessage(), e);
                        return MessageFormat.format("<user {0}>", owner.getId());
                    }
                } else if (owner.isOrganisation()) {
                    try {
                        return haleConnect.getOrganisationInfo(owner.getId()).getName();
                    } catch (HaleConnectException e) {
                        log.error(e.getMessage(), e);
                        return MessageFormat.format("<organisation {0}>", owner.getId());
                    }
                } else {
                    return "<unknown owner type> ID: " + owner.getId();
                }
            }
            return element.toString();
        }
    });
    columnLayout.setColumnData(ownerColumn.getColumn(), new ColumnWeightData(35, 100, true));
    final Table projectsTable = projects.getTable();
    projectsTable.setHeaderVisible(true);
    projectsTable.setLinesVisible(true);
    tableComposite.setLayoutData(GridDataFactory.fillDefaults().span(4, 1).grab(true, true).create());
    projects.setContentProvider(ArrayContentProvider.getInstance());
    populateProjects();
    final ProjectFilter projectFilter = new ProjectFilter(projects);
    projects.addFilter(projectFilter);
    ownerFilter.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                StructuredSelection selection = (StructuredSelection) event.getSelection();
                if (selection.getFirstElement() instanceof OwnerFilterEntry) {
                    OwnerFilterEntry selectedFilter = (OwnerFilterEntry) selection.getFirstElement();
                    if (selectedFilter.equals(NULL_FILTER)) {
                        projectFilter.clearOwnerFilter();
                    } else {
                        projectFilter.filterByOwners(Arrays.asList(selectedFilter.getOwner()));
                    }
                }
            }
        }
    });
    keywordFilter.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            projectFilter.setSearchText(keywordFilter.getText());
        }
    });
    final Button refresh = new Button(page, SWT.FLAT);
    refresh.setText("Refresh");
    GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(refresh);
    refresh.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            populateProjects();
        }
    });
    ownerFilter.getControl().setFocus();
    setControl(page);
    update();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Owner(eu.esdihumboldt.hale.io.haleconnect.Owner) ModifyListener(org.eclipse.swt.events.ModifyListener) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) TableViewer(org.eclipse.jface.viewers.TableViewer) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) HaleConnectProjectInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectProjectInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 2 with HaleConnectUserInfo

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

the class HaleConnectServiceImpl method getUserInfo.

/**
 * @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#getUserInfo(java.lang.String)
 */
@Override
public HaleConnectUserInfo getUserInfo(String userId) throws HaleConnectException {
    if (!this.isLoggedIn()) {
        return null;
    }
    if (!userInfoCache.containsKey(userId)) {
        UsersApi api = UserServiceHelper.getUsersApi(this, this.getSession().getToken());
        try {
            UserInfo info = api.getProfile(userId);
            userInfoCache.put(info.getId(), new HaleConnectUserInfo(info.getId(), info.getScreenName(), info.getFullName()));
        } catch (ApiException e) {
            throw new HaleConnectException(e.getMessage(), e);
        }
    }
    return userInfoCache.get(userId);
}
Also used : UsersApi(com.haleconnect.api.user.v1.api.UsersApi) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) UserInfo(com.haleconnect.api.user.v1.model.UserInfo) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) ApiException(com.haleconnect.api.user.v1.ApiException)

Example 3 with HaleConnectUserInfo

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

HaleConnectException (eu.esdihumboldt.hale.io.haleconnect.HaleConnectException)3 HaleConnectUserInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo)3 HaleConnectProjectInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectProjectInfo)2 ApiException (com.haleconnect.api.user.v1.ApiException)1 UsersApi (com.haleconnect.api.user.v1.api.UsersApi)1 UserInfo (com.haleconnect.api.user.v1.model.UserInfo)1 HaleConnectOrganisationInfo (eu.esdihumboldt.hale.io.haleconnect.HaleConnectOrganisationInfo)1 Owner (eu.esdihumboldt.hale.io.haleconnect.Owner)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1