use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testGetCocNameMap.
@Test
public void testGetCocNameMap() {
DataElementCategoryCombo ccA = createCategoryCombo('A', new DataElementCategory[0]);
DataElementCategoryCombo ccB = createCategoryCombo('B', new DataElementCategory[0]);
DataElementCategoryOptionCombo cocA = createCategoryOptionCombo('A');
DataElementCategoryOptionCombo cocB = createCategoryOptionCombo('B');
ccA.getOptionCombos().add(cocA);
ccB.getOptionCombos().add(cocB);
DataElement deA = createDataElement('A');
DataElement deB = createDataElement('B');
deA.setDataElementCategoryCombo(ccA);
deB.setDataElementCategoryCombo(ccB);
DimensionalObject dx = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB));
DataQueryParams params = DataQueryParams.newBuilder().addDimension(dx).withDisplayProperty(DisplayProperty.NAME).build();
Map<String, String> map = AnalyticsUtils.getCocNameMap(params);
assertEquals(map.get(cocA.getUid()), cocA.getName());
assertEquals(map.get(cocB.getUid()), cocB.getName());
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class DataSetDeletionHandler method deleteDataElementCategoryCombo.
@Override
public void deleteDataElementCategoryCombo(DataElementCategoryCombo categoryCombo) {
DataElementCategoryCombo defaultCategoryCombo = categoryService.getDataElementCategoryComboByName(DEFAULT_CATEGORY_COMBO_NAME);
Collection<DataSet> dataSets = idObjectManager.getAllNoAcl(DataSet.class);
for (DataSet dataSet : dataSets) {
if (dataSet != null && categoryCombo.equals(dataSet.getCategoryCombo())) {
dataSet.setCategoryCombo(defaultCategoryCombo);
idObjectManager.updateNoAcl(dataSet);
}
}
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateDataSetWithSectionsAndGreyedFields.
@Test
public void testCreateDataSetWithSectionsAndGreyedFields() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<Section> sections = manager.getAll(Section.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
List<User> users = manager.getAll(User.class);
List<DataElementOperand> dataElementOperands = manager.getAll(DataElementOperand.class);
List<TrackedEntity> trackedEntities = manager.getAll(TrackedEntity.class);
List<OrganisationUnitLevel> organisationUnitLevels = manager.getAll(OrganisationUnitLevel.class);
assertFalse(organisationUnits.isEmpty());
assertEquals(1, organisationUnitLevels.size());
assertEquals(1, trackedEntities.size());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(1, dataSets.size());
assertEquals(2, sections.size());
assertEquals(1, dataElementOperands.size());
DataSet dataSet = dataSets.get(0);
assertEquals(2, dataSet.getSections().size());
Section section1 = sections.get(0);
Section section2 = sections.get(1);
assertEquals(1, section1.getDataElements().size());
assertEquals(1, section2.getDataElements().size());
assertNotNull(section1.getDataSet());
assertNotNull(section2.getDataSet());
Section section = manager.get(Section.class, "C50M0WxaI7y");
assertNotNull(section.getDataSet());
assertEquals(1, section.getCategoryCombos().size());
assertEquals(1, section.getGreyedFields().size());
DataElementCategoryCombo categoryCombo = manager.get(DataElementCategoryCombo.class, "faV8QvLgIwB");
assertNotNull(categoryCombo);
DataElementCategory category = manager.get(DataElementCategory.class, "XJGLlMAMCcn");
assertNotNull(category);
DataElementCategoryOption categoryOption1 = manager.get(DataElementCategoryOption.class, "JYiFOMKa25J");
DataElementCategoryOption categoryOption2 = manager.get(DataElementCategoryOption.class, "tdaMRD34m8o");
assertNotNull(categoryOption1);
assertNotNull(categoryOption2);
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class LoadFormAction method getDataElementCategoryCombos.
private List<DataElementCategoryCombo> getDataElementCategoryCombos(List<DataElement> dataElements, DataSet dataSet) {
Set<DataElementCategoryCombo> categoryCombos = new HashSet<>();
for (DataElement dataElement : dataElements) {
categoryCombos.add(dataElement.getCategoryCombo(dataSet));
}
List<DataElementCategoryCombo> listCategoryCombos = new ArrayList<>(categoryCombos);
Collections.sort(listCategoryCombos, new DataElementCategoryComboSizeComparator());
return listCategoryCombos;
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class LoadFormAction method getSectionForm.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getSectionForm(Collection<DataElement> dataElements, DataSet dataSet) {
sections = new ArrayList<>(dataSet.getSections());
Collections.sort(sections, new SectionOrderComparator());
for (Section section : sections) {
Set<Integer> categoryComboIds = new HashSet<>();
for (DataElementCategoryCombo categoryCombo : section.getCategoryCombos()) {
categoryComboIds.add(categoryCombo.getId());
sectionCategoryComboDataElements.put(section.getId() + "-" + categoryCombo.getId(), section.getDataElementsByCategoryCombo(categoryCombo));
}
if (!categoryComboIds.isEmpty()) {
sectionCombos.put(section.getId(), categoryComboIds);
}
for (DataElementOperand operand : section.getGreyedFields()) {
if (operand != null && operand.getDataElement() != null && operand.getCategoryOptionCombo() != null) {
greyedFields.put(operand.getDataElement().getUid() + ":" + operand.getCategoryOptionCombo().getUid(), true);
}
}
}
}
Aggregations