⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genericreplicator.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

        ;

        if ((userPartyId == null) || userPartyId.equals("")) {
            Debug.logError(
                "[register] userPartyId is required.  Registration canceled.", module);

            return "";
        }

        ;

        String replNodeId = getNextSeqId("ReplNodeId", getMasterDelegator());

        if ((replNodeId == null) || replNodeId.equals("")) {
            Debug.logError(
                "GenericReplicator.register] Could not get a new node ID.  Registration canceled.", module);

            return "";
        }

        ;

        // Create a new record in the ReplNode table in the master data base.
        Timestamp now = new Timestamp(Calendar.getInstance().getTime().getTime());
        ModelEntity replNodeME = getMasterDelegator().getModelEntity("ReplNode");
        GenericValue replNodeGV = new GenericValue(replNodeME);
        replNodeGV.setDelegator(getMasterDelegator());
        replNodeGV.set("replNodeId", replNodeId);
        replNodeGV.set("replNodeName", replNodeName);
        replNodeGV.set("ownerId", ownerId);
        replNodeGV.set("isActive", new Boolean(isActive));
        replNodeGV.set("createdDate", now);
        replNodeGV.set("createdBy", userPartyId);
        replNodeGV.set("modifiedDate", now);
        replNodeGV.set("modifiedBy", userPartyId);

        try {
            Debug.logVerbose("[register] About to create ReplNode record in master data base.", module);

            Vector gvv = new Vector();
            gvv.add(replNodeGV);
            getMasterDelegator().storeAll(gvv);

            Debug.logVerbose(
                    "[register] Successfully created ReplNode record " +
                    "in master data base.", module);
        } catch (Exception e) {
            Debug.logError("register] Error creating ReplNode " +
                "record in master data base: " + e.getLocalizedMessage() +
                "  Registration canceled.", module);

            return "";
        }

        // Store the new node ID in the system parameters on the local data base.
        ModelEntity codeME = getLocalDelegator().getModelEntity("Code");
        GenericValue codeGV = new GenericValue(codeME);
        codeGV.setDelegator(getLocalDelegator());
        codeGV.set("codeTypeId", "SYSTEM_PARAMETER");
        codeGV.set("codeId", "REPL_NODE_ID");
        codeGV.set("codeValue", replNodeId);
        codeGV.set("createdDate", now);
        codeGV.set("createdBy", userPartyId);
        codeGV.set("modifiedDate", now);
        codeGV.set("modifiedBy", userPartyId);

        try {
            Debug.logVerbose("[register] About to create Code record in local data base.", module);

            Vector gvv = new Vector();
            gvv.add(codeGV);
            getLocalDelegator().storeAll(gvv);

            Debug.logVerbose("[register] Successfully created Code record in local data base.", module);
        } catch (Exception e) {
            Debug.logError("GenericReplicator.register] Error storing Code " +
                "record in local data base: " + e.getLocalizedMessage() +
                "  Registration canceled.", module);

            return "";
        }

        return replNodeId;
    }

    /**
     * This method updates the node record in the master data base to indicate that a successful
     * replication has been completed.
     *
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     *
     * @param masterDelegator Delegator to connect to the master data base
     * @param replNodeId Replication Node ID
     * @param userPartyId The Party ID of the current user
     *
     * @return The status of the replication.  Possible values: STATUS_CONTINUE, STATUS_ERROR,
     *   STATUS_CANCEL
     */
    public int markNodeReplicated(String replNodeId, String userPartyId) {

        if (getMasterDelegator() == null) {
            Debug.logError("[markNodeReplicated] Master delegator is required.", module);

            return STATUS_ERROR;
        }

        ;

        if ((replNodeId == null) || replNodeId.equals("")) {
            Debug.logError("[markNodeReplicated] Node ID is required.", module);

            return STATUS_ERROR;
        }

        ;

        if ((userPartyId == null) || userPartyId.equals("")) {
            Debug.logError("[markNodeReplicated] User Party ID is required.", module);

            return STATUS_ERROR;
        }

        ;

        // Update the node record in the master data base.
        Timestamp now = new Timestamp(Calendar.getInstance().getTime().getTime());
        GenericValue replNodeGV = getReplNodeGenericValue(replNodeId);
        replNodeGV.setDelegator(getMasterDelegator());
        replNodeGV.set("isActive", new Boolean(true));
        replNodeGV.set("lastUpdatedDate", now);
        replNodeGV.set("lastUpdatedBy", userPartyId);
        replNodeGV.set("modifiedDate", now);
        replNodeGV.set("modifiedBy", userPartyId);

        try {

            Debug.logVerbose("[markNodeReplicated] About to update " +
                    "ReplNode record in master data base.", module);

            Vector gvv = new Vector();
            gvv.add(replNodeGV);
            getMasterDelegator().storeAll(gvv);


            Debug.logVerbose("[markNodeReplicated] Successfully updated " +
                    "ReplNode record in master data base.", module);
        } catch (Exception e) {
            Debug.logError("[markNodeReplicated] Error updating ReplNode " +
                "record in master data base: " + e.getLocalizedMessage(), module);

            return STATUS_ERROR;
        }

        return STATUS_CONTINUE;
    }

    /** Gets the next guaranteed unique seq id from the sequence with the given sequence name.
     * if the named sequence doesn't exist, it will be created.  If the local computer is
     * registered as a replicated node, its node ID will be prepended onto the sequence to
     * ensure uniqueness across all nodes.
     *
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     *
     * @param seqName The name of the sequence to get the next seq id from
     *
     * @return The next sequence id for the given sequence name, with the replication node ID
     *   prepended if it exists.
     */
    public static String getNextSeqId(String seqName, GenericDelegator delegator) {

        // Get the sequence number the regular way and convert to a string.
        String seqId = String.valueOf(delegator.getNextSeqId(seqName));

        // See if this computer is registered as a replicated node.  If so, prepend the node ID
        // onto the sequence ID.
        String replNodeId = getReplNodeId(delegator);

        if ((replNodeId != null) && !replNodeId.equals("")) {
            Debug.logVerbose("[getNextSeqId] Node is registered.  " +
                    "Prepending node ID onto sequence number.", module);

            seqId = replNodeId + "." + seqId;
        }

        Debug.logVerbose("[getNextSeqId] Sequence ID: " + seqId, module);

        return seqId;
    }

    /**
     * Looks in the master data base for the given login ID and password
     *
     * Requires that the masterDelegator argument passed to the constructor is valid.
     * Alternatively, requires the setMasterDelegator method to have been called.
     *
     * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
     *
     * @return Status.  Possible values: STATUS_CONTINUE (Login ID and password are valid),
     *   STATUS_CANCEL (ID or password is not correct), or STATUS_ERROR.
     */
    public String validateMasterLogin(String enteredUserLoginId,
        String enteredPassword, UserInfo masterUserInfo) {

        String errorMessage = "";

        Debug.logVerbose("[validateMasterLogin] enteredUserLoginId: " +
                enteredUserLoginId, module);
        Debug.logVerbose("[validateMasterLogin] enteredPassword: " +
                enteredPassword, module);

        if ((enteredUserLoginId == null) || enteredUserLoginId.equals("")) {
            errorMessage = "User ID is required.";
            Debug.logError("[validateMasterLogin] " + errorMessage, module);

            return errorMessage;
        }

        ;

        if ((enteredPassword == null) || enteredPassword.equals("")) {
            errorMessage = "Password is required.";
            Debug.logError("[validateMasterLogin] " + errorMessage, module);

            return errorMessage;
        }

        ;

        if (getMasterDelegator() == null) {
            errorMessage = "Master delegator is required.";
            Debug.logError("[validateMasterLogin] " + errorMessage, module);

            return errorMessage;
        }

        ;

        HashMap userLoginSearchMap = new HashMap();
        userLoginSearchMap.put("userLoginId", enteredUserLoginId);

        try {
            List userLoginGVL = getMasterDelegator().findByAnd("UserLogin",
                    userLoginSearchMap);
            Iterator userLoginGVI = userLoginGVL.iterator();

            if (userLoginGVI.hasNext()) {
                GenericValue userLoginGV = (GenericValue) userLoginGVI.next();
                String currentPassword = userLoginGV.getString(
                        "currentPassword");

                if (enteredPassword.equals(currentPassword)) {
                    // Login successful.
                    String partyId = userLoginGV.getString("partyId");

                    if ((partyId == null) || partyId.equals("")) {
                        errorMessage = "A problem occurred while logging in.";
                        Debug.logError("[validateMasterLogin] User party ID is null.", module);

                        return errorMessage;
                    }

                    // Get the user contact.
                    HashMap contactFindMap = new HashMap();
                    contactFindMap.put("contactId", partyId);

                    try {
                        GenericValue contactGV = getMasterDelegator()
                                                     .findByPrimaryKey("Contact",
                                contactFindMap);
                        String roleId = (contactGV.getString("roleId") == null)
                            ? "" : contactGV.getString("roleId");
                        String accountId = (contactGV.getString("accountId") == null)
                            ? "" : contactGV.getString("accountId");

                        errorMessage = "A problem occurred while logging in.";

                        if ((roleId == null) || roleId.equals("")) {
                            Debug.logError("[validateMasterLogin] User role ID is null.", module);

                            return errorMessage;
                        }

                        if ((accountId == null) || accountId.equals("")) {
                            Debug.logError("[validateMasterLogin] User account ID is null.", module);

                            return errorMessage;
                        }

                        masterUserInfo.setUserName(enteredUserLoginId);
                        masterUserInfo.setPartyId(partyId);
                        masterUserInfo.setRoleId(roleId);
                        masterUserInfo.setAccountId(accountId);

                        return "Success";
                    } catch (GenericEntityException e) {
                        errorMessage = "Error looking for contact: " +
                            e.getLocalizedMessage();
                        Debug.logError("[validateMasterLogin] " + errorMessage, module);

                        return errorMessage;
                    }
                } else {
                    // Password is not correct
                    errorMessage = "Password is not correct.";

                    return errorMessage;
                }
            } else {
                // Login ID was not found.
                errorMessage = "User ID is not valid.";

                return errorMessage;
            }
        } catch (GenericEntityException e) {
            errorMessage = "Error looking for user login record: " +
                e.getLocalizedMessage();

            Debug.logError("[validateMasterLogin] " + errorMessage, module);

            return errorMessage;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -