Erste kompilierfähige Version. Wird wohl noch nicht viel tun, aber sie kompiliert - und das ist doch auch schon mal was.

git-svn-id: https://svn.libreccm.org/ccm/trunk@350 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-02-18 10:39:18 +00:00
parent 1fd85e0a1a
commit db3fc80861
8 changed files with 236 additions and 318 deletions

View File

@ -7,7 +7,7 @@ object type Survey extends ContentPage {
to bebop_form_sections.form_section_id;
// Date[0..1] startDate = ct_surveys.start_date DATE;
// Date[0..1] endDate = ct_surveys.end_date DATE;
Boolean[0..1] responsesPublic = ct_surveys.responses_public CHAR(1);
Boolean[0..1] responsesPublic = ct_surveys.responses_public BOOLEAN;
reference key ( ct_surveys.survey_id );
}

View File

@ -11,7 +11,6 @@ import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.util.Assert;
/**
@ -31,7 +30,6 @@ public class Survey extends ContentPage {
// public static final String END_DATE = "endDate";
/** PDL property name for responsesPublic */
public static final String RESPONSES_PUBLIC = "responsesPublic";
/** Data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.simplesurvey.Survey";
@ -126,9 +124,8 @@ public class Survey extends ContentPage {
return (Date)get(END_DATE);
}
*/
public boolean responsesArePublic() {
return ((Boolean) get(RESPONSES_PUBLIC)).booleanValue();
public boolean getResponsesPublic() {
return ((Boolean) get(RESPONSES_PUBLIC));
}
public void setResponsesPublic(Boolean responsesPublic) {
@ -136,7 +133,6 @@ public class Survey extends ContentPage {
}
/* Class methods *********************************************************/
public static Survey retrieve(BigDecimal id)
throws DataObjectNotFoundException {

View File

@ -1,14 +1,12 @@
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentType;
import com.arsdigita.db.Sequences;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.formbuilder.PersistentLabel;
import com.arsdigita.formbuilder.PersistentWidget;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
import com.arsdigita.util.Assert;
import java.math.BigDecimal;
/**
@ -22,8 +20,6 @@ import java.math.BigDecimal;
*/
public class SurveyAnswer extends ContentItem {
/** PDL property name for id */
public static final String ID = "id";
/** PDL property name for label */
public static final String LABEL = "label";
/** PDL property name for widget */
@ -90,9 +86,6 @@ public class SurveyAnswer extends ContentItem {
}
/* accessors *****************************************************/
public BigDecimal getID() {
return (BigDecimal) get(ID);
}
/* Class methods ********/
public static SurveyAnswer create(PersistentLabel label,
@ -115,5 +108,4 @@ public class SurveyAnswer extends ContentItem {
set(WIDGET, widget);
set(VALUE, value);
}
}

View File

@ -7,7 +7,6 @@ import com.arsdigita.formbuilder.PersistentWidget;
import com.arsdigita.kernel.User;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
import com.arsdigita.simplesurvey.Survey;
import java.math.BigDecimal;
import java.util.Date;

View File

@ -16,8 +16,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.simplesurvey.ui;
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
@ -35,13 +34,11 @@ import java.util.Map;
import java.util.HashMap;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.simplesurvey.Survey;
import com.arsdigita.simplesurvey.Response;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.simplesurvey.ui.Question;
import com.arsdigita.bebop.parameters.ParameterData;
import com.arsdigita.cms.contenttypes.Survey;
import com.arsdigita.cms.contenttypes.SurveyResponse;
import com.arsdigita.persistence.DataAssociationCursor;
import com.arsdigita.persistence.DataOperation;
import com.arsdigita.persistence.SessionManager;
@ -58,27 +55,24 @@ import org.apache.log4j.Logger;
/**
* The process lister that processes a survey response entered by a user.
*
* @author <a href="mailto:pmarklun@arsdigita.com">Peter Marklund</a>
* @version $Id: SurveyProcessListener.java 759 2005-09-02 15:25:32Z sskracic $
*/
public class SurveyProcessListener
implements FormProcessListener {
public static final String SURVEY_ID_NAME = "__ss_survey_id__";
public static final String RESPONSE_ID = "__ss_response_id__";
public static final BigDecimal THE_PUBLIC_USER = new BigDecimal(-200);
private static final String KNOWLEDGE_TEST = "knowledge_test";
protected RequestLocal m_persistentForm = new RequestLocal();
private RequestLocal m_nameQuestionMap = new RequestLocal();
private RequestLocal m_response;
private static org.apache.log4j.Logger s_log =
Logger.getLogger(SurveyProcessListener.class.getName());
public SurveyProcessListener(RequestLocal response) {
m_response = response;
}
public SurveyProcessListener() {
m_response = null;
}
@ -93,9 +87,9 @@ public class SurveyProcessListener
m_response.set(ps, responseID);
Survey survey = (Survey) FormBuilderUtil.instantiateObjectOneArg(Survey.class.getName(), surveyID);
Response response = null;
SurveyResponse response = null;
try {
response = (Response) DomainObjectFactory.newInstance( new OID(Response.class.getName(), responseID));
response = (SurveyResponse) DomainObjectFactory.newInstance(new OID(SurveyResponse.class.getName(), responseID));
} catch (DataObjectNotFoundException ex) {
// s_log.warn("Can't create this object" + responseID);
}
@ -133,21 +127,22 @@ public class SurveyProcessListener
// answer values and add them one by one
String[] valueArray = (String[]) parameterValue;
for (int i = 0; i < valueArray.length; ++i) {
addAnswer(response, ps, valueArray[i], parameterName);
// addAnswer(response, ps, valueArray[i], parameterName);
}
} else {
// Single answer question
addAnswer(response, ps, parameterValue, parameterName);
// addAnswer(response, ps, parameterValue, parameterName);
}
}
// Save the survey response to the database
response.save();
saveScore(survey, response);
// saveScore(survey, response);
}
private void saveScore(Survey survey, Response response) {
/*
private void saveScore(Survey survey, SurveyResponse response) {
String query;
if (survey.getQuizType().equals(KNOWLEDGE_TEST)) {
@ -159,8 +154,9 @@ public class SurveyProcessListener
dao.setParameter("responseID", response.getID());
dao.execute();
}
private void addAnswer(Response surveyResponse,
*/
/*
private void addAnswer(SurveyResponse surveyResponse,
PageState ps,
Object parameterValue,
String parameterName) {
@ -177,12 +173,14 @@ public class SurveyProcessListener
surveyResponse.addAnswer(persistentLabel, persistentWidget, getStringValue(parameterValue));
}
}
*/
/*
private String getStringValue(Object parameterValue) {
return parameterValue == null ? "" : parameterValue.toString();
}
*/
/*
protected Question getQuestion(PageState ps, String parameterName) {
if (m_nameQuestionMap.get(ps) == null) {
@ -234,4 +232,6 @@ public class SurveyProcessListener
return question;
}
*/
}

View File

@ -18,178 +18,124 @@
*/
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.cms.contenttypes.util.SurveyGlobalizationUtil;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.parameters.NotWhiteSpaceValidationListener;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.BlockStylable;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.Date;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.form.RadioGroup;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Survey;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.lang.Boolean;
import com.arsdigita.cms.ui.authoring.BasicPageForm;
public class SurveyPropertiesForm extends Form {
public class SurveyPropertiesForm extends BasicPageForm implements FormProcessListener, FormInitListener, FormSubmissionListener {
private SurveySelectionModel m_survey;
private Class m_type;
private SurveyPropertiesStep m_step;
public static final String DESCRIPTION = Survey.DESCRIPTION;
// public static final String START_DATE = Survey.START_DATE;
// public static final String END_DATE = Survey.END_DATE;
public static final String RESPONSES_PUBLIC = Survey.RESPONSES_PUBLIC;
/**
* ID of the form
*/
public static final String ID = "Survey_edit";
/**
* Constrctor taking an ItemSelectionModel
*
* @param itemModel
*/
public SurveyPropertiesForm(ItemSelectionModel itemModel) {
this(itemModel, null);
}
private TextField m_surveyName;
private TextArea m_description;
private Date m_startDate;
private Date m_endDate;
private RadioGroup m_responsesPublic;
private RadioGroup m_quizType;
/**
* Constrctor taking an ItemSelectionModel and an instance of BaseContactPropertiesStep.
*
* @param itemModel
* @param step
*/
public SurveyPropertiesForm(ItemSelectionModel itemModel, SurveyPropertiesStep step) {
super(ID, itemModel);
m_step = step;
addSubmissionListener(this);
}
public PropertiesForm(SurveySelectionModel survey,
Class type) {
@Override
public void addWidgets() {
super.addWidgets();
super("properties" + type.getName());
add(new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.survey.ui.admin.description").localize()));
ParameterModel descriptionParam = new StringParameter(DESCRIPTION);
descriptionParam.addParameterListener(new StringInRangeValidationListener(0, 4000));
TextArea description = new TextArea(descriptionParam);
description.setRows(20);
description.setCols(60);
add(description);
m_survey = survey;
m_type = type;
// add(new Label(SurveyGlobalizationUtil.globalize("simplesurvey.ui.admin.start_date")));
// add(m_startDate);
//
// add(new Label(SurveyGlobalizationUtil.globalize("simplesurvey.ui.admin.end_date")));
// add(m_endDate);
m_surveyName = new TextField("surveyName");
m_surveyName.addValidationListener(new NotWhiteSpaceValidationListener());
m_description = new TextArea("description");
m_startDate = new Date("startDate");
m_endDate = new Date("endDate");
add(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.name")));
add(m_surveyName);
add(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.description")));
m_description.setRows(20);
m_description.setCols(60);
add(m_description);
add(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.start_date")));
add(m_startDate);
add(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.end_date")));
add(m_endDate);
add(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.should_quiz_responses_be_public")));
m_responsesPublic = new RadioGroup("responsesPublic");
Option o1 = new Option("true", new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.Yes")));
Option o2 = new Option("false", new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.No")));
m_responsesPublic.addOption(o1);
m_responsesPublic.addOption(o2);
add(m_responsesPublic);
// There can be 2 kinds of quizzes: the knowledge test kind of quiz and the personality assessment kind
add(new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.what_type_of_quiz_is_this")));
m_quizType = new RadioGroup("quizType");
Option o3 = new Option("knowledge_test", new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.knowledge_test_quiz")));
Option o4 = new Option("personal_assessment", new Label(GlobalizationUtil.globalize("simplesurvey.ui.admin.personal_assessment_quiz")));
m_quizType.addOption(o3);
m_quizType.addOption(o4);
add(m_quizType);
add(new Submit("submit"), BlockStylable.CENTER);
addInitListener(new SurveyInitListener());
addProcessListener(new PropertiesFormProcessListener());
add(new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.survey.ui.admin.should_quiz_responses_be_public").localize()));
RadioGroup responsesPublic = new RadioGroup("responsesPublic");
Option rp1 = new Option("true", new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.survey.ui.Yes").localize()));
Option rp2 = new Option("false", new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.survey.ui.No").localize()));
responsesPublic.addOption(rp1);
responsesPublic.addOption(rp2);
add(responsesPublic);
}
private class SurveyInitListener implements FormInitListener {
public void init(FormSectionEvent e)
throws FormProcessException {
PageState state = e.getPageState();
@Override
public void init(FormSectionEvent e) throws FormProcessException {
FormData data = e.getFormData();
Survey survey = (Survey) super.initBasicWidgets(e);
if (m_survey.isSelected(state)) {
Survey survey = m_survey.getSelectedSurvey(state);
PersistentForm form = survey.getForm();
m_surveyName.setValue(state, form.getAdminName());
m_description.setValue(state, form.getDescription());
m_startDate.setValue(state, survey.getStartDate());
m_endDate.setValue(state, survey.getEndDate());
m_quizType.setValue(state, survey.getQuizType());
if ( survey.responsesArePublic() ) {
m_responsesPublic.setValue(state, "true");
} else {
m_responsesPublic.setValue(state,"false");
}
} else {
m_surveyName.setValue(state, "");
m_description.setValue(state, "");
Calendar startCalendar = new GregorianCalendar();
startCalendar.add(Calendar.DATE, 0);
java.util.Date startDate = startCalendar.getTime();
Calendar endCalendar = new GregorianCalendar();
endCalendar.add(Calendar.DATE, 15);
java.util.Date endDate = endCalendar.getTime();
m_startDate.setValue(state, startDate);
m_endDate.setValue(state, endDate);
m_responsesPublic.setValue(state, "true");
m_quizType.setValue(state, "knowledge_test");
}
}
data.put(DESCRIPTION, survey.getDescription());
// data.put(START_DATE, survey.getStartDate());
// data.put(END_DATE, survey.getEndDate());
data.put(RESPONSES_PUBLIC, survey.getResponsesPublic());
}
private class PropertiesFormProcessListener implements FormProcessListener {
public void process(FormSectionEvent e)
throws FormProcessException {
PageState state = e.getPageState();
@Override
public void process(FormSectionEvent e) throws FormProcessException {
FormData data = e.getFormData();
Survey survey;
PersistentForm form;
Survey survey = (Survey) super.processBasicWidgets(e);
if (m_survey.isSelected(state)) {
survey = m_survey.getSelectedSurvey(state);
form = survey.getForm();
} else {
survey = m_type.equals(Survey.class) ? new Survey() : new Poll();
survey.setPackageInstance(SimpleSurveyUtil.getPackageInstance(state));
form = new PersistentForm();
survey.setForm(form);
}
if ((survey != null) && (getSaveCancelSection().getSaveButton().isSelected(e.getPageState()))) {
survey.setDescription((String) data.get(DESCRIPTION));
// survey.setStartDate((String)data.get(START_DATE));
// survey.setEndDate((String)data.get(END_DATE));
survey.setResponsesPublic((Boolean) data.get(RESPONSES_PUBLIC));
form.setAdminName((String)m_surveyName.getValue(state));
form.setHTMLName(getHTMLName((String)m_surveyName.getValue(state)));
form.setDescription((String)m_description.getValue(state));
form.save();
survey.setStartDate((java.util.Date)m_startDate.getValue(state));
survey.setEndDate((java.util.Date)m_endDate.getValue(state));
survey.setResponsesPublic(new Boolean((String) m_responsesPublic.getValue(state)));
survey.setQuizType((String) m_quizType.getValue(state));
survey.save();
}
private String getHTMLName(String surveyName) {
String htmlName = surveyName.trim().toLowerCase();
htmlName = htmlName.replace(' ', '_');
return htmlName;
}
if (m_step != null) {
m_step.maybeForwardToNextStep(e.getPageState());
}
}
public void submitted(FormSectionEvent e) throws FormProcessException {
if ((m_step != null) && (getSaveCancelSection().getCancelButton().isSelected(e.getPageState()))) {
m_step.cancelStreamlinedCreation(e.getPageState());
}
}
}

View File

@ -14,7 +14,6 @@ import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.SegmentedPanel;
import com.arsdigita.cms.contenttypes.Survey;
import com.arsdigita.cms.contenttypes.util.SurveyGlobalizationUtil;
import java.text.DateFormat;
@ -26,7 +25,6 @@ import org.apache.log4j.Logger;
public class SurveyPropertiesStep extends SimpleEditStep {
private static final Logger logger = Logger.getLogger(SurveyPropertiesStep.class);
/**
* Name of the this edit sheet (Don't know if this this really needed.
* It has the same value in almost all PropertiesStep classes)
@ -54,29 +52,18 @@ public class SurveyPropertiesStep extends SimpleEditStep {
SimpleEditStep basicProperties = new SimpleEditStep(itemModel, parent, EDIT_BASIC_SHEET_NAME);
/* Create the edit component for this SimpleEditStep and the corresponding link */
BasicPageForm editBasicSheet = new SurveyPropertyForm(itemModel, this);
BasicPageForm editBasicSheet = new SurveyPropertiesForm(itemModel, this);
basicProperties.add(EDIT_BASIC_SHEET_NAME, (String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.edit_basic_properties").localize(), new WorkflowLockedComponentAccess(editBasicSheet, itemModel), editBasicSheet.getSaveCancelSection().getCancelButton());
/* Set the displayComponent for this step */
basicProperties.setDisplayComponent(getSurveyPropertySheet(itemModel));
basicProperties.setDisplayComponent(getSurveyPropertiesSheet(itemModel));
/* Add the SimpleEditStep to the segmented panel */
segmentedPanel.addSegment(new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.basic_properties").localize()), basicProperties);
// If not disabled via registry, add the ui for attaching a person
if(!Survey.getConfig().getHidePerson()) {
SurveyPersonPropertiesStep personProperties = new SurveyPersonPropertiesStep(itemModel, parent);
segmentedPanel.addSegment(new Label((String)SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.person").localize()), personProperties);
}
// If not disabled via registry, add the ui for attaching a baseAddress
if(!Survey.getConfig().getHideAddress()) {
SurveyAddressPropertiesStep addressProperties = new SurveyAddressPropertiesStep(itemModel, parent);
segmentedPanel.addSegment(new Label((String)SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.address").localize()), addressProperties);
}
SurveyEntriesPropertiesStep surveyEntries = new SurveyEntriesPropertiesStep(itemModel, parent);
segmentedPanel.addSegment(new Label((String)SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.contactEntry").localize()), surveyEntries);
// Add the ui for attaching a FormSection
// SurveyPersonPropertiesStep personProperties = new SurveyPersonPropertiesStep(itemModel, parent);
// segmentedPanel.addSegment(new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.person").localize()), personProperties);
/* Sets the composed segmentedPanel as display component */
setDisplayComponent(segmentedPanel);
@ -84,12 +71,12 @@ public class SurveyPropertiesStep extends SimpleEditStep {
/**
* Creates and returns the sheet for editing the basic properties
* of an organization. (@see SurveyPropertyForm).
* of a survey. (@see SurveyPropertiesForm).
*
* @param itemModel
* @return The sheet for editing the properties of the organization.
*/
public static Component getSurveyPropertySheet(ItemSelectionModel itemModel) {
public static Component getSurveyPropertiesSheet(ItemSelectionModel itemModel) {
/* The DisplayComponent for the Basic Properties */
@ -105,8 +92,7 @@ public class SurveyPropertiesStep extends SimpleEditStep {
ContentPage page = (ContentPage) obj;
if (page.getLaunchDate() != null) {
return DateFormat.getDateInstance(DateFormat.LONG).format(page.getLaunchDate());
}
else {
} else {
return (String) GlobalizationUtil.globalize("cms.ui.unknown").localize();
}
}
@ -115,5 +101,4 @@ public class SurveyPropertiesStep extends SimpleEditStep {
return sheet;
}
}

View File

@ -16,14 +16,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.simplesurvey.ui;
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.simplesurvey.Survey;
import com.arsdigita.cms.contenttypes.Survey;
import com.arsdigita.toolbox.ui.ACSObjectSelectionModel;