int AbstractApi::setValueFromString(chaos::common::data::CDataWrapper& dataset, const std::string& type, const std::string& attribute_name, const std::string& value) { int err = 0; if(type.compare("int32") == 0) { dataset.addInt32Value(attribute_name.c_str(), boost::lexical_cast<int32_t>(value)); }else if(type.compare("int64") == 0) { dataset.addInt64Value(attribute_name.c_str(), boost::lexical_cast<int64_t>(value)); }else if(type.compare("double") == 0) { dataset.addDoubleValue(attribute_name.c_str(), boost::lexical_cast<double>(value)); }else if(type.compare("string") == 0) { dataset.addStringValue(attribute_name.c_str(), value); }else if(type.compare("binary") == 0) { std::string decoded_binary = bson::base64::decode(value); dataset.addBinaryValue(attribute_name.c_str(), decoded_binary.c_str(), (uint32_t)decoded_binary.size()); }else if(type.compare("boolean") == 0) { dataset.addBoolValue(attribute_name.c_str(), boost::lexical_cast<bool>(value)); }else{ return -1; } return err; }
/* Return the description of all action into a CDataWrapper */ void DeclareAction::decodeAction(AbstActionDescShrPtr& actionDesc, chaos_data::CDataWrapper& actionDescription) { //add domain for the action actionDescription.addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_DOMAIN, actionDesc->getTypeValue(AbstractActionDescriptor::ActionDomain)); //add name for the action actionDescription.addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_NAME, actionDesc->getTypeValue(AbstractActionDescriptor::ActionName)); //add the information for the action actionDescription.addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_DESCRIPTION, actionDesc->getTypeValue(AbstractActionDescriptor::ActionDescription)); //now i must describe the param for this action vector< boost::shared_ptr<ActionParamDescription> >& paramDescriptionVector = actionDesc->getParamDescriptions(); if(paramDescriptionVector.size()){ //there are some parameter for this action, need to be added to rapresentation boost::shared_ptr<chaos_data::CDataWrapper> paramDescRepresentation(new chaos_data::CDataWrapper()); for (vector< boost::shared_ptr<ActionParamDescription> >::iterator paramIter = paramDescriptionVector.begin(); paramIter !=paramDescriptionVector.end(); paramIter++) { //add thename of the parameter paramDescRepresentation->addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_DESC_PAR_NAME, (*paramIter)->paramName); //add the information about the parameter paramDescRepresentation->addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_DESC_PAR_INFO, (*paramIter)->paramDescription); //add the parameter type paramDescRepresentation->addInt32Value(RpcActionDefinitionKey::CS_CMDM_ACTION_DESC_PAR_TYPE, (*paramIter)->paramType); // add parametere representation object to main action representation actionDescription.appendCDataWrapperToArray(*paramDescRepresentation.get()); } //cloese the array actionDescription.finalizeArrayForKey(RpcActionDefinitionKey::CS_CMDM_ACTION_DESC_PARAM); } }