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

The following examples show how to use org.apache.commons.lang.math.NumberUtils#createLong() . 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: ViewItemController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * Return resource item according to ToolAccessMode.
    *
    * @param request
    * @param sessionMap
    * @param mode
    * @return
    */
   private ResourceItem getResourceItem(HttpServletRequest request, SessionMap<String, Object> sessionMap,
    String mode) {
ResourceItem item = null;
if (ResourceConstants.MODE_AUTHOR_SESSION.equals(mode)) {
    int itemIdx = NumberUtils.stringToInt(request.getParameter(ResourceConstants.PARAM_ITEM_INDEX), 0);
    // authoring: does not save item yet, so only has ItemList from session and identity by Index
    List<ResourceItem> resourceList = new ArrayList<>(getResourceItemList(sessionMap));
    item = resourceList.get(itemIdx);
} else {
    Long itemUid = NumberUtils.createLong(request.getParameter(ResourceConstants.PARAM_RESOURCE_ITEM_UID));
    // get back the resource and item list and display them on page
    item = resourceService.getResourceItemByUid(itemUid);
}
return item;
   }
 
Example 2
Source File: ViewItemController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * Return resoruce item according to ToolAccessMode.
    *
    * @param request
    * @param sessionMap
    * @param mode
    * @return
    */
   private CommonCartridgeItem getCommonCartridgeItem(HttpServletRequest request, SessionMap sessionMap, String mode) {
CommonCartridgeItem item = null;
if (CommonCartridgeConstants.MODE_AUTHOR_SESSION.equals(mode)) {
    int itemIdx = NumberUtils.stringToInt(request.getParameter(CommonCartridgeConstants.PARAM_ITEM_INDEX), 0);
    // authoring: does not save item yet, so only has ItemList from session and identity by Index
    List<CommonCartridgeItem> commonCartridgeList = new ArrayList<>(getCommonCartridgeItemList(sessionMap));
    item = commonCartridgeList.get(itemIdx);
} else {
    Long itemUid = NumberUtils
	    .createLong(request.getParameter(CommonCartridgeConstants.PARAM_RESOURCE_ITEM_UID));
    // get back the commonCartridge and item list and display them on page
    item = commonCartridgeService.getCommonCartridgeItemByUid(itemUid);
}
return item;
   }
 
Example 3
Source File: SetShopCartCommandImpl.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) {
    if (parameters.containsKey(getCmdKey())) {
        final Long value = NumberUtils.createLong(String.valueOf(parameters.get(getCmdKey())));
        if (value != null && !value.equals(shoppingCart.getShoppingContext().getShopId())) {

            shoppingCart.getShoppingContext().clearContext(); // If we are setting new shop we must re-authenticate

            final Shop shop = shopService.getById(value);

            final MutableShoppingContext ctx = shoppingCart.getShoppingContext();
            ctx.setShopId(shop.getShopId());
            ctx.setShopCode(shop.getCode());

            setDefaultOrderInfoOptions(shoppingCart);
            setDefaultTaxOptions(shoppingCart);

            markDirty(shoppingCart);
        }
    }
}
 
Example 4
Source File: ExportToolContentService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
    if (source != null) {
	String className = source.getClass().getName();
	try {
	    for (NameInfo name : fileHandleClassList) {
		if (name.className.equals(className)) {
		    Long uuid = NumberUtils.createLong(BeanUtils.getProperty(source, name.uuidFieldName));
		    if (uuid != null) {
			// version id is optional
			Long version = null;
			if (name.versionFieldName != null) {
			    version = NumberUtils
				    .createLong(BeanUtils.getProperty(source, name.versionFieldName));
			}
			log.debug("XStream get file node [" + uuid + "," + version + "].");
			fileNodes.add(ExportToolContentService.this.new ValueInfo(uuid, version));
		    }
		}
	    }
	} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
	    log.error("Error while marshalling a file", e);
	}
    }

    defaultConverter.marshal(source, writer, context);
}
 
Example 5
Source File: ViewItemController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Display main frame to display instrcution and item content.
    */
   @RequestMapping("/reviewItem")
   private String reviewItem(HttpServletRequest request) {
String mode = request.getParameter(AttributeNames.ATTR_MODE);

String sessionMapID = WebUtil.readStrParam(request, ResourceConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);

ResourceItem item = getResourceItem(request, sessionMap, mode);

String idStr = request.getParameter(ResourceConstants.ATTR_TOOL_SESSION_ID);
Long sessionId = NumberUtils.createLong(idStr);
// mark this item access flag if it is learner
if (ToolAccessMode.LEARNER.toString().equals(mode)) {
    HttpSession ss = SessionManager.getSession();
    // get back login user DTO
    UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
    resourceService.setItemAccess(item.getUid(), new Long(user.getUserID().intValue()), sessionId);
}

if (item == null) {
    return "error";
}
if (item.getType() == ResourceConstants.RESOURCE_TYPE_LEARNING_OBJECT) {
    sessionMap.put(ResourceConstants.ATT_LEARNING_OBJECT, item);
}
// set url to content frame

int itemIdx = NumberUtils.stringToInt(request.getParameter(ResourceConstants.PARAM_ITEM_INDEX));
request.setAttribute(ResourceConstants.ATTR_RESOURCE_REVIEW_URL,
	getReviewUrl(request, item, sessionMapID, mode, itemIdx));

request.setAttribute(ResourceConstants.ATTR_ALLOW_COMMENTS, item.isAllowComments());

// these attribute will be use to instruction navigator page
request.setAttribute(AttributeNames.ATTR_MODE, mode);
request.setAttribute(ResourceConstants.PARAM_ITEM_INDEX, itemIdx);
Long itemUid = NumberUtils.createLong(request.getParameter(ResourceConstants.PARAM_RESOURCE_ITEM_UID));
request.setAttribute(ResourceConstants.PARAM_RESOURCE_ITEM_UID, itemUid);
request.setAttribute(ResourceConstants.ATTR_TOOL_SESSION_ID, sessionId);
request.setAttribute(ResourceConstants.ATTR_SESSION_MAP_ID, sessionMapID);

return "pages/itemreview/mainframe";
   }
 
Example 6
Source File: ViewItemController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Display main frame to display instrcution and item content.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws IOException
    */
   @RequestMapping("/reviewItem")
   private String reviewItem(HttpServletRequest request) throws IOException {
String mode = request.getParameter(AttributeNames.ATTR_MODE);

String sessionMapID = WebUtil.readStrParam(request, CommonCartridgeConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

CommonCartridgeItem item = getCommonCartridgeItem(request, sessionMap, mode);

String idStr = request.getParameter(CommonCartridgeConstants.ATTR_TOOL_SESSION_ID);
Long sessionId = NumberUtils.createLong(idStr);
// mark this item access flag if it is learner
if (ToolAccessMode.LEARNER.toString().equals(mode)) {
    HttpSession ss = SessionManager.getSession();
    // get back login user DTO
    UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
    commonCartridgeService.setItemAccess(item.getUid(), new Long(user.getUserID().intValue()), sessionId);
}

if (item == null) {
    return "error";
}
// set url to content frame

int itemIdx = NumberUtils.stringToInt(request.getParameter(CommonCartridgeConstants.PARAM_ITEM_INDEX));

short type = item.getType();
String url = null;
switch (type) {
    case CommonCartridgeConstants.RESOURCE_TYPE_BASIC_LTI:
	if (item.isOpenUrlNewWindow()) {
	    url = "/openUrlPopup.do?";
	} else {
	    url = "/launchBasicLTI.do?";
	}
	if (CommonCartridgeConstants.MODE_AUTHOR_SESSION.equals(mode)) {
	    url += AttributeNames.ATTR_MODE + "=" + mode + "&" + CommonCartridgeConstants.PARAM_ITEM_INDEX + "="
		    + itemIdx + "&" + CommonCartridgeConstants.ATTR_SESSION_MAP_ID + "=" + sessionMapID;
	} else {
	    url += CommonCartridgeConstants.PARAM_RESOURCE_ITEM_UID + "=" + item.getUid() + "&"
		    + CommonCartridgeConstants.ATTR_SESSION_MAP_ID + "=" + sessionMapID;
	}

	break;
    case CommonCartridgeConstants.RESOURCE_TYPE_COMMON_CARTRIDGE:
	url = "/download/?uuid=" + item.getFileUuid() + "&preferDownload=false";
	break;
}
request.setAttribute(CommonCartridgeConstants.ATTR_RESOURCE_REVIEW_URL, url);

// these attribute will be use to instruction navigator page
request.setAttribute(AttributeNames.ATTR_MODE, mode);
request.setAttribute(CommonCartridgeConstants.PARAM_ITEM_INDEX, itemIdx);
Long itemUid = NumberUtils.createLong(request.getParameter(CommonCartridgeConstants.PARAM_RESOURCE_ITEM_UID));
request.setAttribute(CommonCartridgeConstants.PARAM_RESOURCE_ITEM_UID, itemUid);
request.setAttribute(CommonCartridgeConstants.ATTR_TOOL_SESSION_ID, sessionId);
request.setAttribute(CommonCartridgeConstants.ATTR_SESSION_MAP_ID, sessionMapID);

return "pages/itemreview/mainframe";

   }
 
Example 7
Source File: LearningController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Record in DB that leader has scratched specified answer. And return whether scratchie answer is correct or not.
    */
   @RequestMapping("/recordItemScratched")
   @ResponseStatus(HttpStatus.OK)
   private void recordItemScratched(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ScratchieApplicationException {
String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
final Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID);
final Long answerUid = NumberUtils.createLong(request.getParameter(ScratchieConstants.PARAM_ANSWER_UID));

ScratchieSession toolSession = scratchieService.getScratchieSessionBySessionId(toolSessionId);

ScratchieUser leader = getCurrentUser(toolSessionId);
// only leader is allowed to scratch answers
if (!toolSession.isUserGroupLeader(leader.getUid())) {
    return;
}

// check answer is belong to current session
Set<Long> answerUids = (Set<Long>) sessionMap.get(ScratchieConstants.ATTR_ANSWER_UIDS);
if (!answerUids.contains(answerUid)) {
    return;
}

// Return whether scratchie answer is correct or not
ScratchieAnswer answer = scratchieService.getScratchieAnswerByUid(answerUid);
if (answer == null) {
    return;
}

ObjectNode ObjectNode = JsonNodeFactory.instance.objectNode();
ObjectNode.put(ScratchieConstants.ATTR_ANSWER_CORRECT, answer.isCorrect());
response.setContentType("application/json;charset=utf-8");
response.getWriter().print(ObjectNode);

// create a new thread to record item scratched (in order to do this task in parallel not to slow down sending
// response back)
Thread recordItemScratchedThread = new Thread(new Runnable() {
    @Override
    public void run() {
	scratchieService.recordItemScratched(toolSessionId, answerUid);
    }
}, "LAMS_recordItemScratched_thread");
recordItemScratchedThread.start();
   }