public List<Entity> getEntitiesByType( String type ) { if ( entitiesByType != null ) { return entitiesByType.get( type ); } getEntities(); if ( entities == null ) { return null; } List<Entity> l = null; entitiesByType = new LinkedHashMap<String, List<Entity>>(); for ( Entity entity : entities ) { l = entitiesByType.get( entity.getType() ); if ( l == null ) { l = new ArrayList<Entity>(); entitiesByType.put( entity.getType(), l ); } l.add( entity ); } return l; }
private void handleWriteUniqueVerifyException( Entity entity, WriteUniqueVerifyException wuve ) throws DuplicateUniquePropertyExistsException { // we may have multiple conflicts, but caller expects only one Map<String, Field> violiations = wuve.getViolations(); if ( violiations != null ) { Field conflict = violiations.get( violiations.keySet().iterator().next() ); throw new DuplicateUniquePropertyExistsException( entity.getType(), conflict.getName(), conflict.getValue() ); } else { throw new DuplicateUniquePropertyExistsException( entity.getType(), "Unknown property name", "Unknown property value" ); } }
public List<EntityRef> getEntityRefsByType( String type ) { if ( entitiesByType != null ) { return refsByType.get( type ); } List<EntityRef> l = cast( getEntitiesByType( type ) ); if ( l != null ) { return l; } getRefs(); if ( refs == null ) { return null; } refsByType = new LinkedHashMap<String, List<EntityRef>>(); for ( Entity entity : entities ) { l = refsByType.get( entity.getType() ); if ( l == null ) { l = new ArrayList<EntityRef>(); refsByType.put( entity.getType(), l ); } l.add( entity ); } return l; }
public Entity writeEntity( ServiceRequest request, Entity entity ) throws Exception { Service service = getEntityService( entity.getType() ); if ( service != null ) { return service.writeEntity( request, entity ); } return entity; }
public Entity importEntity( ServiceRequest request, Entity entity ) throws Exception { Service service = getEntityService( entity.getType() ); if ( service != null ) { return service.importEntity( request, entity ); } return entity; }
/** * 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; }
/** * 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(); }
boolean entitySchemaHasProperty = defaultSchema.hasProperty( entity.getType(), propertyName ); .validateEntityPropertyValue( entity.getType(), propertyName, propertyValue ); if ( !defaultSchema.isPropertyMutable( entity.getType(), propertyName ) ) { continue; if ( ( propertyValue == null ) && defaultSchema.isRequiredProperty( entity.getType(), propertyName ) ) { continue;
@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); }
final Entity created = em.create("testType", entityMap ); entityRefs.add( new SimpleEntityRef( created.getType(), created.getUuid() ) );
Id itemEntityId = new SimpleId( itemEntity.getUuid(), itemEntity.getType() ); final Edge edge = createCollectionEdge( cpHeadEntity.getId(), collectionName, itemEntityId );
public EntityRef validate( EntityRef entityRef, boolean verify ) throws Exception { if ( ( entityRef == null ) || ( entityRef.getUuid() == null ) ) { return null; } if ( ( entityRef.getType() == null ) || verify ) { UUID entityId = entityRef.getUuid(); String entityType = entityRef.getType(); try { get( entityRef ).getType(); } catch ( Exception e ) { logger.error( "Unable to load entity {}:{}", entityRef.getType(), entityRef.getUuid(), e ); } if ( entityRef == null ) { throw new EntityNotFoundException( "Entity " + entityId.toString() + " cannot be verified" ); } if ( ( entityType != null ) && !entityType.equalsIgnoreCase( entityRef.getType() ) ) { throw new UnexpectedEntityTypeException( "Entity " + entityId + " is not the expected type, expected " + entityType + ", found " + entityRef.getType() ); } } return entityRef; }
/** * Write some generic entity data into a collection with the entity manager and type specified * @param em * @param type * @param size * @return * @throws Exception */ public static Set<Id> createTypes( final EntityManager em, final String type, final int size ) throws Exception { final Set<Id> identities = new HashSet<>(); for ( int i = 0; i < size; i++ ) { final Entity entity = em.create( type, new HashMap<String, Object>() {{ put( "property", "value" ); }} ); final Id createdId = new SimpleId( entity.getUuid(), entity.getType() ); identities.add( createdId ); } return identities; } }
@Test public void testGetByIdAndNameEdgeReadRepair() throws Exception { EntityManager em = setup.getEmf().getEntityManager( app.getId() ); Entity contributor = app.doCreate( "contributor", "Malaka" ); EntityRef appRef = new SimpleEntityRef("application", app.getId()); em.removeItemFromCollection(appRef, InflectionUtils.pluralize(contributor.getType()), contributor); assertFalse("Entity should not have an edge from app to entity", em.isCollectionMember(appRef, InflectionUtils.pluralize(contributor.getType()), contributor)); app.testRequest( ServiceAction.GET, 1, "contributor", contributor.getName()); assertTrue("Entity should now be member of the collection", em.isCollectionMember(appRef, InflectionUtils.pluralize(contributor.getType()), contributor)); } }
@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; }
@Test public void testFilteringOfDuplicateEdges() throws Exception { logger.info( "EntityManagerIT.testFilteringOfDuplicateEdges" ); EntityManager em = app.getEntityManager(); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put( "name", "fluffy1" ); Entity entity = em.create( "fluffy", properties ); EntityRef appRef = new SimpleEntityRef("application", app.getId()); EntityRef entityRef = new SimpleEntityRef(entity.getType(), entity.getUuid()); assertNotNull( entity ); // create duplicate edges em.addToCollection(appRef, "fluffies", entityRef); em.addToCollection(appRef, "fluffies", entityRef); //app.waitForQueueDrainAndRefreshIndex(); Results results = em.getCollection(appRef, "fluffies", null, 10, Level.ALL_PROPERTIES, true); // we should be filtering duplicate edges so only assert 1 result back and not the # of edges assertEquals(1, results.getEntities().size()); }
final Id target = new SimpleId( entity.getUuid(), entity.getType() );
if ( user != null ) { actor.setDisplayName( ( String ) user.getProperty( "name" ) ); actor.setEntityType( user.getType() ); actor.setUuid( user.getUuid() );