@Override public Map<String, Object> getProperties( EntityRef entityRef ) throws Exception { Entity entity = get( entityRef ); return entity.getProperties(); }
@Override public OrganizationInfo getOrganizationInfoFromAccessToken( String token ) throws Exception { Entity entity = getEntityFromAccessToken(token, null, ORGANIZATION); if ( entity == null ) { return null; } return new OrganizationInfo( entity.getProperties() ); }
@Override public UserInfo getAdminUserInfoFromAccessToken( String token ) throws Exception { Entity user = getAdminUserEntityFromAccessToken(token); return new UserInfo( smf.getManagementAppId(), user.getProperties() ); }
@Override public ApplicationInfo getApplicationInfoFromAccessToken( String token ) throws Exception { Entity entity = getEntityFromAccessToken( token, null, APPLICATION ); if ( entity == null ) { throw new TokenException( "Could not find an entity for that access token: " + token ); } return new ApplicationInfo( entity.getProperties() ); }
@Override public Map<String, String> getServiceProperties() { Map<String, String> props = new HashMap<String,String>(); EntityManager em = getEntityManager(getManagementAppId()); Query q = Query.fromQL("select *"); Results results = null; try { results = em.searchCollection( em.getApplicationRef(), "propertymaps", q); } catch (Exception ex) { logger.error("Error getting system properties", ex); } if ( results == null || results.isEmpty() ) { return props; } org.apache.usergrid.persistence.Entity e = results.getEntity(); for ( String key : e.getProperties().keySet() ) { props.put( key, props.get(key).toString() ); } return props; }
@Override public Results getSourceEntities( String connType, String fromEntityType, Level level, int count ) throws Exception { // looking for edges to the head entity String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connType ); Map<EntityRef, Set<String>> containers = getContainers( count, edgeType, fromEntityType ); if ( Level.REFS.equals( level ) ) { List<EntityRef> refList = new ArrayList<EntityRef>( containers.keySet() ); return Results.fromRefList( refList ); } if ( Level.IDS.equals( level ) ) { // TODO: someday this should return a list of Core Persistence Ids List<UUID> idList = new ArrayList<UUID>(); for ( EntityRef ref : containers.keySet() ) { idList.add( ref.getUuid() ); } return Results.fromIdList( idList ); } List<Entity> entities = new ArrayList<Entity>(); for ( EntityRef ref : containers.keySet() ) { Entity entity = em.get( ref ); if (logger.isTraceEnabled()) { logger.trace(" Found connecting entity: " + entity.getProperties()); } entities.add( entity ); } return Results.fromEntities( entities ); }
@Override public <A extends Entity> A get( EntityRef entityRef, Class<A> entityClass ) throws Exception { if ( entityRef == null ) { return null; } Entity entity = get(entityRef); if ( entity == null ) { logger.warn( "Entity {}/{} not found ", entityRef.getUuid(), entityRef.getType() ); return null; } A ret = EntityFactory.newEntity(entityRef.getUuid(), entityRef.getType(), entityClass); ret.setProperties( entity.getProperties() ); return ret; }
@Override public UserInfo getAppUserFromAccessToken( String token ) throws Exception { AuthPrincipalInfo auth_principal = getPrincipalFromAccessToken( token, null, APPLICATION_USER ); if ( auth_principal == null ) { return null; } UUID appId = auth_principal.getApplicationId(); if ( appId != null ) { Entity user = getAppUserByIdentifier( appId, Identifier.fromUUID( auth_principal.getUuid() ) ); if ( user != null ) { return new UserInfo( appId, user.getProperties() ); } } return null; }
@Override public OrganizationInfo getOrganizationByUuid( UUID id ) throws Exception { EntityManager em = emf.getEntityManager( smf.getManagementAppId() ); Entity entity = em.get( new SimpleEntityRef( Group.ENTITY_TYPE, id ) ); if ( entity == null ) { return null; } Map<Object, Object> properties = em.getDictionaryAsMap( entity, ORGANIZATION_PROPERTIES_DICTIONARY ); OrganizationInfo orgInfo = new OrganizationInfo( entity.getProperties() ); orgInfo.setProperties( properties ); return orgInfo; }
device.getDynamicProperties().get(entry.getKey()).equals(entry.getValue())) || (device.getProperties().get(entry.getKey()) != null && device.getProperties().get(entry.getKey()).equals(entry.getValue()))
new org.apache.usergrid.persistence.model.entity.Entity( entityId ); cpEntity = CpEntityMapUtils.fromMap( cpEntity, entity.getProperties(), entity.getType(), true );
/** * 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; }
@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; }
managementEm.create( new SimpleId( applicationUUID, createTypeName ), oldAppEntity.getProperties() );
assertTrue( "thing name should start with \"thing\"", property.toString().startsWith( "thing" ) ); Map<String, Object> properties = en.getProperties(); assertEquals( "number of properties wrong", 6, properties.size() );
assertTrue( "thing name should start with \"thing\"", property.toString().startsWith( "thing" ) ); Map<String, Object> properties = en.getProperties(); assertEquals( "number of properties wrong", 6, properties.size() );