Program extends BaseNameableObject implements VersionedObject, MetadataObject { public void updateOrganisationUnits( Set<OrganisationUnit> updates ) { Set<OrganisationUnit> toRemove = Sets.difference( organisationUnits, updates ); Set<OrganisationUnit> toAdd = Sets.difference( updates, organisationUnits ); toRemove.forEach( u -> u.getPrograms().remove( this ) ); toAdd.forEach( u -> u.getPrograms().add( this ) ); organisationUnits.clear(); organisationUnits.addAll( updates ); } Program();  Program( String name, String description ); void addOrganisationUnit( OrganisationUnit organisationUnit ); void removeOrganisationUnit( OrganisationUnit organisationUnit ); void updateOrganisationUnits( Set<OrganisationUnit> updates ); List<String> getSearchableAttributeIds(); List<TrackedEntityAttribute> getDisplayInListAttributes(); ProgramTrackedEntityAttribute getAttribute( TrackedEntityAttribute attribute ); Set<DataElement> getDataElements(); Set<DataElement> getDataElementsWithLegendSet(); List<TrackedEntityAttribute> getTrackedEntityAttributes(); List<TrackedEntityAttribute> getNonConfidentialTrackedEntityAttributes(); List<TrackedEntityAttribute> getNonConfidentialTrackedEntityAttributesWithLegendSet(); boolean containsDataElement( DataElement dataElement ); boolean containsAttribute( TrackedEntityAttribute attribute ); ProgramStage getProgramStageByStage( int stage ); boolean isSingleProgramStage(); boolean hasOrganisationUnit( OrganisationUnit unit ); @Override int increaseVersion(); boolean isOpen(); boolean isAudited(); boolean isProtected(); boolean isClosed(); @Override @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) int getVersion(); @Override void setVersion( int version ); @JsonProperty( "organisationUnits" ) @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0 ) Set<OrganisationUnit> getOrganisationUnits(); void setOrganisationUnits( Set<OrganisationUnit> organisationUnits ); @JsonProperty( "programStages" ) @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "programStages", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "programStage", namespace = DxfNamespaces.DXF_2_0 ) Set<ProgramStage> getProgramStages(); void setProgramStages( Set<ProgramStage> programStages ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) @PropertyRange( min = 2 ) String getEnrollmentDateLabel(); void setEnrollmentDateLabel( String enrollmentDateLabel ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) @PropertyRange( min = 2 ) String getIncidentDateLabel(); void setIncidentDateLabel( String incidentDateLabel ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) ProgramType getProgramType(); void setProgramType( ProgramType programType ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Boolean getDisplayIncidentDate(); void setDisplayIncidentDate( Boolean displayIncidentDate ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Boolean getIgnoreOverdueEvents(); void setIgnoreOverdueEvents( Boolean ignoreOverdueEvents ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) boolean isRegistration(); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) boolean isWithoutRegistration(); @JsonProperty @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "userRoles", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "userRole", namespace = DxfNamespaces.DXF_2_0 ) Set<UserAuthorityGroup> getUserRoles(); void setUserRoles( Set<UserAuthorityGroup> userRoles ); @JsonProperty @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "programIndicators", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "programIndicator", namespace = DxfNamespaces.DXF_2_0 ) Set<ProgramIndicator> getProgramIndicators(); void setProgramIndicators( Set<ProgramIndicator> programIndicators ); @JsonProperty @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "programRuleVariables", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "programRuleVariable", namespace = DxfNamespaces.DXF_2_0 ) Set<ProgramRuleVariable> getProgramRuleVariables(); void setProgramRuleVariables( Set<ProgramRuleVariable> programRuleVariables ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Boolean getOnlyEnrollOnce(); void setOnlyEnrollOnce( Boolean onlyEnrollOnce ); @JsonProperty @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlProperty( localName = "notificationTemplate", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlElementWrapper( localName = "notificationTemplates", namespace = DxfNamespaces.DXF_2_0 ) Set<ProgramNotificationTemplate> getNotificationTemplates(); void setNotificationTemplates( Set<ProgramNotificationTemplate> notificationTemplates ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Boolean getSelectEnrollmentDatesInFuture(); void setSelectEnrollmentDatesInFuture( Boolean selectEnrollmentDatesInFuture ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Boolean getSelectIncidentDatesInFuture(); void setSelectIncidentDatesInFuture( Boolean selectIncidentDatesInFuture ); @JsonProperty @JsonSerialize( as = BaseIdentifiableObject.class ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Program getRelatedProgram(); void setRelatedProgram( Program relatedProgram ); @JsonProperty( "programTrackedEntityAttributes" ) @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "programTrackedEntityAttributes", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "programTrackedEntityAttribute", namespace = DxfNamespaces.DXF_2_0 ) List<ProgramTrackedEntityAttribute> getProgramAttributes(); void setProgramAttributes( List<ProgramTrackedEntityAttribute> programAttributes ); @JsonProperty @JacksonXmlElementWrapper( localName = "trackedEntityType", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "trackedEntityType", namespace = DxfNamespaces.DXF_2_0 ) TrackedEntityType getTrackedEntityType(); void setTrackedEntityType( TrackedEntityType trackedEntityType ); @JsonProperty @JacksonXmlProperty( localName = "dataEntryForm", namespace = DxfNamespaces.DXF_2_0 ) DataEntryForm getDataEntryForm(); void setDataEntryForm( DataEntryForm dataEntryForm ); @JsonProperty @JsonSerialize( as = BaseIdentifiableObject.class ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) CategoryCombo getCategoryCombo(); void setCategoryCombo( CategoryCombo categoryCombo ); boolean hasCategoryCombo(); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) boolean isSkipOffline(); void setSkipOffline( boolean skipOffline ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Boolean getDisplayFrontPageList(); void setDisplayFrontPageList( Boolean displayFrontPageList ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) Boolean getUseFirstStageDuringRegistration(); void setUseFirstStageDuringRegistration( Boolean useFirstStageDuringRegistration ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) FeatureType getFeatureType(); void setFeatureType( FeatureType featureType ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) int getExpiryDays(); void setExpiryDays( int expiryDays ); @JsonProperty @JsonSerialize( using = JacksonPeriodTypeSerializer.class ) @JsonDeserialize( using = JacksonPeriodTypeDeserializer.class ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) PeriodType getExpiryPeriodType(); void setExpiryPeriodType( PeriodType expiryPeriodType ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) int getCompleteEventsExpiryDays(); void setCompleteEventsExpiryDays( int completeEventsExpiryDays ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) int getMinAttributesRequiredToSearch(); void setMinAttributesRequiredToSearch( int minAttributesRequiredToSearch ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) int getMaxTeiCountToReturn(); void setMaxTeiCountToReturn( int maxTeiCountToReturn ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) ObjectStyle getStyle(); void setStyle( ObjectStyle style ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) String getFormName(); void setFormName( String formName ); @JsonProperty( "programSections" ) @JsonSerialize( contentAs = BaseIdentifiableObject.class ) @JacksonXmlElementWrapper( localName = "programSections", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "programSection", namespace = DxfNamespaces.DXF_2_0 ) Set<ProgramSection> getProgramSections(); void setProgramSections( Set<ProgramSection> programSections ); @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) AccessLevel getAccessLevel(); void setAccessLevel( AccessLevel accessLevel );  }
@Test public void testUpdateOrganisationUnits() { Program prA = new Program(); OrganisationUnit ouA = new OrganisationUnit( "ouA" ); OrganisationUnit ouB = new OrganisationUnit( "ouB" ); OrganisationUnit ouC = new OrganisationUnit( "ouC" ); OrganisationUnit ouD = new OrganisationUnit( "ouD" ); prA.addOrganisationUnit( ouA ); prA.addOrganisationUnit( ouB ); assertEquals( 2, prA.getOrganisationUnits().size() ); assertTrue( prA.getOrganisationUnits().containsAll( Sets.newHashSet( ouA, ouB ) ) ); assertTrue( ouA.getPrograms().contains( prA ) ); assertTrue( ouB.getPrograms().contains( prA ) ); assertTrue( ouC.getPrograms().isEmpty() ); assertTrue( ouD.getPrograms().isEmpty() ); prA.updateOrganisationUnits( Sets.newHashSet( ouB, ouC ) ); assertEquals( 2, prA.getOrganisationUnits().size() ); assertTrue( prA.getOrganisationUnits().containsAll( Sets.newHashSet( ouB, ouC ) ) ); assertTrue( ouA.getPrograms().isEmpty() ); assertTrue( ouB.getPrograms().contains( prA ) ); assertTrue( ouC.getPrograms().contains( prA ) ); assertTrue( ouD.getPrograms().isEmpty() ); }