private List<ProgramNotificationTemplate> getScheduledTemplates() { return identifiableObjectManager.getAll( ProgramNotificationTemplate.class ).stream() .filter( n -> n.getNotificationTrigger().isScheduled() ) .collect( Collectors.toList() ); }
void preheat( IdentifiableObjectManager manager, final ImportConfig config ) { dataSets.load( manager.getAll( DataSet.class ), ds -> ds.getPropertyValue( config.dsScheme ) ); orgUnits.load( manager.getAll( OrganisationUnit.class ), ou -> ou.getPropertyValue( config.ouScheme ) ); attrOptionCombos.load( manager.getAll( CategoryOptionCombo.class ), oc -> oc.getPropertyValue( config.aocScheme ) ); } }
@Transactional @Override public void sendScheduledNotifications() { Clock clock = new Clock( log ).startClock() .logTime( "Processing ProgramStageNotification messages scheduled by program rules" ); List<ProgramNotificationInstance> templates = identifiableObjectManager.getAll( ProgramNotificationInstance.class ).stream() .filter( IS_SCHEDULED_BY_PROGRAM_RULE ).collect( Collectors.toList() ); if ( templates.isEmpty() ) { return; } int totalMessageCount = 0; List<MessageBatch> batches = templates.stream().filter( ProgramNotificationInstance::hasProgramInstance ) .map( t -> createProgramInstanceMessageBatch( t.getProgramNotificationTemplate(), Arrays.asList( t.getProgramInstance() ) ) ) .collect( Collectors.toList() ); batches.addAll( templates.stream().filter( ProgramNotificationInstance::hasProgramStageInstance ) .map( t -> createProgramStageInstanceMessageBatch( t.getProgramNotificationTemplate(), Arrays.asList( t.getProgramStageInstance() ) ) ) .collect( Collectors.toList() ) ); batches.stream().forEach( this::sendAll ); totalMessageCount = batches.stream().mapToInt( MessageBatch::messageCount ).sum(); clock.logTime( String.format( "Created and sent %d messages in %s", totalMessageCount, clock.time() ) ); }
private void heatCaches( MetaDataCaches caches, ImportConfig config ) { if ( !caches.dataSets.isCacheLoaded() && exceedsThreshold( caches.dataSets ) ) { caches.dataSets.load( idObjManager.getAll( DataSet.class ), ds -> ds.getPropertyValue( config.dsScheme ) ); log.info( "Data set cache heated after cache miss threshold reached" ); } if ( !caches.orgUnits.isCacheLoaded() && exceedsThreshold( caches.orgUnits ) ) { caches.orgUnits.load( idObjManager.getAll( OrganisationUnit.class ), ou -> ou.getPropertyValue( config.ouScheme ) ); log.info( "Org unit cache heated after cache miss threshold reached" ); } // TODO Consider need for checking/re-heating attrOptCombo and period caches if ( !caches.attrOptionCombos.isCacheLoaded() && exceedsThreshold( caches.attrOptionCombos ) ) { caches.attrOptionCombos.load( idObjManager.getAll( CategoryOptionCombo.class ), aoc -> aoc.getPropertyValue( config.aocScheme ) ); log.info( "Attribute option combo cache heated after cache miss threshold reached" ); } if ( !caches.periods.isCacheLoaded() && exceedsThreshold( caches.periods ) ) { caches.periods.load( idObjManager.getAll( Period.class ), pe -> pe.getPropertyValue( null ) ); } }
dataElementMap.load( identifiableObjectManager.getAll( DataElement.class ), o -> o.getPropertyValue( dataElementIdScheme ) ); orgUnitMap.load( identifiableObjectManager.getAll( OrganisationUnit.class ), o -> o.getPropertyValue( orgUnitIdScheme ) ); optionComboMap.load( identifiableObjectManager.getAll( CategoryOptionCombo.class ), o -> o.getPropertyValue( categoryOptComboIdScheme ) ); dataElementMap.load( identifiableObjectManager.getAll( DataElement.class ), o -> o.getPropertyValue( dataElementIdScheme ) ); orgUnitMap.load( identifiableObjectManager.getAll( OrganisationUnit.class ), o -> o.getPropertyValue( orgUnitIdScheme ) ); optionComboMap.load( identifiableObjectManager.getAll( CategoryOptionCombo.class ), o -> o.getPropertyValue( categoryOptComboIdScheme ) );