Java Code Examples for org.apache.commons.beanutils.BeanMap#put()

The following examples show how to use org.apache.commons.beanutils.BeanMap#put() . 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: CiServiceImpl.java    From we-cmdb with Apache License 2.0 6 votes vote down vote up
/**
    * 1. clone current ci to a new one and assign a new guid to it 2. assign the
    * new guid as pguid to current ci
    */
   @Override
   public Object cloneCiAsParent(EntityManager entityManager, int ciTypeId, String guid) {
       DynamicEntityMeta entityMeta = getDynamicEntityMetaMap().get(ciTypeId);
       Object fromBean = JpaQueryUtils.findEager(entityManager, entityMeta.getEntityClazz(), guid);
       if (fromBean == null) {
           throw new InvalidArgumentException(String.format("Can not find CI (ciTypeId:%d, guid:%s)", ciTypeId, guid));
       }
       String newGuid = sequenceService.getNextGuid(entityMeta.getTableName(), ciTypeId);

       BeanMap fromBeanMap = new BeanMap(fromBean);
       DynamicEntityHolder toEntityHolder = DynamicEntityHolder.cloneDynamicEntityBean(entityMeta, fromBean);
       MultiValueFeildOperationUtils.processMultValueFieldsForCloneCi(entityManager, entityMeta, newGuid, fromBeanMap, toEntityHolder, this);

       toEntityHolder.put(CmdbConstants.DEFAULT_FIELD_GUID, newGuid);

       List<AdmCiTypeAttr> refreshableAttrs = ciTypeAttrRepository.findByCiTypeIdAndIsRefreshable(ciTypeId, 1);
       refreshableAttrs.forEach(attr -> {
           fromBeanMap.put(attr.getPropertyName(), null);
       });
fromBeanMap.put(CmdbConstants.DEFAULT_FIELD_PARENT_GUID, newGuid);

       entityManager.merge(fromBean);
       entityManager.persist(toEntityHolder.getEntityObj());
       return fromBean;
   }
 
Example 2
Source File: ConfigBean.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public void onApplyEnvParams() {
    logger.info("onApplyEnvParams: start");
    try {

    	EnvironmentSettings environmentSettings = BeanUtil.getSfContext().getEnvironmentManager().getEnvironmentSettings();
    	BeanMap environmentBeanMap = new BeanMap(environmentSettings);

        for (EnvironmentEntity entry : environmentParamsList) {
        	Class<?> type = environmentBeanMap.getType(entry.getParamName());
        	Object convertedValue = BeanUtilsBean.getInstance().getConvertUtils().convert(entry.getParamValue(), type);
            environmentBeanMap.put(entry.getParamName(), convertedValue);
        }
        BeanUtil.getSfContext().getEnvironmentManager().updateEnvironmentSettings((EnvironmentSettings) environmentBeanMap.getBean());
        BeanUtil.showMessage(FacesMessage.SEVERITY_INFO, "INFO", "Successfully saved. Some options will be applied only after Sailfish restart");
    } catch (Exception e){
        logger.error(e.getMessage(), e);
        BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR, "ERROR", e.getMessage());
    }
    logger.info("onApplyEnvParams: end");
}
 
Example 3
Source File: MultiValueFeildOperationUtils.java    From we-cmdb with Apache License 2.0 5 votes vote down vote up
public static void rollbackMultValueFieldsForDiscard(EntityManager entityManager, String guid, DynamicEntityHolder ciHolder, Collection<FieldNode> fieldNodes, DynamicEntityHolder parentCiHolder) {
    for (FieldNode fn : fieldNodes) {
        if (DynamicEntityType.MultiSelection.equals(fn.getEntityType())) {
            Set multSelSet = (Set) parentCiHolder.get(fn.getName());
            if (multSelSet != null && !multSelSet.isEmpty()) {
                for (Object item : multSelSet) {
                    BeanMap mulSelItemMap = new BeanMap(item);
                    mulSelItemMap.put("from_guid", guid);
                    mulSelItemMap.put("from_guid_guid", ciHolder.getEntityObj());
                    entityManager.merge(item);
                }
            }
        } 
    }
}