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);
}
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();
}
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();
}
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);
}
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;
}
Aggregations