Search in sources :

Example 1 with AbstractUserObject

use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.

the class UserManagementView method detachLDAPUser.

/**
 * Set user/group to non LDAP
 */
private void detachLDAPUser() {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    new ConsoleJob(Messages.get().UserManagementView_DeleteJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (Object object : selection.toList()) {
                ((AbstractUserObject) object).setFlags(((AbstractUserObject) object).getFlags() & ~AbstractUserObject.LDAP_USER);
                session.detachUserFromLdap(((AbstractUserObject) object));
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().UserManagementView_DetachError;
        }
    }.start();
    changePassword();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractUserObject(org.netxms.client.users.AbstractUserObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 2 with AbstractUserObject

use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.

the class GrafanaAlarms method getCollection.

/* (non-Javadoc)
    * @see org.netxms.websvc.handlers.AbstractHandler#getCollection(java.util.Map)
    */
@Override
public Object getCollection(Map<String, String> query) throws Exception {
    if (!getSession().isObjectsSynchronized())
        getSession().syncObjects();
    if (query.isEmpty()) {
        Set<Integer> classFilter = new HashSet<Integer>(5);
        classFilter.add(AbstractObject.OBJECT_NODE);
        classFilter.add(AbstractObject.OBJECT_MOBILEDEVICE);
        classFilter.add(AbstractObject.OBJECT_RACK);
        classFilter.add(AbstractObject.OBJECT_CLUSTER);
        classFilter.add(AbstractObject.OBJECT_SENSOR);
        AbstractObject[] objects = getSession().getTopLevelObjects(classFilter);
        Map<Long, String> result = new HashMap<Long, String>();
        for (AbstractObject o : objects) result.put(o.getObjectId(), o.getObjectName());
        return result;
    }
    JsonObject root = new JsonObject();
    JsonArray columns = new JsonArray();
    columns.add(createColumn("Severity", true, true));
    columns.add(createColumn("State", true, false));
    columns.add(createColumn("Source", true, false));
    columns.add(createColumn("Message", true, false));
    columns.add(createColumn("Count", true, false));
    columns.add(createColumn("Helpdesk ID", true, false));
    columns.add(createColumn("Ack/Resolved By", true, false));
    columns.add(createColumn("Created", true, false));
    columns.add(createColumn("Last Change", true, false));
    root.add("columns", columns);
    JsonArray rows = new JsonArray();
    JsonArray r = new JsonArray();
    DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    AbstractObject object = null;
    AbstractUserObject user = null;
    JsonParser parser = new JsonParser();
    JsonElement element = parser.parse(query.get("targets"));
    if (!element.isJsonArray())
        return new JsonArray();
    JsonArray targets = element.getAsJsonArray();
    JsonObject alarmSource;
    long sourceId = 0;
    Map<Long, Alarm> alarms = getSession().getAlarms();
    for (JsonElement e : targets) {
        for (Alarm a : alarms.values()) {
            if (e.getAsJsonObject().has("alarmSource")) {
                alarmSource = e.getAsJsonObject().getAsJsonObject("alarmSource");
                if (alarmSource.size() > 0)
                    sourceId = Long.parseLong(alarmSource.get("id").getAsString());
            }
            if (sourceId == 0 || a.getSourceObjectId() == sourceId) {
                r.add(a.getCurrentSeverity().name());
                r.add(STATES[a.getState()]);
                object = getSession().findObjectById(a.getSourceObjectId());
                if (object == null)
                    r.add(a.getSourceObjectId());
                else
                    r.add(object.getObjectName());
                r.add(a.getMessage());
                r.add(a.getRepeatCount());
                r.add(a.getHelpdeskReference());
                user = getSession().findUserDBObjectById(a.getAckByUser());
                if (user == null)
                    r.add("");
                else
                    r.add(user.getName());
                r.add(df.format(a.getCreationTime()));
                r.add(df.format(a.getLastChangeTime()));
                rows.add(r);
                r = new JsonArray();
            }
        }
    }
    root.add("rows", rows);
    root.addProperty("type", "table");
    JsonArray wrapper = new JsonArray();
    wrapper.add(root);
    return wrapper;
}
Also used : HashMap(java.util.HashMap) AbstractUserObject(org.netxms.client.users.AbstractUserObject) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) AbstractObject(org.netxms.client.objects.AbstractObject) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Alarm(org.netxms.client.events.Alarm) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet) JsonParser(com.google.gson.JsonParser)

Example 3 with AbstractUserObject

use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.

the class AlarmListLabelProvider method getColumnText.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
@Override
public String getColumnText(Object element, int columnIndex) {
    switch((Integer) viewer.getTable().getColumn(columnIndex).getData("ID")) {
        case AlarmList.COLUMN_SEVERITY:
            return StatusDisplayInfo.getStatusText(((Alarm) element).getCurrentSeverity());
        case AlarmList.COLUMN_STATE:
            int time = ((Alarm) element).getAckTime();
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String timeString = time > 0 ? " (" + RegionalSettings.getDateTimeFormat().format(System.currentTimeMillis() + (time * 1000)) + ")" : "";
            return stateText[((Alarm) element).getState()] + timeString;
        case AlarmList.COLUMN_SOURCE:
            AbstractObject object = session.findObjectById(((Alarm) element).getSourceObjectId());
            // $NON-NLS-1$ //$NON-NLS-2$
            return (object != null) ? object.getObjectName() : ("[" + Long.toString(((Alarm) element).getSourceObjectId()) + "]");
        case AlarmList.COLUMN_ZONE:
            if (session.isZoningEnabled()) {
                ZoneMember zm = session.findObjectById(((Alarm) element).getSourceObjectId(), ZoneMember.class);
                return (zm != null) ? zm.getZoneName() : "";
            }
            return "";
        case AlarmList.COLUMN_MESSAGE:
            return ((Alarm) element).getMessage();
        case AlarmList.COLUMN_COUNT:
            return Integer.toString(((Alarm) element).getRepeatCount());
        case AlarmList.COLUMN_COMMENTS:
            return (((Alarm) element).getCommentsCount() > 0) ? Integer.toString(((Alarm) element).getCommentsCount()) : null;
        case AlarmList.COLUMN_ACK_BY:
            if (((Alarm) element).getState() == Alarm.STATE_OUTSTANDING)
                return null;
            long userId = (((Alarm) element).getState() == Alarm.STATE_ACKNOWLEDGED) ? ((Alarm) element).getAckByUser() : ((Alarm) element).getResolvedByUser();
            AbstractUserObject user = session.findUserDBObjectById(userId);
            // $NON-NLS-1$ //$NON-NLS-2$
            return (user != null) ? user.getName() : ("[" + Long.toString(((Alarm) element).getAckByUser()) + "]");
        case AlarmList.COLUMN_CREATED:
            return RegionalSettings.getDateTimeFormat().format(((Alarm) element).getCreationTime());
        case AlarmList.COLUMN_LASTCHANGE:
            return RegionalSettings.getDateTimeFormat().format(((Alarm) element).getLastChangeTime());
        case AlarmList.COLUMN_HELPDESK_REF:
            switch(((Alarm) element).getHelpdeskState()) {
                case Alarm.HELPDESK_STATE_OPEN:
                    return ((Alarm) element).getHelpdeskReference();
                case Alarm.HELPDESK_STATE_CLOSED:
                    return ((Alarm) element).getHelpdeskReference() + Messages.get().AlarmListLabelProvider_Closed;
            }
            return null;
    }
    return null;
}
Also used : Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractUserObject(org.netxms.client.users.AbstractUserObject) ZoneMember(org.netxms.client.objects.ZoneMember)

Example 4 with AbstractUserObject

use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.

the class AccessControl method createContents.

@Override
protected Control createContents(Composite parent) {
    session = ConsoleSharedData.getSession();
    Composite dialogArea = new Composite(parent, SWT.NONE);
    editor = (AlarmCategoryEditor) getElement().getAdapter(AlarmCategoryEditor.class);
    category = editor.getObjectAsItem();
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    final String[] columnNames = { "Login Name" };
    final int[] columnWidths = { 300 };
    userList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    userList.setContentProvider(new ArrayContentProvider());
    userList.setLabelProvider(new WorkbenchLabelProvider());
    userList.setComparator(new UserComparator());
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    userList.getControl().setLayoutData(gd);
    Composite buttons = new Composite(dialogArea, SWT.NONE);
    FillLayout buttonsLayout = new FillLayout();
    buttonsLayout.spacing = WidgetHelper.INNER_SPACING;
    buttons.setLayout(buttonsLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    gd.widthHint = 184;
    buttons.setLayoutData(gd);
    final Button addButton = new Button(buttons, SWT.PUSH);
    addButton.setText("Add...");
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUserDialog dlg = new SelectUserDialog(AccessControl.this.getShell(), AbstractUserObject.class);
            if (dlg.open() == Window.OK) {
                AbstractUserObject[] selection = dlg.getSelection();
                for (AbstractUserObject user : selection) accessMap.put(user.getId(), user);
                userList.setInput(accessMap.values().toArray(new AbstractUserObject[accessMap.size()]));
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    final Button deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText("Delete");
    deleteButton.setEnabled(false);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selecion = (IStructuredSelection) userList.getSelection();
            Iterator<AbstractUserObject> iterator = selecion.iterator();
            while (iterator.hasNext()) {
                AbstractUserObject element = iterator.next();
                accessMap.remove(element.getId());
            }
            userList.setInput(accessMap.values().toArray());
        }
    });
    userList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            deleteButton.setEnabled(!userList.getSelection().isEmpty());
        }
    });
    // Initial data
    for (long userId : category.getAccessControl()) {
        final AbstractUserObject user = session.findUserDBObjectById(userId);
        if (user != null) {
            accessMap.put(user.getId(), user);
        }
    }
    userList.setInput(accessMap.values().toArray());
    return dialogArea;
}
Also used : SelectUserDialog(org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) UserComparator(org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) AbstractUserObject(org.netxms.client.users.AbstractUserObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 5 with AbstractUserObject

use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.

the class UserConditionEditor method selectUser.

/**
 * Select user
 */
private void selectUser() {
    SelectUserDialog dlg = new SelectUserDialog(getShell(), User.class);
    dlg.enableMultiSelection(false);
    if (dlg.open() == Window.OK) {
        AbstractUserObject[] users = dlg.getSelection();
        if (users.length > 0) {
            userId = users[0].getId();
            objectName.setText(users[0].getName());
            objectName.setImage(labelProvider.getImage(users[0]));
        } else {
            userId = 0;
            objectName.setText(EMPTY_SELECTION_TEXT);
            objectName.setImage(null);
        }
    }
}
Also used : SelectUserDialog(org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog) AbstractUserObject(org.netxms.client.users.AbstractUserObject)

Aggregations

AbstractUserObject (org.netxms.client.users.AbstractUserObject)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 SelectionListener (org.eclipse.swt.events.SelectionListener)9 GridData (org.eclipse.swt.layout.GridData)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 Button (org.eclipse.swt.widgets.Button)9 Composite (org.eclipse.swt.widgets.Composite)9 SelectUserDialog (org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog)9 Iterator (java.util.Iterator)7 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)7 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)7 FillLayout (org.eclipse.swt.layout.FillLayout)7 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)7 NXCSession (org.netxms.client.NXCSession)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 RowLayout (org.eclipse.swt.layout.RowLayout)5 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)5 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)4