use of com.emc.storageos.db.client.model.Encrypt in project coprhd-controller by CoprHD.
the class DbCli method printBeanProperties.
/**
* Print the contents in human readable format
*
* @param pds
* @param object
* @throws Exception
*/
private <T extends DataObject> void printBeanProperties(PropertyDescriptor[] pds, T object) throws Exception {
System.out.println("id: " + object.getId().toString());
Object objValue;
Class type;
for (PropertyDescriptor pd : pds) {
// skip class property
if (pd.getName().equals("class") || pd.getName().equals("id")) {
continue;
}
Name nameAnnotation = pd.getReadMethod().getAnnotation(Name.class);
String objKey;
if (nameAnnotation == null) {
objKey = pd.getName();
} else {
objKey = nameAnnotation.value();
}
objValue = pd.getReadMethod().invoke(object);
if (objValue == null) {
continue;
}
System.out.print("\t" + objKey + " = ");
Encrypt encryptAnnotation = pd.getReadMethod().getAnnotation(Encrypt.class);
if (encryptAnnotation != null) {
System.out.println("*** ENCRYPTED CONTENT ***");
continue;
}
type = pd.getPropertyType();
if (type == URI.class) {
System.out.println("URI: " + objValue);
} else if (type == StringMap.class) {
System.out.println("StringMap " + objValue);
} else if (type == StringSet.class) {
System.out.println("StringSet " + objValue);
} else if (type == StringSetMap.class) {
System.out.println("StringSetMap " + objValue);
} else if (type == OpStatusMap.class) {
System.out.println("OpStatusMap " + objValue);
} else {
System.out.println(objValue);
}
}
System.out.println();
}
use of com.emc.storageos.db.client.model.Encrypt in project coprhd-controller by CoprHD.
the class DBClient method printBeanProperties.
/**
* @param clazz
* @param object
* @param criterias
* Filter with some verify simple criteria
* @return Whether this record is print out
* @throws Exception
*/
private <T extends DataObject> boolean printBeanProperties(Class<T> clazz, T object, Map<String, String> criterias) throws Exception {
Map<String, String> localCriterias = new HashMap<>(criterias);
StringBuilder record = new StringBuilder();
record.append("id: " + object.getId().toString() + "\n");
boolean isPrint = true;
BeanInfo bInfo;
try {
bInfo = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException ex) {
log.error("Unexpected exception getting bean info", ex);
throw new RuntimeException("Unexpected exception getting bean info", ex);
}
PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
Object objValue;
Class type;
Set<String> ignoreList = new HashSet<>();
for (PropertyDescriptor pd : pds) {
// skip class property
if (pd.getName().equals("class") || pd.getName().equals("id")) {
continue;
}
Name nameAnnotation = pd.getReadMethod().getAnnotation(Name.class);
String objKey;
if (nameAnnotation == null) {
objKey = pd.getName();
} else {
objKey = nameAnnotation.value();
}
objValue = pd.getReadMethod().invoke(object);
if (!localCriterias.isEmpty()) {
if (localCriterias.containsKey(objKey)) {
if (!localCriterias.get(objKey).equalsIgnoreCase(String.valueOf(objValue))) {
isPrint = false;
break;
} else {
localCriterias.remove(objKey);
}
}
}
if (objValue == null) {
ignoreList.add(objKey);
continue;
}
if (isEmptyStr(objValue)) {
ignoreList.add(objKey);
continue;
}
record.append("\t" + objKey + " = ");
Encrypt encryptAnnotation = pd.getReadMethod().getAnnotation(Encrypt.class);
if (encryptAnnotation != null) {
record.append("*** ENCRYPTED CONTENT ***\n");
continue;
}
type = pd.getPropertyType();
if (type == URI.class) {
record.append("URI: " + objValue + "\n");
} else if (type == StringMap.class) {
record.append("StringMap " + objValue + "\n");
} else if (type == StringSet.class) {
record.append("StringSet " + objValue + "\n");
} else if (type == OpStatusMap.class) {
record.append("OpStatusMap " + objValue + "\n");
} else {
record.append(objValue + "\n");
}
}
if (this.showModificationTime) {
Column<CompositeColumnName> latestField = _dbClient.getLatestModifiedField(TypeMap.getDoType(clazz), object.getId(), ignoreList);
if (latestField != null) {
record.append(String.format("The latest modified time is %s on Field(%s).\n", new Date(latestField.getTimestamp() / 1000), latestField.getName().getOne()));
}
}
if (isPrint) {
if (!localCriterias.isEmpty()) {
String errMsg = String.format("The filters %s are not available for the CF %s", localCriterias.keySet(), clazz);
throw new IllegalArgumentException(errMsg);
}
System.out.println(record.toString());
}
return isPrint;
}
use of com.emc.storageos.db.client.model.Encrypt in project coprhd-controller by CoprHD.
the class ColumnField method processProperty.
/**
* Helper to reflect on PropertyDescriptor and fill out _type and _name
* information;
*/
private void processProperty() {
// ignore if no get method
if (_property.getReadMethod() == null) {
return;
}
Method readMethod = _property.getReadMethod();
Annotation[] annotations = readMethod.getAnnotations();
ColumnFamily<String, IndexColumnName> indexCF = null;
int minPrefixChars;
boolean isLazyLoadable = false;
boolean hasRelationIndex = false;
for (int i = 0; i < annotations.length; i++) {
Annotation a = annotations[i];
if (a instanceof Id) {
_colType = ColumnType.Id;
_name = "Id";
} else if (a instanceof Name) {
_name = ((Name) a).value();
if (Number.class.isAssignableFrom(_valueType) || _valueType == URI.class || _valueType == String.class || _valueType == Date.class || _valueType == Boolean.class || _valueType == Byte.class || _valueType == Long.class || _valueType == byte[].class || _valueType.isEnum() || _valueType == Calendar.class) {
_colType = ColumnType.Primitive;
compositeName = new CompositeColumnName(_name);
} else if (NamedURI.class == _valueType) {
_colType = ColumnType.NamedURI;
compositeName = new CompositeColumnName(_name);
} else if (AbstractChangeTrackingSet.class.isAssignableFrom(_valueType)) {
_colType = ColumnType.TrackingSet;
} else if (AbstractChangeTrackingMap.class.isAssignableFrom(_valueType)) {
_colType = ColumnType.TrackingMap;
} else if (AbstractChangeTrackingSetMap.class.isAssignableFrom(_valueType)) {
_colType = ColumnType.TrackingSetMap;
} else if (AbstractSerializableNestedObject.class.isAssignableFrom(_valueType)) {
_colType = ColumnType.NestedObject;
compositeName = new CompositeColumnName(_name);
} else if (Collection.class.isAssignableFrom(_valueType) || DataObject.class.isAssignableFrom(_valueType)) {
isLazyLoadable = true;
} else {
throw new IllegalArgumentException(_name + " " + _valueType + " " + _property + " " + _parentType.getDataObjectClass());
}
} else if (a instanceof Ttl) {
_ttl = ((Ttl) a).value();
} else if (a instanceof RelationIndex) {
indexCF = new ColumnFamily<String, IndexColumnName>(((RelationIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
_indexRefType = ((RelationIndex) a).type();
deactivateIfEmpty = ((RelationIndex) a).deactivateIfEmpty();
_index = new RelationDbIndex(indexCF);
} else if (a instanceof AlternateId) {
indexCF = new ColumnFamily<String, IndexColumnName>(((AlternateId) a).value(), StringSerializer.get(), IndexColumnNameSerializer.get());
_index = new AltIdDbIndex(indexCF);
} else if (a instanceof ClassNameTimeSeries) {
ColumnFamily<String, ClassNameTimeSeriesIndexColumnName> newIndexCF = new ColumnFamily<String, ClassNameTimeSeriesIndexColumnName>(((ClassNameTimeSeries) a).value(), StringSerializer.get(), ClassNameTimeSeriesSerializer.get());
_index = new ClassNameTimeSeriesDBIndex(newIndexCF);
} else if (a instanceof TimeSeriesAlternateId) {
ColumnFamily<String, TimeSeriesIndexColumnName> newIndexCF = new ColumnFamily<String, TimeSeriesIndexColumnName>(((TimeSeriesAlternateId) a).value(), StringSerializer.get(), TimeSeriesColumnNameSerializer.get());
_index = new TimeSeriesDbIndex(newIndexCF);
} else if (a instanceof NamedRelationIndex) {
indexCF = new ColumnFamily<String, IndexColumnName>(((NamedRelationIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
_indexRefType = ((NamedRelationIndex) a).type();
_index = new NamedRelationDbIndex(indexCF);
} else if (a instanceof PrefixIndex) {
indexCF = new ColumnFamily<String, IndexColumnName>(((PrefixIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
minPrefixChars = ((PrefixIndex) a).minChars();
_index = new PrefixDbIndex(indexCF, minPrefixChars);
} else if (a instanceof PermissionsIndex && AbstractChangeTrackingSetMap.class.isAssignableFrom(_valueType)) {
indexCF = new ColumnFamily<String, IndexColumnName>(((PermissionsIndex) a).value(), StringSerializer.get(), IndexColumnNameSerializer.get());
_index = new PermissionsDbIndex(indexCF);
} else if (a instanceof Encrypt && _valueType == String.class) {
_encrypt = true;
} else if (a instanceof ScopedLabelIndex) {
ScopedLabelIndex scopeLabelIndex = (ScopedLabelIndex) a;
indexCF = new ColumnFamily<String, IndexColumnName>(scopeLabelIndex.cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
minPrefixChars = scopeLabelIndex.minChars();
_index = new ScopedLabelDbIndex(indexCF, minPrefixChars);
} else if (a instanceof ClockIndependent) {
clockIndValue = ((ClockIndependent) a).value();
} else if (a instanceof DecommissionedIndex && Boolean.class.isAssignableFrom(_valueType)) {
if (!_property.getName().equals(DataObject.INACTIVE_FIELD_NAME) || _parentType.getDataObjectClass().getAnnotation(NoInactiveIndex.class) == null) {
indexCF = new ColumnFamily<String, IndexColumnName>(((DecommissionedIndex) a).value(), StringSerializer.get(), IndexColumnNameSerializer.get());
_index = new DecommissionedDbIndex(indexCF);
}
} else if (a instanceof IndexByKey && (AbstractChangeTrackingMap.class.isAssignableFrom(_valueType) || AbstractChangeTrackingSet.class.isAssignableFrom(_valueType))) {
_indexByKey = true;
} else if (a instanceof Relation) {
hasRelationIndex = true;
if (((Relation) a).type().equals(DataObject.class)) {
_mappedByType = _valueType;
} else {
_mappedByType = ((Relation) a).type();
}
_mappedByField = ((Relation) a).mappedBy();
} else if (a instanceof AggregatedIndex) {
indexCF = new ColumnFamily<String, IndexColumnName>(((AggregatedIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
String groupBy = ((AggregatedIndex) a).groupBy();
boolean global = ((AggregatedIndex) a).classGlobal();
_index = new AggregateDbIndex(indexCF, groupBy, global);
}
}
if (_name == null) {
String className = _parentType.getDataObjectClass().getName();
String fieldName = _property.getName();
throw new IllegalArgumentException(String.format("@Name annotation missing from field '%s' in class '%s'", fieldName, className));
}
if (_index != null) {
_index.setFieldName(_name);
_index.setIndexByKey(_indexByKey);
}
if (isLazyLoadable && hasRelationIndex) {
lazyLoaded = true;
}
}
Aggregations