Example usage for java.lang Long intValue

List of usage examples for java.lang Long intValue

Introduction

In this page you can find the example usage for java.lang Long intValue.

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Long as an int after a narrowing primitive conversion.

Usage

From source file:gr.abiss.calipso.hibernate.HibernateDao.java

@Override
public int loadCountOfHistoryInvolvingUser(User user) {
    Long count = (Long) getHibernateTemplate().find("select count(history) from History history where "
            + " history.loggedBy = ? or history.assignedTo = ?", new Object[] { user, user }).get(0);
    return count.intValue();
}

From source file:gr.abiss.calipso.hibernate.HibernateDao.java

@Override
public int loadCountUnassignedItemsForSpace(Space space) {
    Long count = (Long) getHibernateTemplate()
            .find("select count(item) from Item item where item.space.id=? and item.assignedTo is null",
                    space.getId())//from  w  w w.j a  va2  s.  co m
            .get(0);
    return count.intValue();
}

From source file:gr.abiss.calipso.hibernate.HibernateDao.java

/**
 * Counts records for a given Custom Attribute. 
 * *//*from   w  ww  .java  2 s .co m*/
@Override
public int loadCountAssetsForCustomAttribute(AssetTypeCustomAttribute customAttribute) {
    Long count = (Long) getHibernateTemplate().find(
            "select count(*) from AssetTypeCustomAttribute atca join atca.assetTypes at join at.assets a where atca.id =?",
            customAttribute.getId()).get(0);
    return count.intValue();
}

From source file:org.geoserver.geofence.gui.server.service.impl.RulesManagerServiceImpl.java

public PagingLoadResult<RuleModel> getRules(int offset, int limit, boolean full) throws ApplicationException {
    int start = offset;

    List<RuleModel> ruleListDTO = new ArrayList<RuleModel>();

    long rulesCount = geofenceRemoteService.getRuleAdminService().getCountAll();

    Long t = new Long(rulesCount);

    int page = (start == 0) ? start : (start / limit);

    RuleFilter any = new RuleFilter(SpecialFilterType.ANY);
    List<ShortRule> rulesList = geofenceRemoteService.getRuleAdminService().getList(any, page, limit);

    if (rulesList == null) {
        if (logger.isErrorEnabled()) {
            logger.error("No rule found on server");
        }// w w  w.  j a  va 2s .c  om
        throw new ApplicationException("No rule found on server");
    }

    Iterator<ShortRule> it = rulesList.iterator();

    while (it.hasNext()) {
        ShortRule shortRule = it.next();

        Rule fullRule;
        try {
            fullRule = geofenceRemoteService.getRuleAdminService().get(shortRule.getId());
        } catch (NotFoundServiceEx e) {
            if (logger.isErrorEnabled()) {
                logger.error("Details for rule " + shortRule.getPriority() + " not found on Server!");
            }
            throw new ApplicationException(
                    "Details for profile " + shortRule.getPriority() + " not found on Server!");
        }

        RuleModel ruleDTO = new RuleModel();

        ruleDTO.setId(shortRule.getId());
        ruleDTO.setPriority(fullRule.getPriority());

        ruleDTO.setUsername(fullRule.getUsername() == null ? "*" : fullRule.getUsername());
        ruleDTO.setRolename(fullRule.getRolename() == null ? "*" : fullRule.getRolename());

        if (fullRule.getInstance() == null) {
            GSInstanceModel all = new GSInstanceModel();
            all.setId(-1);
            all.setName("*");
            all.setBaseURL("*");
        } else {
            org.geoserver.geofence.core.model.GSInstance remote_instance = fullRule.getInstance();
            GSInstanceModel local_instance = new GSInstanceModel();
            local_instance.setId(remote_instance.getId());
            local_instance.setName(remote_instance.getName());
            local_instance.setBaseURL(remote_instance.getBaseURL());
            local_instance.setUsername(remote_instance.getUsername());
            local_instance.setPassword(remote_instance.getPassword());
            ruleDTO.setInstance(local_instance);
        }

        ruleDTO.setSourceIPRange(
                fullRule.getAddressRange() != null ? fullRule.getAddressRange().getCidrSignature() : "*");

        ruleDTO.setService((fullRule.getService() != null) ? fullRule.getService() : "*");

        ruleDTO.setRequest((fullRule.getRequest() != null) ? fullRule.getRequest() : "*");

        ruleDTO.setWorkspace((fullRule.getWorkspace() != null) ? fullRule.getWorkspace() : "*");

        ruleDTO.setLayer((fullRule.getLayer() != null) ? fullRule.getLayer() : "*");

        ruleDTO.setGrant((fullRule.getAccess() != null) ? fullRule.getAccess().toString() : "ALLOW");

        ruleListDTO.add(ruleDTO);
    }

    return new RpcPageLoadResult<RuleModel>(ruleListDTO, offset, t.intValue());
}

From source file:com.kodemore.utility.Kmu.java

/**
 * Cast an object to an integer./* ww w .java  2  s .  com*/
 * Null => null.
 * Integer => Integer
 * Long => Integer, iff in Integer range.
 * Otherwise throw an unchecked exception.
 */
public static Integer toInteger(Object e) {
    if (e == null)
        return null;

    if (e instanceof Integer)
        return (Integer) e;

    if (e instanceof Long) {
        Long j = (Long) e;
        if (j >= Integer.MIN_VALUE && j <= Integer.MAX_VALUE)
            return j.intValue();

        throw new RuntimeException("Long out of range: " + j);
    }

    throw new RuntimeException("Invalid type: " + e.getClass().getName());
}

From source file:gr.abiss.calipso.hibernate.HibernateDao.java

/**
 * Check how many times the given option value has been used.
 *//*from   w  w  w.  j  av  a  2  s .  co  m*/
@Override
public int loadCountForCustomAttributeLookupValue(CustomAttributeLookupValue lookupValue) {
    //Long count = (Long) getHibernateTemplate().find("select count(*) from AssetCustomAttributeValue acav where acav.attributeValue = ?", String.valueOf(lookupValue.getId())).get(0);
    Long count = (Long) getHibernateTemplate().find(
            "select count(asset) from Asset asset left join asset.customAttributes as customAttribute where customAttribute=?",
            String.valueOf(lookupValue.getId())).get(0);
    return count.intValue();
}

From source file:gr.abiss.calipso.hibernate.HibernateDao.java

@Override
public int loadCountSpacesForInforamaDocument(InforamaDocument inforamaDocument) {
    Long count = (Long) getHibernateTemplate().find(
            "select count(space) from Space space, InforamaDocument inforamaDocument where space in elements (inforamaDocument.spaces) and inforamaDocument.id=?",
            inforamaDocument.getId()).get(0);

    return count.intValue();
}

From source file:gr.abiss.calipso.hibernate.HibernateDao.java

/**
* Counts records for a given Asset Type and a Custom Attribute
* *//*from   ww  w  .  j a v  a2s . com*/
@Override
public int loadCountForAssetTypeAndCustomAttribute(AssetType assetType, CustomAttribute customAttribute) {
    //Long count = (Long) getHibernateTemplate()
    //      .find("select count(*) from AssetCustomAttributeValue acav join acav.asset a where a.assetType.id = ? and acav.customAttribute.id = ?",
    //            new Object[] { assetType.getId(),
    //                  customAttribute.getId() }).get(0);
    Long count = (Long) getHibernateTemplate().find(
            "select count(asset) from Asset asset left join asset.customAttributes as customAttribute where asset.assetType = ? and index(customAttribute) = ?",
            new Object[] { assetType, customAttribute }).get(0);
    return count.intValue();
}

From source file:com.mmj.app.web.controller.comments.CommentsController.java

@RequestMapping(value = "/comments/create")
public ModelAndView create(Long linkId, Long parentId, String jid, String isAssent, String content,
        String sortType) {//  ww w.ja va2s . c o  m
    if (WebUserTools.getIsBan()) {
        return createJsonMav("-1", "???", "");
    }
    // if (StringUtils.isEmpty(WebUserTools.getPhone())) {
    // return createJsonMav("-1", "?????~", "");
    // }
    // ?
    if (Argument.isNotPositive(linkId) || StringUtils.isEmpty(content)) {
        return createJsonMav("10008", "?", "");
    }
    float titleSize = StringFormatter.getWordSize(content);
    if (titleSize > 150) {
        return createJsonMav("30003",
                "???," + (titleSize - 150) + "", "");
    }
    if (Argument.isNotPositive(parentId)) {
        parentId = 0l;
    }
    TopicDO topicDO = topicService.getTopicById(linkId);
    if (topicDO == null) {
        return createJsonMav("10008", "?", "");
    }
    if (NumberParser.isEqual(topicDO.getIsBan(), 1)) {
        return createJsonMav("10008", "??????", "");
    }
    CommentsDO parentComments = null;
    if (!Argument.isNotPositive(parentId)) {
        parentComments = commentsService.getCommentsById(parentId);
        if (parentComments == null) {
            return createJsonMav("49998", "???", "");
        }
        if (NumberParser.isEqual(parentComments.getIsBan(), 1)) {
            return createJsonMav("10008", "??????", "");
        }
    }
    // 
    CommentsDO comments = new CommentsDO(WebUserTools.getUid(), parentId, linkId, content,
            WebUserTools.getName());
    if (parentComments != null) {
        comments.setDepth(parentComments.getDepth() + 1);
    }
    // ?
    commentsService.add(comments);
    // 
    topicService.update(new TopicDO(linkId, topicDO.getComments() + 1));
    // ??
    CommentsQuery commentsQuery = new CommentsQuery();
    commentsQuery.getT().setId(comments.getId());
    List<CommentsFullDO> fullList = commentsService.commentsListPagination(commentsQuery);
    if (Argument.isEmpty(fullList)) {
        return createJsonMav("10008", "?", "");
    }
    initUserInfo4List(fullList);

    CommentsFullDO commentsFull = fullList.get(0);
    CommentsItemVO commentsItem = new CommentsItemVO(commentsFull, parentComments);
    commentsItem.setJid(WebUserTools.getName());
    commentsItem.setNick(WebUserTools.getNick());
    commentsItem.setNickImgUrl(WebUserTools.getImg());
    commentsItem.setPhoneBan(false);
    commentsItem.setPhoneNum("+86" + WebUserTools.getPhone());
    commentsItem.setIsVote(1);

    // 
    Integer count = commentsService.count(new CommentsQuery(null, linkId));
    commentsItem.setItems(count);

    // 
    MemberDO memberDO = userService.getMemberById(WebUserTools.getUid());
    userService.update(new MemberDO(memberDO.getId(), memberDO.getIntegral() + 1));

    // ??
    // ?
    NotificationDO notification = new NotificationDO();
    notification.setActionUserId(WebUserTools.getUid());
    notification.setUnRead(1);
    notification.setNotificationAction(linkId.intValue());
    notification.setLinkId(topicDO.getId());
    notification.setCommentsId(comments.getId());
    if (parentComments != null) {
        Integer trunComment = memberDO.getTrunComment();
        if (NumberParser.isEqual(trunComment, 0)
                && !NumberParser.isEqual(WebUserTools.getUid(), parentComments.getUserId())) {
            notification.setUserId(parentComments.getUserId());
            notification.setContent(comments.getContent());
            notification.setNotificationType(3);
        }
    }
    // ?
    else {
        Integer trunReply = memberDO.getTrunReply();
        if (NumberParser.isEqual(trunReply, 0)
                && !NumberParser.isEqual(WebUserTools.getUid(), topicDO.getUserId())) {
            notification.setUserId(topicDO.getUserId());
            notification.setContent(topicDO.getTitle());
            notification.setNotificationType(2);
        }
    }
    letterService.add(notification);

    return createJsonMav("9999", "??", commentsItem);
}

From source file:com.visionet.platform.cooperation.service.OrderService.java

/**
 * ????//  w w  w . j av  a  2 s . c  o m
 * @param orderNo
 * @param partnerOrderNo
 * @param driverId
 * @param sign
 * @param channel
 */
public void usingTheDriver(String orderNo, String partnerOrderNo, Integer driverId, String sign,
        String channel) {

    if (StringUtils.isBlank(orderNo)) {
        throw new BizException("???");
    }
    if (StringUtils.isBlank(partnerOrderNo)) {
        throw new BizException("????");
    }
    if (driverId == null) {
        throw new BizException("?ID?");
    }
    String data = RedisUtil.getData("RETURN_CODE_ERROR_" + orderNo);
    if (StringUtils.isNotBlank(data)) {
        throw new BizException("???");
    }
    CarUser carUser = carUserMapper.selectByPrimaryKey(driverId);
    if (carUser == null) {
        throw new BizException("??");
    }
    Order order = orderMapper.selectByPrimaryKey(orderNo);
    if (order == null) {
        throw new BizException("??");
    }
    Date bookDate = order.getBookDate();
    Long seconds = 24 * 60 * 60l;
    if (bookDate != null) {
        seconds = (bookDate.getTime() - System.currentTimeMillis()) / 1000;
        seconds += 4 * 60 * 60;
    }
    Order parameterOrder = new Order();
    parameterOrder.setOrderId(orderNo);
    parameterOrder.setCarId(driverId);
    parameterOrder.setBusinessType(carUser.getBusinessType());
    parameterOrder.setOrderType(6);//?(0.app1.allcenter2.app3.callcenter4.??5.?6.)
    parameterOrder.setOrderSource(4);//???0 android1 IOS2 wechat3 callcenter4 
    //        parameterOrder.setCarType(carUser.getCarType() + "");
    parameterOrder.setCarUserPhone(carUser.getPhone());
    parameterOrder.setCarUserName(carUser.getName());
    parameterOrder.setStatus(1);//?01?2?3? ......
    parameterOrder.setUpdateDate(new Date());
    parameterOrder.setOrderStartDate(new Date());
    int i = orderMapper.updateByPrimaryKeySelective(parameterOrder);
    if (i != 1) {
        throw new BizException("?");
    }

    //????
    OrderStatusTracking orderStatusTracking = new OrderStatusTracking();
    orderStatusTracking.setOrderId(orderNo);
    orderStatusTracking.setCarUserPhone(carUser.getPhone());
    orderStatusTracking.setCustomerPhone(order.getCustomerPhone());
    orderStatusTracking.setBusinessType(order.getBusinessType());
    orderStatusTracking.setPreStatus(order.getStatus());
    orderStatusTracking.setNewStatus(1);
    orderStatusTracking.setCreateDate(new Date());
    orderStatusTracking.setOperator(4);//?01?2?? 3??4
    int i1 = orderStatusTrackingMapper.insertSelective(orderStatusTracking);
    if (i1 != 1) {
        throw new BizException("????");
    }
    ThirdPartyOrder thirdPartyOrder = thirdPartyOrderMapper.selectByOrderIdAndPartnerOrderNo(orderNo,
            partnerOrderNo);
    thirdPartyOrder.setDriverInfoNoticeCallBack(1);
    thirdPartyOrder.setDriverId(driverId);
    thirdPartyOrderMapper.updateByPrimaryKey(thirdPartyOrder);
    RedisUtil.setData(Constants.SQORDER_DZCAR_ + orderNo, driverId + "", seconds.intValue());
}