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"); } }
protected Entity getOrganizationEntityForApplication( UUID applicationInfoId ) throws Exception { if ( applicationInfoId == null ) { return null; } final EntityManager em = emf.getEntityManager(smf.getManagementAppId()); Results r = em.getSourceEntities( new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId), ORG_APP_RELATIONSHIP, Group.ENTITY_TYPE, Level.ALL_PROPERTIES); return r.getEntity(); }
Results results = em.getSourceEntities( new SimpleEntityRef(user.getType(), user.getUuid()), "following", User.ENTITY_TYPE, Level.REFS);
/** * This method is called when the job is retried maximum times by the scheduler but still fails. * Thus the scheduler marks it as DEAD. */ @Override public void dead( final JobExecution execution ) throws Exception { // Get the root entity manager EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() ); // Mark the sub-job i.e. File Import Job as Failed FileImport fileImport = null;//importService.getFileImportEntity(execution); fileImport.setErrorMessage("The Job has been tried maximum times but still failed"); fileImport.setState(FileImport.State.FAILED); rootEm.update(fileImport); // If one file Job fails, mark the main import Job also as failed Results ImportJobResults = rootEm.getSourceEntities( fileImport, "includes", null, Level.ALL_PROPERTIES); List<Entity> importEntity = ImportJobResults.getEntities(); UUID importId = importEntity.get(0).getUuid(); Import importUG = rootEm.get(importId, Import.class); importUG.setState(Import.State.FAILED); rootEm.update(importUG); } }
public OrganizationConfig load( UUID applicationInfoId ) { try { if (applicationInfoId != null && applicationInfoId != CpNamingUtils.MANAGEMENT_APPLICATION_ID) { final EntityManager em = emf.getEntityManager(smf.getManagementAppId()); Results r = em.getSourceEntities( new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId), ORG_APP_RELATIONSHIP, Group.ENTITY_TYPE, Level.ALL_PROPERTIES); Group org = (Group) r.getEntity(); if (org != null) { Map<Object, Object> entityProperties = em.getDictionaryAsMap(org, ORGANIZATION_CONFIG_DICTIONARY); return new OrganizationConfig(orgConfigProperties, org.getUuid(), org.getPath(), entityProperties, false); } } return new OrganizationConfig(orgConfigProperties); } catch (Exception e) { return new OrganizationConfig(orgConfigProperties); } }} );
PagingResultsIterator itr = new PagingResultsIterator(em.getSourceEntities( returned, "following", "user", Level.ALL_PROPERTIES, 1000));
public void distribute( EntityRef group, EntityRef user, Entity activity ) throws Exception { if ( activity == null ) { return; } em.addToCollection( user, "feed", activity ); Results r1 = em.getCollection( group, "users", null, 10000, Level.IDS, false ); if ( ( r1 == null ) || ( r1.isEmpty() ) ) { return; } Results r2 = em.getSourceEntities(new SimpleEntityRef(user.getType(), user.getUuid()), "following", User.ENTITY_TYPE, Level.IDS); if ( ( r2 == null ) || ( r2.isEmpty() ) ) { return; } r1.and( r2 ); List<EntityRef> refs = Results.fromIdList( r1.getIds(), User.ENTITY_TYPE ).getRefs(); if ( refs != null ) { em.addToCollections( refs, "feed", activity ); } } }
@Override public ServiceResults getCollection( ServiceContext context ) throws Exception { checkPermissionsForCollection( context ); Results r = null; if ( connecting() ) { r = em.getSourceEntities( new SimpleEntityRef(context.getOwner().getType(), context.getOwner().getUuid()), context.getCollectionName(), null, Level.ALL_PROPERTIES); } else { r = em.getTargetEntities( new SimpleEntityRef(context.getOwner().getType(), context.getOwner().getUuid()), context.getCollectionName(), null, Level.ALL_PROPERTIES); } importEntities( context, r ); return new ServiceResults( this, context, Type.CONNECTION, r, null, null ); }
Results res = em.getSourceEntities(wilmaEntity, "likes", null, Level.ALL_PROPERTIES); assertEquals( 1, res.size() ); assertEquals( "user", res.getEntity().getType() ); // fred is a user res = em.getSourceEntities(wilmaEntity, "likes", "user", Level.ALL_PROPERTIES); assertEquals( 1, res.size() ); assertEquals( "user", res.getEntity().getType() );