Example usage for com.mongodb DBObject put

List of usage examples for com.mongodb DBObject put

Introduction

In this page you can find the example usage for com.mongodb DBObject put.

Prototype

Object put(String key, Object v);

Source Link

Document

Sets a name/value pair in this object.

Usage

From source file:com.cc.manage.logic.BcompanyapplyLogic.java

/**
 * ?/*from   w  ww  .j a v a  2  s.com*/
 * 
 * @param request
 */
public String check(HttpServletRequest request) {
    String data = RequestUtils.getString(request, "param");

    DBObject updateBean = new BasicDBObject();
    if (StringUtils.isNotBlank(data)) {
        JSONObject jsonBean = JSONObject.fromObject(data);
        String flowno = (String) jsonBean.get("flowno");
        String type = JSONUtils.getString(jsonBean, "type");

        if (AuditKey.AGREE_TYPE.equals(type)) {// ??
            DBObject queryBean = new BasicDBObject();
            queryBean.put("flowid", flowno);
            updateBean.put("state", StateConstant.B_COMPANY_APPLY_STATE1);// ??
            companyapplyDao.update(queryBean, updateBean);
            HistoryUtils.saveHistory("", request, "b_companyapply", queryBean);
            // ??
            List<DBObject> dbobject = companyapplyDao.find(TableNameConstant.T_COMPANY_APPLY, queryBean);
            DBObject object = dbobject.get(0);
            // ??
            object.put("companyno", String.valueOf(System.nanoTime()));
            DBObject stateBean = new BasicDBObject();
            stateBean.put("frame", StateConstant.B_COMPANY_UNALLOCAT);
            stateBean.put("role", StateConstant.B_COMPANY_UNALLOCAT);
            stateBean.put("product", StateConstant.B_COMPANY_UNALLOCAT);
            stateBean.put("companycc", StateConstant.B_COMPANY_UNALLOCAT);
            object.put("state", stateBean);
            object.removeField("_id");
            object.removeField("history");
            companyDao.add(object);
            HistoryUtils.saveHistory(object.get("history"), request, TableNameConstant.T_COMPANY,
                    new BasicDBObject());
        }
        JSONObject userSession = JSONObject
                .fromObject(request.getSession().getAttribute(SessionKey.SESSION_KEY_USER));
        if (userSession == null) {
            return ResultConstant.FAIL;
        }
        String uuid = JSONUtils.getString(userSession, "uuid"); // ?uuid
        jsonBean.put("uuid", uuid);

        AuditUtils.AuditRegister(jsonBean.toString());
        // ?
        return ResultConstant.SUCCESS;
    }
    return ResultConstant.FAIL;
}

From source file:com.cc.manage.logic.BcompanyapplyLogic.java

public String getSchedule(HttpServletRequest request) {
    JSONObject userSession = JSONObject//from   w  w  w .  j a v a 2  s.c om
            .fromObject(request.getSession().getAttribute(SessionKey.SESSION_KEY_USER));
    String uuid = JSONUtils.getString(userSession, "uuid");
    String companyno = JSONUtils.getString(userSession, "companyno"); // ???

    String map = "function(){emit(this.actno,{count:1})}";

    String reduce = "function(key,emits){ total=0; for(var i in emits){ total+=1;  } return {count:total,size:emits.length,key:key}; }";

    DBObject conditionBean = new BasicDBObject();

    JSONObject jo = new JSONObject();
    jo.put("uuid", uuid);
    jo.put("state", "0");

    JSONObject elemMatch = new JSONObject();
    elemMatch.put("$elemMatch", jo);
    conditionBean.put("flows", elemMatch);

    JSONArray json = commonDaoImpl.mapReduceCommon("p_flow", map, reduce, conditionBean);

    // ip?
    String address = CommonUtils.getIpAddress(companyno);
    // ??
    String resultBean = businessService.getSchedule(json.toString(), address);
    if (resultBean != null) {
        resultBean = AplicationKeyConstant.CHARACTER_BIG_LEFT + resultBean
                + AplicationKeyConstant.CHARACTER_BIG_right;
    }
    return resultBean;
}

From source file:com.cc.manage.logic.BcompanyapplyLogic.java

public String scheduleList(HttpServletRequest request) {
    JSONObject userSession = JSONObject//www. j  av  a2s. co  m
            .fromObject(request.getSession().getAttribute(SessionKey.SESSION_KEY_USER));
    if (userSession == null) {
        return ResultConstant.FAIL;
    }

    String companyno = JSONUtils.getString(userSession, "companyno"); // ???
    // ip?
    String address = CommonUtils.getIpAddress(companyno);

    String actno = RequestUtils.getString(request, "actno");

    DBObject conditionBean = new BasicDBObject();
    conditionBean.put("actno", actno);
    conditionBean.put("state", StateConstant.B_COMPANY_APPLY_STATE0);
    Object obj = commonDaoImpl.searchCommon(TableNameConstant.T_FLOW, conditionBean);
    String resultBean = null;
    if (!CollectionUtils.isEmpty(obj.toString())) {
        // ??
        resultBean = businessService.scheduleList(obj.toString(), actno, address);
        if (StringUtils.isNotBlank(resultBean)) {
            resultBean = AplicationKeyConstant.CHARACTER_BIG_LEFT + resultBean
                    + AplicationKeyConstant.CHARACTER_BIG_right;
        }
        return resultBean;

    }
    return resultBean;
}

From source file:com.cedac.security.acls.mongo.MongoMutableAclService.java

License:Apache License

@Override
public MutableAcl updateAcl(MutableAcl acl) throws NotFoundException {
    Assert.notNull(acl.getId(), "Object Identity doesn't provide an identifier");

    DBObject persistedAcl = getAclCollection().findOne(queryByObjectIdentity(acl.getObjectIdentity()));

    if (persistedAcl == null) {
        LOG.trace(ACL, "No ACL found for object identity {}", acl.getObjectIdentity());

        throw new NotFoundException("No acl found for object identity " + acl.getObjectIdentity());
    }/*  ww  w  .j  a v a 2 s. c om*/

    LOG.debug(ACL, "Updating persisted ACL object");

    if (acl.getParentAcl() != null) {
        ObjectIdentity parentOid = acl.getParentAcl().getObjectIdentity();
        persistedAcl.put(parentObjectFieldName, toDBObject(parentOid));
    }

    persistedAcl.put(ownerFieldName, toDBObject(acl.getOwner()));
    persistedAcl.put(entriesInheritingFieldName, acl.isEntriesInheriting());

    BasicDBList list = new BasicDBList();
    for (AccessControlEntry entry : acl.getEntries()) {
        list.add(toDBObject(entry));
    }
    persistedAcl.put(entriesFieldName, list);

    getAclCollection().save(persistedAcl, writeConcern);

    LOG.trace(ACL, "Clearing cache including children for object identity {}", acl.getObjectIdentity());

    clearCacheIncludingChildren(acl.getObjectIdentity());

    LOG.trace(ACL, "Retrieve ACL via superclass.");

    return (MutableAcl) super.readAclById(acl.getObjectIdentity());
}

From source file:com.cedac.security.oauth2.provider.approval.MongoApprovalStore.java

License:Apache License

@Override
public boolean addApprovals(final Collection<Approval> approvals) {
    LOG.debug(APPROVAL, "Adding approvals: {}", approvals);

    boolean success = true;
    for (Approval approval : approvals) {
        DBObject query = new BasicDBObject(userIdFieldName, approval.getUserId())
                .append(clientIdFieldName, approval.getClientId()).append(scopeFieldName, approval.getScope());
        DBObject obj = getApprovalsCollection().findOne(query);
        if (obj == null) {
            obj = new BasicDBObject(userIdFieldName, approval.getUserId())
                    .append(clientIdFieldName, approval.getClientId())
                    .append(scopeFieldName, approval.getScope());
        }//from ww  w . j  av a 2  s .  c  o m
        obj.put(statusFieldName, approval.getStatus().name());
        obj.put(expiresAtFieldName, approval.getExpiresAt());
        obj.put(lastModifiedAtFieldName, approval.getLastUpdatedAt());

        LOG.trace(APPROVAL, "Saving approval {}", obj);

        WriteResult result = getApprovalsCollection().save(obj, writeConcern);

        LOG.trace(APPROVAL, "Approval save result is {}", result);

        success = success && result.getN() == 1;
    }
    return success;
}

From source file:com.cedac.security.oauth2.provider.approval.MongoApprovalStore.java

License:Apache License

@Override
public boolean revokeApprovals(Collection<Approval> approvals) {
    LOG.debug("Revoking approvals: {}", approvals);

    boolean success = true;
    for (Approval approval : approvals) {
        DBObject query = new BasicDBObject(userIdFieldName, approval.getUserId())
                .append(clientIdFieldName, approval.getClientId()).append(scopeFieldName, approval.getScope());
        DBObject result = getApprovalsCollection().findOne(query);
        if (result != null) {
            WriteResult writeResult;/* ww  w .j  a v  a2 s . co  m*/
            if (handleRevocationsAsExpiry) {
                LOG.trace(APPROVAL, "Handling revocation as expiry: updating approval {} field",
                        expiresAtFieldName);

                result.put(expiresAtFieldName, new Date());
                writeResult = getApprovalsCollection().save(result, writeConcern);
            } else {
                LOG.trace(APPROVAL, "Handling revocation as delete: removing approval {}", result);

                writeResult = getApprovalsCollection().remove(result, writeConcern);
            }
            success = success && writeResult.getN() == 1;
        } else {
            LOG.debug(APPROVAL, "No approval found for sample {}", query);
            success = false;
        }
    }
    return success;
}

From source file:com.cedac.security.oauth2.provider.client.MongoClientDetailsService.java

License:Apache License

public void updateClientSecret(String clientId, String secret) throws NoSuchClientException {
    DBObject query = new BasicDBObject(clientIdFieldName, clientId);
    DBObject entry = getClientDetailsCollection().findOne(query);
    if (entry != null) {
        entry.put(clientSecretFieldName, passwordEncoder.encode(secret));
        getClientDetailsCollection().save(entry, writeConcern);
    } else {/*from w ww  .j  a va 2  s . c o m*/
        throw new NoSuchClientException("No client found with id = " + clientId);
    }
}

From source file:com.cedac.security.oauth2.provider.client.MongoClientDetailsService.java

License:Apache License

private void updateDBObject(DBObject dbo, ClientDetails clientDetails) {
    dbo.put(resourceIdsFieldName, clientDetails.getResourceIds());
    dbo.put(scopeFieldName, clientDetails.getScope());
    dbo.put(authorizedGrantTypesFieldName, clientDetails.getAuthorizedGrantTypes());
    dbo.put(registeredRedirectUrisFieldName, clientDetails.getRegisteredRedirectUri());
    dbo.put(authoritiesFieldName, AuthorityUtils.authorityListToSet(clientDetails.getAuthorities()));
    dbo.put(accessTokenValidityFieldName, clientDetails.getAccessTokenValiditySeconds());
    dbo.put(refreshTokenValidityFieldName, clientDetails.getRefreshTokenValiditySeconds());
    dbo.put(additionalInformationFieldName, clientDetails.getAdditionalInformation());
    Set<String> autoApprove = new HashSet<String>();
    for (String scope : clientDetails.getScope()) {
        if (clientDetails.isAutoApprove(scope)) {
            autoApprove.add(scope);//from  w  ww.  j  a  v  a2s .c  om
        }
    }
    dbo.put(autoApproveFieldName, autoApprove.size() == 1 ? autoApprove.iterator().next() : autoApprove);
}

From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java

License:Apache License

public void storeAccessToken(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
    String refreshToken = null;/*from   w w  w .  j a v  a2  s.co  m*/
    if (accessToken.getRefreshToken() != null) {
        refreshToken = accessToken.getRefreshToken().getValue();
    }

    if (readAccessToken(accessToken.getValue()) != null) {
        removeAccessToken(accessToken.getValue());
    }

    DBObject token = new BasicDBObject();
    token.put(tokenIdFieldName, extractTokenKey(accessToken.getValue()));
    token.put(tokenFieldName, serializeAccessToken(accessToken));
    token.put(authenticationIdFieldName, authenticationKeyGenerator.extractKey(authentication));
    if (!authentication.isClientOnly()) {
        token.put(usernameFieldName, authentication.getName());
    } else {
        token.put(usernameFieldName, null);
    }
    token.put(clientIdFieldName, authentication.getOAuth2Request().getClientId());
    token.put(authenticationFieldName, serializeAuthentication(authentication));
    token.put(refreshTokenFieldName, extractTokenKey(refreshToken));

    getAccessTokenCollection().insert(token, writeConcern);
}

From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java

License:Apache License

public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) {
    DBObject token = new BasicDBObject();
    token.put(tokenIdFieldName, extractTokenKey(refreshToken.getValue()));
    token.put(tokenFieldName, serializeRefreshToken(refreshToken));
    token.put(authenticationFieldName, serializeAuthentication(authentication));

    getRefreshTokenCollection().insert(token, writeConcern);
}