Author: [email protected]
Date: Tue Aug 16 11:41:11 2011
New Revision: 1323
Log:
Added:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/SubmittedSurvey.java
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/SubmittedSurveyAnswer.java
sandbox/ivol/ntlm/src/main/resources/jsp/survey.jsp
- copied, changed from r1322,
/sandbox/ivol/ntlm/src/main/resources/jsp/enquete.jsp
sandbox/ivol/ntlm/src/main/resources/jsp/surveyresults.jsp
Removed:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/AnswerResult.java
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/SurveyResult.java
sandbox/ivol/ntlm/src/main/resources/jsp/enquete.jsp
Modified:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyStorageProvider.java
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Answer.java
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Question.java
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/osgi/Activator.java
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/NTLMFilterRegistrationServiceImpl.java
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyRESTServiceImpl.java
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyStoreImpl.java
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/WebResourceProvider.java
sandbox/ivol/ntlm/src/main/resources/static/css/cr.css
Modified:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyStorageProvider.java
==============================================================================
---
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyStorageProvider.java
(original)
+++
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/SurveyStorageProvider.java
Tue Aug 16 11:41:11 2011
@@ -18,9 +18,8 @@
import java.util.List;
import org.amdatu.auth.ntlm.domain.Answer;
+import org.amdatu.auth.ntlm.domain.SubmittedSurvey;
import org.amdatu.auth.ntlm.domain.Survey;
-import org.amdatu.auth.ntlm.domain.SurveyResult;
-import org.json.JSONException;
/**
* This interface represents a storage provider for survey questions and
answers.
@@ -35,9 +34,26 @@
*/
Survey getSurvey(String surveyId);
- void addAnswers(String surveyId, List<Answer> answers, String username);
+ /**
+ * Returns if the specified user already submitted this survey or not.
+ * @param surveyId the id of the survey
+ * @param username The name of the user
+ * @return if the specified user already submitted this survey or not.
+ */
+ boolean hasSubmitted(String surveyId, String username);
- SurveyResult loadAnswers(String surveyId) throws JSONException;
+ /**
+ * Submits survey answers for the specified survey and user.
+ * @param surveyId The id of the survey to submit the answers for
+ * @param answers List of answers
+ * @param username the user that submitted the survey
+ */
+ void submitAnswers(String surveyId, List<Answer> answers, String username);
- boolean hasSubmitted(String surveyId, String username);
+ /**
+ * Loads the answers of a submitted survey.
+ * @param surveyId id of the survey to load.
+ * @return the submitted survey answers
+ */
+ SubmittedSurvey loadAnswers(String surveyId);
}
Modified:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Answer.java
==============================================================================
--- sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Answer.java
(original)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Answer.java
Tue Aug 16 11:41:11 2011
@@ -20,33 +20,39 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
+/**
+ * Represents a single answer to some question in a submitted survey.
+ *
+ * @author ivol
+ */
@SuppressWarnings("restriction")
@XmlRootElement(name = "answer")
@XmlAccessorType(XmlAccessType.NONE)
public class Answer {
@XmlAttribute(name = "questionId")
private String m_questionId;
-
+
@XmlAttribute(name = "answer")
private String[] m_answer;
-
+
public Answer(String questionId, String[] answer) {
m_questionId = questionId;
m_answer = answer;
}
-
+
public String getQuestionId() {
return m_questionId;
}
+
public void setQuestionId(String questionId) {
m_questionId = questionId;
}
+
public String[] getAnswer() {
return m_answer;
}
+
public void setAnswer(String[] answer) {
m_answer = answer;
}
-
-
}
Modified:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Question.java
==============================================================================
--- sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Question.java
(original)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/Question.java
Tue Aug 16 11:41:11 2011
@@ -24,69 +24,73 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
-import me.prettyprint.hector.api.beans.HColumn;
-
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Represents a single question in a survey.
+ *
* @author ivol
- *
*/
@SuppressWarnings("restriction")
@XmlRootElement(name = "question")
@XmlAccessorType(XmlAccessType.NONE)
-public class Question {
+public class Question implements Comparable<Question> {
@XmlAttribute(name = "id")
private String m_id;
-
+
@XmlAttribute(name = "description")
private String m_description;
-
+
@XmlAttribute(name = "type")
private String m_type;
-
+
@XmlElement(name = "value")
private List<String> m_values;
-
+
public Question() {
}
public String getId() {
return m_id;
}
+
public void setId(String id) {
m_id = id;
}
-
+
public String getDescription() {
return m_description;
}
+
public void setDescription(String description) {
m_description = description;
}
+
public String getType() {
return m_type;
}
+
public void setType(String type) {
m_type = type;
}
+
public List<String> getValues() {
return m_values;
}
+
public void setValues(List<String> values) {
m_values = values;
}
-
+
public void addValue(String value) {
if (m_values == null) {
m_values = new ArrayList<String>();
}
m_values.add(value);
}
-
+
public String toJSON() throws JSONException {
JSONObject question = new JSONObject();
question.put("description", getDescription());
@@ -94,7 +98,7 @@
question.put("values", getValues());
return new JSONObject().put("question", question).toString();
}
-
+
public static Question fromJSON(String json) throws JSONException {
JSONObject jsonObject = new JSONObject(json).getJSONObject("question");
Question question = new Question();
@@ -102,18 +106,15 @@
question.setType(jsonObject.getString("type"));
JSONArray values = jsonObject.getJSONArray("values");
List<String> sValues = new ArrayList<String>();
- for (int i=0; i<values.length(); i++) {
+ for (int i = 0; i < values.length(); i++) {
sValues.add(values.getString(i));
}
question.setValues(sValues);
return question;
}
-
- public static Question load(HColumn<String, String> question) throws
JSONException {
- String id = question.getName();
- String value = question.getValue();
- Question q = fromJSON(value);
- q.setId(id);
- return q;
+
+ public int compareTo(Question question) {
+ String questionid = ((Question) question).getId();
+ return questionid.compareTo(m_id);
}
}
Added:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/SubmittedSurvey.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/SubmittedSurvey.java
Tue Aug 16 11:41:11 2011
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.amdatu.auth.ntlm.domain;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Represents a submitted survey. Holds a list of answers that were submitted
+ * for a specific survey.
+ *
+ * @author ivol
+ */
+@SuppressWarnings("restriction")
+@XmlRootElement(name = "surveyresults")
+@XmlAccessorType(XmlAccessType.NONE)
+public class SubmittedSurvey {
+ @XmlAttribute(name = "id")
+ private String m_id;
+
+ @XmlElement(name = "questions")
+ private List<SubmittedSurveyAnswer> m_answers;
+
+ public String getId() {
+ return m_id;
+ }
+
+ public void setId(String id) {
+ m_id = id;
+ }
+
+ public List<SubmittedSurveyAnswer> getAnswers() {
+ return m_answers;
+ }
+
+ public void setAnswers(List<SubmittedSurveyAnswer> answers) {
+ m_answers = answers;
+ }
+
+ public void addAnswer(SubmittedSurveyAnswer answerResult) {
+ if (m_answers == null) {
+ m_answers = new ArrayList<SubmittedSurveyAnswer>();
+ }
+ m_answers.add(answerResult);
+ }
+}
Added:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/SubmittedSurveyAnswer.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/domain/SubmittedSurveyAnswer.java
Tue Aug 16 11:41:11 2011
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.amdatu.auth.ntlm.domain;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Represents a single answer in a submitted survey.
+ *
+ * @author ivol
+ */
+@SuppressWarnings("restriction")
+@XmlRootElement(name = "answerResult")
+public class SubmittedSurveyAnswer {
+ private String m_id;
+
+ private String m_description;
+
+ private List<String> m_answers;
+
+ public SubmittedSurveyAnswer() {
+ }
+
+ public String getId() {
+ return m_id;
+ }
+
+ public void setId(String id) {
+ m_id = id;
+ }
+
+ public String getDescription() {
+ return m_description;
+ }
+
+ public void setDescription(String description) {
+ m_description = description;
+ }
+
+ @XmlElementWrapper(name = "answers")
+ @XmlElements(@XmlElement(name = "answer"))
+ public List<String> getAnswers() {
+ return m_answers;
+ }
+
+ public void setAnswers(List<String> answers) {
+ m_answers = answers;
+ }
+}
Modified:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/osgi/Activator.java
==============================================================================
--- sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/osgi/Activator.java
(original)
+++ sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/osgi/Activator.java
Tue Aug 16 11:41:11 2011
@@ -43,17 +43,17 @@
*/
public class Activator extends DependencyActivatorBase {
/**
- * URL alias hosting the resources of this Twitter example.
+ * URL alias hosting the resources of this bundle.
*/
public static final String ALIAS = "/ntlm";
/**
- * URL alias hosting the JSPs of this Twitter example.
+ * URL alias hosting the JSPs of this bundle.
*/
public static final String JSP_ALIAS = ALIAS + "/jsp";
/**
- * URL alias hosting the statics of this Twitter example.
+ * URL alias hosting the statics of this bundle.
*/
public static final String RES_ALIAS = ALIAS + "/static";
Modified:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/NTLMFilterRegistrationServiceImpl.java
==============================================================================
---
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/NTLMFilterRegistrationServiceImpl.java
(original)
+++
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/NTLMFilterRegistrationServiceImpl.java
Tue Aug 16 11:41:11 2011
@@ -80,7 +80,7 @@
@SuppressWarnings("unchecked")
private void setExtraFilterProperties() {
m_filterProperties.put(Constants.SERVICE_RANKING, 0);
- m_filterProperties.put(DispatcherService.PATTERN_KEY, Activator.ALIAS
+ "/.*");
+ m_filterProperties.put(DispatcherService.PATTERN_KEY, "((" +
Activator.ALIAS + ")|(/rest/survey))/.*");
m_filterProperties.put(DispatcherService.CONTEXT_ID_KEY,
Activator.CONTEXTID);
}
Modified:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyRESTServiceImpl.java
==============================================================================
---
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyRESTServiceImpl.java
(original)
+++
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyRESTServiceImpl.java
Tue Aug 16 11:41:11 2011
@@ -37,26 +37,52 @@
import org.amdatu.auth.ntlm.SurveyStorageProvider;
import org.amdatu.auth.ntlm.domain.Answer;
+import org.amdatu.auth.ntlm.domain.SubmittedSurvey;
import org.amdatu.auth.ntlm.domain.Survey;
-import org.amdatu.auth.ntlm.domain.SurveyResult;
import org.amdatu.web.rest.jaxrs.RESTService;
+/**
+ * Implementation of a survey REST service.
+ *
+ * @author ivol
+ */
@Path("survey")
public class SurveyRESTServiceImpl implements RESTService {
- // HTTP caching policy for this REST interface
+ // Hard codes list of Windows users authorized to view the survey results
+ private static final String[] AUTHORIZED_USERS = new String[]{"ivol",
"suzannen", "jasper", "martijnvdm", "ericvdv"};
+
+ // HTTP caching policy for this REST interface
private static CacheControl NO_CACHE_CONTROL;
static {
NO_CACHE_CONTROL = new CacheControl();
NO_CACHE_CONTROL.setNoCache(true);
}
private volatile SurveyStorageProvider m_surveyStore;
+
+ private boolean isAuthorized(@Context final HttpServletRequest request) {
+ NtlmPasswordAuthentication session =
+ (NtlmPasswordAuthentication) request.getSession().getAttribute(
+ NTLMFilterRegistrationServiceImpl.NTLM_SESION_KEY);
+ if (session != null) {
+ String userName = session.getUsername();
+ if (userName != null) {
+ for (String user : AUTHORIZED_USERS) {
+ if (userName.equals(user)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
@GET
@Path("submitted/{id}")
@Produces({MediaType.TEXT_PLAIN})
public Response hasSubmitted(@Context final HttpServletRequest request,
@PathParam("id") final String surveyId) {
NtlmPasswordAuthentication session =
- (NtlmPasswordAuthentication)
request.getSession().getAttribute(NTLMFilterRegistrationServiceImpl.NTLM_SESION_KEY);
+ (NtlmPasswordAuthentication) request.getSession().getAttribute(
+ NTLMFilterRegistrationServiceImpl.NTLM_SESION_KEY);
if (session != null) {
String userName = session.getUsername();
if (userName != null) {
@@ -78,7 +104,8 @@
@Produces({MediaType.TEXT_PLAIN})
public Response status(@Context final HttpServletRequest request) {
NtlmPasswordAuthentication session =
- (NtlmPasswordAuthentication)
request.getSession().getAttribute(NTLMFilterRegistrationServiceImpl.NTLM_SESION_KEY);
+ (NtlmPasswordAuthentication) request.getSession().getAttribute(
+ NTLMFilterRegistrationServiceImpl.NTLM_SESION_KEY);
if (session != null) {
String username = session.getUsername();
if (username != null) {
@@ -88,6 +115,7 @@
return
Response.status(Status.UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
}
+ @SuppressWarnings("rawtypes")
@POST
@Consumes("application/x-www-form-urlencoded")
public void addSurvey(@Context final HttpServletRequest request) {
@@ -108,7 +136,7 @@
}
}
- m_surveyStore.addAnswers(surveyId, answers, userName);
+ m_surveyStore.submitAnswers(surveyId, answers, userName);
}
catch (Exception e) {
throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
@@ -121,8 +149,12 @@
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getSurveyAnswers(@Context final HttpServletRequest
request, @PathParam("id") final String surveyId) {
try {
- SurveyResult survey = m_surveyStore.loadAnswers(surveyId);
- return Response.ok(survey).cacheControl(NO_CACHE_CONTROL).build();
+ if (isAuthorized(request)) {
+ SubmittedSurvey survey = m_surveyStore.loadAnswers(surveyId);
+ return
Response.ok(survey).cacheControl(NO_CACHE_CONTROL).build();
+ } else {
+ return
Response.status(Status.UNAUTHORIZED).cacheControl(NO_CACHE_CONTROL).build();
+ }
}
catch (Exception e) {
throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
@@ -141,5 +173,4 @@
throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
}
}
-
}
Modified:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyStoreImpl.java
==============================================================================
---
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyStoreImpl.java
(original)
+++
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/SurveyStoreImpl.java
Tue Aug 16 11:41:11 2011
@@ -16,19 +16,18 @@
package org.amdatu.auth.ntlm.service;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
+import java.util.TreeMap;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.beans.HSuperColumn;
import org.amdatu.auth.ntlm.SurveyStorageProvider;
import org.amdatu.auth.ntlm.domain.Answer;
-import org.amdatu.auth.ntlm.domain.AnswerResult;
import org.amdatu.auth.ntlm.domain.Question;
+import org.amdatu.auth.ntlm.domain.SubmittedSurvey;
+import org.amdatu.auth.ntlm.domain.SubmittedSurveyAnswer;
import org.amdatu.auth.ntlm.domain.Survey;
-import org.amdatu.auth.ntlm.domain.SurveyResult;
import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager;
import org.json.JSONException;
import org.osgi.service.log.LogService;
@@ -46,14 +45,8 @@
private volatile LogService m_logService;
public void start() throws JSONException {
- // Add a test survey
+ // TODO: For now a survey can only be added using the Java API. A REST
interface + UI should be added.
addTestSurvey();
-
- // Retrieve the survey
- Survey survey = getSurvey("1");
-
- List<Question> questions = survey.getQuestions();
- questions.get(0);
}
public Survey getSurvey(String surveyId) {
@@ -79,10 +72,18 @@
List<HColumn<String, String>> questions = questionSC.getColumns();
List<Question> questionList = new ArrayList<Question>();
for (HColumn<String, String> question : questions) {
- questionList.add(Question.load(question));
+ questionList.add(load(question));
}
survey.setQuestions(questionList);
}
+
+ private Question load(HColumn<String, String> question) throws
JSONException {
+ String id = question.getName();
+ String value = question.getValue();
+ Question q = Question.fromJSON(value);
+ q.setId(id);
+ return q;
+ }
public boolean hasSubmitted(String surveyId, String username) {
String submitted =
@@ -90,7 +91,7 @@
return "true".equals(submitted);
}
- public void addAnswers(String surveyId, List<Answer> answers, String
username) {
+ public void submitAnswers(String surveyId, List<Answer> answers, String
username) {
if (hasSubmitted(surveyId, username)) {
// The user already submitted this survey!
return;
@@ -116,13 +117,13 @@
m_pm.setValue(SurveyColumnFamilyProvider.CF_SURVEY_USERS, surveyId,
null, username, "true");
}
- public SurveyResult loadAnswers(String surveyId) throws JSONException {
+ public SubmittedSurvey loadAnswers(String surveyId) {
List<HSuperColumn<String, String, String[]>> superColumns =
m_pm.getSuperColumns(SurveyColumnFamilyProvider.CF_SURVEY_ANSWERS,
surveyId, String[].class);
Survey survey = getSurvey(surveyId);
// Each SuperColumn represents a submitted survey including answers
- Map<Question, List<String[]>> results = new HashMap<Question,
List<String[]>>();
+ TreeMap<Question, List<String[]>> results = new TreeMap<Question,
List<String[]>>();
for (HSuperColumn<String, String, String[]> superColumn :
superColumns) {
List<HColumn<String, String[]>> columns = superColumn.getColumns();
for (HColumn<String, String[]> column : columns) {
@@ -141,15 +142,15 @@
}
}
- SurveyResult surveyResult = new SurveyResult();
+ SubmittedSurvey surveyResult = new SubmittedSurvey();
surveyResult.setId(surveyId);
for (Question question : results.keySet()) {
- AnswerResult result = new AnswerResult();
+ SubmittedSurveyAnswer result = new SubmittedSurveyAnswer();
result.setId(question.getId());
result.setDescription(question.getDescription());
if (question.getType().equals("check") ||
question.getType().equals("radio")) {
// Generate statistics
- result.setAnswers(getStats(question.getValues(),
results.get(question)));
+ result.setAnswers(getStats(question, results.get(question)));
}
else {
result.setAnswers(toSingleList(results.get(question)));
@@ -167,7 +168,8 @@
return values;
}
- private List<String> getStats(List<String> values, List<String[]> answers)
{
+ private List<String> getStats(Question question, List<String[]> answers) {
+ List<String> values = question.getValues();
List<String> stats = new ArrayList<String>();
for (String value : values) {
int count = 0;
@@ -178,11 +180,23 @@
}
}
}
- stats.add(value + " - " + count);
+ String statValue = value + " - " + count;
+ if (question.getType().equals("radio") ||
question.getType().equals("check")) {
+ // For radio answers the percentage is the amount of times the
radiobox
+ // was checked compared to the total amount of answers
+ statValue += " (" + toPercentage(count, answers.size()) + ")";
+ }
+ stats.add(statValue);
}
return stats;
}
+
+ private String toPercentage(int a, int b) {
+ long value = Math.round(100*new Double(a)/new Double(b));
+ return value + "%";
+ }
+ // TODO: This is an example survey
private void addTestSurvey() throws JSONException {
Question q1 = new Question();
q1.setDescription("Wil je salarisverhoging?");
Modified:
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/WebResourceProvider.java
==============================================================================
---
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/WebResourceProvider.java
(original)
+++
sandbox/ivol/ntlm/src/main/java/org/amdatu/auth/ntlm/service/WebResourceProvider.java
Tue Aug 16 11:41:11 2011
@@ -22,32 +22,31 @@
import org.amdatu.auth.ntlm.osgi.Activator;
import org.amdatu.web.httpcontext.ResourceProvider;
import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
/**
* This class provides the web resources.
*/
public class WebResourceProvider implements ResourceProvider {
+ private static final String LOCAL_DEV_DIR =
"D:\\Amdatu-svn\\sandbox\\ivol\\ntlm\\src\\main\\resources\\jsp\\";
+
// Service dependencies, injected by the Felix dependency manager
- private volatile LogService m_logService;
private volatile BundleContext m_bundleContext;
+ @SuppressWarnings("deprecation")
public URL getResource(final String name) {
final String pathPrefix = Activator.ALIAS + "/";
if (name != null && name.startsWith(pathPrefix)) {
- if (name.contains("/resources/")) {
- String jspName = name.substring(name.lastIndexOf("/") + 1);
- File jspFile = new
File("D:\\Amdatu-svn\\sandbox\\ivol\\ntlm\\src\\main\\resources\\jsp\\" +
jspName);
+ if (name.contains("/src/")) {
+ String fileName = name.substring(name.lastIndexOf("/src/") +
"/src/".length());
+ File file = new File(LOCAL_DEV_DIR + fileName);
try {
- return jspFile.toURL();
+ return file.toURL();
}
catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
}
return
m_bundleContext.getBundle().getResource(name.substring(pathPrefix.length()));
}
return null;
}
-}
+}
\ No newline at end of file
Copied: sandbox/ivol/ntlm/src/main/resources/jsp/survey.jsp (from r1322,
/sandbox/ivol/ntlm/src/main/resources/jsp/enquete.jsp)
==============================================================================
--- /sandbox/ivol/ntlm/src/main/resources/jsp/enquete.jsp (original)
+++ sandbox/ivol/ntlm/src/main/resources/jsp/survey.jsp Tue Aug 16 11:41:11 2011
@@ -26,7 +26,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ondernemingsraad - Online enquete</title>
+ <title>Ondernemingsraad - Online enquête</title>
<link rel="stylesheet" href="${staticPath}/css/cr.css">
<script type="text/javascript"
src="${contextPath}/dashboard/static/js/lib/jquery-1.4.2.min.js"></script>
</head>
@@ -41,15 +41,14 @@
<hr/>
<div class="leftbox">
- <h3>Waarom?</h3>
- <p>Deze online enquete moet ons inzicht geven in wat de achterban vindt.
Meer blablabla.</p>
+ <h3>Waarom deze enquête?</h3>
+ <p>Deze online enquête moet ons meer inzicht geven in wat jullie,
onze achterban, vinden van bepaalde onderwerpen. Met enige regelmaat zullen we
jullie vragen een dergelijke enquête in te vullen zodat we jullie mening
kunnen vertegenwoordigen.</p>
<h3>Is dit anoniem?</h3>
- <p>Ja. Om te garanderen dat werknemers maar eenmaal deze enquete in
kunnen vullen wordt wel de gebruikersnaam opgeslagen.
- Deze wordt echter niet gekoppeld aan de gegeven antwoorden, waardoor het
achteraf niet mogelijk is te bepalen wie welk antwoord gegeven heeft.</p>
+ <p>Ja, ondanks het feit dat deze enquête gekoppeld is aan je
Windows account. Om te voorkomen dat één en dezelfde persoon de
enquête meerdere malen invult onthoud het systeem welke werknemers de
enquête hebben ingevuld. Dit wordt echter niet gekoppeld aan de de
gegeven antwoorden, waardoor het technisch onmogelijk is om te achterhalen
welke antwoorden een bepaalde werknemer gegeven heeft.</p>
- <h3>Wat gebeurd hiermee?</h3>
- <p>En meer blablablal</p>
+ <h3>Wat gebeurd er met de resultaten?</h3>
+ <p>De resultaten van de online enquête zullen we publiceren op
intranet en rondmailen. De resultaten zijn belangrijke input voor de
structurele overleggen die wij voeren met de directie.</p>
</div>
<div class="rightbox">
@@ -87,7 +86,7 @@
async:true,
success: function(response) {
if (response == "1") {
- var html = "Je hebt deze enquete reeds ingevuld. Je kunt de enquete
slechts eenmalig invullen. Bedankt voor je medewerking!";
+ var html = "Je hebt deze enquête reeds ingevuld. Je kunt de
enquête slechts eenmalig invullen. Bedankt voor je medewerking!";
document.getElementById("survey").innerHTML = html;
} else {
showSurvey();
@@ -158,9 +157,7 @@
return results[1];
}
-
var surveyId = getParameter("id");
-
showUsername();
loadSurveyForm();
Added: sandbox/ivol/ntlm/src/main/resources/jsp/surveyresults.jsp
==============================================================================
--- (empty file)
+++ sandbox/ivol/ntlm/src/main/resources/jsp/surveyresults.jsp Tue Aug 16
11:41:11 2011
@@ -0,0 +1,83 @@
+<%--
+ Copyright (c) 2010, 2011 The Amdatu Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.verning permissions and limitations
+ under the License.
+--%>
+
+<%@ page language="java" session="false" buffer="none" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
+<c:set var="staticPath" value="${contextPath}/oauth-consumerregistry/static"/>
+<c:set var="surveyUrl" value="${baseUrl}/rest/survey"/>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Ondernemingsraad - Uitslagen online enquete</title>
+ <link rel="stylesheet" href="${staticPath}/css/cr.css">
+ <script type="text/javascript"
src="${contextPath}/dashboard/static/js/lib/jquery-1.4.2.min.js"></script>
+ </head>
+
+ <div id="result"></div>
+</html>
+
+<script type="text/javascript">
+
+ function loadSurveyAnswers() {
+ var url = "${surveyUrl}/answers/" + surveyId;
+ jQuery.ajax({
+ url: url,
+ type: "GET",
+ dataType: "json",
+ async:true,
+ success: function(data, textStatus, jqXHR) {
+ var survey = jQuery.parseJSON(jqXHR.responseText).surveyresults;
+ var html = "<ul>";
+ for (i=0; i<survey.questions.length; i++) {
+ var question = survey.questions[i];
+ var description = question.description;
+ html += "<li><b>" + description + "</b><br/>";
+ var answers = question.answers.answer;
+ if(typeof answers == 'string') {
+ html += answers + "<br/>";
+ } else {
+ for (j=0; j<answers.length;j++) {
+ html += answers[j] + "<br/>";
+ }
+ }
+ html += "</li>";
+ }
+ html += "</ul>";
+ document.getElementById("result").innerHTML = html;
+ }
+ });
+ }
+
+ function getParameter(name) {
+ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
+ var regexS = "[\\?&]"+name+"=([^&#]*)";
+ var regex = new RegExp( regexS );
+ var results = regex.exec( window.location.href );
+ if( results == null )
+ return "";
+ else
+ return results[1];
+ }
+
+ var surveyId = getParameter("id");
+ loadSurveyAnswers();
+
+</script>
Modified: sandbox/ivol/ntlm/src/main/resources/static/css/cr.css
==============================================================================
--- sandbox/ivol/ntlm/src/main/resources/static/css/cr.css (original)
+++ sandbox/ivol/ntlm/src/main/resources/static/css/cr.css Tue Aug 16
11:41:11 2011
@@ -40,7 +40,7 @@
div.leftbox {
width:22%;
- height:600px;
+ height:750px;
float:left;
margin-left:10px;
background: #282828;
@@ -74,7 +74,7 @@
div.rightbox {
width: 75%;
- height:600px;
+ height:750px;
float:left;
margin-left:15px;
background: #282828;
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits