/*
 * Copyright (c) 2017, University of Oslo
 *
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * Neither the name of the HISP project nor the names of its contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.hisp.dhis.android.core.dataset;

import org.hisp.dhis.android.core.common.ObjectWithUid;
import org.hisp.dhis.android.core.dataelement.DataElement;
import org.hisp.dhis.android.core.indicator.Indicator;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

final class DataSetParentUidsHelper {

    private DataSetParentUidsHelper() {
    }

    static Set<String> getDataElementUids(List<DataSet> dataSets) {
        Set<String> uids = new HashSet<>();
        for (DataSet dataSet : dataSets) {
            List<DataSetElement> dataSetElements = dataSet.dataSetElements();
            assert dataSetElements != null;
            for (DataSetElement dataSetElement : dataSetElements) {
                uids.add(dataSetElement.dataElement().uid());
            }
        }
        return uids;
    }

    static Set<String> getIndicatorUids(List<DataSet> dataSets) {
        Set<String> uids = new HashSet<>();
        for (DataSet dataSet : dataSets) {
            for (ObjectWithUid indicator : dataSet.indicators()) {
                uids.add(indicator.uid());
            }
        }
        return uids;
    }

    static Set<String> getIndicatorTypeUids(List<Indicator> indicators) {
        Set<String> uids = new HashSet<>();
        for (Indicator indicator : indicators) {
            ObjectWithUid type = indicator.indicatorType();
            if (type != null) {
                uids.add(type.uid());
            }
        }
        return uids;
    }

    static Set<String> getAssignedOptionSetUids(List<DataElement> dataElements) {

        Set<String> dataElementUids = new HashSet<>();

        if (dataElements != null) {

            for (DataElement dataElement : dataElements) {
                String optionSetUid = dataElement.optionSetUid();

                dataElementUids.add(optionSetUid);
            }

            dataElementUids.remove(null);
        }
        return dataElementUids;
    }
}

@@ -1584,186 +1584,16 @@
 ore.
-dataset;%0A%0Aimport org.hisp.dhis.android.core.common.ObjectWithUid;%0Aimport org.hisp.dhis.android.core.dataelement.DataElement;%0Aimport org.hisp.dhis.android.core.indicator.Indicator
+category
 ;%0A%0Ai
@@ -1663,16 +1663,23 @@
 l.Set;%0A%0A
+public 
 final cl
@@ -1682,23 +1682,24 @@
 l class 
-DataSet
+Category
 ParentUi
@@ -1722,23 +1722,24 @@
 private 
-DataSet
+Category
 ParentUi
@@ -1754,32 +1754,39 @@
 () %7B%0A    %7D%0A%0A    
+public 
 static Set%3CStrin
@@ -1791,27 +1791,24 @@
 ing%3E get
-DataElement
+Category
 Uids(Lis
@@ -1813,1246 +1813,239 @@
 ist%3C
-DataSet%3E dataSets) %7B%0A        Set%3CString%3E uids = new HashSet%3C%3E();%0A        for (DataSet dataSet : dataSets) %7B%0A            List%3CDataSetElement%3E dataSetElements = dataSet.dataSetElements();%0A            assert dataSetElements != null;%0A            for (DataSetElement dataSetElement : dataSetElements) %7B%0A                uids.add(dataSetElement.dataElement().uid());%0A            %7D%0A        %7D%0A        return uids;%0A    %7D%0A%0A    static Set%3CString%3E getIndicatorUids(List%3CDataSet%3E dataSets) %7B%0A        Set%3CString%3E uids = new HashSet%3C%3E();%0A        for (DataSet dataSet : dataSets) %7B%0A            for (ObjectWithUid indicator : dataSet.indicators()) %7B%0A                uids.add(indicator.uid());%0A            %7D%0A        %7D%0A        return uids;%0A    %7D%0A%0A    static Set%3CString%3E getIndicatorTypeUids(List%3CIndicator%3E indicators) %7B%0A        Set%3CString%3E uids = new HashSet%3C%3E();%0A        for (Indicator indicator : indicators) %7B%0A            ObjectWithUid type = indicator.indicatorType();%0A            if (type != null) %7B%0A                uids.add(type.uid());%0A            %7D%0A        %7D%0A        return uids;%0A    %7D%0A%0A    static Set%3CString%3E getAssignedOptionSetUids(List%3CDataElement%3E dataElements) %7B%0A%0A        Set%3CString%3E dataElementUids = new HashSet%3C%3E();%0A%0A        if (dataElement
+CategoryCombo%3E categoryCombos) %7B%0A        Set%3CString%3E uids = new HashSet%3C%3E();%0A        for (CategoryCombo categoryCombo : categoryCombos) %7B%0A            List%3CCategory%3E categories = categoryCombo.categories();%0A            if (categorie
 s !=
@@ -2053,17 +2053,18 @@
 null) %7B%0A
-%0A
+  
         
@@ -2071,50 +2071,44 @@
     
+  
 for (
-DataElement dataElement : dataElement
+Category category : categorie
 s) %7B
@@ -2128,107 +2128,35 @@
     
-String optionSetUid = dataElement.optionSetUid();%0A%0A                dataElementUids.add(optionSetUid
+    uids.add(category.uid()
 );%0A 
@@ -2162,26 +2162,29 @@
             
+    
 %7D
-%0A
 %0A           
@@ -2188,37 +2188,9 @@
     
-dataElementUids.remove(null);
+%7D
 %0A   
@@ -2215,20 +2215,9 @@
 urn 
-dataElementU
+u
 ids;
@@ -2224,9 +2224,8 @@
 %0A    %7D%0A%7D
-%0A

Add CategoryParentUidsHelper