Example usage for org.apache.commons.beanutils PropertyUtils copyProperties

List of usage examples for org.apache.commons.beanutils PropertyUtils copyProperties

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils copyProperties.

Prototype

public static void copyProperties(Object dest, Object orig)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfo classes).

For more details see PropertyUtilsBean.

Usage

From source file:org.kuali.continuity.admin.main.server.SimpleServiceImpl.java

/**
 * Transform simple Items for the UI. Consider refactoring into Transform
 * Class with instances mapped by Domain AND Item
 * //from   w w w .j  a va2s .  com
 * @param rootName
 *            : Name of root element
 * @param orig
 *            Database Domain instance
 * @return Mapped UI xxxxItem instance
 */
NamedItem transform2UI(String rootName, BaseAdminDomainObject orig) {
    NamedItem dest = null;

    if (null != orig) {
        String action = "getting destination instance for " + rootName;
        try {

            dest = (NamedItem) itemDaoFactory.getNamedItem(rootName);
            System.out.println("Dest class is: " + dest.getClass().getName());
            action = "transforming";
            PropertyUtils.copyProperties(dest, orig);
            // Refactoring notes: Now do getTransformClass(rootName)
            // Amd call the Transform Post-process
            if (rootName.equals("activitylog")) {
                AcronymItem aitem = (AcronymItem) dest;
                SystemLog sorig = (SystemLog) orig;
                aitem.setActDate(sorig.getEventDate().toString());
                System.out.println("Setting activityDate to: " + sorig.getEventDate().toString());
                aitem.setFullName(sorig.getEventType().getDescription());

            } else if (dest instanceof BuildingItem) {
                BuildingItem bi = (BuildingItem) dest;
                String idstr = ((Building) orig).getOwnership().getId();
                Integer ownerIndex = ownerindexindex[Integer.parseInt(idstr)];
                bi.setOwnerIndex(ownerIndex);
                String owner = ((Building) orig).getOwnership().getDescription();

                bi.setOwner(ownerDescr[ownerIndex]);

            } else if (dest instanceof LocationItem) {
                // System.out.println("Getting Location: " +
                // orig.getName()s);
                LocationItem ldest = (LocationItem) dest;
                SystemDomain sorig = (SystemDomain) orig;
                System.out.println("Transfering: " + ldest.getName());
                // ldest.setParentSystemDomainName(ldest.getName());
                // TODO --- please take a look at this - OK
                if (sorig.getSystemDomainGroup() != null && sorig.getSystemDomainGroup() != null) {
                    ldest.setGroup(sorig.getSystemDomainGroup());
                    //ldest.setGroupId(sorig.getSystemDomainGroup().getId())
                    // ;

                }

                if (sorig.isShibMode()) {
                    ldest.setShibMode(true);
                } else {
                    ldest.setShibMode(false);
                }

                if (sorig.getShibIDP() != null && !"".equals(sorig.getShibIDP())) {
                    ldest.setAuthLocation(sorig.getShibIDP());
                }

                String[] accstrs = { "System Admin Only", "Admins Only", "All Users" };

                // ldest.setAuthId(sorig.getParentSystemDomainId());
                ldest.setAuthId(sorig.getId());
                // ldest.setTypestr(sorig.getType().getDescription());
                System.out.println(
                        "SS: LI: Setting access to: " + sorig.getSystemDomainAccess().getDescription());

                ldest.setAccessstr(sorig.getSystemDomainAccess().getDescription());
                if (ldest.getAccessstr().trim().length() == 0) {
                    System.out.println("SS: LI: access String was blank ");
                    int acId = Integer.parseInt(sorig.getSystemDomainAccess().getId());
                    System.out.println("SS: LI: access value: " + acId);
                    ldest.setAccessstr(accstrs[acId]);
                }
                ldest.setAccess(sorig.getSystemDomainAccess().getId());
                ldest.setShibUniqueId(sorig.getShibUniqueId());
                ldest.setCustomUrl(sorig.getCustomUrl());

                // custom images
                Map<UIImageEnum, UIImage> imageMap = this.systemDomainUIImageService
                        .getByOwnerId(sorig.getId());
                ldest.setCustomImage1(imageMap.get(UIImageEnum.BEGIN) != null);
                ldest.setCustomImage2(imageMap.get(UIImageEnum.BEGIN_TEXT) != null);
                ldest.setCustomImage3(imageMap.get(UIImageEnum.BANNER) != null);
                ldest.setCustomImage4(imageMap.get(UIImageEnum.BANNER_TEXT) != null);

            } else if (rootName.equals("function")) {
                CriticalFunctionExample corig = (CriticalFunctionExample) orig;
                dest.setName(corig.getPlans());

            } else if (dest instanceof SettingItem) {
                System.out.println("single transform:" + rootName);
                // This code could be moved to transform2UI
                SettingItem dset = (SettingItem) dest;

                SystemDomain dget = (SystemDomain) orig;

                Map m = getUserInfo();
                SessionUserDTO sud = (SessionUserDTO) m.get(SessionKey.user.name());
                if (sud != null) {
                    dset.setLoggedUserAccessLevel(sud.getDomainObject().getSecurityType().getId());
                } else {
                    System.out.println("SessionUserDTO is null");
                }
                //SecurityType

                dset.setId(dget.getId());
                System.out.println("Settings: 1 of 3 Getting Access:" + rootName);
                Integer access = Integer.parseInt(dget.getSystemDomainAccess().getId());
                dset.setAccess(access);
                SystemDomainSettings sds = dget.getSettings();

                Boolean[] opts = { false, false, false, false, false, false };
                System.out.println("Settings: 2 of 3 opts:" + rootName);
                opts[SettingItem.optionType.Skills.ordinal()] = sds.isSkillsScreenVisible();
                opts[SettingItem.optionType.Teams.ordinal()] = sds.isTeamsScreenVisible();
                opts[SettingItem.optionType.Staffing.ordinal()] = sds.isStaffRequirementsScreenVisible();
                opts[SettingItem.optionType.Functions.ordinal()] = sds.isCriticalFunctionsScreenVisible();
                opts[SettingItem.optionType.Replace.ordinal()] = sds.isInstructionVisible();
                opts[SettingItem.optionType.CriticalityLevel.ordinal()] = sds.isCriticalLevelDetailsVisible();

                dset.setOptions(opts);
                dset.setSublocation("");
                System.out.println("Settings: 3 of 3 getting NetDomains:" + rootName);
                Set<String> dnet = dget.getNetDomains();
                String[] dnetArray = new String[dnet.size()];
                dnet.toArray(dnetArray);

                dset.setDomainList(dnetArray);
                // if (dget.getId() != dget.getParentSystemDomainId()) {
                // int parentId = dget.getParentSystemDomainId();
                // dset.setSublocation(dset.getName());
                // SystemDomain parent = (SystemDomain) getAdminDao(
                // rootName).getById(parentId);
                // dset.setName(parent.getName());
                //
                // }
                dset.setInTestMode(this.isInTestMode(sud.id));
                dset.setFullModeration(dget.getFullModeration());
                dset.setSystemName(dget.getSystemName());
                dset.setEmail(dget.getEmail());
                dset.setShibMode((Boolean) this.getContextAttribute("shibMode"));

            }
        } catch (Exception e) {
            logger.warn("SS Transform: Failed to retrieve  Admin Object while" + action + ":" + rootName, e);
            System.out.println("SS Transform: FFailed to retrieve  Admin Object while" + action + ":" + rootName
                    + " " + e);
        }
    }
    return dest;
}

From source file:org.kuali.continuity.admin.main.server.SimpleServiceImpl.java

/**
 * This is the rest of the transform mechanism.
 * /*from   ww w .ja  v  a2s . com*/
 * @param rootName
 *            name of the tranform
 * @param dest
 *            the domain instance to transform into (this must be included
 *            because it may be being updated)
 * @param item
 *            the UI value object from which the transform takes place
 * @return returns a completed domain instance.
 * @throws Exception
 */
protected BaseAdminDomainObject transformFromUI2Domain(String rootName, BaseAdminDomainObject dest,
        NamedItem item, boolean upflag) throws Exception {
    System.out.println("Name before transform: " + dest.getName());
    if (!rootName.equals("setting")) {
        PropertyUtils.copyProperties(dest, item);
        dest.setName(item.getName());
    }

    if (item instanceof BuildingItem) {
        // Name is building Name.
        System.out.println("UI2: Starting transformof Building Item");
        // CaanName is commonName
        BuildingItem bitem = (BuildingItem) item;
        System.out.println("UI2: Got Building Item");
        Building bdest = (Building) dest;
        bdest.setCaan(((BuildingItem) item).getCaan());

        bdest.setCommonName(((BuildingItem) item).getCommonName());
        bdest.setName(((BuildingItem) item).getName());
        bdest.setAddress(((BuildingItem) item).getAddress());

        System.out.println("Building ownership index: " + bitem.getOwnerIndex());
        String ox = "" + bitem.getOwnerIndex();
        // Set with ownership index.
        if (null == bdest.getOwnership()) {
            bdest.setOwnership(new BuildingOwnership(ox));
        } else {
            bdest.getOwnership().setId(ox);

        }
        System.out.println("UI2:  Building Item transform done");
        logger.info("Building Object to store: " + bdest.getAddress() + "|" + bdest.getCommonName() + "|"
                + bdest.getName() + "|" + bdest.getCaan() + "|" + bdest.getOwnership().getId() + "|"
                + bdest.getSystemDomainId());
    } else if (rootName.equals("acronym")) {
        AcronymItem aitem = (AcronymItem) item;
        Acronym adest = (Acronym) dest;
        logger.info("SETTING acronym: " + aitem.getName());
        adest.setName(aitem.getName());
        adest.setFullName(aitem.getFullName());

    } else if (rootName.equals("setting")) {
        logger.info("Start save settings transform.");
        SettingItem sitem = (SettingItem) item;

        SystemDomain sdest = (SystemDomain) dest;
        SystemDomainAccess sda = new SystemDomainAccess();
        sda.setId(sitem.getAccess().toString());
        sdest.setSystemDomainAccess(sda);
        SystemDomainSettings sds = new SystemDomainSettings();
        Boolean opts[] = sitem.getOptions();
        sds.setSkillsScreenVisible(opts[SettingItem.optionType.Skills.ordinal()]);
        sds.setCriticalFunctionsScreenVisible(opts[SettingItem.optionType.Functions.ordinal()]);
        sds.setStaffRequirementsScreenVisible(opts[SettingItem.optionType.Staffing.ordinal()]);
        sds.setTeamsScreenVisible(opts[SettingItem.optionType.Teams.ordinal()]);

        sds.setInstructionVisible(opts[SettingItem.optionType.Replace.ordinal()]);
        sds.setCriticalLevelDetailsVisible(opts[SettingItem.optionType.CriticalityLevel.ordinal()]);
        sdest.setSettings(sds);
        List<String> netList = Arrays.asList(sitem.getDomainList());

        sdest.setNetDomains(new HashSet<String>(netList));

        sdest.setFullModeration(sitem.getFullModeration());
        sdest.setSystemName(sitem.getSystemName());
        sdest.setEmail(sitem.getEmail());
        logger.info("End save settings transform.");

    } else if (rootName.equals("function")) {
        logger.info("Start saving critical function example");
        CriticalFunctionExample cdest = (CriticalFunctionExample) dest;
        cdest.setPlans(item.getName());
    } else if (rootName.equals("location")) {
        // Location is a complex item and has fields that are not updated from the UI.
        if (upflag) {
            SystemDomain sdest = (SystemDomain) this.getAdminDao("location").getById(item.getId());
            // Recopy properties again to new object.
            BeanUtils.copyProperties(sdest, item);
            dest = sdest;
        } else {
            SystemDomain sdest = (SystemDomain) dest;
            sdest.setShibMode(false);
            sdest.setLBNL(false);
            sdest.setShibIDP("");
            sdest.setEmail("");
            sdest.setFax("");
            sdest.setPhone("");
            Set<String> domains = new HashSet<String>();
            sdest.setNetDomains(domains);
        }
        LocationItem li = (LocationItem) item;
        SystemDomain sdest = (SystemDomain) dest;
        sdest.setId(li.getAuthId());
        sdest.setSystemDomainGroup(li.getGroup());
        sdest.setShibUniqueId(li.getShibUniqueId());
        sdest.setCustomUrl(li.getCustomUrl());
        SystemDomainAccess systemDomainAccess = new SystemDomainAccess();
        systemDomainAccess.setId("0");

        if (null != li.getAccess() && li.getAccess().length() > 0) {
            systemDomainAccess.setId(li.getAccess());
        }
        sdest.setSystemDomainAccess(systemDomainAccess);
        // Optional fields.

        if (sdest.getSettings() == null) {
            SystemDomainSettings systemDomainSetting = new SystemDomainSettings();
            systemDomainSetting.setInstructionVisible(true);
            sdest.setSettings(systemDomainSetting);
        }
        System.out.println(" Location UI2:  " + sdest.getName() + " group: " + sdest.getSystemDomainGroup()
                + " " + sdest.getSystemDomainAccess().getId());
        // sdest.setParentSystemDomainId(li.getAuthId());
        // } else if (rootName.equals("department")) {
        // InstructionalDepartment idest = (InstructionalDepartment) dest;
        // AcronymItem aitem = (AcronymItem) item;
        // idest.setName(aitem.getName());

        sdest.setShibIDP(li.getAuthLocation());
        if (li.isShibMode()) {
            sdest.setShibMode(true);
        } else {
            sdest.setShibMode(false);
        }

    }
    System.out.println("Name after transform: " + dest.getName());
    return dest;

}

From source file:org.kuali.continuity.service.OrderingServiceListImpl.java

protected BaseAdminOrderedDomainObject transformFromUI2Domain(BaseAdminOrderedDomainObject dest, NamedItem item)
        throws Exception {
    PropertyUtils.copyProperties(dest, item);
    if (item instanceof DependencyItem) {
        DependencyItem dItem = (DependencyItem) item;
        Dependency dDest = (Dependency) dest;
        dDest.setDependencyType(new DependencyType("" + dItem.getType()));
    }/*from  w  w  w.j  a  v  a 2 s .  com*/
    return dest;
}

From source file:org.kuali.maven.plugins.graph.util.Helper.java

public static final <T> T copyProperties(Class<T> c, Object orig) {
    try {/*from  w  w  w  .  ja  va 2s.c  om*/
        T dest = c.newInstance();
        PropertyUtils.copyProperties(dest, orig);
        return dest;
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.kuali.rice.kew.rule.service.impl.RuleServiceImpl.java

protected RuleBaseValues createNewRuleVersion(RuleBaseValues existingRule, Long documentId) throws Exception {
    RuleBaseValues rule = new RuleBaseValues();
    PropertyUtils.copyProperties(rule, existingRule);
    rule.setPreviousVersion(existingRule);
    rule.setPreviousVersionId(existingRule.getRuleBaseValuesId());
    rule.setRuleBaseValuesId(null);/*www  .  j ava  2 s .co m*/
    rule.setActivationDate(null);
    rule.setDeactivationDate(null);
    rule.setVersionNumber(0L);
    rule.setRouteHeaderId(documentId);

    // TODO: FIXME: need to copy the rule expression here too?

    rule.setResponsibilities(new ArrayList());
    for (RuleResponsibility existingResponsibility : (List<RuleResponsibility>) existingRule
            .getResponsibilities()) {
        RuleResponsibility responsibility = new RuleResponsibility();
        PropertyUtils.copyProperties(responsibility, existingResponsibility);
        responsibility.setRuleBaseValues(rule);
        responsibility.setRuleBaseValuesId(null);
        responsibility.setRuleResponsibilityKey(null);
        responsibility.setVersionNumber(0L);
        rule.getResponsibilities().add(responsibility);
        //            responsibility.setDelegationRules(new ArrayList());
        //            for (RuleDelegation existingDelegation : (List<RuleDelegation>)existingResponsibility.getDelegationRules()) {
        //                RuleDelegation delegation = new RuleDelegation();
        //                PropertyUtils.copyProperties(delegation, existingDelegation);
        //                delegation.setRuleDelegationId(null);
        //                delegation.setRuleResponsibility(responsibility);
        //                delegation.setRuleResponsibilityId(null);
        //                delegation.setVersionNumber(0L);
        //                // it's very important that we do NOT recurse down into the delegation rules and reversion those,
        //                // this is important to how rule versioning works
        //                responsibility.getDelegationRules().add(delegation);
        //            }
    }
    rule.setRuleExtensions(new ArrayList());
    for (RuleExtension existingExtension : (List<RuleExtension>) existingRule.getRuleExtensions()) {
        RuleExtension extension = new RuleExtension();
        PropertyUtils.copyProperties(extension, existingExtension);
        extension.setLockVerNbr(0);
        extension.setRuleBaseValues(rule);
        extension.setRuleBaseValuesId(null);
        extension.setRuleExtensionId(null);
        rule.getRuleExtensions().add(extension);
        extension.setExtensionValues(new ArrayList<RuleExtensionValue>());
        for (RuleExtensionValue existingExtensionValue : extension.getExtensionValues()) {
            RuleExtensionValue extensionValue = new RuleExtensionValue();
            PropertyUtils.copyProperties(extensionValue, existingExtensionValue);
            extensionValue.setExtension(extension);
            extensionValue.setRuleExtensionId(null);
            extensionValue.setLockVerNbr(0);
            extensionValue.setRuleExtensionValueId(null);
            extension.getExtensionValues().add(extensionValue);
        }
    }
    return rule;
}

From source file:org.kuali.rice.kew.rule.service.impl.RuleServiceInternalImpl.java

protected RuleBaseValues createNewRuleVersion(RuleBaseValues existingRule, String documentId) throws Exception {
    RuleBaseValues rule = new RuleBaseValues();
    PropertyUtils.copyProperties(rule, existingRule);
    rule.setPreviousVersion(existingRule);
    rule.setPreviousRuleId(existingRule.getId());
    rule.setId(null);/*from  w  w  w.  j a v a  2  s .c  o  m*/
    rule.setActivationDate(null);
    rule.setDeactivationDate(null);
    rule.setVersionNumber(null);
    rule.setDocumentId(documentId);

    // TODO: FIXME: need to copy the rule expression here too?

    rule.setRuleResponsibilities(new ArrayList<RuleResponsibilityBo>());
    for (RuleResponsibilityBo existingResponsibility : existingRule.getRuleResponsibilities()) {
        RuleResponsibilityBo responsibility = new RuleResponsibilityBo();
        PropertyUtils.copyProperties(responsibility, existingResponsibility);
        responsibility.setRuleBaseValues(rule);
        responsibility.setRuleBaseValuesId(null);
        responsibility.setId(null);
        responsibility.setVersionNumber(null);
        rule.getRuleResponsibilities().add(responsibility);
        //            responsibility.setDelegationRules(new ArrayList());
        //            for (RuleDelegation existingDelegation : (List<RuleDelegation>)existingResponsibility.getDelegationRules()) {
        //                RuleDelegation delegation = new RuleDelegation();
        //                PropertyUtils.copyProperties(delegation, existingDelegation);
        //                delegation.setRuleDelegationId(null);
        //                delegation.setRuleResponsibility(responsibility);
        //                delegation.setRuleResponsibilityId(null);
        //                delegation.setVersionNumber(0L);
        //                // it's very important that we do NOT recurse down into the delegation rules and reversion those,
        //                // this is important to how rule versioning works
        //                responsibility.getDelegationRules().add(delegation);
        //            }
    }
    rule.setRuleExtensions(new ArrayList());
    for (RuleExtensionBo existingExtension : existingRule.getRuleExtensions()) {
        RuleExtensionBo extension = new RuleExtensionBo();
        PropertyUtils.copyProperties(extension, existingExtension);
        extension.setVersionNumber(new Long(0));
        extension.setRuleBaseValues(rule);
        extension.setRuleBaseValuesId(null);
        extension.setRuleExtensionId(null);
        rule.getRuleExtensions().add(extension);
        extension.setExtensionValues(new ArrayList<RuleExtensionValue>());
        for (RuleExtensionValue existingExtensionValue : extension.getExtensionValues()) {
            RuleExtensionValue extensionValue = new RuleExtensionValue();
            PropertyUtils.copyProperties(extensionValue, existingExtensionValue);
            extensionValue.setExtension(extension);
            extensionValue.getExtension().setRuleExtensionId(null);
            extensionValue.setLockVerNbr(0);
            extensionValue.setRuleExtensionValueId(null);
            extension.getExtensionValues().add(extensionValue);
        }
    }
    return rule;
}

From source file:org.kuali.rice.kew.rule.web.WebRuleBaseValues.java

/**
 * Loads the given rule into this WebRuleBaseValues.
 *///w ww  .j a  va 2s . c o  m
public void load(RuleBaseValues rule) throws Exception {
    PropertyUtils.copyProperties(this, rule);
    injectWebMembers();
}

From source file:org.kuali.rice.kew.rule.web.WebRuleResponsibility.java

public void load(RuleResponsibilityBo ruleResponsibility) throws Exception {
    PropertyUtils.copyProperties(this, ruleResponsibility);
    injectWebMembers();// w  w w .j  ava  2  s  . c  o  m
}

From source file:org.kuali.rice.kew.rule.web.WebRuleUtils.java

/**
 * Copies the existing rule onto the current document.  This is used within the web-based rule GUI to make a
 * copy of a rule on the existing document.  Essentially, this method makes a copy of the rule and all
 * delegates but preserves the document ID of the original rule.
 *///from   w ww  .jav a  2 s. c om
public static WebRuleBaseValues copyRuleOntoExistingDocument(WebRuleBaseValues rule) throws Exception {
    WebRuleBaseValues ruleCopy = new WebRuleBaseValues();
    PropertyUtils.copyProperties(ruleCopy, rule);
    ruleCopy.setPreviousRuleId(null);
    ruleCopy.setCurrentInd(null);
    ruleCopy.setVersionNbr(null);

    List responsibilities = new ArrayList();
    for (Iterator iter = ruleCopy.getRuleResponsibilities().iterator(); iter.hasNext();) {
        WebRuleResponsibility responsibility = (WebRuleResponsibility) iter.next();
        WebRuleResponsibility responsibilityCopy = new WebRuleResponsibility();
        PropertyUtils.copyProperties(responsibilityCopy, responsibility);

        responsibilityCopy.setResponsibilityId(null);
        responsibilityCopy.setId(null);

        List delegations = new ArrayList();
        for (Iterator iterator = responsibilityCopy.getDelegationRules().iterator(); iterator.hasNext();) {
            RuleDelegationBo delegation = (RuleDelegationBo) iterator.next();
            RuleDelegationBo delegationCopy = new RuleDelegationBo();
            PropertyUtils.copyProperties(delegationCopy, delegation);

            delegationCopy.setDelegateRuleId(null);
            delegationCopy.setVersionNumber(null);
            delegationCopy.setRuleDelegationId(null);
            delegationCopy.setResponsibilityId(null);

            WebRuleBaseValues delegationRule = ((WebRuleBaseValues) delegation.getDelegationRule());
            WebRuleBaseValues ruleDelegateCopy = new WebRuleBaseValues();
            PropertyUtils.copyProperties(ruleDelegateCopy, delegationRule);

            ruleDelegateCopy.setPreviousRuleId(null);
            ruleDelegateCopy.setCurrentInd(null);
            ruleDelegateCopy.setVersionNbr(null);

            List delegateResps = new ArrayList();
            for (Iterator iterator1 = ruleDelegateCopy.getRuleResponsibilities().iterator(); iterator1
                    .hasNext();) {
                WebRuleResponsibility delegateResp = (WebRuleResponsibility) iterator1.next();
                WebRuleResponsibility delegateRespCopy = new WebRuleResponsibility();
                PropertyUtils.copyProperties(delegateRespCopy, delegateResp);

                delegateRespCopy.setResponsibilityId(null);
                delegateRespCopy.setId(null);
                delegateResps.add(delegateRespCopy);
            }
            ruleDelegateCopy.setRuleResponsibilities(delegateResps);
            delegationCopy.setDelegationRule(ruleDelegateCopy);
            delegations.add(delegationCopy);
        }
        //responsibilityCopy.setDelegationRules(delegations);
        responsibilities.add(responsibilityCopy);
    }
    ruleCopy.setRuleResponsibilities(responsibilities);
    return ruleCopy;
}

From source file:org.kuali.rice.kew.rule.web.WebRuleUtils.java

public static void establishDefaultRuleValues(RuleBaseValues rule) {
    rule.setActive(true);//w  ww  . j  a v a 2 s .  co  m

    if (rule.getRuleTemplate().getDelegationTemplateId() != null) {
        RuleBaseValues defaultRule = ((RuleServiceInternal) KEWServiceLocator
                .getService(KEWServiceLocator.RULE_SERVICE))
                        .findDefaultRuleByRuleTemplateId(rule.getRuleTemplate().getDelegationTemplateId());

        if (defaultRule != null) {
            defaultRule.setActivationDate(null);
            defaultRule.setCurrentInd(null);
            defaultRule.setDeactivationDate(null);
            defaultRule.setDocTypeName(null);
            defaultRule.setVersionNumber(null);
            defaultRule.setId(null);
            defaultRule.setTemplateRuleInd(Boolean.FALSE);
            defaultRule.setVersionNbr(null);
            try {
                PropertyUtils.copyProperties(rule, defaultRule);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e);
            } catch (NoSuchMethodException e) {
                throw new RuntimeException(e);
            }
        }
    }
}