use of org.hisp.dhis.common.ValueType in project dhis2-core by dhis2.
the class DefaultQueryItemLocator method getDataElement.
private Optional<QueryItem> getDataElement(String dimension, Program program, LegendSet legendSet, EventOutputType type) {
QueryItem qi = null;
ProgramStage programStage = getProgramStageOrFail(dimension);
DataElement de = dataElementService.getDataElement(getSecondElement(dimension));
if (de != null && program.containsDataElement(de)) {
ValueType valueType = legendSet != null ? ValueType.TEXT : de.getValueType();
qi = new QueryItem(de, program, legendSet, valueType, de.getAggregationType(), de.getOptionSet());
if (programStage != null) {
qi.setProgramStage(programStage);
qi.setRepeatableStageParams(getRepeatableStageParams(dimension));
} else if (type != null && type.equals(EventOutputType.ENROLLMENT)) {
throwIllegalQueryEx(ErrorCode.E7225, dimension);
}
}
return Optional.ofNullable(qi);
}
use of org.hisp.dhis.common.ValueType in project dhis2-core by dhis2.
the class QueryPlannerUtils method getDataTypeDataElementMap.
/**
* Creates a mapping between data type and data elements for the given data
* elements.
*
* @param dataElements list of data elements.
*/
public static ListMap<DataType, DimensionalItemObject> getDataTypeDataElementMap(List<DimensionalItemObject> dataElements) {
ListMap<DataType, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject element : dataElements) {
DataElement dataElement = (DataElement) element;
ValueType valueType = dataElement.getValueType();
// Both text and date types are recognized as DataType.TEXT
DataType dataType = (valueType.isText() || valueType.isDate()) ? DataType.TEXT : DataType.NUMERIC;
map.putValue(dataType, dataElement);
}
return map;
}
use of org.hisp.dhis.common.ValueType in project dhis2-core by dhis2.
the class AbstractAnalyticsService method getGrid.
protected Grid getGrid(EventQueryParams params) {
// ---------------------------------------------------------------------
// Decide access, add constraints and validate
// ---------------------------------------------------------------------
securityManager.decideAccessEventQuery(params);
params = securityManager.withUserConstraints(params);
queryValidator.validate(params);
// keywords as well as their periods are removed in the next step,
// params object is modified
List<DimensionItemKeywords.Keyword> periodKeywords = params.getDimensions().stream().map(DimensionalObject::getDimensionItemKeywords).filter(dimensionItemKeywords -> dimensionItemKeywords != null && !dimensionItemKeywords.isEmpty()).flatMap(dk -> dk.getKeywords().stream()).collect(Collectors.toList());
params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
// ---------------------------------------------------------------------
// Headers
// ---------------------------------------------------------------------
Grid grid = createGridWithHeaders(params);
for (DimensionalObject dimension : params.getDimensions()) {
grid.addHeader(new GridHeader(dimension.getDimension(), dimension.getDimensionDisplayName(), ValueType.TEXT, false, true));
}
for (QueryItem item : params.getItems()) {
/**
* Special case: If the request contains an item of Org Unit value
* type and the item UID is linked to coordinates (coordinateField),
* then create an Header of ValueType COORDINATE and type "Point"
*/
if (item.getValueType() == ValueType.ORGANISATION_UNIT && params.getCoordinateField().equals(item.getItem().getUid())) {
grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getDisplayProperty(params.getDisplayProperty()), COORDINATE, false, true, item.getOptionSet(), item.getLegendSet()));
} else if (hasNonDefaultRepeatableProgramStageOffset(item)) {
String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
RepeatableStageParams repeatableStageParams = item.getRepeatableStageParams();
String name = repeatableStageParams.getDimension();
grid.addHeader(new GridHeader(name, column, repeatableStageParams.simpleStageValueExpected() ? item.getValueType() : ValueType.REFERENCE, false, true, item.getOptionSet(), item.getLegendSet(), item.getProgramStage().getUid(), item.getRepeatableStageParams()));
} else {
final String uid = getItemUid(item);
final String column = item.getItem().getDisplayProperty(params.getDisplayProperty());
grid.addHeader(new GridHeader(uid, column, item.getValueType(), false, true, item.getOptionSet(), item.getLegendSet()));
}
}
// ---------------------------------------------------------------------
// Data
// ---------------------------------------------------------------------
long count = 0;
if (!params.isSkipData() || params.analyzeOnly()) {
count = addEventData(grid, params);
}
// ---------------------------------------------------------------------
// Meta-data
// ---------------------------------------------------------------------
addMetadata(params, periodKeywords, grid);
if (params.hasDataIdScheme()) {
substituteData(grid);
}
if (params.isPaging()) {
Pager pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
grid.getMetaData().put(PAGER.getKey(), pager);
}
maybeApplyHeaders(params, grid);
return grid;
}
use of org.hisp.dhis.common.ValueType in project dhis2-core by dhis2.
the class DefaultPdfDataEntryFormService method insertTable_DataSetSections.
private void insertTable_DataSetSections(PdfPTable mainTable, PdfWriter writer, Rectangle rectangle, Collection<DataElement> dataElements, String sectionName) throws IOException, DocumentException {
boolean hasBorder = true;
// Add Section Name and Section Spacing
insertTable_TextRow(writer, mainTable, TEXT_BLANK);
if (sectionName != null && !sectionName.isEmpty()) {
insertTable_TextRow(writer, mainTable, sectionName, pdfFormFontSettings.getFont(PdfFormFontSettings.FONTTYPE_SECTIONHEADER));
}
// Create A Table To Add For Each Section
PdfPTable table = new PdfPTable(2);
table.setWidths(new int[] { 2, 1 });
table.setWidthPercentage(100.0f);
table.setHorizontalAlignment(Element.ALIGN_LEFT);
// row.
for (DataElement dataElement : dataElements) {
for (CategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
String categoryOptionComboDisplayName = "";
// Hide Default category option combo name
if (!categoryOptionCombo.isDefault()) {
categoryOptionComboDisplayName = categoryOptionCombo.getDisplayName();
}
addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), dataElement.getFormNameFallback() + " " + categoryOptionComboDisplayName, Element.ALIGN_RIGHT);
String strFieldLabel = PdfDataEntryFormUtil.LABELCODE_DATAENTRYTEXTFIELD + dataElement.getUid() + "_" + categoryOptionCombo.getUid();
ValueType valueType = dataElement.getValueType();
// Yes Only case - render as check-box
if (ValueType.TRUE_ONLY == valueType) {
addCell_WithCheckBox(table, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
} else if (ValueType.BOOLEAN == valueType) {
// Create Yes - true, No - false, Select..
String[] optionList = new String[] { "[No Value]", "Yes", "No" };
String[] valueList = new String[] { "", "true", "false" };
// addCell_WithRadioButton(table, writer, strFieldLabel);
addCell_WithDropDownListField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, optionList, valueList);
} else if (valueType.isNumeric()) {
Rectangle rectNum = new Rectangle(TEXTBOXWIDTH_NUMBERTYPE, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT);
addCell_WithTextField(table, rectNum, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel, PdfFieldCell.TYPE_TEXT_NUMBER);
} else {
addCell_WithTextField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), strFieldLabel);
}
}
}
PdfPCell cell_withInnerTable = new PdfPCell(table);
cell_withInnerTable.setBorder(Rectangle.NO_BORDER);
mainTable.addCell(cell_withInnerTable);
}
use of org.hisp.dhis.common.ValueType in project dhis2-core by dhis2.
the class ValidationUtilsTest method testFileValueTypeOptionValidation.
@Test
void testFileValueTypeOptionValidation() throws IOException {
long oneHundredMegaBytes = 1024 * (1024 * 100L);
ValueType valueType = ValueType.FILE_RESOURCE;
FileTypeValueOptions options = new FileTypeValueOptions();
options.setMaxFileSize(oneHundredMegaBytes);
options.setAllowedContentTypes(ImmutableSet.of("jpg", "pdf"));
FileResource fileResource = new FileResource("name", "jpg", oneHundredMegaBytes, "md5sum", FileResourceDomain.DOCUMENT);
assertNull(dataValueIsValid(fileResource, valueType, options));
fileResource = new FileResource("name", "jpg", 1024 * (1024 * 101L), "md5sum", FileResourceDomain.DOCUMENT);
assertEquals("not_valid_file_size_too_big", dataValueIsValid(fileResource, valueType, options));
fileResource = new FileResource("name", "exe", oneHundredMegaBytes, "md5sum", FileResourceDomain.DOCUMENT);
assertEquals("not_valid_file_content_type", dataValueIsValid(fileResource, valueType, options));
}
Aggregations