/** * Returns the first of the data view organisation units associated with the * user. If none, returns the first of the data capture organisation units. * If none, return nulls. */ public OrganisationUnit getDataViewOrganisationUnitWithFallback() { return hasDataViewOrganisationUnit() ? getDataViewOrganisationUnit() : getOrganisationUnit(); }
/** * Returns the first of the tei search organisation units associated with the * user. If none, returns the first of the data capture organisation units. * If none, return nulls. */ public OrganisationUnit getTeiSearchOrganisationUnitWithFallback() { return hasTeiSearchOrganisationUnit() ? getTeiSearchOrganisationUnit() : getOrganisationUnit(); }
/** * Builds a HTML table representing the ReportTable input * * @param reportTable reportTable to generate HTML for * @param user user to generate reportTable data for * @return a HTML representation of the reportTable * @throws Exception */ private String generateReportTableHtml( ReportTable reportTable, User user ) { StringWriter stringWriter = new StringWriter(); GridUtils.toHtmlInlineCss( reportTableService .getReportTableGridByUser( reportTable.getUid(), new Date(), user.getOrganisationUnit().getUid(), user ), stringWriter ); return stringWriter.toString().replaceAll( "\\R", "" ); }
/** * Resolve all distinct recipients for the given MessagePair. */ private static Set<User> resolveRecipients( MessagePair pair ) { ValidationResult validationResult = pair.result; ValidationNotificationTemplate template = pair.template; // Limit recipients to be withing org unit hierarchy only, effectively // producing a cross-cut of all users in the configured user groups. final boolean limitToHierarchy = BooleanUtils.toBoolean( template.getNotifyUsersInHierarchyOnly() ); final boolean parentOrgUnitOnly = BooleanUtils.toBoolean( template.getNotifyParentOrganisationUnitOnly() ); Set<OrganisationUnit> orgUnitsToInclude = Sets.newHashSet(); Set<User> recipients = template.getRecipientUserGroups().stream() .flatMap( ug -> ug.getMembers().stream() ).collect( Collectors.toSet() ); if ( limitToHierarchy ) { orgUnitsToInclude.add( validationResult.getOrganisationUnit() ); // Include self orgUnitsToInclude.addAll( validationResult.getOrganisationUnit().getAncestors() ); recipients = recipients.stream() .filter( user -> orgUnitsToInclude.contains( user.getOrganisationUnit() ) ).collect( Collectors.toSet() ); } else if ( parentOrgUnitOnly ) { Set<User> parents = Sets.newHashSet(); recipients.forEach( user -> parents.addAll( user.getOrganisationUnit().getParent().getUsers() ) ); return parents; } return recipients; }
orgUnitInHierarchy.addAll( eventOrgUnit.getAncestors() ); recipients = recipients.stream().filter( r -> orgUnitInHierarchy.contains( r.getOrganisationUnit() ) ).collect( Collectors.toSet() ); recipients.stream().forEach( r -> parents.addAll( r.getOrganisationUnit().getParent().getUsers() ) );
public static User getUser( String sender, SMSCommand smsCommand, List<User> userList ) { OrganisationUnit orgunit = null; User user = null; for ( User u : userList ) { OrganisationUnit ou = u.getOrganisationUnit(); if ( ou != null ) { if ( orgunit == null ) { orgunit = ou; } else if ( orgunit.getId() == ou.getId() ) { } else { throw new SMSParserException( StringUtils.defaultIfBlank( smsCommand.getMoreThanOneOrgUnitMessage(), SMSCommand.MORE_THAN_ONE_ORGUNIT_MESSAGE ) ); } } user = u; } if ( user == null ) { throw new SMSParserException( "User is not associated with any orgunit. Please contact your supervisor." ); } return user; }
@Override public JFreeChart getJFreeChart( BaseChart chart, Date date, OrganisationUnit organisationUnit, I18nFormat format, User currentUser ) { User user = (currentUser != null ? currentUser : currentUserService.getCurrentUser()); if ( organisationUnit == null && user != null ) { organisationUnit = user.getOrganisationUnit(); } List<OrganisationUnit> atLevels = new ArrayList<>(); List<OrganisationUnit> inGroups = new ArrayList<>(); if ( chart.hasOrganisationUnitLevels() ) { atLevels.addAll( organisationUnitService.getOrganisationUnitsAtLevels( chart.getOrganisationUnitLevels(), chart.getOrganisationUnits() ) ); } if ( chart.hasItemOrganisationUnitGroups() ) { inGroups.addAll( organisationUnitService.getOrganisationUnits( chart.getItemOrganisationUnitGroups(), chart.getOrganisationUnits() ) ); } chart.init( user, date, organisationUnit, atLevels, inGroups, format ); JFreeChart resultChart = getJFreeChart( chart ); chart.clearTransientState(); return resultChart; }
OrganisationUnit organisationUnit = user.getOrganisationUnit();