Search in sources :

Example 1 with Encrypt

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();
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) PropertyDescriptor(java.beans.PropertyDescriptor) DataObject(com.emc.storageos.db.client.model.DataObject) Encrypt(com.emc.storageos.db.client.model.Encrypt) Name(com.emc.storageos.db.client.model.Name)

Example 2 with Encrypt

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;
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) StringMap(com.emc.storageos.db.client.model.StringMap) PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Encrypt(com.emc.storageos.db.client.model.Encrypt) Date(java.util.Date) Name(com.emc.storageos.db.client.model.Name) CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) DataObject(com.emc.storageos.db.client.model.DataObject) HashSet(java.util.HashSet)

Example 3 with Encrypt

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;
    }
}
Also used : NamedRelationIndex(com.emc.storageos.db.client.model.NamedRelationIndex) DecommissionedIndex(com.emc.storageos.db.client.model.DecommissionedIndex) Name(com.emc.storageos.db.client.model.Name) PrefixIndex(com.emc.storageos.db.client.model.PrefixIndex) NoInactiveIndex(com.emc.storageos.db.client.model.NoInactiveIndex) AggregatedIndex(com.emc.storageos.db.client.model.AggregatedIndex) Method(java.lang.reflect.Method) Encrypt(com.emc.storageos.db.client.model.Encrypt) PermissionsIndex(com.emc.storageos.db.client.model.PermissionsIndex) DataObject(com.emc.storageos.db.client.model.DataObject) IndexByKey(com.emc.storageos.db.client.model.IndexByKey) AbstractChangeTrackingMap(com.emc.storageos.db.client.model.AbstractChangeTrackingMap) AlternateId(com.emc.storageos.db.client.model.AlternateId) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId) Id(com.emc.storageos.db.client.model.Id) AlternateId(com.emc.storageos.db.client.model.AlternateId) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) AbstractChangeTrackingSetMap(com.emc.storageos.db.client.model.AbstractChangeTrackingSetMap) Ttl(com.emc.storageos.db.client.model.Ttl) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) ClockIndependent(com.emc.storageos.db.client.model.ClockIndependent) Relation(com.emc.storageos.db.client.model.Relation) ScopedLabelIndex(com.emc.storageos.db.client.model.ScopedLabelIndex) NamedRelationIndex(com.emc.storageos.db.client.model.NamedRelationIndex) RelationIndex(com.emc.storageos.db.client.model.RelationIndex) Annotation(java.lang.annotation.Annotation) ClassNameTimeSeries(com.emc.storageos.db.client.model.ClassNameTimeSeries) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId)

Aggregations

DataObject (com.emc.storageos.db.client.model.DataObject)3 Encrypt (com.emc.storageos.db.client.model.Encrypt)3 Name (com.emc.storageos.db.client.model.Name)3 StringMap (com.emc.storageos.db.client.model.StringMap)2 PropertyDescriptor (java.beans.PropertyDescriptor)2 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)1 AbstractChangeTrackingMap (com.emc.storageos.db.client.model.AbstractChangeTrackingMap)1 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)1 AbstractChangeTrackingSetMap (com.emc.storageos.db.client.model.AbstractChangeTrackingSetMap)1 AggregatedIndex (com.emc.storageos.db.client.model.AggregatedIndex)1 AlternateId (com.emc.storageos.db.client.model.AlternateId)1 ClassNameTimeSeries (com.emc.storageos.db.client.model.ClassNameTimeSeries)1 ClockIndependent (com.emc.storageos.db.client.model.ClockIndependent)1 DecommissionedIndex (com.emc.storageos.db.client.model.DecommissionedIndex)1 Id (com.emc.storageos.db.client.model.Id)1 IndexByKey (com.emc.storageos.db.client.model.IndexByKey)1 NamedRelationIndex (com.emc.storageos.db.client.model.NamedRelationIndex)1 NoInactiveIndex (com.emc.storageos.db.client.model.NoInactiveIndex)1 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)1 PermissionsIndex (com.emc.storageos.db.client.model.PermissionsIndex)1