* SurveyPersistenProcessListener angelegt
 * SurveyAnswerCollection fertiggestellt
 * SurveyResponseCollection fertiggestellt
 * SurveyProcessListener erweitert
 * ResponsesAnonym eingebaut

Diverse Anpassungen in survey.pdl

git-svn-id: https://svn.libreccm.org/ccm/trunk@358 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-02-25 10:23:16 +00:00
parent b7f5b05a1e
commit c03789093c
10 changed files with 204 additions and 225 deletions

View File

@ -8,6 +8,7 @@ object type Survey extends ContentPage {
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;
Boolean[0..1] responsesAnonym = ct_surveys.responses_anonym;
component FormSection[1..1] form = join ct_surveys.form_id
to bebop_form_sections.form_section_id;
component SurveyResponse[0..n] responses = join ct_surveys.survey_id
@ -32,10 +33,8 @@ object type SurveyResponse extends ContentItem {
object type SurveyAnswer extends ContentItem {
Component[1..1] label = join ct_surveys_answers.label_id
to bebop_components.component_id;
Component[1..1] widget = join ct_surveys_answers.widget_id
to bebop_components.component_id;
BigDecimal[1..1] questionNumber = ct_surveys_answers.question_number INTEGER;
String[1..1] key = ct_surveys_answers.key VARCHAR(4000);
String[0..1] value = ct_surveys_answers.value VARCHAR(4000);
reference key (ct_surveys_answers.answer_id);

View File

@ -1,6 +1,9 @@
package com.arsdigita.cms.contenttypes;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.contenttypes.ui.SurveyPersistentProcessListener;
import com.arsdigita.cms.contenttypes.ui.SurveyProcessListener;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.SessionManager;
@ -10,6 +13,7 @@ import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.formbuilder.PersistentHidden;
import com.arsdigita.kernel.User;
import java.util.Date;
@ -22,6 +26,8 @@ import java.util.Date;
*/
public class Survey extends ContentPage {
/** PDL property name for formSection */
public static final String SURVEY_ID = "survey_id";
/** PDL property name for formSection */
public static final String FORM = "form";
/** PDL property name for surveyResponses */
@ -32,6 +38,8 @@ public class Survey extends ContentPage {
public static final String END_DATE = "endDate";
/** PDL property name for responsesPublic */
public static final String RESPONSES_PUBLIC = "responsesPublic";
/** PDL property name for responsesAnonym */
public static final String RESPONSES_ANONYM = "responsesAnonym";
/** Data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.Survey";
@ -121,6 +129,12 @@ public class Survey extends ContentPage {
setResponsesPublic(false);
}
*/
/*
// Preset the responsesAnonym
if (getResponsesAnonym() == null) {
setResponsesAnonym(false);
}
*/
}
super.beforeSave();
@ -128,6 +142,10 @@ public class Survey extends ContentPage {
/* accessors *****************************************************/
public void setForm(PersistentForm persistentForm) {
// persistentForm.addProcessListener(new SurveyPersistentProcessListener());
// PersistentHidden survey_id = PersistentHidden.create(SURVEY_ID);
// survey_id.setDefaultValue(getSurveyID());
// persistentForm.addComponent(survey_id);
set(FORM, persistentForm);
}
@ -135,6 +153,10 @@ public class Survey extends ContentPage {
return new PersistentForm((DataObject) get(FORM));
}
public BigDecimal getSurveyID() {
return (BigDecimal) get(SURVEY_ID);
}
public void setStartDate(Date startDate) {
set(START_DATE, startDate);
}
@ -159,8 +181,16 @@ public class Survey extends ContentPage {
set(RESPONSES_PUBLIC, responsesPublic);
}
public SurveyResponse addResponse() {
SurveyResponse surveyResponse = new SurveyResponse();
public Boolean getResponsesAnonym() {
return (Boolean) get(RESPONSES_ANONYM);
}
public void setResponsesAnonym(Boolean responsesAnonym) {
set(RESPONSES_ANONYM, responsesAnonym);
}
public SurveyResponse addResponse(User user) {
SurveyResponse surveyResponse = new SurveyResponse(user);
addResponse(surveyResponse);
return surveyResponse;
}
@ -177,6 +207,7 @@ public class Survey extends ContentPage {
return new SurveyResponseCollection ((DataCollection) get(RESPONSES), user);
}
/* methods ****************************************************************/
public boolean hasResponses() {
return !this.getResponses().isEmpty();
}
@ -185,23 +216,11 @@ public class Survey extends ContentPage {
return !this.getResponses(user).isEmpty();
}
/*
public DataQuery getLabelDataQuery() {
String queryName = "com.arsdigita.simplesurvey.GetFormLabels";
DataQuery dataQuery =
SessionManager.getSession().retrieveQuery(queryName);
dataQuery.setParameter("surveyID", getID());
return dataQuery;
}
public boolean isLive() {
public boolean isActive() {
Date currentDate = new Date();
return getStartDate().compareTo(currentDate) < 0 &&
getEndDate().compareTo(currentDate) > 0;
return currentDate.compareTo(getStartDate()) > 0 && currentDate.compareTo(getEndDate()) > 0;
}
*/
/*
* Retrieves most recent survey that isn't completed
*/

View File

@ -21,21 +21,24 @@ import java.math.BigDecimal;
public class SurveyAnswer extends ContentItem {
/** PDL property name for label */
public static final String LABEL = "label";
public static final String QUESTION_NUMBER = "questionNumber";
/** PDL property name for widget */
public static final String WIDGET = "widget";
public static final String KEY = "key";
/** PDL property name for value */
public static final String VALUE = "value";
/** PDL property name for response */
public static final String RESPONSE = "response";
/** Data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.SurveyAnswer";
/**
* Default constructor. This creates a new (empty) Survey.
**/
public SurveyAnswer() {
public SurveyAnswer(int order, String key, String value) {
this(BASE_DATA_OBJECT_TYPE);
// Set the data
setOrder(order);
setKey(key);
setValue(value);
}
/**
@ -86,26 +89,28 @@ public class SurveyAnswer extends ContentItem {
}
/* accessors *****************************************************/
/* Class methods ********/
public static SurveyAnswer create(PersistentLabel label,
PersistentWidget widget,
String value) {
SurveyAnswer answer = new SurveyAnswer();
answer.setup(label, widget, value);
return answer;
private void setOrder(int order) {
set(QUESTION_NUMBER, order);
}
protected void setup(PersistentLabel label,
PersistentWidget widget,
String value) {
try {
set(ID, Sequences.getNextValue("ss_answers_seq"));
} catch (java.sql.SQLException e) {
throw new com.arsdigita.util.UncheckedWrapperException(e);
public int getOrder() {
return ((Integer) get(QUESTION_NUMBER)).intValue();
}
set(LABEL, label);
set(WIDGET, widget);
private void setKey(String key) {
set(KEY, key);
}
public String getKey() {
return (String) get(KEY);
}
private void setValue(String value) {
set(VALUE, value);
}
public String getValue() {
return (String) get(VALUE);
}
}

View File

@ -16,17 +16,17 @@ public class SurveyAnswerCollection extends DomainCollection {
public SurveyAnswerCollection(DataCollection dataCollection) {
super(dataCollection);
// m_dataCollection.addOrder(ORDER);
m_dataCollection.addOrder(SurveyAnswer.QUESTION_NUMBER);
}
// Get the label
public String getLabel() {
return (String) m_dataCollection.get(SurveyAnswer.LABEL);
// Get the order
public int getOrder() {
return ((Integer) m_dataCollection.get(SurveyAnswer.QUESTION_NUMBER)).intValue();
}
// Get the widget
public String getWidget() {
return (String) m_dataCollection.get(SurveyAnswer.WIDGET);
// Get the key
public String getKey() {
return (String) m_dataCollection.get(SurveyAnswer.KEY);
}
// Get the value

View File

@ -2,8 +2,6 @@ package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.formbuilder.PersistentLabel;
import com.arsdigita.formbuilder.PersistentWidget;
import com.arsdigita.kernel.User;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject;
@ -39,17 +37,14 @@ public class SurveyResponse extends ContentItem {
*
* @param survey The <code>survey</code> for this SurveyResponse.
**/
public SurveyResponse() {
public SurveyResponse(User user) {
this(BASE_DATA_OBJECT_TYPE);
// Save the date
setEntryDate();
// Save the corresponding survey
// setSurvey(survey);
// XXX hack - see pdl file
// set(USER + "ID", user.getID());
// Save the user, if any
setUser(user);
}
/**
@ -107,63 +102,33 @@ public class SurveyResponse extends ContentItem {
return (Date) get(ENTRY_DATE);
}
private void setSurvey(Survey survey) {
// set(SURVEY, survey);
set(SURVEY + "ID", survey.getID());
private void setUser(User user) {
set(USER, user);
}
public User getUser() {
return (User) get(USER);
}
// private void setSurvey(Survey survey) {
// set(SURVEY, survey);
// set(SURVEY + "ID", survey.getID());
// }
public Survey getSurvey() {
return (Survey) get(SURVEY);
}
public void addAnswer(PersistentLabel label, PersistentWidget widget, String value) {
SurveyAnswer answer = SurveyAnswer.create(label, widget, value);
public void addAnswer(int order, String key, String value) {
SurveyAnswer answer = new SurveyAnswer(order, key, value);
add(ANSWERS, answer);
}
public SurveyAnswerCollection getAnswers() {
return new SurveyAnswerCollection ((DataCollection) get(ANSWERS));
return new SurveyAnswerCollection((DataCollection) get(ANSWERS));
}
/* Methods **************************************************/
public boolean hasAnswers() {
return !this.getAnswers().isEmpty();
}
/* Class methods **********************************************************/
/*
public static SurveyResponseCollection retrieveBySurvey(Survey survey) {
DataCollection responses =
SessionManager.getSession().retrieve(BASE_DATA_OBJECT_TYPE);
responses.addEqualsFilter(SURVEY + "ID",
survey.getID());
return new SurveyResponseCollection(responses);
}
public static SurveyResponseCollection retrieveBySurvey(Survey survey, User user) {
SurveyResponseCollection responses = retrieveBySurvey(survey);
responses.addEqualsFilter(USER + "ID",
user.getID());
return responses;
}
*/
public boolean questionsAnswered() {
// Returns true of questions have been answered on this response
BigDecimal responseID = this.getID();
// DataQuery dq = SessionManager.getSession().retrieveQuery("com.arsdigita.simplesurvey.questionsAnswered");
// dq.setParameter("responseID", responseID);
// dq.next();
// Boolean questionsAnswered = (Boolean) dq.get(QUESTIONS_ANSWERED);
// dq.close();
// return questionsAnswered.booleanValue();
// HACK: Brauche ich diese Funktion?
return true;
}
}

View File

@ -24,7 +24,7 @@ public class SurveyResponseCollection extends DomainCollection {
public SurveyResponseCollection(DataCollection dataCollection, User user) {
this(dataCollection);
// m_dataCollection.addFilter(SurveyResponse.USER);
m_dataCollection.addEqualsFilter(SurveyResponse.USER, user);
}
// Get the entry date

View File

@ -0,0 +1,67 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.metadata.ObjectType;
import com.arsdigita.formbuilder.PersistentProcessListener;
import java.math.BigDecimal;
public class SurveyPersistentProcessListener extends PersistentProcessListener {
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.ui.SurveyPersistentProcessListener";
public SurveyPersistentProcessListener() {
this(BASE_DATA_OBJECT_TYPE);
}
public SurveyPersistentProcessListener(String typeName) {
super(typeName);
}
public SurveyPersistentProcessListener(ObjectType type) {
super(type);
}
public SurveyPersistentProcessListener(DataObject obj) {
super(obj);
}
public SurveyPersistentProcessListener(BigDecimal id) {
this(new OID(BASE_DATA_OBJECT_TYPE, id));
}
public SurveyPersistentProcessListener(OID oid) {
super(oid);
}
public static SurveyPersistentProcessListener create(String name, String description) {
SurveyPersistentProcessListener l = new SurveyPersistentProcessListener();
l.setup(name, description);
return l;
}
@Override
protected void setup(String name, String description) {
super.setup(name, description);
}
// XXX hack to get around some wierd issues
// with mdsql associations where the object
// type in question is a subtype of the
// one named in the association definition
@Override
public boolean isContainerModified() {
return false;
}
@Override
public FormProcessListener createProcessListener() {
return new SurveyProcessListener();
}
}

View File

@ -3,30 +3,16 @@ package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.formbuilder.PersistentComponent;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.formbuilder.PersistentLabel;
import com.arsdigita.formbuilder.PersistentWidget;
import com.arsdigita.kernel.KernelHelper;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.OID;
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.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;
import java.util.Iterator;
import com.arsdigita.formbuilder.util.FormBuilderUtil;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.kernel.User;
@ -42,12 +28,9 @@ import org.apache.log4j.Logger;
*/
public class SurveyProcessListener implements FormProcessListener {
public static final String SURVEY_ID = "SurveyID";
public static final String SURVEY_ID = Survey.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());
@ -62,8 +45,10 @@ public class SurveyProcessListener implements FormProcessListener {
public void process(FormSectionEvent event) {
int numQuestions = 0;
Survey survey = null;
SurveyResponse surveyResponse = null;
User user = null;
// Get the form data
FormData formData = event.getFormData();
@ -79,18 +64,22 @@ public class SurveyProcessListener implements FormProcessListener {
} catch (DataObjectNotFoundException ex) {
// Strange, there is no survey with this id. Someone is messing aroound
// Strange, there is no survey with this id. Someone is messing around
s_log.warn("Can't find survey object with ID " + surveyID + ". Someone is messing around.");
// Abort processing
return;
}
// Get the user
User user = (User) Kernel.getContext().getParty();
// If this survey isn't anonymous
if(!survey.getResponsesAnonym()) {
// Get the current user
user = (User) Kernel.getContext().getParty();
}
// Create the new SurveyResponse object
surveyResponse = survey.addResponse();
surveyResponse = survey.addResponse(user);
@ -99,110 +88,22 @@ public class SurveyProcessListener implements FormProcessListener {
while (parameterIterator.hasNext()) {
ParameterData parameterData = (ParameterData) parameterIterator.next();
addAnswer(surveyResponse, parameterData.getName(), parameterData.getValue());
addAnswer(surveyResponse, ++numQuestions, parameterData.getName(), parameterData.getValue());
}
}
private void addAnswer(SurveyResponse surveyResponse, Object name, Object value) {
private void addAnswer(SurveyResponse surveyResponse, int questionNumber, Object name, Object value) {
// Test if value is a string array
if(value instanceof String[]) {
// This is a multi-answer question, so iterate over the answers
for (int i = 0; i < ((String[]) value).length; i++) {
addAnswer(surveyResponse, name, ((String[]) value)[i]);
addAnswer(surveyResponse, questionNumber, name, ((String[]) value)[i]);
}
} else {
// Create new SurveyAnswer object
// surveyResponse.addAnswer(,, (String) value);
surveyResponse.addAnswer(questionNumber, (String) name, (String) value);
}
}
/*
PageState ps = event.getPageState();
BigDecimal responseID = (BigDecimal) formData.get(RESPONSE_ID);
m_response.set(ps, responseID);
m_persistentForm.set(ps, survey.getForm());
*/
/*
private void addAnswer(SurveyResponse surveyResponse,
PageState ps,
Object parameterValue,
String parameterName) {
s_log.debug("formData name " + parameterName + " value " + parameterValue);
Question question = getQuestion(ps, parameterName);
if (question != null) {
PersistentLabel persistentLabel = question.getLabel();
PersistentWidget persistentWidget = question.getWidget();
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) {
// Populate the parameter name label id map
synchronized (this) {
Map nameQuestionMap = new HashMap();
s_log.debug("initializing the parameter name persistent label map");
PersistentForm persistentForm = (PersistentForm) m_persistentForm.get(ps);
DataAssociationCursor componentCursor = persistentForm.getComponents();
PersistentLabel lastPersistentLabel = null;
while (componentCursor.next()) {
PersistentComponent factory = (PersistentComponent) DomainObjectFactory.newInstance(componentCursor.getDataObject());
s_log.debug("iterating, component " + factory.toString());
// If this is a PersistentLabel save its id
if (factory instanceof com.arsdigita.formbuilder.PersistentLabel) {
lastPersistentLabel = (PersistentLabel) factory;
}
// Add the previous label id if this is a PersistentWidget
if (factory instanceof com.arsdigita.formbuilder.PersistentWidget) {
s_log.debug("adding to map " + ((PersistentWidget) factory).getParameterName() +
" mapped to " + lastPersistentLabel);
Question question = new Question(lastPersistentLabel,
(PersistentWidget) factory);
nameQuestionMap.put(((PersistentWidget) factory).getParameterName(), question);
}
}
m_nameQuestionMap.set(ps, nameQuestionMap);
}
}
s_log.debug("fetching label for parameter name " + parameterName);
Question question = (Question) ((Map) m_nameQuestionMap.get(ps)).get(parameterName);
s_log.debug("returning " + question);
return question;
}
*/
}

View File

@ -35,8 +35,6 @@ import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.parameters.BooleanParameter;
import com.arsdigita.bebop.parameters.DateParameter;
import com.arsdigita.bebop.parameters.DateParameter;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
@ -53,6 +51,7 @@ public class SurveyPropertiesForm extends BasicPageForm implements FormProcessLi
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;
public static final String RESPONSES_ANONYM = Survey.RESPONSES_ANONYM;
/**
* ID of the form
*/
@ -109,6 +108,16 @@ public class SurveyPropertiesForm extends BasicPageForm implements FormProcessLi
responsesPublic.addOption(rp2);
add(responsesPublic);
add(new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.should_quiz_responses_be_anonym").localize()));
ParameterModel responsesAnonymParam = new BooleanParameter(RESPONSES_ANONYM);
responsesAnonymParam.addParameterListener(new NotNullValidationListener());
RadioGroup responsesAnonym = new RadioGroup("responsesAnonym");
Option ra1 = new Option("true", new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.Yes").localize()));
Option ra2 = new Option("false", new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.No").localize()));
responsesAnonym.addOption(ra1);
responsesAnonym.addOption(ra2);
add(responsesAnonym);
}
@Override
@ -135,6 +144,7 @@ public class SurveyPropertiesForm extends BasicPageForm implements FormProcessLi
survey.setStartDate((java.util.Date) data.get(START_DATE));
survey.setEndDate((java.util.Date) data.get(END_DATE));
survey.setResponsesPublic(new Boolean((String) data.get(RESPONSES_PUBLIC)));
survey.setResponsesAnonym(new Boolean((String) data.get(RESPONSES_ANONYM)));
survey.save();
}

View File

@ -62,10 +62,6 @@ public class SurveyPropertiesStep extends SimpleEditStep {
/* Add the SimpleEditStep to the segmented panel */
segmentedPanel.addSegment(new Label((String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.basic_properties").localize()), basicProperties);
// 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);
}
@ -107,6 +103,23 @@ public class SurveyPropertiesStep extends SimpleEditStep {
}
});
/* Display the Status of ResponsesPublic in localized form */
sheet.add(SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.should_quiz_responses_be_anonym"), Survey.RESPONSES_ANONYM, new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject obj, String attribute, PageState state) {
Survey survey = (Survey) obj;
if (survey.getResponsesAnonym() != null) {
if (survey.getResponsesAnonym().booleanValue() == true) {
return (String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.Yes").localize();
} else {
return (String) SurveyGlobalizationUtil.globalize("cms.contenttypes.ui.survey.No").localize();
}
} else {
return (String) GlobalizationUtil.globalize("cms.ui.unknown").localize();
}
}
});
if (!ContentSection.getConfig().getHideLaunchDate()) {
sheet.add(GlobalizationUtil.globalize("cms.ui.authoring.page_launch_date"), ContentPage.LAUNCH_DATE, new DomainObjectPropertySheet.AttributeFormatter() {