public UserInfo getUserInfo( UUID applicationId, Entity entity ) { if ( entity == null ) { return null; } return new UserInfo( applicationId, entity.getUuid(), ( String ) entity.getProperty( "username" ), entity.getName(), ( String ) entity.getProperty( "email" ), ConversionUtils.getBoolean( entity.getProperty( "confirmed" ) ), ConversionUtils.getBoolean( entity.getProperty( "activated" ) ), ConversionUtils.getBoolean( entity.getProperty( "disabled" ) ), entity.getDynamicProperties(), ConversionUtils.getBoolean( entity.getProperty( "admin" ))); }
/** * Convert a usergrid 1.0 entity into a usergrid 2.0 entity */ public static org.apache.usergrid.persistence.model.entity.Entity entityToCpEntity( org.apache.usergrid.persistence.Entity entity, UUID importId ) { UUID uuid = importId != null ? importId : entity.getUuid(); org.apache.usergrid.persistence.model.entity.Entity cpEntity = new org.apache.usergrid.persistence.model.entity.Entity( new SimpleId( uuid, entity.getType() ) ); cpEntity = CpEntityMapUtils.fromMap( cpEntity, entity.getProperties(), entity.getType(), true ); cpEntity = CpEntityMapUtils.fromMap( cpEntity, entity.getDynamicProperties(), entity.getType(), true ); return cpEntity; }
/** side-effect: sets file-metadata on the entity if not present */ public static Map<String, Object> getFileMetadata( Entity entity ) { Map<String, Object> metadata = ( Map<String, Object> ) entity.getProperty( AssetUtils.FILE_METADATA ); if ( metadata == null ) { metadata = new HashMap<String, Object>(); entity.setProperty( AssetUtils.FILE_METADATA, metadata ); addLegacyMetadata( entity, metadata ); } // must always have a last modified. if not in the metadata, grab the entity's if ( metadata.get( LAST_MODIFIED ) == null ) { metadata.put( LAST_MODIFIED, entity.getModified() ); } return metadata; }
public static SimpleRoleRef forRoleEntity( Entity role ) { if ( role == null ) { return null; } UUID groupId = ( UUID ) role.getProperty( "group" ); String name = role.getName(); return new SimpleRoleRef( groupId, name ); }
@Override public UserInfo verifyMongoCredentials( String name, String nonce, String key ) throws Exception { Entity user = findUserEntity( smf.getManagementAppId(), name ); if ( user == null ) { return null; } String mongo_pwd = readUserMongoPassword( smf.getManagementAppId(), user.getUuid(), user.getType() ).getSecret(); if ( mongo_pwd == null ) { throw new IncorrectPasswordException( "Your mongo password has not be set" ); } String expected_key = DigestUtils.md5Hex( nonce + user.getProperty( "username" ) + mongo_pwd ); if ( !expected_key.equalsIgnoreCase( key ) ) { throw new IncorrectPasswordException(); } UserInfo userInfo = new UserInfo( smf.getManagementAppId(), user.getProperties() ); if ( !userInfo.isActivated() ) { throw new UnactivatedAdminUserException(); } if ( userInfo.isDisabled() ) { throw new DisabledAdminUserException(); } return userInfo; }
entity.addProperties( properties ); Event event = ( Event ) entity.toTypedEntity(); for ( String prop_name : properties.keySet() ) { Object propertyValue = properties.get( prop_name ); entity.setUuid( message.getUuid() ); batch.execute(); entity.getType(), entity.getUuid(), applicationId, CpEntityMapUtils.toMap( cpEntity )); String region = lookupAuthoritativeRegionForType( entity.getType() ); entity.setSize(cpEntity.getSize()); entity.setUuid( cpEntity.getId().getUuid() ); entity.setProperties( cpEntity ); mm.putString( itemId.toString(), entity.getType() );
@Test public void emptyPushNotification() throws Exception { app.clear(); app.put("name", "foo"); app.put("provider", PROVIDER); app.put("environment", "development"); app.put("apiKey", API_KEY); Notifier n = (Notifier) app .testRequest(ServiceAction.POST, 1, "notifiers").getEntity() .toTypedEntity(); app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put("foo", payload); app.put("payloads", payloads); app.put("debug", true); app.put("queued", System.currentTimeMillis()); Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications") .getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 0); }
assertEquals( user.getUuid(), returned.getUuid() ); user.setProperty( "firstname", newFirstName ); assertEquals( user.getUuid(), returned.getUuid() );
/** Invoked when our actor is a map */ private void handleDynamicPayload( Map<String, String> actor, Entity user, ServicePayload payload ) { // create a new actor object if ( actor == null ) { actor = new HashMap<String, String>(); payload.setProperty( Activity.PROPERTY_ACTOR, actor ); } if ( user != null ) { if ( actor.get( User.PROPERTY_UUID ) == null && user.getUuid() != null ) { actor.put( User.PROPERTY_UUID, user.getUuid().toString() ); } if ( actor.get( User.PROPERTY_EMAIL ) == null && user.getProperty( User.PROPERTY_EMAIL ) != null ) { actor.put( User.PROPERTY_EMAIL, user.getProperty( User.PROPERTY_EMAIL ).toString() ); } } }
/** * Persists the connection for this entity. */ private void saveConnections( Entity entity, EntityManager em, JsonGenerator jg ) throws Exception { jg.writeFieldName( "connections" ); jg.writeStartObject(); Set<String> connectionTypes = em.getConnectionTypes( entity ); for ( String connectionType : connectionTypes ) { jg.writeFieldName( connectionType ); jg.writeStartArray(); Results results = em.getTargetEntities( new SimpleEntityRef(entity.getType(), entity.getUuid()), connectionType, null, Level.IDS); List<ConnectionRef> connections = results.getConnections(); for ( ConnectionRef connectionRef : connections ) { jg.writeObject( connectionRef.getTargetRefs().getUuid() ); } jg.writeEndArray(); } jg.writeEndObject(); }
@Test public void testNestedRetrieveNameWithSpace() throws Exception { Entity contributor = app.doCreate( "contributor", "Malaka Mahanama" ); app.testRequest( ServiceAction.GET, 1, "contributors" ); app.testRequest( ServiceAction.GET, 1, "contributor", contributor.getName()); Entity project = app.doCreate( "project", "Usergrid" ); app.testRequest( ServiceAction.GET, 1, "projects" ); app.testRequest( ServiceAction.POST, 1, "projects", project.getName(), "contains", "contributors", contributor.getName()); app.testRequest( ServiceAction.GET, 1, "projects", project.getName(), "contains", "contributors", contributor.getName()); }
@Override public void update( Entity entity ) throws Exception { Preconditions.checkNotNull(entity,"entity should never be null"); String type = entity.getType(); Preconditions.checkNotNull(type,"entity type should never be null"); Id appId = getApplicationScope().getApplication(); Id entityId = new SimpleId( entity.getUuid(), entity.getType() ); new org.apache.usergrid.persistence.model.entity.Entity( entityId ); cpEntity = CpEntityMapUtils.fromMap( cpEntity, entity.getProperties(), entity.getType(), true ); String region = lookupAuthoritativeRegionForType( entity.getType() );
assertEquals(String.valueOf(count), entity.getName()); Object distanceObject = entity.getMetadata("distance"); assertNotNull( distanceObject ); assertTrue( distanceObject instanceof Double );
/** Returns the key for the bucket in the following form: [appId]/[{@link org.apache.usergrid.persistence.entities * .Asset#getPath()} */ public static String buildAssetKey( UUID appId, Entity entity ) { Preconditions.checkArgument( entity.getUuid() != null, "The asset provided to buildAssetKey had a null UUID" ); Preconditions.checkArgument( appId != null, "The appId provided to buildAssetKey was null" ); return appId.toString().concat( "/" ).concat( entity.getUuid().toString() ); }
@Test public void testEntityClasses() throws Exception { logger.info( "testEntityClasses" ); Schema mapper = Schema.getDefaultSchema(); assertEquals( "group", mapper.getEntityType( Group.class ) ); assertEquals( User.class, mapper.getEntityClass( "user" ) ); Entity entity = EntityFactory.newEntity( null, "user" ); assertEquals( User.class, entity.getClass() ); User user = ( User ) entity; user.setUsername( "testuser" ); assertEquals( user.getUsername(), user.getProperty( "username" ) ); user.setProperty( "username", "blahblah" ); assertEquals( "blahblah", user.getUsername() ); entity = EntityFactory.newEntity( null, "foobar" ); assertEquals( DynamicEntity.class, entity.getClass() ); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put( Schema.PROPERTY_UUID, new UUID( 1, 2 ) ); properties.put( "foo", "bar" ); entity.setProperties( properties ); assertEquals( new UUID( 1, 2 ), entity.getUuid() ); assertEquals( new UUID( 1, 2 ), entity.getProperty( Schema.PROPERTY_UUID ) ); assertEquals( "bar", entity.getProperty( "foo" ) ); }
private Import getImportEntity(final EntityManager rootEm, final FileImport fileImport) { try { Results importJobResults = rootEm.getSourceEntities(fileImport, IMPORT_FILE_INCLUDES_CONNECTION, null, Level.ALL_PROPERTIES); List<Entity> importEntities = importJobResults.getEntities(); final Import importEntity = (Import) importEntities.get(0).toTypedEntity(); return importEntity; } catch (Exception e) { throw new RuntimeException("Unable to import entity"); } }
@Override public void setProperty( EntityRef entityRef, String propertyName, Object propertyValue, boolean override ) throws Exception { if ( ( propertyValue instanceof String ) && ( ( String ) propertyValue ).equals( "" ) ) { propertyValue = null; } Entity entity = get( entityRef ); propertyValue = Schema.getDefaultSchema().validateEntityPropertyValue( entity.getType(), propertyName, propertyValue ); entity.setProperty( propertyName, propertyValue ); entity.setProperty( PROPERTY_MODIFIED, UUIDUtils.getTimestampInMillis( UUIDUtils.newTimeUUID() ) ); update(entity); }
logger.trace("Filtering device: {}", device.getUuid()); if ((device.getDynamicProperties().get(entry.getKey()) != null && device.getDynamicProperties().get(entry.getKey()).equals(entry.getValue())) || (device.getProperties().get(entry.getKey()) != null && device.getProperties().get(entry.getKey()).equals(entry.getValue())) device.getUuid(), notification.getUuid());
@Test public void testSizeReturnedInMetadata() throws Exception { app.put( "name", "Tom" ); Entity cat = app.testRequest( ServiceAction.POST, 1, "cats" ).getEntity(); assertNotNull( cat ); Entity getEntityByName = app.testRequest( ServiceAction.GET, 1, "cats", cat.getName() ).getEntity(); Entity getEntityByUUID = app.testRequest( ServiceAction.GET, 1, "cats", cat.getUuid() ).getEntity(); assertNotNull(getEntityByName.getSize()); assertNotNull(getEntityByUUID.getSize()); app.clear(); }
/** @deprecated for legacy use */ private static void addLegacyMetadata( Entity entity, Map<String, Object> metadata ) { if ( entity.getProperty( CONTENT_TYPE ) != null ) { metadata.put( CONTENT_TYPE, entity.getProperty( CONTENT_TYPE ) ); } if ( entity.getProperty( CONTENT_LENGTH ) != null ) { metadata.put( CONTENT_LENGTH, entity.getProperty( CONTENT_LENGTH ) ); } if ( entity.getProperty( CONTENT_DISPOSITION ) != null ) { metadata.put( CONTENT_DISPOSITION, entity.getProperty( CONTENT_DISPOSITION ) ); } if ( entity.getProperty( E_TAG ) != null ) { metadata.put( E_TAG, entity.getProperty( E_TAG ) ); } if ( entity.getProperty( CHECKSUM ) != null ) { metadata.put( CHECKSUM, entity.getProperty( CHECKSUM ) ); } }