<commit_before>package org.devocative.metis.web.dPage.data.form;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
import org.devocative.adroit.ObjectUtil;
import org.devocative.demeter.web.DPage;
import org.devocative.demeter.web.UrlUtil;
import org.devocative.metis.iservice.IDataService;
import org.devocative.metis.vo.DataVO;
import org.devocative.metis.web.dPage.data.DataViewExecutorDPage;
import org.devocative.wickomp.form.wizard.OWizard;
import org.devocative.wickomp.form.wizard.WWizardPanel;
import org.devocative.wickomp.html.WMessager;
import org.devocative.wickomp.wrcs.EasyUIBehavior;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.io.Serializable;
import java.util.List;

public class DataViewFormDPage extends DPage {
	private static Logger logger = LoggerFactory.getLogger(DataViewFormDPage.class);
	private DataVO dataVO;

	@Inject
	private IDataService dataService;

	public DataViewFormDPage(String id, List<String> params) {
		super(id, params);

		if (params.size() > 0) {
			dataVO = dataService.loadDataVO(params.get(0));
		} else {
			dataVO = new DataVO();
			String dsName = getWebRequest().getRequestParameters().getParameterValue("dsName").toOptionalString();
			if (dsName != null) {
				dataService.updateDataVOByDataSource(dataVO, dsName);
			}
		}

		Form form = new Form("form");
		add(form);

		OWizard oWizard = new OWizard()
			.addStep("init", new InitStep(dataVO))
			.addStep("query", new QueryStep(dataVO))
			.addStep("param", new ParamStep(dataVO))
			.addStep("columnDef", new ColumnDefStep(dataVO))
			.addStep("lookup", new DefineLookupStep(dataVO))
			.addStep("columnUI", new ColumnUIStep(dataVO));

		form.add(new WWizardPanel("wizard", oWizard, WWizardPanel.ButtonBarPlace.TOP) {
				@Override
				protected void onNext(AjaxRequestTarget target, String stepId) {
					if (logger.isDebugEnabled()) {
						logger.debug("Step={}, DataVO = {}", stepId, ObjectUtil.toString(dataVO));
					}

					setTitle(dataVO.getName());
				}

				@Override
				protected void onFinish(AjaxRequestTarget target, String stepId) {
					//dataSourceService.saveOrUpdate(dataSource, xdsQuery, xdsFields, xdsParams);
					dataService.saveOrUpdate(dataVO);
					UrlUtil.redirectTo(DataViewExecutorDPage.class, dataVO.getName());
				}

				@Override
				protected void onError(AjaxRequestTarget target, String stepId, List<Serializable> errors) {
					WMessager.show(getString("label.error"), errors, target);
				}

			}.setTitle(dataVO.getName())<commit_msg>- setTitle() on init - onCancel() enabled to redirect to execution of dataView<commit_after>package org.devocative.metis.web.dPage.data.form;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
import org.devocative.adroit.ObjectUtil;
import org.devocative.demeter.web.DPage;
import org.devocative.demeter.web.UrlUtil;
import org.devocative.metis.iservice.IDataService;
import org.devocative.metis.vo.DataVO;
import org.devocative.metis.web.dPage.data.DataViewExecutorDPage;
import org.devocative.wickomp.form.wizard.OWizard;
import org.devocative.wickomp.form.wizard.WWizardPanel;
import org.devocative.wickomp.html.WMessager;
import org.devocative.wickomp.wrcs.EasyUIBehavior;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.io.Serializable;
import java.util.List;

public class DataViewFormDPage extends DPage {
	private static Logger logger = LoggerFactory.getLogger(DataViewFormDPage.class);
	private DataVO dataVO;

	@Inject
	private IDataService dataService;

	public DataViewFormDPage(String id, List<String> params) {
		super(id, params);

		if (params.size() > 0) {
			dataVO = dataService.loadDataVO(params.get(0));
		} else {
			dataVO = new DataVO();
			String dsName = getWebRequest().getRequestParameters().getParameterValue("dsName").toOptionalString();
			if (dsName != null) {
				dataService.updateDataVOByDataSource(dataVO, dsName);
			}
		}

		Form form = new Form("form");
		add(form);

		OWizard oWizard = new OWizard()
			.addStep("init", new InitStep(dataVO))
			.addStep("query", new QueryStep(dataVO))
			.addStep("param", new ParamStep(dataVO))
			.addStep("columnDef", new ColumnDefStep(dataVO))
			.addStep("lookup", new DefineLookupStep(dataVO))
			.addStep("columnUI", new ColumnUIStep(dataVO));

		form.add(new WWizardPanel("wizard", oWizard, WWizardPanel.ButtonBarPlace.TOP) {
				@Override
				protected void onNext(AjaxRequestTarget target, String stepId) {
					if (logger.isDebugEnabled()) {
						logger.debug("Step={}, DataVO = {}", stepId, ObjectUtil.toString(dataVO));
					}

					if ("init".equals(stepId)) {
						setTitle(dataVO.getName());
					}
				}

				@Override
				protected void onFinish(AjaxRequestTarget target, String stepId) {
					//dataSourceService.saveOrUpdate(dataSource, xdsQuery, xdsFields, xdsParams);
					dataService.saveOrUpdate(dataVO);
					UrlUtil.redirectTo(DataViewExecutorDPage.class, dataVO.getName());
				}

				@Override
				protected void onError(AjaxRequestTarget target, String stepId, List<Serializable> errors) {
					WMessager.show(getString("label.error"), errors, target);
				}

				@Override
				protected void onCancel(AjaxRequestTarget target, String stepId) {
					UrlUtil.redirectTo(DataViewExecutorDPage.class, dataVO.getName());
				}
			}.setTitle(dataVO.getName())
				.setCancelButtonVisible(dataVO.getName() != null)
{'fraction_non_alphanumeric': 0.124, 'fraction_numerical': 0.0014545454545454545, 'mean_word_length': 4.934196332254585, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5110462', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1793, 'n_words': 321}