Search in sources :

Example 11 with AlternateIdConstraint

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

the class DbIndexTest method testAlternateIdIndex.

@Test
public void testAlternateIdIndex() {
    URI id = URIUtil.createId(FileShare.class);
    String nid0 = UUID.randomUUID().toString();
    String nid1 = UUID.randomUUID().toString();
    AlternateIdConstraint constraint0 = AlternateIdConstraint.Factory.getFileShareNativeIdConstraint(nid0);
    AlternateIdConstraint constraint1 = AlternateIdConstraint.Factory.getFileShareNativeIdConstraint(nid1);
    {
        FileShare obj = new FileShare();
        obj.setId(id);
        obj.setNativeGuid(nid0);
        _dbClient.createObject(obj);
    }
    verifyContain(constraint0, id, 1);
    verifyContain(constraint1, null, 0);
    {
        FileShare obj = _dbClient.queryObject(FileShare.class, id);
        obj.setNativeGuid(nid1);
        _dbClient.persistObject(obj);
    }
    verifyContain(constraint1, id, 1);
    verifyContain(constraint0, null, 0);
}
Also used : URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) Test(org.junit.Test)

Example 12 with AlternateIdConstraint

use of com.emc.storageos.db.client.constraint.AlternateIdConstraint 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 13 with AlternateIdConstraint

use of com.emc.storageos.db.client.constraint.AlternateIdConstraint 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 14 with AlternateIdConstraint

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

the class BourneDbClient method findByAlternateId.

public <T extends DataObject> List<NamedElement> findByAlternateId(Class<T> clazz, String columnField, String value) throws DataAccessException {
    LOG.debug("findByAlternateId(class={}, columnField={}, value={})", new Object[] { clazz, columnField, value });
    DataObjectType doType = TypeMap.getDoType(clazz);
    AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField(columnField), value);
    return queryNamedElementsByConstraint(constraint);
}
Also used : DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 15 with AlternateIdConstraint

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

the class WorkflowService method getWorkflowStepData.

/**
 * Returns a WorkflowStepData from database based on workflowURI and stepId
 *
 * @param workflowURI -- required workflow URI
 * @param stepId -- optional stepId (required); can either be stepId or workflowId
 * @param label -- optional label (ignored if not supplied)
 * @return WorkflowStepData
 */
private WorkflowStepData getWorkflowStepData(URI workflowURI, String stepId, String label) {
    AlternateIdConstraint constraint = AlternateIdConstraint.Factory.getWorkflowStepDataByStep(stepId);
    List<WorkflowStepData> dataRecords = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, WorkflowStepData.class, constraint);
    if (dataRecords == null || dataRecords.isEmpty()) {
        _log.info(String.format("data records null or empty for workflow %s and step %s", workflowURI, stepId));
    }
    for (WorkflowStepData dataRecord : dataRecords) {
        if (dataRecord == null || dataRecord.getInactive()) {
            _log.info("WorkflowStepData record inactive: " + ((dataRecord != null) ? dataRecord.getId().toString() : stepId));
            continue;
        }
        if (dataRecord.getWorkflowId().equals(workflowURI) && dataRecord.getStepId().equals(stepId)) {
            if (label == null && NullColumnValueGetter.isNullValue(dataRecord.getLabel()) || label != null && label.equals(dataRecord.getLabel())) {
                return dataRecord;
            }
        }
    }
    return null;
}
Also used : WorkflowStepData(com.emc.storageos.db.client.model.WorkflowStepData) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Aggregations

AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)17 URI (java.net.URI)11 AlternateIdConstraintImpl (com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl)7 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)6 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)4 UserPreferences (com.emc.storageos.db.client.model.UserPreferences)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 DbClient (com.emc.storageos.db.client.DbClient)1 Constraint (com.emc.storageos.db.client.constraint.Constraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 ContainmentPermissionsConstraint (com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint)1 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 TypeMap (com.emc.storageos.db.client.impl.TypeMap)1 DataObject (com.emc.storageos.db.client.model.DataObject)1