use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class ExpressionUpgrader method upgradeDataEntryForms.
private void upgradeDataEntryForms() {
Collection<DataEntryForm> forms = dataEntryFormService.getAllDataEntryForms();
for (DataEntryForm form : forms) {
if (DataEntryForm.CURRENT_FORMAT > form.getFormat() && form.getHtmlCode() != null && !form.getHtmlCode().trim().isEmpty()) {
try {
// ---------------------------------------------------------
// Identifiers
// ---------------------------------------------------------
Matcher matcher = IDENTIFIER_PATTERN.matcher(form.getHtmlCode());
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
DataElement de = dataElementService.getDataElement(Integer.parseInt(matcher.group(1)));
DataElementCategoryOptionCombo coc = categoryService.getDataElementCategoryOptionCombo(Integer.parseInt(matcher.group(2)));
String replacement = "id=\"" + de.getUid() + "-" + coc.getUid() + "-val\"";
matcher.appendReplacement(sb, replacement);
}
matcher.appendTail(sb);
form.setHtmlCode(sb.toString());
// ---------------------------------------------------------
// Data element totals
// ---------------------------------------------------------
matcher = DATAELEMENT_TOTAL_PATTERN.matcher(form.getHtmlCode());
sb = new StringBuffer();
while (matcher.find()) {
DataElement de = dataElementService.getDataElement(Integer.parseInt(matcher.group(1)));
String replacement = "dataelementid=\"" + de.getUid() + "\"";
matcher.appendReplacement(sb, replacement);
}
matcher.appendTail(sb);
form.setHtmlCode(sb.toString());
// ---------------------------------------------------------
// Indicators
// ---------------------------------------------------------
matcher = INDICATOR_PATTERN.matcher(form.getHtmlCode());
sb = new StringBuffer();
while (matcher.find()) {
Indicator in = indicatorService.getIndicator(Integer.parseInt(matcher.group(1)));
String replacement = "indicatorid=\"" + in.getUid() + "\"";
matcher.appendReplacement(sb, replacement);
}
matcher.appendTail(sb);
form.setHtmlCode(sb.toString());
// ---------------------------------------------------------
// Update format and save
// ---------------------------------------------------------
form.setFormat(DataEntryForm.CURRENT_FORMAT);
dataEntryFormService.updateDataEntryForm(form);
log.info("Upgraded custom data entry form: " + form.getName());
} catch (Exception ex) {
log.error("Upgrading custom data entry form failed: " + form.getName());
// Log and continue
log.error(ex);
}
}
}
}
use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class ValidateDataEntryFormAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
name = name.trim();
DataEntryForm match = dataEntryFormService.getDataEntryFormByName(name);
if (match != null && (dataEntryFormId == null || match.getId() != dataEntryFormId)) {
message = i18n.getString("duplicate_names");
return ERROR;
}
message = i18n.getString("everything_is_ok");
return SUCCESS;
}
use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class RemoveDataEntryFormAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
DataEntryForm dataEntryForm = dataEntryFormService.getDataEntryForm(id);
Program program = programStageService.getProgramStage(programStageId).getProgram();
programId = program.getId();
Set<ProgramStage> programStages = program.getProgramStages();
for (ProgramStage programStage : programStages) {
DataEntryForm programEntryForm = programStage.getDataEntryForm();
if (programEntryForm != null && programEntryForm.equals(dataEntryForm)) {
programStage.setDataEntryForm(null);
programStageService.updateProgramStage(programStage);
}
}
program.increaseVersion();
dataEntryFormService.deleteDataEntryForm(dataEntryForm);
return SUCCESS;
}
use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class RemoveProgramEntryFormAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
Program program = programService.getProgram(programId);
program.setDataEntryForm(null);
programService.updateProgram(program);
DataEntryForm dataEntryForm = program.getDataEntryForm();
dataEntryFormService.deleteDataEntryForm(dataEntryForm);
return SUCCESS;
}
use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class SaveDataEntryFormAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
ProgramStage programStage = programStageService.getProgramStage(programStageId);
Program program = programStage.getProgram();
programId = program.getId();
DataEntryForm dataEntryForm = null;
if (dataEntryFormId == null) {
dataEntryForm = programStage.getDataEntryForm();
} else {
dataEntryForm = dataEntryFormService.getDataEntryForm(dataEntryFormId);
}
if (dataEntryForm == null || !dataEntryForm.getHtmlCode().equals(designTextarea)) {
program.increaseVersion();
}
designTextarea = dataEntryFormService.prepareDataEntryFormForSave(designTextarea);
if (dataEntryForm == null) {
program.increaseVersion();
dataEntryForm = new DataEntryForm(StringUtils.trimToNull(name), designTextarea);
dataEntryFormService.addDataEntryForm(dataEntryForm);
} else {
dataEntryForm.setName(StringUtils.trimToNull(name));
dataEntryForm.setHtmlCode(designTextarea);
dataEntryFormService.updateDataEntryForm(dataEntryForm);
}
programStage.setDataEntryForm(dataEntryForm);
programStageService.updateProgramStage(programStage);
return SUCCESS;
}
Aggregations