Search in sources :

Example 11 with NamedElementQueryResultList

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.

the class MailHandler method getMailAddressOfUser.

/**
 * get user's mail address from UserPreference CF
 *
 * @param userName
 * @return
 */
private String getMailAddressOfUser(String userName) {
    DataObjectType doType = TypeMap.getDoType(UserPreferences.class);
    AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField(UserPreferences.USER_ID), userName);
    NamedElementQueryResultList queryResults = new NamedElementQueryResultList();
    this.dbClient.queryByConstraint(constraint, queryResults);
    List<URI> userPrefsIds = new ArrayList<>();
    for (NamedElementQueryResultList.NamedElement namedElement : queryResults) {
        userPrefsIds.add(namedElement.getId());
    }
    if (userPrefsIds.isEmpty()) {
        return null;
    }
    final List<UserPreferences> userPrefs = new ArrayList<>();
    Iterator<UserPreferences> iter = this.dbClient.queryIterativeObjects(UserPreferences.class, userPrefsIds);
    while (iter.hasNext()) {
        userPrefs.add(iter.next());
    }
    if (userPrefs.size() > 1) {
        throw new IllegalStateException("There should only be 1 user preferences object for a user");
    }
    if (userPrefs.isEmpty()) {
        // if there isn't a user prefs object in the DB yet then we haven't saved one for this user yet.
        return null;
    }
    return userPrefs.get(0).getEmail();
}
Also used : UserPreferences(com.emc.storageos.db.client.model.UserPreferences) AlternateIdConstraintImpl(com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl) ArrayList(java.util.ArrayList) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 12 with NamedElementQueryResultList

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.

the class SchedulerConfig method getMailAddressOfUser.

/**
 * get user's mail address from UserPreference CF
 *
 * @param userName
 * @return
 */
private String getMailAddressOfUser(String userName) {
    DataObjectType doType = TypeMap.getDoType(UserPreferences.class);
    AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField(UserPreferences.USER_ID), userName);
    NamedElementQueryResultList queryResults = new NamedElementQueryResultList();
    this.dbClient.queryByConstraint(constraint, queryResults);
    List<URI> userPrefsIds = new ArrayList<>();
    for (NamedElementQueryResultList.NamedElement namedElement : queryResults) {
        userPrefsIds.add(namedElement.getId());
    }
    if (userPrefsIds.isEmpty()) {
        return null;
    }
    final List<UserPreferences> userPrefs = new ArrayList<>();
    Iterator<UserPreferences> iter = this.dbClient.queryIterativeObjects(UserPreferences.class, userPrefsIds);
    while (iter.hasNext()) {
        userPrefs.add(iter.next());
    }
    if (userPrefs.size() > 1) {
        throw new IllegalStateException("There should only be 1 user preferences object for a user");
    }
    if (userPrefs.isEmpty()) {
        // if there isn't a user prefs object in the DB yet then we haven't saved one for this user yet.
        return null;
    }
    return userPrefs.get(0).getEmail();
}
Also used : UserPreferences(com.emc.storageos.db.client.model.UserPreferences) AlternateIdConstraintImpl(com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl) ArrayList(java.util.ArrayList) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 13 with NamedElementQueryResultList

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.

the class BasePermissionsHelper method getSubtenantRolesForUser.

public Map<String, Collection<String>> getSubtenantRolesForUser(StorageOSUser user) {
    Map<String, Collection<String>> subTenantRoles = new HashMap<String, Collection<String>>();
    URI userHomeTenant = URI.create(user.getTenantId());
    NamedElementQueryResultList subtenants = new NamedElementQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSubTenantConstraint(userHomeTenant), subtenants);
    for (NamedElement sub : subtenants) {
        Collection<String> roles = getTenantRolesForUser(user, sub.getId(), false);
        if (!CollectionUtils.isEmpty(roles)) {
            subTenantRoles.put(sub.getId().toString(), roles);
        }
    }
    return subTenantRoles;
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 14 with NamedElementQueryResultList

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.

the class DbDowntimeTracker method getMailAddressOfUser.

/**
 * get user's mail address from UserPreference CF
 *
 * @param userName
 * @return
 */
private String getMailAddressOfUser(String userName) {
    DataObjectType doType = TypeMap.getDoType(UserPreferences.class);
    AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField(UserPreferences.USER_ID), userName);
    NamedElementQueryResultList queryResults = new NamedElementQueryResultList();
    this.dbClient.queryByConstraint(constraint, queryResults);
    List<URI> userPrefsIds = new ArrayList<>();
    for (NamedElementQueryResultList.NamedElement namedElement : queryResults) {
        userPrefsIds.add(namedElement.getId());
    }
    if (userPrefsIds.isEmpty()) {
        return null;
    }
    final List<UserPreferences> userPrefs = new ArrayList<>();
    Iterator<UserPreferences> iter = this.dbClient.queryIterativeObjects(UserPreferences.class, userPrefsIds);
    while (iter.hasNext()) {
        userPrefs.add(iter.next());
    }
    if (userPrefs.size() > 1) {
        throw new IllegalStateException("There should only be 1 user preferences object for a user");
    }
    if (userPrefs.isEmpty()) {
        // if there isn't a user prefs object in the DB yet then we haven't saved one for this user yet.
        return null;
    }
    return userPrefs.get(0).getEmail();
}
Also used : UserPreferences(com.emc.storageos.db.client.model.UserPreferences) AlternateIdConstraintImpl(com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 15 with NamedElementQueryResultList

use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.

the class NotificationManager method getMailAddressOfUser.

/**
 * get user's mail address from UserPreference CF
 *
 * @param userName
 * @return
 */
private String getMailAddressOfUser(String userName) {
    DataObjectType doType = TypeMap.getDoType(UserPreferences.class);
    AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField(UserPreferences.USER_ID), userName);
    NamedElementQueryResultList queryResults = new NamedElementQueryResultList();
    _dbClient.queryByConstraint(constraint, queryResults);
    List<URI> userPrefsIds = Lists.newArrayList();
    for (NamedElementQueryResultList.NamedElement namedElement : queryResults) {
        userPrefsIds.add(namedElement.getId());
    }
    final List<UserPreferences> userPrefs = Lists.newArrayList();
    Iterator<UserPreferences> iter = _dbClient.queryIterativeObjects(UserPreferences.class, userPrefsIds);
    while (iter.hasNext()) {
        userPrefs.add(iter.next());
    }
    if (userPrefs.size() > 1) {
        throw new IllegalStateException("There should only be 1 user preferences object for a user");
    } else if (userPrefs.isEmpty()) {
        // if there isn't a user prefs object in the DB yet then we haven't saved one for this user yet.
        return null;
    }
    return userPrefs.get(0).getEmail();
}
Also used : UserPreferences(com.emc.storageos.db.client.model.UserPreferences) AlternateIdConstraintImpl(com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Aggregations

NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)18 URI (java.net.URI)11 ArrayList (java.util.ArrayList)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)5 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)4 AlternateIdConstraintImpl (com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl)4 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)4 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)4 UserPreferences (com.emc.storageos.db.client.model.UserPreferences)4 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)4 HashSet (java.util.HashSet)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 Set (java.util.Set)3 Path (javax.ws.rs.Path)3 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)2 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)2 Order (com.emc.storageos.db.client.model.uimodels.Order)2