/** * @param bytes * @param offset * @param length * @return */ public static String string( byte[] bytes, int offset, int length ) { return string( bytes, offset, length, UTF8_ENCODING ); }
/** * @param bytes * @return */ public static String string( byte[] bytes ) { if ( bytes == null ) { return null; } return string( bytes, 0, bytes.length, UTF8_ENCODING ); }
public static String toString( Object obj ) { return string( obj ); }
/** * @param obj * @return */ public static String string( Object obj ) { if ( obj instanceof String ) { return ( String ) obj; } else if ( obj instanceof byte[] ) { return string( ( byte[] ) obj ); } else if ( obj instanceof ByteBuffer ) { return string( ( ByteBuffer ) obj ); } else if ( obj != null ) { return obj.toString(); } return null; }
public static <T> List<String> strings( Collection<T> items ) { List<String> strings = new ArrayList<String>(); for ( T item : items ) { strings.add( string( item ) ); } return strings; }
public static String string( ByteBuffer bytes ) { if ( bytes == null ) { return null; } return string( bytes.array(), bytes.arrayOffset() + bytes.position(), bytes.remaining(), UTF8_ENCODING ); }
public static String toStringFormat( Object obj, String format ) { if ( obj != null ) { if ( format != null ) { if ( obj.getClass().isArray() ) { return String.format( format, Arrays.toString( ( Object[] ) obj ) ); } return String.format( format, string( obj ) ); } else { return string( obj ); } } return ""; }
public UserInfo( UUID applicationId, Map<String, Object> properties ) { this.applicationId = applicationId; id = uuid( properties.remove( PROPERTY_UUID ) ); username = string( properties.remove( PROPERTY_USERNAME ) ); name = string( properties.remove( PROPERTY_NAME ) ); email = string( properties.remove( PROPERTY_EMAIL ) ); confirmed = getBoolean( properties.remove( PROPERTY_CONFIRMED ) ); activated = getBoolean( properties.remove( PROPERTY_ACTIVATED ) ); disabled = getBoolean( properties.remove( PROPERTY_DISABLED ) ); admin = getBoolean( properties.remove( PROPERTY_ADMIN) ); this.properties = properties; }
@Override public String getRoleTitle( String roleName ) throws Exception { String title = string( getDictionaryElementValue( getApplicationRef(), DICTIONARY_ROLENAMES, roleName ) ); if ( title == null ) { title = roleName; } return title; }
return string( bytes );
String entityType = string( columns.get( PROPERTY_TYPE ) );
return string( bytes );
/** @return object of correct type deserialize from column bytes */ public static Object deserializeEntityProperty( String entityType, String propertyName, ByteBuffer bytes ) { Object propertyValue = null; if ( PROPERTY_UUID.equals( propertyName ) ) { propertyValue = uuid( bytes ); } else if ( PROPERTY_TYPE.equals( propertyName ) ) { propertyValue = string( bytes ); } else { if ( Schema.getDefaultSchema().isPropertyEncrypted( entityType, propertyName ) ) { bytes = decrypt( bytes ); } propertyValue = Schema.deserializePropertyValueFromJsonBinary( bytes ); } return propertyValue; }
return string( obj );
@Override public Set<String> getDictionaryNames( EntityRef entity ) throws Exception { Set<String> dictionaryNames = new TreeSet<String>( CASE_INSENSITIVE_ORDER ); List<HColumn<String, ByteBuffer>> results = cass.getAllColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_DICTIONARIES, CassandraPersistenceUtils.key( entity.getUuid(), DICTIONARY_SETS ) ); for ( HColumn<String, ByteBuffer> result : results ) { String str = string( result.getName() ); if ( str != null ) { dictionaryNames.add( str ); } } Set<String> schemaSets = Schema.getDefaultSchema().getDictionaryNames( entity.getType() ); if ( ( schemaSets != null ) && !schemaSets.isEmpty() ) { dictionaryNames.addAll( schemaSets ); } return dictionaryNames; }
@Override public Map<String, Role> getRolesWithTitles( Set<String> roleNames ) throws Exception { Map<String, Role> rolesWithTitles = new HashMap<String, Role>(); Map<String, Object> nameResults = null; if ( roleNames != null ) { nameResults = getDictionaryElementValues( getApplicationRef(), DICTIONARY_ROLENAMES, roleNames.toArray( new String[roleNames.size()] ) ); } else { nameResults = cast( getDictionaryAsMap( getApplicationRef(), DICTIONARY_ROLENAMES ) ); roleNames = nameResults.keySet(); } Map<String, Object> timeResults = getDictionaryElementValues( getApplicationRef(), DICTIONARY_ROLETIMES, roleNames.toArray( new String[roleNames.size()] ) ); for ( String roleName : roleNames ) { String savedTitle = string( nameResults.get( roleName ) ); // no title, skip the role if ( savedTitle == null ) { continue; } Role newRole = new Role(); newRole.setName( roleName ); newRole.setTitle( savedTitle ); newRole.setInactivity( getLong( timeResults.get( roleName ) ) ); rolesWithTitles.put( roleName, newRole ); } return rolesWithTitles; }
public static ByteBuffer serializeEntityProperty( String entityType, String propertyName, Object propertyValue ) { ByteBuffer bytes = null; if ( PROPERTY_UUID.equals( propertyName ) ) { bytes = bytebuffer( uuid( propertyValue ) ); } else if ( PROPERTY_TYPE.equals( propertyName ) ) { bytes = bytebuffer( string( propertyValue ) ); } else { bytes = Schema.serializePropertyValueToJsonBinary( toJsonNode( propertyValue ) ); if ( Schema.getDefaultSchema().isPropertyEncrypted( entityType, propertyName ) ) { bytes.rewind(); bytes = encrypt( bytes ); } } return bytes; }
values = new HashMap<String, Object>(); for ( HColumn<ByteBuffer, ByteBuffer> result : results.getColumns() ) { String name = entityHasDictionary ? string( result.getName() ) : DynamicComposite.fromByteBuffer( result.getName() ).get( 0, se ); if ( entityHasDictionary && coTypeIsBasic ) {