Search in sources :

Example 21 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType 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 22 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType 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)

Example 23 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.

the class DBClient method init.

public void init() {
    try {
        System.out.println("Initializing db client ...");
        ctx = new ClassPathXmlApplicationContext("/dbutils-conf.xml");
        InternalDbClientImpl dbClient = (InternalDbClientImpl) ctx.getBean("dbclient");
        _geodbContext = (DbClientContext) ctx.getBean("geodbclientcontext");
        vdcConfHelper = (VdcConfigHelper) ctx.getBean("vdcConfHelper");
        geoEncryptionProvider = (EncryptionProviderImpl) ctx.getBean("geoEncryptionProvider");
        encryptionProvider = (EncryptionProviderImpl) ctx.getBean("encryptionProvider");
        dbClient.setBypassMigrationLock(skipMigrationCheck);
        dbClient.start();
        _dbClient = dbClient;
        // scan for classes with @Cf annotation
        System.out.println("Initializing column family map ...");
        AnnotationScannerListener scannerListener = new AnnotationScannerListener(Cf.class);
        String[] packages = { pkgs };
        PackageNamesScanner scanner = new PackageNamesScanner(packages);
        scanner.scan(scannerListener);
        Iterator<Class<?>> it = scannerListener.getAnnotatedClasses().iterator();
        while (it.hasNext()) {
            Class clazz = it.next();
            // The fields of SchemaRecord don't have Name annotation either.
            if (DataObject.class.isAssignableFrom(clazz)) {
                DataObjectType doType = TypeMap.getDoType(clazz);
                _cfMap.put(doType.getCF().getName(), clazz);
            }
        }
    } catch (Exception e) {
        System.err.println("Caught Exception: " + e);
        log.error("Caught Exception: ", e);
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) PackageNamesScanner(com.sun.jersey.core.spi.scanning.PackageNamesScanner) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) AnnotationScannerListener(com.sun.jersey.spi.scanning.AnnotationScannerListener)

Example 24 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.

the class BourneDbClient method findBy.

public <T extends DataObject> List<NamedElement> findBy(Class<T> clazz, String columnField, URI id) throws DataAccessException {
    LOG.debug("findBy({}, {}, {})", new Object[] { clazz, columnField, id });
    DataObjectType doType = TypeMap.getDoType(clazz);
    ColumnField field = doType.getColumnField(columnField);
    ContainmentConstraint constraint = new ContainmentConstraintImpl(id, clazz, field);
    return queryNamedElementsByConstraint(constraint);
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ColumnField(com.emc.storageos.db.client.impl.ColumnField) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType)

Example 25 with DataObjectType

use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.

the class BourneDbClient method findByPrefix.

public <T extends DataObject> List<NamedElement> findByPrefix(Class<T> clazz, String prefixColumnField, String prefix) throws DataAccessException {
    LOG.debug("findByPrefix({}, {}, {})", new Object[] { clazz, prefixColumnField, prefix });
    DataObjectType doType = TypeMap.getDoType(clazz);
    PrefixConstraint constraint = new PrefixConstraintImpl(prefix, doType.getColumnField(prefixColumnField));
    return queryNamedElementsByConstraint(constraint);
}
Also used : PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType)

Aggregations

DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)28 ColumnField (com.emc.storageos.db.client.impl.ColumnField)10 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)8 URI (java.net.URI)8 ArrayList (java.util.ArrayList)7 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)5 AlternateIdConstraintImpl (com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl)5 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)4 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)4 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)4 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)4 UserPreferences (com.emc.storageos.db.client.model.UserPreferences)4 Test (org.junit.Test)4 Constraint (com.emc.storageos.db.client.constraint.Constraint)3 ContainmentPermissionsConstraint (com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint)3 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)3 Rows (com.netflix.astyanax.model.Rows)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 com.emc.storageos.db.client.constraint (com.emc.storageos.db.client.constraint)2 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)2