private Period getPeriod( int id ) { Period p = context.getPeriodIdMap().get( id ); if ( p == null ) { log.trace("DataValidationTask calling getPeriod( id " + id + " )" ); p = periodService.getPeriod( id ); log.trace("DataValidationTask called getPeriod( id " + id + " )" ); context.getPeriodIdMap().put( id, p ); } return p; }
@Override @Transactional public List<DataSetCompletenessResult> getDataSetCompleteness( int periodId, Collection<Integer> organisationUnitIds, int dataSetId, Set<Integer> groupIds ) { final DataSet dataSet = dataSetService.getDataSet( dataSetId ); final Period period = periodService.getPeriod( periodId ); final List<Integer> periodsBetweenDates = getIdentifiers( periodService.getPeriodsBetweenDates( dataSet.getPeriodType(), period.getStartDate(), period.getEndDate() ) ); final Map<Integer, OrganisationUnit> orgUnits = Maps.uniqueIndex( organisationUnitService.getOrganisationUnits( organisationUnitIds ), OrganisationUnit::getId ); final Set<OrganisationUnitGroup> groups = groupIds != null ? Sets.newHashSet( idObjectManager.getObjects( OrganisationUnitGroup.class, groupIds ) ) : null; final List<DataSetCompletenessResult> results = new ArrayList<>(); for ( final Integer unitId : organisationUnitIds ) { final OrganisationUnit unit = orgUnits.get( unitId ); final Set<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren( unit.getId() ); final Set<Integer> relevantSources = getRelevantSources( dataSet, children, groups ); final DataSetCompletenessResult result = getDataSetCompleteness( period, periodsBetweenDates, unit, relevantSources, dataSet ); if ( result.getSources() > 0 ) { results.add( result ); } } return results; }
private void setPeriod( IdentifiableObject object ) { DataInputPeriod dataInputPeriod = (DataInputPeriod) object; Period period = periodService.getPeriod( dataInputPeriod.getPeriod().getIsoDate() ); dataInputPeriod.setPeriod( period ); sessionFactory.getCurrentSession().save( period ); } }
public List<DataSetCompletenessResult> getDataSetCompleteness( int periodId, int organisationUnitId, Set<Integer> groupIds ) final Period period = periodService.getPeriod( periodId );
@Override public void processRow( ResultSet rs ) throws SQLException { int dataSetId = rs.getInt( 1 ); int periodId = rs.getInt( 2 ); LockException lockException = new LockException(); Period period = periodService.getPeriod( periodId ); DataSet dataSet = dataSetStore.get( dataSetId ); lockException.setDataSet( dataSet ); lockException.setPeriod( period ); lockExceptions.add( lockException ); } } );
private Period getPeriod( String periodName, PeriodType periodType ) { Period period = PeriodUtil.getPeriod( periodName, periodType ); if ( period == null ) { return null; } Period persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(), periodType ); if ( persistedPeriod == null ) { periodService.addPeriod( period ); persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(), periodType ); } return persistedPeriod; }
/** * Finds the set of periods that exist, from a list of periods. * * Only adds the period if it is found in the database, because: * (a) We will need the period id, and * (b) If the period does not exist in the database, then * there is no data in the database to look for. * * @param periods the periods to look for * @return the set of periods that exist, with ids. */ private Set<Period> getExistingPeriods( Set<Period> periods ) { Set<Period> existingPeriods = new HashSet<>(); for ( Period period : periods ) { Period existingPeriod = period.getId() != 0 ? period : periodService.getPeriod( period.getStartDate(), period.getEndDate(), period.getPeriodType() ); if ( existingPeriod != null ) { existingPeriods.add( existingPeriod ); } } return existingPeriods; }
private CompleteDataSetRegistration createRespectiveRegistrationObject( DataSet dataSet, OrganisationUnit ou ) { Period period = dataSet.getPeriodType().createPeriod(); CompleteDataSetRegistration registration = new CompleteDataSetRegistration(); registration.setDataSet( dataSet ); registration.setPeriod( periodService.getPeriod( period.getStartDate(), period.getEndDate(), period.getPeriodType() ) ); registration.setPeriodName( getPeriodString( registration.getPeriod() ) ); registration.setAttributeOptionCombo( categoryService.getDefaultCategoryOptionCombo() ); registration.setSource( ou ); return registration; }