Wednesday 21 December 2016

Teamcenter ITK : Action handler and Rule handler

Problem statement
 - Add action handler for adding the Marketing decision and Proposal file as dataset if some condition satisfied and Add rule handler for checking the few attributes on the submitted target object

Note: AE_* api used for dealing with dataset (AE->Application Encapsulation)
Must read the comment in the code because it explains everything

#include <tc/tc.h>
#include <custom.h>
#include <dataset.h>
#include <epm/epm.h>
#include <ict_userservice.h>
#include <method.h>
#include <property/prop.h>
#include <property/prop_errors.h>
#include <property/prop_msg.h>
#include <reservation.h>
#include <stdarg.h>
#include <string.h>
#include <tc.h>
#include <tc/emh_const.h>
#include <tc/envelope.h>
#include <tc/emh.h>
#include <tccore/aom.h>
#include <tccore/aom_prop.h>
#include <tccore/custom.h>
#include <tccore/item.h>
#include <tccore/item_errors.h>
#include <tccore/item_msg.h>
#include <tccore/method.h>
#include <tccore/tctype.h>
#include <tccore/workspaceobject.h>
#include <tctype.h>
#include <item_errors.h>
#include <user_exits/user_exits.h>
#include <workspaceobject.h>
#include <project.h>
#include <sa/tcfile.h>
#include <folder.h>
#include <fclasses/tc_date.h>
#define CONNECT_FAIL (EMH_USER_error_base + 2)
#define ITK_err 919002


//must add generated libary can be .so/.dll under  TC_customization_libraries preference
//This is first method get called when libraries get loaded
extern DLLAPI int addtarget_register_callbacks ()
{
    printf("\n\naddtarget_register_callbacks changed\n\n");fflush(stdout);
   //This will further call addtarget_register_method to register a action handler
   //and rule handler which are then can be added in the workflow

    if(CUSTOM_register_exit ( "addtarget", "USER_gs_shell_init_module", (CUSTOM_EXIT_ftn_t)  addtarget_register_method) !=ITK_ok)
     PrintErrorStack();
  return ( ITK_ok );

}
char* subString (char* mainStringf ,int fromCharf,int toCharf);
char* subString
(
 char* mainStringf ,
 int fromCharf     ,
 int toCharf
)
{
 int i;
 char *retStringf;
 retStringf = (char*) malloc(toCharf+1);
 for(i=0; i < toCharf; i++ )
              *(retStringf+i) = *(mainStringf+i+fromCharf);
 *(retStringf+i) = '\0';
        return retStringf;
}
static void ECHO(char *format, ...)
{
    char msg[1000];
    va_list args;
    va_start(args, format);
//  vsprintf(msg, format, args);
    printf(msg);
    va_end(args);
    TC_write_syslog(msg);
}
static int PrintErrorStack( void )
{
    int iNumErrs = 0;
    int *pSevLst = NULL;
    int *pErrCdeLst = NULL;
    char **pMsgLst = NULL;
    register int i = 0;

    EMH_ask_errors( &iNumErrs, &pSevLst, &pErrCdeLst, &pMsgLst );
    fprintf( stderr, "Error(s): \n");
    for ( i = 0; i < iNumErrs; i++ )
    {
        fprintf( stderr, "\t%6d: %s\n", pErrCdeLst[i], pMsgLst[i] );
    }

   return ITK_ok;
}
int save_object (tag_t     object_tag)
{
    int ReturnCode;

   /*  Save the object.  */
    ReturnCode = AOM_save (object_tag);
    if (ReturnCode != ITK_ok)
    {
        //output_error ("ERROR %d save object.\n", ReturnCode);
        return (ReturnCode);
    }
    /* Unlock the object. */
    ReturnCode = AOM_unlock (object_tag);
    if (ReturnCode != ITK_ok)
    {
        //output_error ("ERROR %d unlock object.\n", ReturnCode);
    }
    return (ReturnCode);
}
static void Write_To_Log(char *format, ...)
{
    char msg[1000];
    va_list args;
    va_start(args, format);
    vsprintf(msg, format, args);
    va_end(args);
    printf(msg);
    TC_write_syslog(msg);
}
//---------------------------------------------------------------------------------------------------
//if some condition satisfied
//Import file to TC then create new data set and add file into it
//Import Marketing Input
//Import a proposal
tag_t GetCopiedFileWithNewDataset( int templates, tag_t InPutTag, char * inTask ,tag_t roottask )
{

tag_t dataset_tag  = NULLTAG;
tag_t dataset_tag1  = NULLTAG;
tag_t dataset_tag2  = NULLTAG;
tag_t dataset_tag3  = NULLTAG;
tag_t dataset_tag4  = NULLTAG;
tag_t dataset_tag5  = NULLTAG;
tag_t newfile   = NULLTAG;
tag_t newfile1   = NULLTAG;
tag_t newfile2   = NULLTAG;
tag_t newfile3   = NULLTAG;
tag_t newfile4   = NULLTAG;
tag_t newfile5   = NULLTAG;
tag_t datasettype_tag = NULLTAG;
tag_t default_tool_tag = NULLTAG;
tag_t *tWSOM_Find  = NULLTAG;
tag_t *list_of_WSO_tags = NULLTAG;
tag_t dataset   = NULLTAG;
tag_t new_dataset  = NULLTAG;
date_t   projCrDate ; 

char * name   = NULL;
char * new_name  = NULL;
char * new_name1  = NULL;
char * new_name2  = NULL;
char * new_name3  = NULL;
char * new_name4  = NULL;
char * new_code  = NULL;
char * new_code1  = NULL;
char * projId  = NULL;  
char * projGrp  = NULL;  
char * projCls  = NULL; 
char * projtype  = NULL;  
char * t8_SAPCode = NULL;  
char * markup_aclVal = NULL; 
char * Wso_code  = NULL; 
char  Wso_Name[WSO_name_size_c+1];
const char *   format_str;
char   *date_str = NULL;
char   *year     = NULL;
char   *subcode  = NULL;
char   *subcodeVal   = NULL;
char   *Sap_code   = NULL;
int error_code;
int number_found;
int SkipHandle=0;
int foundcnt=-1;
int NwStuffFdrSize=-1;
int NwStuffFdrSize1=-1;
int subcodeI=-1;
int sapcodeI=-1;
int  attachtype = 1;

WSO_search_criteria_t  criteria;
IMF_file_t  fileDescriptor ;
AE_reference_type_t reference_type;
FL_sort_criteria_t   FL_fsc_by_date_modified;

//get the object name property value for input object
if ( AOM_ask_value_string(InPutTag,"object_name",&projId) !=ITK_ok ) PrintErrorStack();
printf("\nProject id:%s\n",projId); fflush(stdout);
printf("\ntemplates count:%d\n",templates); fflush(stdout);

markup_aclVal=(char *)malloc(sizeof(char)*20);
name=(char*)MEM_alloc(sizeof(char)*120);
new_name=(char*)MEM_alloc(sizeof(char)*120);
new_name1=(char*)MEM_alloc(sizeof(char)*120);
new_name2=(char*)MEM_alloc(sizeof(char)*120);
new_name3=(char*)MEM_alloc(sizeof(char)*120);
new_name4=(char*)MEM_alloc(sizeof(char)*120);
new_code=(char*)MEM_alloc(sizeof(char)*120);
new_code1=(char*)MEM_alloc(sizeof(char)*120);
subcodeVal=(char*)MEM_alloc(sizeof(char)*120);
Wso_code=(char*)MEM_alloc(sizeof(char)*120);

//Finds a datasettype object with t ->MSExcel
//An error code not equal to ITK_ok means that some error occurred while searching for the datasettype with the name specified.
//A return of ITK_ok means that there was no error. It does not mean that a datasettype was found.
//The value of datasettype must be compared with NULLTAG to determine if a datasettype was actually found.
AE_find_datasettype ("MSExcel",&datasettype_tag);

//the set of tools that can be used with a particular datasettype
AE_ask_datasettype_def_tool(datasettype_tag,&default_tool_tag);

SkipHandle=0;
//Main flow Marketing Input templates
if(!strcmp(inTask,"Marketing SPOC1"))
{
   FL_ask_references(InPutTag,FL_fsc_by_date_modified ,&NwStuffFdrSize1,&tWSOM_Find);

   for (foundcnt=0;foundcnt<NwStuffFdrSize1;foundcnt++)
    {
       if (WSOM_ask_name(tWSOM_Find[foundcnt],Wso_Name))PrintErrorStack();
 Write_To_Log("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);
 printf("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);
 if(strstr(Wso_Name,"Marketing_FeaturesList")!=NULL)
 {

    printf("\nMatch Found : Wso_Name[%s]",Wso_Name);fflush(stdout);
           SkipHandle=1;
       break;

 }

    }

if(SkipHandle==0)
{
 strcpy(markup_aclVal,"PIP_Marketing");
 strcpy(new_name1,projId);
 strcat(new_name1,"_");
 strcat(new_name1,"Marketing_FeaturesList");
 printf("\n  I am inside the function and New Name prepared FeatureList= %s\n",new_name1);fflush(stdout);

 //This function is used to bring existing files under the control of Teamcenter.
 // It creates a new file in the operating system and a new TcFile object in the database,
 //where the new operating system file is a copy of the input OS file.
 //The new file is closed and TcFile Object is locked for further modification. It returns both the tag and the file descriptor
 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/Marketing_FeaturesList.xls",new_name1,SS_BINARY,&newfile,&fileDescriptor) !=ITK_ok ) PrintErrorStack();
 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile);

 printf("\n  222222222222222222222 \n");fflush(stdout);

        IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name1,"Marketing_FeaturesList", 0, 0, &dataset_tag); 

        printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag,"markup_acl",1,&markup_aclVal);

 

 //save_object(dataset_tag);

 AE_set_dataset_tool (dataset_tag, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag);

 CreateAndAttachDS( InPutTag, dataset_tag ,newfile ,roottask);

 printf("\n Marketing_FeaturesList Added..");fflush(stdout);


 strcpy(new_name2,projId);
 strcat(new_name2,"_");
 strcat(new_name2,"Product_Proposal");

 printf("\n  I am inside the function and New Name prepared Product_Proposal= %s\n",new_name2);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/Product_Proposal.xls",new_name2,SS_BINARY,&newfile1,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile1);

 printf("\n  222222222222222222222 \n");fflush(stdout);

       IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name2,"Product_Proposal", 0, 0, &dataset_tag1); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag1,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag1);



  AE_set_dataset_tool (dataset_tag1, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag1,"excel",reference_type,newfile1);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag1);

 CreateAndAttachDS( InPutTag, dataset_tag1 ,newfile1 ,roottask);

 printf("\n Product_Proposal Added..");fflush(stdout);

 strcpy(new_name3,projId);
 strcat(new_name3,"_");
 strcat(new_name3,"Marketing_Inputs");

 printf("\n  I am inside the function and New Name prepared Marketing_Inputs= %s\n",new_name3);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/Marketing_Inputs.xls",new_name3,SS_BINARY,&newfile2,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile2);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name3,"Marketing_Inputs", 0, 0, &dataset_tag2); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag2,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag2);

 AE_set_dataset_tool (dataset_tag2, default_tool_tag);
 reference_type = AE_PART_OF;
 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag2,"excel",reference_type,newfile2);
 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag2);

 CreateAndAttachDS( InPutTag, dataset_tag2 ,newfile2 ,roottask);

 printf("\n Marketing_Inputs Added..");fflush(stdout);

}
else
{
 printf("\nSkip Handler Activated  On  Rejection \n");fflush(stdout);
}

}

//anil auto code generation

if(!strcmp(inTask,"NPI Head1"))
{
 printf(" \n inside NPI Head1\n");fflush(stdout);

 if(AOM_get_value_string(InPutTag,"t8_SAPCode",&Sap_code))PrintErrorStack();

 printf(" \n  Sap_code %s\n",Sap_code);fflush(stdout);

 if(!strcmp(Sap_code,""))
 {
  strcpy(new_code,"T.");

  printf(" \n new_code %s\n",new_code);fflush(stdout);
               //date logic has to be written 
  if ( AOM_ask_creation_date(InPutTag,&projCrDate)!=ITK_ok ) PrintErrorStack(); 

  if ( ITK_date_to_string (projCrDate,&date_str)!=ITK_ok ) PrintErrorStack();  

  printf(" \n projCrDate %s\n",date_str);fflush(stdout);

  year=subString (date_str ,9,2);

  printf(" \n year %s\n",year);fflush(stdout);

  strcat(new_code,year);

  strcat(new_code,".C");

                //adding project classification

  if ( AOM_ask_value_string(InPutTag,"t8_ProjectGroup",&projGrp) !=ITK_ok ) PrintErrorStack();

  printf(" \n projGrp %s\n",projGrp);fflush(stdout);

         if(!strcmp(projGrp,"HCV"))
  {
   strcat(new_code,"A");
  }
  else if(!strcmp(projGrp,"MCV"))
  {
   strcat(new_code,"B");  
  }
  else if(!strcmp(projGrp,"LCV"))
  {
   strcat(new_code,"C");
  }
  else if(!strcmp(projGrp,"SUB FOUR TONNE-SCV"))
  {
      strcat(new_code,"D");
  }
  else if(!strcmp(projGrp,"BUS HCV"))
  {
       strcat(new_code,"E");
  }

  else if(!strcmp(projGrp,"BUS MCV"))
  {
   strcat(new_code,"F");
  }
  else if(!strcmp(projGrp,"BUS LCV"))
  {
   strcat(new_code,"G");
  }
  else if(!strcmp(projGrp,"ENGINES"))
  {
   strcat(new_code,"H");
  }
  else if(!strcmp(projGrp,"TRANSMISSION"))
  {
   strcat(new_code,"I");
  }
  else if(!strcmp(projGrp,"AXLE"))
  {
   strcat(new_code,"J");
  }
  else if(!strcmp(projGrp,"CAB"))
  {
   strcat(new_code,"K");
  }
  else if(!strcmp(projGrp,"SUMO/SPACIO"))
  {
   strcat(new_code,"L");
  }
  else if(!strcmp(projGrp,"SAFARI"))
  {
     strcat(new_code,"M");
  }
  else if(!strcmp(projGrp,"207"))
  {
    strcat(new_code,"N");
  }
  else if(!strcmp(projGrp,"INDICA"))
  {
   strcat(new_code,"O");
  }
  else if(!strcmp(projGrp,"SEDAN"))
  {
   strcat(new_code,"P");
  }
  else if(!strcmp(projGrp,"ESTATE"))
  {
   strcat(new_code,"Q");
  }
  else if(!strcmp(projGrp,"New MUV"))
  {
   strcat(new_code,"R");
  }
  else if(!strcmp(projGrp,"FEV Application"))
  {
   strcat(new_code,"S");
  }
  else
  {
   strcat(new_code,"X");
   printf(" \n new_code else %s\n",new_code);fflush(stdout);
  }

  printf(" \n new_code1 %s\n",new_code);fflush(stdout);


//adding project classification

  if ( AOM_ask_value_string(InPutTag,"t8_Category",&projCls) !=ITK_ok ) PrintErrorStack();
  printf(" \n projCls %s\n",projCls);fflush(stdout);

  if(!strcmp(projCls,"New Generation"))
  {
   strcat(new_code,"N");
  }
  else if(!strcmp(projCls,"Derivative"))
  {
   strcat(new_code,"D");
  }
  else if(!strcmp(projCls,"Enhancement"))
  {
   strcat(new_code,"E");
  }
  else if(!strcmp(projCls,"Facelift"))
  {
   strcat(new_code,"F");
  }
  else if(!strcmp(projCls,"Upgrade"))
  {
   strcat(new_code,"U");
  }
  else if(!strcmp(projCls,"Version"))
  {
   strcat(new_code,"V");
  }
  else if(!strcmp(projCls,"Application"))
  {
   strcat(new_code,"A");
  }
  else
  {
   strcat(new_code,"X");
  } 
  strcat(new_code,".");

  printf(" \n new_code %s\n",new_code);fflush(stdout);  

  WSOM_clear_search_criteria(&criteria);
  strcpy(criteria.class_name,"t8_project_cvbu");
  error_code = WSOM_search(criteria, &number_found,&list_of_WSO_tags);
  printf(" \n CVBU number_found %d\n",number_found);fflush(stdout);  

  for (foundcnt=0;foundcnt<number_found;foundcnt++)
  {
   Wso_code  = NULL;

   if(WSOM_ask_name(list_of_WSO_tags[foundcnt],Wso_Name))PrintErrorStack();

   printf(" \n  Wso_Name %s\n",Wso_Name);fflush(stdout);

   if(AOM_get_value_string(list_of_WSO_tags[foundcnt],"t8_SAPCode",&Wso_code))PrintErrorStack();

   printf(" \n  Wso_code %s\n",Wso_code);fflush(stdout); 

   if (tc_strcmp(Wso_code,"")==0 )
   {   
    printf("\nSap code is empity\n");fflush(stdout);   
   } 
   else
   {  
    strcpy(new_code1,Wso_code);   
    printf(" \n new_code1 %s\n",new_code1);fflush(stdout);
    subcode=subString (new_code1 ,9,3);
    printf(" \n subcode %s\n",subcode);fflush(stdout);
    
    subcodeI = atoi(subcode);   
    printf("\n subcodeI==>%d \n", subcodeI);fflush(stdout);
    if(subcodeI>sapcodeI)
    {
     sapcodeI=subcodeI;    
    }   
   }
  }

  sapcodeI=sapcodeI+1;

  printf("\n sapcodeI+1==>%d \n", sapcodeI);fflush(stdout);   

  sprintf(subcodeVal,"%d",sapcodeI);

  printf("\n subcodeVal==>%s \n", subcodeVal);fflush(stdout);

  strcat(new_code,subcodeVal);  
  
  AOM_refresh(InPutTag ,1);
  AOM_load(InPutTag) ;
  AOM_set_value_string(InPutTag,"t8_SAPCode",new_code); 
  printf(" \n new_code after set %s\n",new_code);fflush(stdout);
  AOM_save(InPutTag);
  AOM_refresh(InPutTag ,1);

  MEM_free(list_of_WSO_tags);
 }
}


//anil auto code generation end


//Main flow ERC Input templates

if(!strcmp(inTask,"ERC Chief Engineer"))
{
 FL_ask_size(InPutTag,&NwStuffFdrSize);
 FL_ask_references(InPutTag,FL_fsc_by_date_modified ,&NwStuffFdrSize1,&tWSOM_Find);
   for (foundcnt=0;foundcnt<NwStuffFdrSize1;foundcnt++)
     {
  if (WSOM_ask_name(tWSOM_Find[foundcnt],Wso_Name))PrintErrorStack();

  printf("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);

  if(strstr(Wso_Name,"ERC_TimePlan")!=NULL)
  {
   printf("Match Found : Wso_Name[%s]",Wso_Name);fflush(stdout);
   SkipHandle=1;
   break;
  }

 }

if(SkipHandle==0)
{ 

 strcpy(markup_aclVal,"PIP_ERC");
 strcpy(new_name1,projId);
 strcat(new_name1,"_");

 strcpy(name,new_name1);
 strcat(name,"Marketing_Inputs");

 strcat(new_name1,"ERC_TimePlan");
 printf("\n  I am inside the function and New Name prepared ERC_TimePlan= %s\n",new_name1);fflush(stdout);
 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/ERC_TimePlan.xls",new_name1,SS_BINARY,&newfile1,&fileDescriptor) !=ITK_ok ) PrintErrorStack();
 printf("\n  11111111111111111111111 \n");fflush(stdout);
 save_object(newfile1);
 printf("\n  222222222222222222222 \n");fflush(stdout);

       IMF_close_file (fileDescriptor);
 printf("\n  44444444444444444444444 \n");fflush(stdout);
 AE_create_dataset_with_id(datasettype_tag, new_name1,"ERC_TimePlan", 0, 0, &dataset_tag); 
 printf("\n  5555555555555555 \n");fflush(stdout);
 AOM_set_value_strings  (dataset_tag,"markup_acl",1,&markup_aclVal);
 //save_object(dataset_tag);



 AE_set_dataset_tool (dataset_tag, default_tool_tag);
 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);
 AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile1);
 printf(" \n After named ref\n");fflush(stdout);
 save_object(dataset_tag);

 CreateAndAttachDS(InPutTag,dataset_tag ,newfile1 ,roottask);
 printf("\n ERC_TimePlan Added..");fflush(stdout);

 strcpy(new_name2,projId);
 strcat(new_name2,"_");
 strcat(new_name2,"ERC_Inputs");

 printf("\n  I am inside the function and New Name prepared ERC_Inputs= %s\n",new_name2);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/ERC_Inputs.xls",new_name2,SS_BINARY,&newfile2,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile2);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name2,"ERC_Inputs", 0, 0, &dataset_tag2); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings (dataset_tag2,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag2);

 AE_set_dataset_tool (dataset_tag2, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag2,"excel",reference_type,newfile2);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag2);

 CreateAndAttachDS( InPutTag, dataset_tag2 ,newfile2 ,roottask);

 printf("\n ERC_Inputs Added..");fflush(stdout);

 strcpy(new_name3,projId);
 strcat(new_name3,"_");
 strcat(new_name3,"ERC_Estimates");

 printf("\n  I am inside the function and New Name prepared ERC_Estimates= %s\n",new_name3);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/ERC_Estimates.xls",new_name3,SS_BINARY,&newfile3,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile3);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name3,"ERC_Estimates", 0, 0, &dataset_tag3); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag3,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag3);

 AE_set_dataset_tool (dataset_tag3, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag3,"excel",reference_type,newfile3);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag3);

 CreateAndAttachDS( InPutTag, dataset_tag3 ,newfile3 ,roottask);

 printf("\n ERC_Estimates Added..");fflush(stdout);



//anil

 printf("\n datasetname ..%s",name);fflush(stdout);

 if(AE_find_dataset (name,&dataset))PrintErrorStack();

 printf(" \n Afterfind dataset\n");fflush(stdout);

 if (dataset==NULLTAG)
 {
  printf("\n no dataset found.");fflush(stdout);
 }
 else
 {
  strcat(name,"_erc");

  printf("\n datasetname after..%s",name);fflush(stdout);

  //if(AE_copy_dataset(dataset,name,&new_dataset))PrintErrorStack();

  if(AE_copy_dataset_with_id(dataset,name,"1","1",&new_dataset))PrintErrorStack();

  AOM_set_value_strings  (new_dataset,"markup_acl",1,&markup_aclVal);  

  if ( AOM_save(new_dataset) != ITK_ok )PrintErrorStack();

  AOM_refresh(InPutTag ,1);

  AOM_load(InPutTag) ;

  if ( FL_insert(InPutTag,new_dataset,999) != ITK_ok )PrintErrorStack();

  printf(" \n AfterFL_insert\n");fflush(stdout);

  if ( AOM_save(InPutTag) != ITK_ok )PrintErrorStack();

  if ( EPM_add_attachments(roottask,1,&new_dataset,&attachtype) != ITK_ok )PrintErrorStack();

         printf(" \n final AOM_save .... Add Target ...\n");fflush(stdout);
 }
//anil end
 }
 else
 {
  printf("\nSkip Handler Activated  On  Rejection \n");fflush(stdout);
 }
}

//Main flow APL Input templates
if(!strcmp(inTask,"APL SPOC1"))
{
 FL_ask_references(InPutTag,FL_fsc_by_date_modified ,&NwStuffFdrSize1,&tWSOM_Find);
   for (foundcnt=0;foundcnt<NwStuffFdrSize1;foundcnt++)
 {
  if (WSOM_ask_name(tWSOM_Find[foundcnt],Wso_Name))PrintErrorStack();
  Write_To_Log("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);
           printf("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);
 
  if(strstr(Wso_Name,"APL_Project_Inputs")!=NULL)
  {
   printf("\nMatch Found : Wso_Name[%s]",Wso_Name);fflush(stdout);
   SkipHandle=1;
   break;
  }

 }
if(SkipHandle==0)
 {

 strcpy(markup_aclVal,"PIP_APL");
 strcpy(new_name,projId);
 strcat(new_name,"_");
 strcat(new_name,"APL_Project_Inputs");
 printf("\n  I am inside the function and New Name prepared APL_Project_Inputs= %s\n",new_name);fflush(stdout);
 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/Manufacturing_Inputs.xls",new_name,SS_BINARY,&newfile,&fileDescriptor) !=ITK_ok ) PrintErrorStack();
 printf("\n  11111111111111111111111 \n");fflush(stdout);
 save_object(newfile);
 printf("\n  222222222222222222222 \n");fflush(stdout);
    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name,"APL_Project_Inputs", 0, 0, &dataset_tag); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag);

 AE_set_dataset_tool (dataset_tag, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag);

 CreateAndAttachDS( InPutTag, dataset_tag ,newfile ,roottask);

 printf("\n APL_Project_Inputs Added..");fflush(stdout);
 }
 else
 {
 printf("\nSkip Handler Activated  On  Rejection \n");fflush(stdout);
 }
}

//Main flow ADD Input templates
if(!strcmp(inTask,"Add SPOC1"))
{
 FL_ask_references(InPutTag,FL_fsc_by_date_modified ,&NwStuffFdrSize1,&tWSOM_Find);
   for (foundcnt=0;foundcnt<NwStuffFdrSize1;foundcnt++)
 {

  if (WSOM_ask_name(tWSOM_Find[foundcnt],Wso_Name))PrintErrorStack();
  Write_To_Log("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);
          printf("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);
  if(strstr(Wso_Name,"VD_TimePlan")!=NULL)
  {
   printf("\nMatch Found : Wso_Name[%s]",Wso_Name);fflush(stdout);
   SkipHandle=1;
          break;
  }
 }
if(SkipHandle==0)
 {
 strcpy(markup_aclVal,"PIP_ADD");
 strcpy(new_name1,projId);
 strcat(new_name1,"_");
 strcat(new_name1,"VD_TimePlan");

 printf("\n  I am inside the function and New Name prepared VD_TimePlan= %s\n",new_name1);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/VD_TimePlan.xls",new_name1,SS_BINARY,&newfile,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name1,"VD_TimePlan", 0, 0, &dataset_tag); 

 AOM_set_value_strings  (dataset_tag,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag);

 AE_set_dataset_tool (dataset_tag, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag);

 printf("\n  5555555555555555 \n");fflush(stdout);

 CreateAndAttachDS( InPutTag, dataset_tag ,newfile ,roottask);

 printf("\n VD_TimePlan Added..");fflush(stdout);


 strcpy(new_name2,projId);
 strcat(new_name2,"_");
 strcat(new_name2,"VD_Inputs");

 printf("\n  I am inside the function and New Name prepared VD_Inputs= %s\n",new_name2);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/VD_Inputs.xls",new_name2,SS_BINARY,&newfile1,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile1);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name2,"VD_Inputs", 0, 0, &dataset_tag1); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag1,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag1);


 AE_set_dataset_tool (dataset_tag1, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag1,"excel",reference_type,newfile1);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag1);

 CreateAndAttachDS( InPutTag, dataset_tag1 ,newfile1 ,roottask);

 printf("\n VD_Inputs Added..");fflush(stdout);

 }
 else
 {
 printf("\nSkip Handler Activated  On  Rejection \n");fflush(stdout);
 }

}



//Main flow PE Input templates

if(!strcmp(inTask,"PE SPOC1"))
{
 FL_ask_references(InPutTag,FL_fsc_by_date_modified ,&NwStuffFdrSize1,&tWSOM_Find);
   for (foundcnt=0;foundcnt<NwStuffFdrSize1;foundcnt++)
 {
  if (WSOM_ask_name(tWSOM_Find[foundcnt],Wso_Name))PrintErrorStack();  
  printf("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);
  if(strstr(Wso_Name,"PE_Project_Inputs")!=NULL)
  {
   printf("\nMatch Found : Wso_Name[%s]",Wso_Name);fflush(stdout);
   SkipHandle=1;
   break;
  }
 }
 printf("\nWSO_Name test[%s] ",Wso_Name);fflush(stdout);
 if(SkipHandle==0)
 { 
 strcpy(markup_aclVal,"PIP_PE");
 strcpy(new_name,projId);
 strcat(new_name,"_");
 strcat(new_name,"PE_Project_Inputs");

 printf("\n  I am inside the function and New Name prepared PE_Project_Inputs= %s\n",new_name);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/XYZ_Template.xls",new_name,SS_BINARY,&newfile,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name,"PE_Project_Inputs", 0, 0, &dataset_tag); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag);


 AE_set_dataset_tool (dataset_tag, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag);


 CreateAndAttachDS( InPutTag, dataset_tag ,newfile ,roottask);

 printf("\n PE_Project_Inputs Added..");fflush(stdout);
 }
 else
 {
  printf("\nSkip Handler Activated  On  Rejection \n");fflush(stdout);
 }

}



//Main flow APL Final Input templates

if(!strcmp(inTask,"APL Final SPOC1"))
{
 FL_ask_references(InPutTag,FL_fsc_by_date_modified ,&NwStuffFdrSize1,&tWSOM_Find);
   for (foundcnt=0;foundcnt<NwStuffFdrSize1;foundcnt++)
 {
  if (WSOM_ask_name(tWSOM_Find[foundcnt],Wso_Name))PrintErrorStack();  
  printf("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);
  
  if(strstr(Wso_Name,"Manufacturing_TimePlan")!=NULL)
  {
   printf("\nMatch Found : Wso_Name[%s]",Wso_Name);fflush(stdout);
   SkipHandle=1;
   break;
  }
 }
 if(SkipHandle==0)
 { 
 strcpy(markup_aclVal,"PIP_APL");
 strcpy(new_name,projId);
 strcat(new_name,"_");
 strcat(new_name,"Manufacturing_TimePlan");

 printf("\n  I am inside the function and New Name prepared Manufacturing_TimePlan= %s\n",new_name);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/Manufacturing_TimePlan.xls",new_name,SS_BINARY,&newfile,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name,"Manufacturing_TimePlan", 0, 0, &dataset_tag); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 

 AOM_set_value_strings  (dataset_tag,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag);



 AE_set_dataset_tool (dataset_tag, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag);

 

 CreateAndAttachDS( InPutTag, dataset_tag ,newfile ,roottask);

 printf("\n Manufacturing_TimePlan Added..");fflush(stdout);



 strcpy(new_name,projId);
 strcat(new_name,"_");
 strcat(new_name,"Manufacturing_Investments");

 printf("\n  I am inside the function and New Name prepared Manufacturing_Investments= %s\n",new_name);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/Manufacturing_Investments.xls",new_name,SS_BINARY,&newfile1,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile1);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name,"Manufacturing_Investments", 0, 0, &dataset_tag1); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag1,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag1);

 AE_set_dataset_tool (dataset_tag1, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag1,"excel",reference_type,newfile1);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag1);

 CreateAndAttachDS( InPutTag, dataset_tag1 ,newfile1 ,roottask);

 printf("\n Manufacturing_Investments Added..");fflush(stdout);
 }
 else
 {            printf("\nSkip Handler Activated  On  Rejection \n");fflush(stdout);
 }
}

//Main flow Finance Input templates
if(!strcmp(inTask,"Finance SPOC1"))
{
 FL_ask_references(InPutTag,FL_fsc_by_date_modified ,&NwStuffFdrSize1,&tWSOM_Find);
   for (foundcnt=0;foundcnt<NwStuffFdrSize1;foundcnt++)
 {
  if (WSOM_ask_name(tWSOM_Find[foundcnt],Wso_Name))PrintErrorStack();  
  printf("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);

             if(strstr(Wso_Name,"Finance_BusinessCase")!=NULL)
  {
      printf("\nMatch Found : Wso_Name[%s]",Wso_Name);fflush(stdout);
        SkipHandle=1;
      break;
  }

 }

if(SkipHandle==0)
 {

         strcpy(markup_aclVal,"PIP_FIN");
 strcpy(new_name,projId);
 strcat(new_name,"_");

 strcat(new_name,"Finance_BusinessCase");

 printf("\n  I am inside the function and New Name prepared Finance_BusinessCase= %s\n",new_name);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/Finance_BusinessCase.xls",new_name,SS_BINARY,&newfile,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name,"Finance_BusinessCase", 0, 0, &dataset_tag); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag);

 AE_set_dataset_tool (dataset_tag, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag);

 CreateAndAttachDS( InPutTag, dataset_tag ,newfile ,roottask);

 printf("\n Finance_BusinessCase Added..");fflush(stdout);

 }
 else
 {
  printf("\nSkip Handler Activated  On  Rejection \n");fflush(stdout);
 }
}

//Main flow NPI Input templates

if(!strcmp(inTask,"Project Group Head"))
{
 FL_ask_references(InPutTag,FL_fsc_by_date_modified ,&NwStuffFdrSize1,&tWSOM_Find);

   for (foundcnt=0;foundcnt<NwStuffFdrSize1;foundcnt++)
 {
  if (WSOM_ask_name(tWSOM_Find[foundcnt],Wso_Name))PrintErrorStack(); 
  printf("\nWSO_Name [%s] ",Wso_Name);fflush(stdout);
  if(strstr(Wso_Name,"NPI_9_Box")!=NULL)
  {
   printf("\nMatch Found : Wso_Name[%s]",Wso_Name);fflush(stdout);
   SkipHandle=1;
   break;

  }





 }



if(SkipHandle==0)

 {



 strcpy(markup_aclVal,"NPI");

 strcpy(new_name,projId);

 strcat(new_name,"_");

 strcat(new_name,"NPI_9_Box");

 printf("\n  I am inside the function and New Name prepared NPI_9_Box= %s\n",new_name);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/NPI_9_Box.xls",new_name,SS_BINARY,&newfile1,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile1);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name,"NPI_9_Box", 0, 0, &dataset_tag1); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag1,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag1);

 AE_set_dataset_tool (dataset_tag1, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag1,"excel",reference_type,newfile1);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag1);



 CreateAndAttachDS( InPutTag, dataset_tag1 ,newfile1 ,roottask);

 printf("\n NPI_9_Box Added..");fflush(stdout);



 strcpy(new_name1,projId);

 strcat(new_name1,"_");

 strcat(new_name1,"Variant_Tree");

 printf("\n  I am inside the function and New Name prepared Variant_Tree= %s\n",new_name1);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/XYZ_Template.xls",new_name1,SS_BINARY,&newfile2,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile2);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name1,"Variant_Tree", 0, 0, &dataset_tag2); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag2,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag2);

 AE_set_dataset_tool (dataset_tag2, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag2,"excel",reference_type,newfile2);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag2);

 CreateAndAttachDS( InPutTag, dataset_tag2 ,newfile2 ,roottask);

 printf("\n Variant_Tree Added..");fflush(stdout);



 strcpy(new_name2,projId);

 strcat(new_name2,"_");

 strcat(new_name2,"Total_Investmet");

 printf("\n  I am inside the function and New Name prepared Total_Investmet= %s\n",new_name2);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/XYZ_Template.xls",new_name2,SS_BINARY,&newfile3,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile3);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name2,"Total_Investmet", 0, 0, &dataset_tag3); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag3,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag3);

 AE_set_dataset_tool (dataset_tag3, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag3,"excel",reference_type,newfile3);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag3);

 CreateAndAttachDS( InPutTag, dataset_tag3 ,newfile3 ,roottask);

 printf("\n Total_Investmet Added..");fflush(stdout);



 strcpy(new_name3,projId);

 strcat(new_name3,"_");

 strcat(new_name3,"Classification_Chart");

 printf("\n  I am inside the function and New Name prepared Classification_Chart= %s\n",new_name3);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/XYZ_Template.xls",new_name3,SS_BINARY,&newfile4,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile4);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name3,"Classification_Chart", 0, 0, &dataset_tag4); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag4,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag4);

 AE_set_dataset_tool (dataset_tag4, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag4,"excel",reference_type,newfile4);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag4);

 CreateAndAttachDS( InPutTag, dataset_tag4 ,newfile4 ,roottask);

 printf("\n Classification_Chart Added..");fflush(stdout);



 strcpy(new_name4,projId);

 strcat(new_name4,"_");

 strcat(new_name4,"DDEstimates");

 printf("\n  I am inside the function and New Name prepared DDEstimates= %s\n",new_name4);fflush(stdout);

 if ( IMF_import_file("/home/req83/anil/CVBU_PIP_Template/XYZ_Template.xls",new_name4,SS_BINARY,&newfile5,&fileDescriptor) !=ITK_ok ) PrintErrorStack();

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile5);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name4,"DDEstimates", 0, 0, &dataset_tag5); 

 printf("\n  5555555555555555 \n");fflush(stdout);

 AOM_set_value_strings  (dataset_tag5,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag5);

 AE_set_dataset_tool (dataset_tag5, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag5,"excel",reference_type,newfile5);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag5);



 CreateAndAttachDS( InPutTag, dataset_tag5 ,newfile5 ,roottask);

 printf("\n DDEstimates Added..");fflush(stdout);

      }
 else
 {
  printf("\nSkip Handler Activated  On  Rejection \n");fflush(stdout);
 }
}


if(!strcmp(inTask,"4Box"))
{

 strcpy(new_name,projId);
 strcat(new_name,"_");
 strcat(new_name,"Marketing_4_Box");

 printf("\n  I am inside the function and New Name prepared 4Box= %s\n",new_name);fflush(stdout);

 IMF_import_file("/home/req83/anil/CVBU_PIP_Template/Marketing_4_Box.xls",new_name,SS_BINARY,&newfile,&fileDescriptor);

 printf("\n  11111111111111111111111 \n");fflush(stdout);

 save_object(newfile);

 printf("\n  222222222222222222222 \n");fflush(stdout);

    IMF_close_file (fileDescriptor); 

 printf("\n  3333333333333333333 \n");fflush(stdout);

 AE_create_dataset_with_id(datasettype_tag, new_name,"Marketing_4_Box", 0, 0, &dataset_tag);

 printf("\n  44444444444444444444444 \n");fflush(stdout);

 strcpy(markup_aclVal,"PIP_Marketing");

 AOM_set_value_strings  (dataset_tag,"markup_acl",1,&markup_aclVal);

 //save_object(dataset_tag);



 AE_set_dataset_tool (dataset_tag, default_tool_tag);

 reference_type = AE_PART_OF;

 printf(" \n Before named ref\n");fflush(stdout);

 AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile);

 printf(" \n After named ref\n");fflush(stdout);

 save_object(dataset_tag);

  CreateAndAttachDS( InPutTag,dataset_tag ,newfile ,roottask);

 printf("\n Marketing_4_Box Added..");fflush(stdout);
}



//AE_set_dataset_tool (dataset_tag, default_tool_tag);

//reference_type = AE_PART_OF;

//AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile);

//save_object(dataset_tag);

return dataset_tag;
}
//Add dataset as attachment to root task

int CreateAndAttachDS(tag_t InPutTag,tag_t dataset_tag ,tag_t newfile ,tag_t roottask)
 {
  AE_reference_type_t reference_type;
  int  attachtype = 1;

        if ( FL_insert(InPutTag,dataset_tag,999) != ITK_ok )PrintErrorStack();

  printf(" \n AfterFL_insert\n");fflush(stdout);

  if ( AOM_save(InPutTag) != ITK_ok )PrintErrorStack();

  printf(" \n After AOM_save .... Add Target ...\n");fflush(stdout);
   
  if ( EPM_add_attachments(roottask,1,&dataset_tag,&attachtype) != ITK_ok )PrintErrorStack();

         return ITK_ok;
 }
//---------------------------------------------------------------------------------------------------

//Method registered for action handler must have below function signature

// Paramter for EPM_action_message_t structure are as below
// tag_t task
// EPM_action_t action
// EPM_state_t proposed_state
// TC_argument_list_t * arguments
// tag_t data

int Add_To_Target( EPM_action_message_t msg )
{ 

   register int i = 0;
   int iNumAttch = 0;
   int  attachtype = 1;
   int  templates = 1;
   tag_t tagOwner, tagEnvelope;
   tag_t * pTagAttch;
   tag_t roottask  = NULLTAG;
   tag_t   datasettype_tag = NULLTAG;
   tag_t   di_objects  = NULLTAG;
   char *tem_object_name;
   char *inTask    = NULL;
   char *CVBU    = NULL;
   tag_t objTypeTag;
   char   type_name1[TCTYPE_name_size_c+1];
   //tag_t   MyDataset  = NULL;

   //Returns root task of the given task or job.
   if ( EPM_ask_root_task(msg.task,&roottask) != ITK_ok) PrintErrorStack();

   //Get the value for roottask object_name attribute

  if ( AOM_ask_value_string(msg.task,"object_name",&inTask)!= ITK_ok) PrintErrorStack();

  printf("\nInput Task Name:%s\n",inTask);fflush(stdout);
 
  printf("\n After root task \n");fflush(stdout);

 //Returns all the objects attached to the given task (for the given attachment type).

 //attachment types: EPM_target_attachment, EPM_reference_attachment, EPM_signoff_attachment, or EPM_release_status_attachment

 //Rule or action handlers dealing with target or reference attachment types should use the root task

 if ( EPM_ask_attachments( roottask, EPM_target_attachment,&iNumAttch, &pTagAttch ) !=ITK_ok ) PrintErrorStack();

 printf("Add_To_Target: (%d) - iNumAttch\n", iNumAttch);fflush(stdout);

 if (strcmp(inTask,"Marketing SPOC1")==0)
 {
  templates=3;
 }
               //Asks an object for its type.
  if (TCTYPE_ask_object_type(pTagAttch[0],&objTypeTag)!=ITK_ok)PrintErrorStack();
  
  //Asks a type for its name.
  if (TCTYPE_ask_name(objTypeTag,type_name1)!=ITK_ok)PrintErrorStack();

  printf("\n type_name1: %s \n",type_name1);fflush(stdout);

  if(strcmp(type_name1,"T8_Project_CVBU")==0)
  {   di_objects=GetCopiedFileWithNewDataset(templates,pTagAttch[0],inTask,roottask);

  }
   printf(" \n After .. Add Target ...\n");fflush(stdout);
  printf("Out of for of Add_To_Target\n");fflush(stdout);

    return ITK_ok;
}
//Check for the few attributes of the attached object like t5_Weight,t5_Volume
//if value not present then return EPM_decision_t as EPM_nogo else return EPM_go
//EPM_nogo -> stop the workflow
//EPM_go  -> continue in the workflow
EPM_decision_t Target_rule( EPM_rule_message_t msg )
{ 
   register int i = 0;
   int iNumAttch = 0;
   char* diameter;
   char* length;
   char* itemid;
   char* revid;
   char objTypeName[TCTYPE_name_size_c +1];
   tag_t * pTagAttch;
   tag_t objType;
 
   EPM_decision_t decision=EPM_go;

   if ( EPM_ask_attachments( msg.task, EPM_target_attachment,
            &iNumAttch, &pTagAttch ) !=ITK_ok )
   PrintErrorStack();

   if( EMH_clear_errors( )!= ITK_ok ) // Emtpy the error stack
        PrintErrorStack();

    printf("Target_rule: (%d) - iNumAttch\n", iNumAttch);fflush(stdout);

    for (i=0; i < iNumAttch; i++)
    {
      printf("inside for of Target_rule\n");fflush(stdout);
      if( TCTYPE_ask_object_type  ( pTagAttch[i], &objType )!= ITK_ok ) // Get the type of object
      PrintErrorStack();
      if( TCTYPE_ask_name   ( objType, objTypeName )!= ITK_ok )   // Get the name of the type
      PrintErrorStack();
      if( strcmp(objTypeName, "Design Revision") == 0)      // If it's our IR, then process the properties
      {
        if( AOM_ask_value_string ( pTagAttch[i], "t5_Weight", &diameter )!= ITK_ok ) // Get the Diamter
         PrintErrorStack();
        else
         if( !strlen(diameter) )                 // If it's blank...
         {
           decision = EPM_nogo;
           if( AOM_ask_value_string ( pTagAttch[i], "item_id", &itemid )!= ITK_ok )    // Get the Item ID
           PrintErrorStack();

            if( AOM_ask_value_string ( pTagAttch[i], "item_revision_id", &revid )!= ITK_ok )  // Get the Rev ID
            PrintErrorStack();
          }

          if( AOM_ask_value_string ( pTagAttch[i], "t5_Volume", &length )!= ITK_ok )  // Get the Length
            PrintErrorStack();
          else
           if( !strlen(length) )                 // If it's blank...
           {
             decision = EPM_nogo;
             if( AOM_ask_value_string ( pTagAttch[i], "item_id", &itemid )!= ITK_ok )    // Get the Item ID
               PrintErrorStack();
             if( AOM_ask_value_string ( pTagAttch[i], "item_revision_id", &revid )!= ITK_ok )  // Get the Rev ID
               PrintErrorStack();
            }
            printf("CustVerifyDimensions: (%3d) - %s: d=%10s(%d), l=%10s\n", i, objTypeName, diameter, strlen(diameter), length );fflush(stdout);
       }
       else
         printf("CustVerifyDimensions: (%3d) - Skipping\n", i);fflush(stdout);
  }
  printf("Out of for of Target_rule\n");fflush(stdout);
  MEM_free( pTagAttch );

  return decision;
}
extern int addtarget_register_method(int *decision, va_list args)
{
    *decision = ALL_CUSTOMIZATIONS;
 //Register action handler .Last parameter specify which method to execute when this handler is used in the workflow
   if( ITK_ok == EPM_register_action_handler("Add_Target", "", Add_To_Target))
   {
  printf("\t Registered CustSendToOwner Add_Target\n");fflush(stdout);
   }
   else
   {
  printf("\t FAILED to register CustSendToOwner\n");fflush(stdout);
   }
    //Register rule handler

 if( ITK_ok == EPM_register_rule_handler("TargetRule", "", Target_rule))
 {
  printf("\t Registered CustSendToOwner TargetRule\n");fflush(stdout);
 }
    else
 {
  printf("\t FAILED to register CustSendToOwner\n");fflush(stdout);
 }

   return ITK_ok;
}
Explanation : Important API
EPM_register_action_handler("Add_Target", "", Add_To_Target) EPM_register_rule_handler("TargetRule", "", Target_rule) EPM_ask_root_task(msg.task,&roottask) 
EPM_ask_attachments( roottask, EPM_target_attachment,&iNumAttch, &pTagAttch ) 
AE_find_datasettype ("MSExcel",&datasettype_tag); AE_ask_datasettype_def_tool(datasettype_tag,&default_tool_tag); IMF_import_file("/home/req83/anil/CVBU_PIP_Template/Marketing_FeaturesList.xls",new_name1,SS_BINARY,&newfile,&fileDescriptor) AE_create_dataset_with_id(datasettype_tag,new_name1,"Marketing_FeaturesList", 0, 0, &dataset_tag); 
AE_set_dataset_tool (dataset_tag, default_tool_tag); AE_add_dataset_named_ref(dataset_tag,"excel",reference_type,newfile);
EPM_add_attachments(roottask,1,&dataset_tag,&attachtype)

No comments:

Post a Comment