Common Question ITK Algorithm and Code

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Question no.

1
1.Based on the value entered in the one property according to that second property LOV should be selected if entered
value is positive first Lov value should be select if not second value should be select.

ALGORITHM
(Every api is sent to the api check function.)
(After fetching the tag, all tags are sent to the function to check for NULLTAG.)
1. Initialize variables:
 tag_t tlov_tag (for LOV tag)
 char* cpPropName (for the property name to check)
 char** cdpLovValues (for LOV values)
 const char* cpLovPropName (for the LOV property name)
 int iCode (to store the property value)
 int iVlaues (to store the number of LOV values)
2. Check if ‘tObjectTag’is not a null tag .
 If ‘tObjectTag’is null, log an error message and exit.
 Otherwise, proceed.
3. Retrieve the integer property value (‘iCode’) using AOM_ask_value_int with ‘cpPropName’.
4. Retrieve the LOV tag (‘tlov_tag’) associated with the LOV property (‘cpLovPropName’) using AOM_ask_lov.
5. Check if ‘tlov_tag’is not a null tag.
 If ‘tlov_tag’is null, log an error message and exit.
 Otherwise, proceed.
6. Retrieve the LOV values (‘cdpLovValues’) as array format of strings from ‘tlov_tag’using
LOV_ask_values_string.
7. Determine whether ‘iCode’is even or odd by checking if ‘iCode % 2’:
 If ‘iCode’is even, log a message indicating that the value is even in the syslog.
 Set the property of ‘tObjectTag’with ‘cpLovPropName’to the first LOV value (cdpLovValues[0]) using
AOM_set_value_string.
 If ‘iCode’is odd, log a message indicating that the value is odd in the syslog.
 Set the property of ‘tObjectTag’with ‘cpLovPropName’to the second LOV value (cdpLovValues[1]) using
AOM_set_value_string.
 Log a message indicating the successful LOV value update.
8. Free the memory allocated for ‘cdpLovValues’using SAFE_SM_FREE.
9. END.
CODE

#include <A7new_lib_test_itk/A7Extension_itk.hxx>
#undef ITKCALL // The macro function to check for the api errors
#define ITKCALL(argument) \
do { \
int retcode = argument; \
if (retcode != ITK_ok) { \
char* s; \
TC_write_syslog(“Function call: %s\n”, #argument); \
TC_write_syslog(“Returns [%d]\n”, retcode); \
EMH_store_error(EMH_severity_error, retcode);\
EMH_ask_error_text(retcode, &s); \
TC_write_syslog(“Teamcenter ERROR--------------------: [%s]\n”, s); \
TC_write_syslog(“File: %s, Line-----------------------: %d\n\n”, __FILE__, __LINE__); \
if (s != NULL) MEM_free(s); \
}\
} while (0)

int CheckNull(tag_t Tag)// function to check the nulltag


{
if(Tag!=NULLTAG)return 0;
else {
TC_write_syslog(“\n The tag is empty\n”);
return 1;}
}

int A7Extension_itk( METHOD_message_t * msg, va_list /*args*/ )


{
TC_write_syslog(“\nEntering A7Extension_itk function\n”);
tag_t tObjectTag = msg->object_tag;
tag_t tlov_tag = NULLTAG;

char* cpPropName=“a7Item_code”;
char **cdpLovValues = NULL;
const char* cpLovPropName=“a7Item_LOV”;
int iCode=0;
int iVlaues=0;

CheckNull(tObjectTag);
ITKCALL(AOM_ask_value_int(tObjectTag, cpPropName, &iCode)); // feching the property value
ITKCALL(AOM_ask_lov(tObjectTag,cpLovPropName, &tlov_tag)); // feching the lov tag using the
property name
CheckNull(tlov_tag);
ITKCALL(LOV_ask_values_string(tlov_tag, &iVlaues, &cdpLovValues)); // storing the lov value in the
array format

if (iCode%2 == 0) // check the property which is odd or even


{
TC_write_syslog(“\nThe value is even\n”);
ITKCALL(AOM_set_value_string(tObjectTag,cpLovPropName,cdpLovValues[0])); //
set the value to the property
TC_write_syslog(“\nLOV value fetch successfully = %s\n”,cdpLovValues[0]);
}
else
{
TC_write_syslog(“\nThe value is ODD\n”);
ITKCALL(AOM_set_value_string(tObjectTag,cpLovPropName,cdpLovValues[1])); // set the value to the property
TC_write_syslog(“\nLOV value fetch successfully = %s\n”,cdpLovValues[1]);

}
SAFE_SM_FREE(cdpLovValues);
TC_write_syslog(“\nExiting A7Extension_itk function\n”);

return 0;

}
Question no.2
2.While creating ITEM empty dataset should be created with name as itemid_revision_id_ATT in pdf format.

ALGORITHM
(Every api is sent to the api check function.)
(After fetching the tag, all tags are sent to the function to check for NULLTAG.)
1. Initialize various variables and tags:
 tag_t tSpecification, tRelation, tDatasettype, titem, ttRev, tnewDataset
 int iSize
 char* cpRevID, cpItemid, cpcRevid
 char* newDsName
2. Check if ‘tRev’ is not a null tag.
 If ‘tRev’ is null, log an error message and exit.
 Otherwise, proceed.
3. Retrieve the revision ID (‘cpRevID’) of ‘tRev’using ITEM_ask_rev_id2.
4. Retrieve the value of the “current_id” property (‘cpItemid’) from ‘tRev’using AOM_ask_value_string.
5. Find the item with the current ID (‘cpItemid’) and store its tag in ‘titem’.
6. Retrieve the latest revision of ‘titem’and store its tag in ‘ttRev’.
7. Retrieve the “current_id” and “current_revision_id” properties from ‘ttRev’and store them in ‘cpItemid’and
‘cpcRevid’, respectively.
8. Calculate the size (‘iSize’) required to store the name for the dataset based on ‘cpItemid’and ‘cpcRevid’.
9. Allocate memory for the ‘newDsName’character array with a size of ‘iSize * sizeof(char)’.
10. Find the dataset type (‘tDatasettype’) with the name “PDF” using AE_find_datasettype2.
11. Check if ‘tDatasettype’is not a null tag.
 If ‘tDatasettype’is null, log an error message and exit.
 Otherwise, proceed.
12. Log a message indicating that the dataset type is fetched.
13. Create a new dataset (‘tnewDataset’) with the specified dataset type, ‘newDsName’, “datasetDesc,” “001,” and
‘cpcRevid’using AE_create_dataset_with_id.
14. Check if ‘tnewDataset’is not a null tag.
 If ‘tnewDataset’is null, log an error message and exit.
 Otherwise, proceed.
15. Save ‘tnewDataset’using AOM_save_without_extensions.
16. Find the relation type “IMAN_specification” and store it in ‘tSpecification’using GRM_find_relation_type.

17. Check if ‘tSpecification’is not a null tag.


 If ‘tSpecification’is null, log an error message and exit.
 Otherwise, proceed.
18. Create a relation (‘tRelation’) between ‘ttRev’and ‘tnewDataset’using GRM_create_relation.
19. Save the relation using GRM_save_relation.
20. END.

CODE
#include <A7new_lib_test_itk/A7Ext_itk_test2.hxx>
#undef ITKCALL // The macro function to check for the api errors
#define ITKCALL(argument) \
do { \
int retcode = argument; \
if (retcode != ITK_ok) { \
char* s; \
TC_write_syslog(“Function call: %s\n”, #argument); \
TC_write_syslog(“Returns [%d]\n”, retcode); \
EMH_store_error(EMH_severity_error, retcode);\
EMH_ask_error_text(retcode, &s); \
TC_write_syslog(“Teamcenter ERROR--------------------: [%s]\n”, s); \
TC_write_syslog(“File: %s, Line-----------------------: %d\n\n”, __FILE__, __LINE__); \
if (s != NULL) MEM_free(s); \
}\
} while (0)

int CheckNull1(tag_t Tag) // function to check the nulltag


{
if(Tag!=NULLTAG)return 0;
else {
TC_write_syslog(“\n The tag is empty\n”);
return 1;}
}

int A7Ext_itk_test2( METHOD_message_t * msg, va_list /*args*/ )


{
TC_write_syslog(“\n -------------Entry------------\n”);
tag_t tRev = msg ->object_tag; // fetching the revision tag.
tag_t tSpecification = NULLTAG;
tag_t tRelation = NULLTAG;
tag_t tDatasettype = NULLTAG;
tag_t titem=NULLTAG;
tag_t ttRev=NULLTAG;
int iSize=0;
tag_t tnewDataset = NULLTAG;
char* cpRevID = NULL;
char* cpItemid=NULL;
char* cpcRevid=NULL;
// char revisionid=NULL;

CheckNull1(tRev); // check for nulltag


ITKCALL(ITEM_ask_rev_id2(tRev,&cpRevID)); // taking the revision id

ITKCALL(AOM_ask_value_string(tRev,”current_id”,&cpItemid)); // taking the value from the current_id


property
ITKCALL(ITEM_find_item (cpItemid,&titem));
TC_write_syslog(“\nthe item tag is %d “,titem);
ITKCALL(ITEM_ask_latest_rev(titem, &ttRev));
ITKCALL(AOM_ask_value_string(ttRev,”current_id”,&cpItemid));
ITKCALL(AOM_ask_value_string(ttRev,”current_revision_id”,&cpcRevid)); // taking the value from the
current_revision_id property
TC_write_syslog(“\nThe Item id is %s\n”,cpItemid);
TC_write_syslog(“\nThe Revision ID:%s\n”,cpcRevid);

iSize=tc_strlen(cpItemid)+tc_strlen(cpcRevid)+4; // calculating the size to store the name for the dataset

char* newDsName = (char*)MEM_alloc(iSize * sizeof(char)); // allocation of memory for the name variable
ITKCALL(AE_find_datasettype2(“PDF”,&tDatasettype)); // finding the data set tag
CheckNull1(tDatasettype);

TC_write_syslog(“\ndataset type is fetched\n”);


sprintf(newDsName, “%s_%s_ATT”,cpItemid, cpcRevid); // concatenate the things to name the dataset

ITKCALL(AE_create_dataset_with_id(tDatasettype,newDsName,”datasetDesc”,”001”, cpcRevid,
&tnewDataset)); // creation of dataset
CheckNull1(tnewDataset);

AOM_save_without_extensions(tnewDataset);
ITKCALL(GRM_find_relation_type(“IMAN_specification”,&tSpecification)); // finding the relation to attach the
created dataset to the item revision
CheckNull1(tSpecification);

ITKCALL(GRM_create_relation(ttRev,tnewDataset,tSpecification,NULLTAG,&tRelation)); // creating the


relation
GRM_save_relation(tRelation);

TC_write_syslog(“-------------End-------------\n”);

return 0;

}
Question no.3
3. User should provide the CAR model, then based on that Car's three property should be set (ex. Mileage,
HP,Torque)

ALGORITHM
(Every api is sent to the api check function.)
(After fetching the tag, all tags are sent to the function to check for NULLTAG.)
1. Initialize various variables and constant property names:
 const char* cpProModelName, cpProMileageName, cpProTorqueName, cpProHPName, cpPreferenceName.
 char* cpToken, cpPropValue, cpModelName, cpTorque
 char** cdpPref_Value
 int iMileage, iHorsepower, iIndex, iPrefCount
2. Check if ‘tObjectTag’is not a null tag.
 If ‘tObjectTag’is null, log an error message and exit.
 Otherwise, proceed.
3. Retrieve the string property value (‘cpPropValue’) for ‘cpProModelName’ using AOM_ask_value_string.
4. Log the fetched property value.
5. Retrieve preference values (‘cdpPref_Value’) for ‘cpPreferenceName’using PREF_ask_char_values.
6. Iterate through the preference values for up to three models (iIndex from 0 to 2).
 Set ‘cpToken’to the current preference value.

 Check if ‘cpToken’is not NULL.


 If ‘cpToken’is NULL, skip to the next iteration.

 Split ‘cpToken’into separate parts:


 Extract ‘cpModelName’as the first part.
 Extract ‘iMileage’as the second part.
 Extract ‘cpTorque’as the third part.
 Extract ‘iHorsepower’as the fourth part.

 Check if ‘cpModelName’matches ‘cpPropValue’.


 If there is a match, proceed to set the properties.

 Call the ‘setMultipleIntProperties’ function to set integer properties:


 ‘cpProMileageName’with ‘iMileage’.
 ‘cpProHPName’with ‘iHorsepower’.

 Call the ‘setMultiplestrProperties’function to set string property:

 ‘cpProTorqueName’with ‘cpTorque’.

 Log information about the set properties.


 Move to the next preference value by setting ‘cpToken’to the next line using ‘tc_strtok’.

7. Free the memory allocated for ‘cdpPref_Value’


8.END

CODE
#undef ITKCALL // Undefine the existing ITKCALL macro
#define ITKCALL(argument) \
do { \
int retcode = argument; \
if (retcode != ITK_ok) { \
char* s; \
TC_write_syslog("Function call: %s\n", #argument); \
TC_write_syslog("Returns [%d]\n", retcode); \
EMH_store_error(EMH_severity_error, retcode);\
EMH_ask_error_text(retcode, &s); \
TC_write_syslog("Teamcenter ERROR--------------------: [%s]\n", s); \
TC_write_syslog("File: %s, Line-----------------------: %d\n\n", __FILE__, __LINE__); \
if (s != NULL) MEM_free(s); \
/* Add your custom error handling code here */ \
}\
} while (0)

int CheckNull2(tag_t Tag)


{
if(Tag!=NULLTAG)return 0;
else {
TC_write_syslog("\n The tag is empty\n");
return 1;}
}
void setMultipleIntProperties(tag_t tObjectTag, const char* propertyName, int value)
{

ITKCALL(AOM_set_value_int(tObjectTag, propertyName, value)); // set the property value

}
void setMultiplestrProperties(tag_t tObjectTag, const char* propertyName, char* value)
{

ITKCALL(AOM_set_value_string(tObjectTag, propertyName, value)); // set the property value


}

int A7Car_extension( METHOD_message_t * msg, va_list /*args*/ )


{
TC_write_syslog("\nOperation Entry\n");
tag_t tObjectTag= msg->object_tag; // take the object tag from object_tag
const char* cpProModelName="a7Model";
const char* cpProMileageName="a7Mileage";
const char* cpProTorqueName="a7Torque";
const char* cpProHPName="a7Horse_power";
const char* cpPreferenceName="Auto_populate_car_prop";
char* cpToken=NULL;
char* cpPropValue=NULL;
char* cpModelName=NULL;
char** cdpPref_Value=NULL;
int iMileage=0;
char* cpTorque=NULL;
int iHorsepower=0;
int iIndex=0;
int iPrefCount=0;
CheckNull2(tObjectTag); // Check for the nulltag

ITKCALL(AOM_ask_value_string(tObjectTag, cpProModelName, &cpPropValue)); //fetch the property


value using the objecttag
TC_write_syslog("\nproperty value is %s \n",cpPropValue);
ITKCALL(PREF_ask_char_values(cpPreferenceName, &iPrefCount, &cdpPref_Value)); // Fetch the
preference value and storing it array format

for(iIndex=0;iIndex<3;iIndex++){
cpToken = cdpPref_Value[iIndex];
if(cpToken!=NULL)
{
while(cpToken!=NULL)
{
cpModelName=tc_strtok(cpToken,"|"); // separate the preference value
iMileage=atoi(tc_strtok(NULL, "|"));// separate the preference value
cpTorque=tc_strtok(NULL, "|");// separate the preference value
iHorsepower=atoi(tc_strtok(NULL, "|"));// separate the preference value

if(tc_strcmp(cpModelName,cpPropValue)==0)
{

setMultipleIntProperties(tObjectTag,cpProMileageName, iMileage); // calls the function


to set the property value
setMultiplestrProperties(tObjectTag,cpProTorqueName, cpTorque); // calls the function
to set the property value
setMultipleIntProperties(tObjectTag,cpProHPName, iHorsepower); // calls the function to set
the property value
TC_write_syslog("Model Name: %s\n", cpModelName);
TC_write_syslog("Mileage: %d\n", iMileage);
TC_write_syslog("Horsepower: %d\n", iHorsepower);
TC_write_syslog("Torque: %d\n", cpTorque);
}

cpToken = tc_strtok(NULL, "\n"); //set the cpToken to next line


}
}
else
{
TC_write_syslog("\nPreference string values are empty\n");
}
}

MEM_free(cdpPref_Value);
TC_write_syslog("\n--------------Operation Exit---------------------\n");

return 0;

You might also like