Java Code Examples for org.apache.commons.lang.math.NumberUtils#stringToInt()

The following examples show how to use org.apache.commons.lang.math.NumberUtils#stringToInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * Display edit page for existed commonCartridge item.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    */

   @RequestMapping("/editItemInit")
   private String editItemInit(
    @ModelAttribute("commonCartridgeItemForm") CommonCartridgeItemForm commonCartridgeItemForm,
    HttpServletRequest request) {

// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, CommonCartridgeConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);

int itemIdx = NumberUtils.stringToInt(request.getParameter(CommonCartridgeConstants.PARAM_ITEM_INDEX), -1);
CommonCartridgeItem item = null;
if (itemIdx != -1) {
    SortedSet<CommonCartridgeItem> commonCartridgeList = getCommonCartridgeItemList(sessionMap);
    List<CommonCartridgeItem> rList = new ArrayList<>(commonCartridgeList);
    item = rList.get(itemIdx);
    if (item != null) {
	populateItemToForm(itemIdx, item, commonCartridgeItemForm, request);
    }
}
return findForward(item == null ? -1 : item.getType());
   }
 
Example 2
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * Display edit page for existed taskList item.
    */
   @RequestMapping("editItemInit")
   public String editItemInit(@ModelAttribute TaskListItemForm taskListItemForm, HttpServletRequest request) {

// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);

int itemIdx = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_ITEM_INDEX), -1);
TaskListItem item = null;
if (itemIdx != -1) {
    SortedSet<TaskListItem> taskListList = getTaskListItemList(sessionMap);
    List<TaskListItem> rList = new ArrayList<>(taskListList);
    item = rList.get(itemIdx);
    if (item != null) {
	populateItemToForm(itemIdx, item, taskListItemForm, request);
    }
}

return item == null ? null : "pages/authoring/parts/addtask";
   }
 
Example 3
Source File: AuthoringConditionController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * Display edit page for an existing condition.
    */
   @RequestMapping("/editCondition")
   public String editCondition(@ModelAttribute ForumConditionForm forumConditionForm, HttpServletRequest request) {

String sessionMapID = forumConditionForm.getSessionMapID();
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(ForumConstants.PARAM_ORDER_ID), -1);
ForumCondition condition = null;
if (orderId != -1) {
    SortedSet<ForumCondition> conditionSet = getForumConditionSet(sessionMap);
    List<ForumCondition> conditionList = new ArrayList<>(conditionSet);
    condition = conditionList.get(orderId);
    if (condition != null) {
	populateConditionToForm(orderId, condition, forumConditionForm, request);
    }
}

populateFormWithPossibleItems(forumConditionForm, request);
return condition == null ? null : "jsps/authoring/addCondition";
   }
 
Example 4
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * Display edit page for existed imageGallery item.
    */
   @RequestMapping("/editImage")
   public String editImage(@ModelAttribute ImageGalleryItemForm imageGalleryItemForm, HttpServletRequest request) {

// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);

int itemIdx = NumberUtils.stringToInt(request.getParameter(ImageGalleryConstants.PARAM_IMAGE_INDEX), -1);
ImageGalleryItem item = null;
if (itemIdx != -1) {
    SortedSet<ImageGalleryItem> imageGalleryList = getImageList(sessionMap);
    List<ImageGalleryItem> rList = new ArrayList<>(imageGalleryList);
    item = rList.get(itemIdx);
    if (item != null) {
	populateItemToForm(itemIdx, item, imageGalleryItemForm, request);
    }
}
return (item == null) ? null : "pages/authoring/parts/addimage";
   }
 
Example 5
Source File: AuthoringConditionController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * Display edit page for an existing condition.
    *
    * @param QaConditionForm
    * @param request
    * @return
    */
   @RequestMapping("/editCondition")
   private String editCondition(@ModelAttribute("QaConditionForm") QaConditionForm QaConditionForm,
    HttpServletRequest request) {

String sessionMapID = QaConditionForm.getSessionMapID();
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(QaAppConstants.PARAM_ORDER_ID), -1);
QaCondition condition = null;
if (orderId != -1) {
    SortedSet<QaCondition> conditionSet = getQaConditionSet(sessionMap);
    List<QaCondition> conditionList = new ArrayList<>(conditionSet);
    condition = conditionList.get(orderId);
    if (condition != null) {
	populateConditionToForm(orderId, condition, QaConditionForm, request);
    }
}

populateFormWithPossibleItems(QaConditionForm, request);
return condition == null ? null : "authoring/addCondition";
   }
 
Example 6
Source File: AuthoringChatConditionController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@RequestMapping("/switchItem")
   public String switchItem(HttpServletRequest request, boolean up) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, ChatConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(ChatConstants.PARAM_ORDER_ID), -1);
if (orderId != -1) {
    SortedSet<ChatCondition> conditionSet = getChatConditionSet(sessionMap);
    List<ChatCondition> conditionList = new ArrayList<>(conditionSet);
    // get current and the target item, and switch their sequnece
    ChatCondition condition = conditionList.get(orderId);
    ChatCondition repCondition;
    if (up) {
	repCondition = conditionList.get(--orderId);
    } else {
	repCondition = conditionList.get(++orderId);
    }
    int upSeqId = repCondition.getOrderId();
    repCondition.setOrderId(condition.getOrderId());
    condition.setOrderId(upSeqId);

    // put back list, it will be sorted again
    conditionSet.clear();
    conditionSet.addAll(conditionList);
}

request.setAttribute(ChatConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "pages/authoring/conditionList";
   }
 
Example 7
Source File: AuthoringNotebookConditionController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Remove taskList item from HttpSession list and update page display. As authoring rule, all persist only happen
    * when user submit whole page. So this remove is just impact HttpSession values.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    */
   @RequestMapping(path = "/removeCondition", method = RequestMethod.POST)
   private String removeCondition(HttpServletRequest request) {

// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, NotebookConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(NotebookConstants.PARAM_ORDER_ID), -1);
if (orderId != -1) {
    SortedSet<NotebookCondition> conditionSet = getNotebookConditionSet(sessionMap);
    List<NotebookCondition> conditionList = new ArrayList<>(conditionSet);
    NotebookCondition condition = conditionList.remove(orderId);
    for (NotebookCondition otherCondition : conditionSet) {
	if (otherCondition.getOrderId() > orderId) {
	    otherCondition.setOrderId(otherCondition.getOrderId() - 1);
	}
    }
    conditionSet.clear();
    conditionSet.addAll(conditionList);
    // add to delList
    List delList = getDeletedNotebookConditionList(sessionMap);
    delList.add(condition);
}

request.setAttribute(NotebookConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "pages/authoring/conditionList";
   }
 
Example 8
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Display empty page for new commonCartridge item.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    */
   @RequestMapping("/newItemInit")
   private String newItemInit(
    @ModelAttribute("commonCartridgeItemForm") CommonCartridgeItemForm commonCartridgeItemForm,
    HttpServletRequest request) {
String sessionMapID = WebUtil.readStrParam(request, CommonCartridgeConstants.ATTR_SESSION_MAP_ID);
commonCartridgeItemForm.setSessionMapID(sessionMapID);

short type = (short) NumberUtils.stringToInt(request.getParameter(AuthoringController.ITEM_TYPE));
return findForward(type);
   }
 
Example 9
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Delete a topic form current topic list. But database record will be deleted only when user save whole authoring
    * page.
    */
   @RequestMapping(path = "/deleteTopic", method = RequestMethod.POST)
   public String deleteTopic(HttpServletRequest request) throws PersistenceException {

// get SessionMAP
String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMapID);
String topicIndex = request.getParameter(ForumConstants.AUTHORING_TOPICS_INDEX);
int topicIdx = NumberUtils.stringToInt(topicIndex, -1);

if (topicIdx != -1) {
    Set topics = getTopics(sessionMap);
    List<MessageDTO> rList = new ArrayList<MessageDTO>(topics);
    MessageDTO item = rList.remove(topicIdx);
    topics.clear();
    topics.addAll(rList);
    // add to delList
    List delList = getDeletedTopicList(sessionMap);
    delList.add(item);

    SortedSet<ForumCondition> list = getForumConditionSet(sessionMap);
    Iterator<ForumCondition> conditionIter = list.iterator();

    while (conditionIter.hasNext()) {
	ForumCondition condition = conditionIter.next();
	Set<Message> topicList = condition.getTopics();
	if (topicList.contains(item.getMessage())) {
	    topicList.remove(item.getMessage());
	}
    }
}

return "jsps/authoring/message/topiclist";
   }
 
Example 10
Source File: AuthoringConditionController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String switchItem(HttpServletRequest request, boolean up) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(ForumConstants.PARAM_ORDER_ID), -1);
if (orderId != -1) {
    SortedSet<ForumCondition> conditionSet = getForumConditionSet(sessionMap);
    List<ForumCondition> conditionList = new ArrayList<>(conditionSet);
    // get current and the target item, and switch their sequnece
    ForumCondition condition = conditionList.get(orderId);
    ForumCondition repCondition;
    if (up) {
	repCondition = conditionList.get(--orderId);
    } else {
	repCondition = conditionList.get(++orderId);
    }
    int upSeqId = repCondition.getOrderId();
    repCondition.setOrderId(condition.getOrderId());
    condition.setOrderId(upSeqId);

    // put back list, it will be sorted again
    conditionSet.clear();
    conditionSet.addAll(conditionList);
}

request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "jsps/authoring/conditionList";
   }
 
Example 11
Source File: AuthoringConditionController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String switchItem(HttpServletRequest request, boolean up) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, QaAppConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(QaAppConstants.PARAM_ORDER_ID), -1);
if (orderId != -1) {
    SortedSet<QaCondition> conditionSet = getQaConditionSet(sessionMap);
    List<QaCondition> conditionList = new ArrayList<>(conditionSet);
    // get current and the target item, and switch their sequnece
    QaCondition condition = conditionList.get(orderId);
    QaCondition repCondition;
    if (up) {
	repCondition = conditionList.get(--orderId);
    } else {
	repCondition = conditionList.get(++orderId);
    }
    int upSeqId = repCondition.getOrderId();
    repCondition.setOrderId(condition.getOrderId());
    condition.setOrderId(upSeqId);

    // put back list, it will be sorted again
    conditionSet.clear();
    conditionSet.addAll(conditionList);
}

request.setAttribute(QaAppConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "authoring/conditionList";
   }
 
Example 12
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Remove survey item from HttpSession list and update page display. As authoring rule, all persist only happen when
    * user submit whole page. So this remove is just impact HttpSession values.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    */
   @RequestMapping(value = "/removeItem")
   public String removeItem(HttpServletRequest request) {

// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);

int itemIdx = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ITEM_INDEX), -1);
if (itemIdx != -1) {
    SortedSet<SurveyQuestion> surveyList = getSurveyItemList(sessionMap);
    List<SurveyQuestion> rList = new ArrayList<>(surveyList);
    SurveyQuestion item = rList.remove(itemIdx);
    surveyList.clear();
    surveyList.addAll(rList);
    // add to delList
    List delList = getDeletedSurveyItemList(sessionMap);
    delList.add(item);

    SortedSet<SurveyCondition> list = getSurveyConditionSet(sessionMap);
    Iterator<SurveyCondition> conditionIter = list.iterator();

    while (conditionIter.hasNext()) {
	SurveyCondition condition = conditionIter.next();
	Set<SurveyQuestion> questions = condition.getQuestions();
	if (questions.contains(item)) {
	    questions.remove(item);
	}
    }
}

request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "pages/authoring/parts/itemlist";
   }
 
Example 13
Source File: AuthoringConditionController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@RequestMapping(value = "/switchItem")
   public String switchItem(HttpServletRequest request, boolean up) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ORDER_ID), -1);
if (orderId != -1) {
    SortedSet<SurveyCondition> conditionSet = getSurveyConditionSet(sessionMap);
    List<SurveyCondition> conditionList = new ArrayList<>(conditionSet);
    // get current and the target item, and switch their sequnece
    SurveyCondition condition = conditionList.get(orderId);
    SurveyCondition repCondition;
    if (up) {
	repCondition = conditionList.get(--orderId);
    } else {
	repCondition = conditionList.get(++orderId);
    }
    int upSeqId = repCondition.getOrderId();
    repCondition.setOrderId(condition.getOrderId());
    condition.setOrderId(upSeqId);

    // put back list, it will be sorted again
    conditionSet.clear();
    conditionSet.addAll(conditionList);
}

request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "pages/authoring/conditionList";
   }
 
Example 14
Source File: AuthoringConditionController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Remove condition from HttpSession list and update page display. As authoring rule, all persist only happen when
    * user submit whole page. So this remove is just impact HttpSession values.
    *
    * @param mapping
    * @param surveyConditionForm
    * @param request
    * @param response
    * @return
    */
   @RequestMapping(value = "/removeCondition")
   public String removeCondition(HttpServletRequest request) {

// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ORDER_ID), -1);
if (orderId != -1) {
    SortedSet<SurveyCondition> conditionSet = getSurveyConditionSet(sessionMap);
    List<SurveyCondition> conditionList = new ArrayList<>(conditionSet);
    SurveyCondition condition = conditionList.remove(orderId);
    for (SurveyCondition otherCondition : conditionSet) {
	if (otherCondition.getOrderId() > orderId) {
	    otherCondition.setOrderId(otherCondition.getOrderId() - 1);
	}
    }
    conditionSet.clear();
    conditionSet.addAll(conditionList);
    // add to delList
    List deletedList = getDeletedSurveyConditionList(sessionMap);
    deletedList.add(condition);
}

request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "pages/authoring/conditionList";
   }
 
Example 15
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Ajax call, remove the given line of instruction of resource item.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    */
   @RequestMapping("/removeAnswerOption")
   protected String removeAnswerOption(HttpServletRequest request) {
int count = NumberUtils.stringToInt(request.getParameter(DacoConstants.ANSWER_OPTION_COUNT), 0);
int removeIndex = NumberUtils.stringToInt(request.getParameter(DacoConstants.PARAM_ANSWER_OPTION_INDEX), -1);
List answerOptionList = new ArrayList(count - 1);
for (int index = 1; index <= count; index++) {
    if (index != removeIndex) {
	String answerOption = request.getParameter(DacoConstants.ANSWER_OPTION_DESC_PREFIX + index);
	answerOptionList.add(answerOption == null ? "" : answerOption);
    }
}
request.setAttribute(DacoConstants.ATTR_ANSWER_OPTION_LIST, answerOptionList);
return "pages/authoring/parts/answeroptions";
   }
 
Example 16
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@RequestMapping(value = "/switchItem")
   public String switchItem(HttpServletRequest request, boolean up) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);

int itemIdx = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ITEM_INDEX), -1);
if (itemIdx != -1) {
    SortedSet<SurveyQuestion> surveyList = getSurveyItemList(sessionMap);
    List<SurveyQuestion> rList = new ArrayList<>(surveyList);
    // get current and the target item, and switch their sequnece
    SurveyQuestion item = rList.get(itemIdx);
    SurveyQuestion repItem;
    if (up) {
	repItem = rList.get(--itemIdx);
    } else {
	repItem = rList.get(++itemIdx);
    }
    int upSeqId = repItem.getSequenceId();
    repItem.setSequenceId(item.getSequenceId());
    item.setSequenceId(upSeqId);

    // put back list, it will be sorted again
    surveyList.clear();
    surveyList.addAll(rList);
}

request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "pages/authoring/parts/itemlist";
   }
 
Example 17
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Extract web from content to daco question.
    *
    * @param request
    * @param questionForm
    * @param answerOptionList
    * @throws DacoApplicationException
    */
   protected void extractFormToDacoQuestion(HttpServletRequest request, List<String> answerOptionList,
    DacoQuestionForm questionForm) throws Exception {
/*
 * BE CAREFUL: This method will copy nessary info from request form to a old or new DacoQuestion instance. It
 * gets all
 * info EXCEPT DacoQuestion.createDate and DacoQuestion.createBy, which need be set when persisting this daco
 * question.
 */

SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(questionForm.getSessionMapID());
// check whether it is "edit(old question)" or "add(new question)"
SortedSet<DacoQuestion> questionSet = getQuestionList(sessionMap);
int questionIndex = NumberUtils.stringToInt(questionForm.getQuestionIndex(), -1);
DacoQuestion question = null;
if (questionIndex == -1) { // add
    question = new DacoQuestion();
    question.setCreateDate(new Timestamp(new Date().getTime()));
    questionSet.add(question);

} else { // edit
    List<DacoQuestion> questionList = new ArrayList<>(questionSet);
    question = questionList.get(questionIndex);
}

question.setType(questionForm.getQuestionType());

String constraint = questionForm.getMax();
if (!StringUtils.isBlank(constraint)) {
    question.setMax(Float.parseFloat(constraint));
} else {
    question.setMax(null);
}
constraint = questionForm.getMin();
if (!StringUtils.isBlank(constraint)) {
    question.setMin(Float.parseFloat(constraint));
} else {
    question.setMin(null);
}
constraint = questionForm.getDigitsDecimal();
if (!StringUtils.isBlank(constraint)) {
    question.setDigitsDecimal(Short.parseShort(constraint));
}

Set<DacoAnswerOption> answerOptions = new LinkedHashSet<>();
if (answerOptionList != null) {
    int index = 1;
    for (String ins : answerOptionList) {
	DacoAnswerOption answerOption = new DacoAnswerOption();
	answerOption.setAnswerOption(ins.trim());
	answerOption.setSequenceNumber(index++);
	answerOptions.add(answerOption);
    }
}
question.setRequired(questionForm.isQuestionRequired());
question.setAnswerOptions(answerOptions);

Short summary = questionForm.getSummary();
if (summary != null && summary > 0) {
    question.setSummary(questionForm.getSummary());
} else {
    question.setSummary(null);
}

question.setDescription(
	StringUtils.isBlank(questionForm.getDescription()) ? null : questionForm.getDescription().trim());

   }
 
Example 18
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Extract web from content to resource item.
    *
    * BE CAREFUL: This method will copy nessary info from request form to a
    * old or new ResourceItem instance. It gets all info EXCEPT
    * ResourceItem.createDate and ResourceItem.createBy, which need be set
    * when persisting this resource item.
    */
   private void extractFormToResourceItem(HttpServletRequest request, List<String> instructionList,
    ResourceItemForm itemForm) throws Exception {

SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(itemForm.getSessionMapID());
// check whether it is "edit(old item)" or "add(new item)"
SortedSet<ResourceItem> resourceList = getResourceItemList(sessionMap);
int itemIdx = NumberUtils.stringToInt(itemForm.getItemIndex(), -1);
ResourceItem item = null;

if (itemIdx == -1) { // add
    item = new ResourceItem();
    item.setCreateDate(new Timestamp(new Date().getTime()));
    item.setOrderId(resourceList.size() + 1);
    
} else { // edit
    List<ResourceItem> rList = new ArrayList<>(resourceList);
    item = rList.get(itemIdx);
}
short type = itemForm.getItemType();
item.setType(itemForm.getItemType());
/*
 * Set following fields regards to the type: item.setFileUuid();
 * item.setFileVersionId(); item.setFileType(); item.setFileName();
 *
 * item.getInitialItem() item.setImsSchema() item.setOrganizationXml()
 */
// if the item is edit (not new add) then the getFile may return null
// it may throw exception, so put it as first, to avoid other invlidate
// update:
if (itemForm.getFile() != null) {
    if (type == ResourceConstants.RESOURCE_TYPE_WEBSITE
	    || type == ResourceConstants.RESOURCE_TYPE_LEARNING_OBJECT
	    || type == ResourceConstants.RESOURCE_TYPE_FILE) {
	// if it has old file, and upload a new, then save old to deleteList
	ResourceItem delAttItem = new ResourceItem();
	boolean hasOld = false;
	if (item.getFileUuid() != null) {
	    hasOld = true;
	    // be careful, This new ResourceItem object never be save
	    // into database
	    // just temporarily use for saving fileUuid and versionID
	    // use:
	    delAttItem.setFileUuid(item.getFileUuid());
	    delAttItem.setFileVersionId(item.getFileVersionId());
	}

	//throws UploadResourceFileException
	resourceService.uploadResourceItemFile(item, itemForm.getFile());
	
	// put it after "upload" to ensure deleted file added into list
	// only no exception happens during upload
	if (hasOld) {
	    List<ResourceItem> delAtt = getDeletedItemAttachmentList(sessionMap);
	    delAtt.add(delAttItem);
	}
    }
}
item.setTitle(itemForm.getTitle());
item.setCreateByAuthor(true);
item.setHide(false);
item.setAllowRating(itemForm.isAllowRating());
item.setAllowComments(itemForm.isAllowComments());
// set instructions
Set<ResourceItemInstruction> instructions = new LinkedHashSet<>();
int idx = 0;
for (String ins : instructionList) {
    ResourceItemInstruction instruction = new ResourceItemInstruction();
    instruction.setDescription(ins);
    instruction.setSequenceId(idx++);
    instructions.add(instruction);
}
item.setItemInstructions(instructions);

if (type == ResourceConstants.RESOURCE_TYPE_URL) {
    item.setUrl(itemForm.getUrl());
}
if (type == ResourceConstants.RESOURCE_TYPE_URL || type == ResourceConstants.RESOURCE_TYPE_FILE) {
    item.setOpenUrlNewWindow(itemForm.isOpenUrlNewWindow());
}
item.setDescription(itemForm.getDescription());

// if it's a new item, add it to resourceList
if (itemIdx == -1) {
    resourceList.add(item);
}
   }
 
Example 19
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Extract web from content to survey item.
    *
    * @param request
    * @param instructionList
    * @param itemForm
    * @throws SurveyApplicationException
    */
   private void extractFormToSurveyItem(HttpServletRequest request, List<String> instructionList,
    QuestionForm itemForm) throws Exception {
/*
 * BE CAREFUL: This method will copy nessary info from request form to a old or new SurveyItem instance. It gets
 * all info EXCEPT SurveyItem.createDate and SurveyItem.createBy, which need be set when persisting this survey
 * item.
 */

SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(itemForm.getSessionMapID());
// check whether it is "edit(old item)" or "add(new item)"
SortedSet<SurveyQuestion> surveyList = getSurveyItemList(sessionMap);
int itemIdx = NumberUtils.stringToInt(itemForm.getItemIndex(), -1);
SurveyQuestion item = itemForm.getQuestion();

if (itemIdx == -1) { // add
    item.setCreateDate(new Timestamp(new Date().getTime()));
    int maxSeq = 1;
    if (surveyList != null && surveyList.size() > 0) {
	SurveyQuestion last = surveyList.last();
	maxSeq = last.getSequenceId() + 1;
    }
    item.setSequenceId(maxSeq);
    surveyList.add(item);
} else { // edit
    List<SurveyQuestion> rList = new ArrayList<>(surveyList);
    item = rList.get(itemIdx);
    item.setDescription(itemForm.getQuestion().getDescription());
    item.setOptional(itemForm.getQuestion().isOptional());
    item.setAppendText(itemForm.getQuestion().isAppendText());
    item.setAllowMultipleAnswer(itemForm.getQuestion().isAllowMultipleAnswer());

}
item.updateShortTitleFromDescription();
short type = getQuestionType(itemForm);
item.setType(type);

// set instrcutions
Set instructions = new LinkedHashSet();
int idx = 0;
for (String ins : instructionList) {
    SurveyOption rii = new SurveyOption();
    rii.setDescription(ins);
    rii.setSequenceId(idx++);
    instructions.add(rii);
}
item.setOptions(instructions);

   }
 
Example 20
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Extract web from content to commonCartridge item.
    *
    * @param request
    * @param itemForm
    * @throws CommonCartridgeApplicationException
    */
   private void extractFormToCommonCartridgeItem(HttpServletRequest request, CommonCartridgeItemForm itemForm)
    throws Exception {
/*
 * BE CAREFUL: This method will copy nessary info from request form to a old or new CommonCartridgeItem
 * instance. It gets all info EXCEPT CommonCartridgeItem.createDate and CommonCartridgeItem.createBy, which need
 * be set when persisting this commonCartridge item.
 */

SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(itemForm.getSessionMapID());
// check whether it is "edit(old item)" or "add(new item)"
SortedSet<CommonCartridgeItem> commonCartridgeList = getCommonCartridgeItemList(sessionMap);
int itemIdx = NumberUtils.stringToInt(itemForm.getItemIndex(), -1);
CommonCartridgeItem item = null;

if (itemIdx == -1) { // add
    item = new CommonCartridgeItem();
    item.setCreateDate(new Timestamp(new Date().getTime()));
    commonCartridgeList.add(item);
} else { // edit
    List<CommonCartridgeItem> rList = new ArrayList<>(commonCartridgeList);
    item = rList.get(itemIdx);
}
short type = itemForm.getItemType();
item.setType(itemForm.getItemType());

item.setTitle(itemForm.getTitle());
item.setCreateByAuthor(true);
item.setHide(false);

if (type == CommonCartridgeConstants.RESOURCE_TYPE_BASIC_LTI) {

    if (StringUtils.isBlank(item.getLaunchUrl()) && StringUtils.isNotBlank(item.getSecureLaunchUrl())) {
	item.setSecureLaunchUrl(itemForm.getUrl());
    } else {
	item.setLaunchUrl(itemForm.getUrl());
    }

    item.setKey(itemForm.getKey());
    item.setSecret(itemForm.getSecret());
    item.setButtonText(itemForm.getButtonText());
    item.setOpenUrlNewWindow(itemForm.isOpenUrlNewWindow());
    item.setFrameHeight(itemForm.getFrameHeight());
    item.setCustomStr(itemForm.getCustomStr());
}
// if(type == CommonCartridgeConstants.RESOURCE_TYPE_WEBSITE
// ||itemForm.getItemType() == CommonCartridgeConstants.RESOURCE_TYPE_LEARNING_OBJECT){
item.setDescription(itemForm.getDescription());
// }

   }