/** * @addtogroup workflow * @{ */ /** * @file xy_create_material_code.cpp * * @brief create material code according to some rev master properties * * @author Ray Li * * @history * =================================================================================== * Date Name Description * 27-Jul-2009 Ray created */ /** * @remarks: handler usage description * * @Handler: xy-create-material-code * * @Description: This handler will assign some value to its form property * * @Syntax: xy-create-material-code -type=产品,零组件 -required_props=prop1,prop2,prop3 -sid_leng=3 -target_prop=target_prop_name [-debug=true|false] * @Arguments: -type = ItemRevision types, like 产品,零组件 * specified target ItemRevision will be processed, others skipped, * eg: 产品,零组件 * * -target_prop = target property * the new prop value assigned to this property * * -target_value = target property * the new prop value assigned to this property * * -debug = true | false * When the argument is set to 'true' (case-insensitive), there will be more messages written in the syslog file. The default value is false. * * @Placement: not specified * * @Restrictions: none * */ #pragma warning (disable: 4996) #pragma warning (disable: 4819) /** * @headerfile tcua 头文件 */ #include #include #include #include #include #include #include #include #include #include #include /** * @headerfile standard c & cpp header files */ #include #include #include #include #include #include #include #include #include //#include using namespace std; /** * @headerfile user's header files */ #include "string_helper.h" #include "itk_service_common.h" #include "mdbks_register.h" #include "error_handling.h" static int CycleLovFilter( tag_t lov_tag, const char *prop_value, int lov_order, int filter_level, string &prop_desc ) { int ifail = ITK_ok; if (lov_tag == NULLTAG) return ITK_ok; else if ( prop_desc.size()==0 ) { if (filter_level == lov_order) { int n_values = 0, lov_index = 0; char **lov_values = NULL; logical find_prop_value = FALSE; ITKCALL( LOV_ask_values_string( lov_tag, &n_values, &lov_values ) ); for (int li=0; li0) { for (int li=0; li0) prop_value.assign(prop_desc); } if (prop_value.size()==0) { prop_value.assign(str_value); } MEM_free(str_value); return ITK_ok; } } } else if (prop_type == PROP_int) { int int_value = NULL; ITKCALL( AOM_ask_value_int( object, prop_name, &int_value ) ); char buf[100] = ""; sprintf( buf, "%d", int_value ); prop_value.assign(buf); } } return ITK_ok; } int xy_assign_form_props(EPM_action_message_t msg) { int ifail = ITK_ok; logical is_debug = FALSE; char buf[BUFSIZ] = "", *flag = NULL, *value = NULL; //item master form relation type tag_t master_form_rel_type = NULLTAG; ITKCALL( GRM_find_relation_type( TC_master_form_rtype, &master_form_rel_type ) ); //parse some arguments map item_types_map; map::iterator item_types_map_iter = item_types_map.begin(); vector required_props_vec; int sid_leng = 0, max_sid = 0; char target_prop[WSO_name_size_c + 1] = ""; char target_value[WSO_name_size_c + 1] = ""; int num_of_arguments = TC_number_of_arguments( msg.arguments ); for (int i=0; i ans; Split( value, ',', ans ); for (size_t j=0; j ans; // Split( value, ',', ans ); printf( "ans size = %d\n", ans.size() ); // for (size_t j=0; jfirst.c_str(), NULL, &item_type ) ); // ITKCALL( TCTYPE_ask_class_name( item_type, item_type_class ) ); // if (strcmp( item_type_class, "Item" ) != 0) // { // sprintf( buf, "type %s not Item or its sub type%s\n", item_types_map_iter->first.c_str() ); // LOG_ECHO( (buf) ); // break; // } // char *rev_master_type_name = NULL; // ITKCALL( ITEM_ask_rev_master_form_type( item_types_map_iter->first.c_str(), &rev_master_type_name ) ); // tag_t rev_master_type = NULLTAG; // ITKCALL( TCTYPE_find_type( rev_master_type_name, NULL, &rev_master_type ) ); // for ( int ri=0; ri<(int)required_props_vec.size(); ri++) // { // char one_prop[WSO_name_size_c + 1] = ""; // strcpy( one_prop, required_props_vec[ri].c_str() ); // tag_t pd_tag = NULLTAG; // ifail = TCTYPE_ask_property_by_name( rev_master_type, one_prop, &pd_tag ); // if (ifail != ITK_ok || pd_tag == NULLTAG) // { // sprintf( buf, "property %s not found from type %s\n", one_prop, rev_master_type_name ); // LOG_ECHO( (buf) ); // prop_not_defined = TRUE; // break; // } // } // if (!prop_not_defined) // { // tag_t pd_tag = NULLTAG; // ifail = TCTYPE_ask_property_by_name( rev_master_type, target_prop, &pd_tag ); // if (ifail != ITK_ok || pd_tag == NULLTAG) // { // sprintf( buf, "property %s not found from type %s\n", target_prop, rev_master_type_name ); // LOG_ECHO( (buf) ); // prop_not_defined = TRUE; // break; // } // } // if (prop_not_defined) // { // break; // } //} //if (prop_not_defined) //{ // return PROP_no_properties; //} //if ( is_debug ) //print arguments specified for handler //{ // item_types_map_iter = item_types_map.begin(); // for (; item_types_map_iter!=item_types_map.end(); item_types_map_iter++) // { // sprintf( buf, "Type: %s, ", item_types_map_iter->first.c_str() ); // LOG_ECHO( (buf) ); // } // sprintf( buf, "\n" ); // LOG_ECHO( (buf) ); // for ( int ri=0; ri<(int)required_props_vec.size(); ri++) // { // sprintf( buf, "Prop: %s, ", required_props_vec[ri].c_str() ); // LOG_ECHO( (buf) ); // } // sprintf( buf, "Prop: %s\n", target_prop ); // LOG_ECHO( (buf) ); // sprintf( buf, "Max Flow ID Leng: %d\n", max_sid ); // LOG_ECHO( (buf) ); //} //STEP 2: //retrieve item revisions related in reference's list tag_t job = NULLTAG, root_task = NULLTAG; ITKCALL( EPM_ask_job( msg.task, &job ) ); ITKCALL( EPM_ask_root_task( job, &root_task ) ); //current task's reference list int reference_count = 0; tag_t *reference_list = NULL; ITKCALL( EPM_ask_attachments( root_task, EPM_target_attachment, &reference_count, &reference_list ) ); vector reference_revs_vec; for (int ri=0; ri prop_type_map; map::iterator prop_type_map_iter; ////得到指定属性的值类型 //for ( int ri=0; ri<(int)required_props_vec.size(); ri++) //{ // PROP_value_type_t valtype; // char *valtype_n = NULL; // ITKCALL( AOM_ask_value_type( master_form, required_props_vec[ri].c_str(), &valtype, &valtype_n ) ); // if (is_debug) // { // sprintf( buf, "prop type = %s\n", valtype_n ); // } // MEM_free(valtype_n); // prop_type_map.insert( make_pair(required_props_vec[ri], valtype) ); //} /*得到指定的属性 string material_code_mark(""); for ( int ri=0; ri<(int)required_props_vec.size(); ri++) { prop_type_map_iter = prop_type_map.find(required_props_vec[ri]); PROP_value_type_t valtype = prop_type_map_iter->second; string prop_value; FindPropLovDesc( master_form, required_props_vec[ri].c_str(), valtype, prop_value ); if (prop_value.size()>0) { material_code_mark.append(prop_value); } } char *newID = NULL; ITKCALL( SERVICE_internal_part_no( material_code_mark.c_str(), sid_leng, 1, max_sid, 1, &newID ) ); if (newID && *newID && strlen(newID)>0) { material_code_mark.assign(newID); MEM_free(newID); } if (is_debug) { sprintf( buf, "new material code is %s\n", material_code_mark.c_str() ); LOG_ECHO( (buf) ); }*/ //检查写权限 printf("7777777\n"); logical can_change_form = FALSE; ITKCALL( AM_check_privilege( master_form, "WRITE", &can_change_form ) ); if (can_change_form) { //PROP_value_type_t valtype; //char *valtype_n = NULL; //ITKCALL( AOM_ask_value_type( master_form, target_prop, &valtype, &valtype_n ) ); //if (is_debug) //{ // sprintf( buf, "prop type = %s\n", valtype_n ); //} //MEM_free(valtype_n); //if (valtype == PROP_string) //{ // tag_t prop_descriptor = NULLTAG; // ITKCALL( AOM_ask_descriptor( object, prop_name, &prop_descriptor ) ); // logical is_lov_des_attached = FALSE; // ITKCALL( PROPDESC_is_lov_desc_attach( prop_descriptor, &is_lov_des_attached ) ); // if (is_lov_des_attached) //如果当前属性已经是lov的描述,则不再处理,仅赋值给返回对象 // { // //char *str_value = NULL; // //ITKCALL( AOM_ask_value_string( object, prop_name, &str_value ) ); // //if (str_value && *str_value) // //{ // // prop_value.assign(str_value); // // MEM_free(str_value); // //} // } //} //TC8============= //ITKCALL( AOM_lock( master_form ) ); //ITKCALL( AOM_set_value_string( master_form, target_prop, material_code_mark.c_str() ) ); ITKCALL(RES_checkout2(master_form,"","","",RES_EXCLUSIVE_RESERVE)); ITKCALL(RES_cancel_checkout (master_form,false)); ITKCALL( AOM_set_value_string( master_form, target_prop, target_value ) ); ITKCALL( AOM_save( master_form ) ); ITKCALL( AOM_unlock( master_form ) ); } else { printf( ("reviewer has no write privilege to add attachment\n" ) ); return AM_insufficient_access; } } return ITK_ok; }