private static String commaDelimitedIds( Collection<? extends IdentifiableObject> idObjects ) { return TextUtils.getCommaDelimitedString( IdentifiableObjectUtils.getIdentifiers( idObjects ) ); }
/** * Transforms a collection of Integers into a comma delimited String. If the * given collection of elements are null or is empty, an empty String is * returned. * * @param delimitPrefix whether to prefix the string with a delimiter. * @param delimitSuffix whether to suffix the string with a delimiter. * @param elements the collection of Integers * @return a comma delimited String. */ public static String getCommaDelimitedString( Collection<?> elements, boolean delimitPrefix, boolean delimitSuffix ) { final StringBuilder builder = new StringBuilder(); if ( elements != null && !elements.isEmpty() ) { if ( delimitPrefix ) { builder.append( DELIMITER ); } builder.append( getCommaDelimitedString( elements ) ); if ( delimitSuffix ) { builder.append( DELIMITER ); } } return builder.toString(); }
@Override public Integer getCompleteDataSetRegistrations( DataSet dataSet, Collection<Integer> periods, Collection<Integer> relevantSources ) { if ( relevantSources == null || relevantSources.isEmpty() || periods == null || periods.isEmpty() ) { return 0; } final String sql = "SELECT COUNT(*) " + "FROM completedatasetregistration cr " + "WHERE cr.datasetid = " + dataSet.getId() + " " + "AND cr.periodid IN ( " + getCommaDelimitedString( periods ) + " ) " + "AND cr.sourceid IN ( " + getCommaDelimitedString( relevantSources ) + " )"; return statementManager.getHolder().queryForInteger( sql ); }
@Override public Integer getCompleteDataSetRegistrationsWithTimeliness( DataSet dataSet, Collection<Integer> periods, Collection<Integer> relevantSources ) { if ( relevantSources == null || relevantSources.isEmpty() || periods == null || periods.isEmpty() ) { return 0; } final String sql = "SELECT COUNT(*) " + "FROM completedatasetregistration cr " + "JOIN period pe ON (cr.periodid = pe.periodid) " + "WHERE cr.datasetid = " + dataSet.getId() + " " + "AND cr.periodid IN ( " + getCommaDelimitedString( periods ) + " ) " + "AND cr.sourceid IN ( " + getCommaDelimitedString( relevantSources ) + " ) " + "AND cr.date <= " + statementBuilder.getAddDate( "pe.enddate", dataSet.getTimelyDays() ); return statementManager.getHolder().queryForInteger( sql ); }
@Override public Integer getCompulsoryDataElementRegistrations( DataSet dataSet, Collection<Integer> children, Collection<Integer> periods, int completenessOffset ) { if ( children == null || children.isEmpty() || periods == null || periods.isEmpty() ) { return 0; } final int compulsoryElements = dataSet.getCompulsoryDataElementOperands().size(); final String deadlineCriteria = completenessOffset >= 0 ? "AND lastupdated <= " + statementBuilder.getAddDate( "pe.enddate", completenessOffset ) : ""; final String sql = "SELECT COUNT(completed) FROM ( " + "SELECT sourceid, COUNT(sourceid) AS sources " + "FROM datavalue dv " + "JOIN dataelementoperand deo ON dv.dataelementid=deo.dataelementid AND dv.categoryoptioncomboid=deo.categoryoptioncomboid " + "JOIN datasetoperands dso ON deo.dataelementoperandid=dso.dataelementoperandid " + "JOIN period pe ON dv.periodid=pe.periodid " + "WHERE dv.periodid IN ( " + getCommaDelimitedString( periods ) + " ) " + deadlineCriteria + "AND sourceid IN ( " + getCommaDelimitedString( children ) + " ) " + "AND datasetid = " + dataSet.getId() + " " + "AND dv.deleted is false " + "GROUP BY sourceid) AS completed " + "WHERE completed.sources = " + compulsoryElements; return statementManager.getHolder().queryForInteger( sql ); }
String dataElementIds = getCommaDelimitedString( getIdentifiers( dataElements ) ); String periodIds = getCommaDelimitedString( getIdentifiers( periods ) ); String categoryOptionComboIds = getCommaDelimitedString( getIdentifiers( categoryOptionCombos ) );
private String getCategoryOptionSharingForUser( User user ) { List<Integer> userGroupIds = getIdentifiers( user.getGroups() ); String sql = " left join ( "; sql += "select categoryoptioncomboid, count(categoryoptioncomboid) as option_size from categoryoptioncombos_categoryoptions group by categoryoptioncomboid) " + "as cocount on coc.categoryoptioncomboid = cocount.categoryoptioncomboid " + "left join (" + "select deco.categoryoptionid as deco_id, deco.uid as deco_uid, deco.publicaccess AS deco_publicaccess, " + "couga.usergroupaccessid as uga_id, coua.useraccessid as ua_id, uga.access as uga_access, uga.usergroupid AS usrgrp_id, " + "ua.access as ua_access, ua.userid as usr_id from dataelementcategoryoption deco " + "left join dataelementcategoryoptionusergroupaccesses couga on deco.categoryoptionid = couga.categoryoptionid " + "left join dataelementcategoryoptionuseraccesses coua on deco.categoryoptionid = coua.categoryoptionid " + "left join usergroupaccess uga on couga.usergroupaccessid = uga.usergroupaccessid " + "left join useraccess ua on coua.useraccessid = ua.useraccessid " + " where ua.userid=" + user.getId(); if ( userGroupIds != null && !userGroupIds.isEmpty() ) { sql += " or uga.usergroupid in (" + getCommaDelimitedString( userGroupIds ) + ") "; } sql += " ) as decoa on cocco.categoryoptionid = decoa.deco_id "; return sql; }
String dataElementIds = getCommaDelimitedString( getIdentifiers( dataElements ) ); String periodIds = getCommaDelimitedString( getIdentifiers( periods ) ); String categoryOptionComboIds = getCommaDelimitedString( getIdentifiers( categoryOptionCombos ) );
Map<Integer, Integer> upperBoundMap ) String periodIds = TextUtils.getCommaDelimitedString( getIdentifiers( periods ) );
financialYearStart ); String periodString = getCommaDelimitedString( getIdentifiers( periodService.reloadPeriods( relativePeriods ) ) ); String isoPeriodString = getCommaDelimitedString( IdentifiableObjectUtils.getUids( relativePeriods ) );
String catOptionComboIds = TextUtils.getCommaDelimitedString( getIdentifiers( categoryOptionCombos ) );
String dataElementIdList = getCommaDelimitedString( getIdentifiers( params.getDataElements() ) ); String periodIdList = getCommaDelimitedString( getIdentifiers( params.getPeriods() ) ); String periodTypeIdList = getCommaDelimitedString( params.getPeriodTypes().stream().map( o -> o.getId() ).collect( Collectors.toList() ) ); String orgUnitIdList = getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ); String aocIdList = getCommaDelimitedString( getIdentifiers( params.getAttributeOptionCombos() ) ); String coDimConstraintsList = getCommaDelimitedString( getIdentifiers( params.getCoDimensionConstraints() ) ); String cogDimConstraintsList = getCommaDelimitedString( getIdentifiers( params.getCogDimensionConstraints() ) );
String cocScheme = idScheme.getCategoryOptionComboIdScheme().getIdentifiableString().toLowerCase(); String dataElements = getCommaDelimitedString( getIdentifiers( params.getAllDataElements() ) ); String orgUnits = getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ); String orgUnitGroups = getCommaDelimitedString( getIdentifiers( params.getOrganisationUnitGroups() ) ); sql += "and dv.periodid in (" + getCommaDelimitedString( getIdentifiers( params.getPeriods() ) ) + ") "; sql += "and dv.attributeoptioncomboid in (" + getCommaDelimitedString( getIdentifiers( params.getAttributeOptionCombos() ) ) + ") ";
+ getCommaDelimitedString( getIdentifiers( organisationUnits ) ) + ") ";
sql += hlp.whereAnd() + " psi.organisationunitid in (" + getCommaDelimitedString( orgUnitIds ) + ") ";
TextUtils.getCommaDelimitedString( params.getPartitions().getPartitions() ) + ") ";
+ getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ) + ") ";