You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
213 lines
6.8 KiB
213 lines
6.8 KiB
#include "util.h"
|
|
|
|
static void add_int_to_int_array(int add_int, int *n_int_array, int **int_array) {
|
|
int count = *n_int_array;
|
|
count++;
|
|
if (count == 1) {
|
|
(*int_array) = (int *)MEM_alloc(sizeof(int));
|
|
} else {
|
|
(*int_array) = (int *)MEM_realloc((*int_array), count * sizeof(int));
|
|
}
|
|
(*int_array)[count - 1] = add_int;
|
|
*n_int_array = count;
|
|
}
|
|
|
|
static void add_tag_to_tag_array(tag_t add_tag, int *n_tag_array, tag_t **tag_array) {
|
|
int count = *n_tag_array;
|
|
count++;
|
|
if (count == 1) {
|
|
(*tag_array) = (tag_t *)MEM_alloc(sizeof(tag_t));
|
|
} else {
|
|
(*tag_array) = (tag_t *)MEM_realloc((*tag_array), count * sizeof(tag_t));
|
|
}
|
|
(*tag_array)[count - 1] = add_tag;
|
|
*n_tag_array = count;
|
|
}
|
|
|
|
static void revise_item_revisions(int num_target_objs, tag_t *target_object_tags, vector<tag_t> *tags) {
|
|
int *all_attached_object_count = NULL;
|
|
tag_t *all_deepcopydata_tags;
|
|
|
|
int n_ints_in_list = 0;
|
|
int n_tags_in_list = 0;
|
|
int *ifails = NULL;
|
|
char *id_string = NULL;
|
|
char type_name[TCTYPE_name_size_c + 1] = "";
|
|
tag_t object_tag = NULLTAG;
|
|
tag_t type_tag = NULLTAG;
|
|
tag_t *attached_objs_tags = NULL;
|
|
tag_t *target_copy_tags = NULL;
|
|
tag_t *revise_input_tags = NULL;
|
|
|
|
revise_input_tags = (tag_t *)MEM_alloc(num_target_objs * sizeof(tag_t));
|
|
|
|
for (int ii = 0; ii < num_target_objs; ii++) {
|
|
tag_t type_tag = NULLTAG;
|
|
TCTYPE_ask_object_type(target_object_tags[ii], &type_tag);
|
|
|
|
tag_t revise_input_tag = NULLTAG;
|
|
TCTYPE_construct_operationinput(type_tag, TCTYPE_OPERATIONINPUT_REVISE, &revise_input_tag);
|
|
revise_input_tags[ii] = revise_input_tag;
|
|
|
|
printf("\nTarget Objects::\n");
|
|
int attached_object_count = 0;
|
|
tag_t *deepcopydata_tags = NULL;
|
|
TCTYPE_ask_deepcopydata(target_object_tags[ii],
|
|
TCTYPE_OPERATIONINPUT_REVISE, &attached_object_count, &deepcopydata_tags);
|
|
tag_t last_object = NULLTAG;
|
|
for (int jj = 0; jj < attached_object_count; jj++) {
|
|
AOM_ask_value_tag(deepcopydata_tags[jj], "targetObject",
|
|
&object_tag);
|
|
if (object_tag != last_object) {
|
|
WSOM_ask_object_id_string(object_tag, &id_string);
|
|
TCTYPE_ask_object_type(object_tag, &type_tag);
|
|
TCTYPE_ask_name(type_tag, type_name);
|
|
printf("%s (%s)\n", id_string, type_name);
|
|
}
|
|
last_object = object_tag;
|
|
|
|
AOM_ask_value_tag(deepcopydata_tags[jj], "attachedObject", &object_tag);
|
|
if (object_tag != NULLTAG) {
|
|
WSOM_ask_object_id_string(object_tag, &id_string);
|
|
TCTYPE_ask_object_type(object_tag, &type_tag);
|
|
TCTYPE_ask_name(type_tag, type_name);
|
|
printf("attachedObject: %s (%s)\n", id_string, type_name);
|
|
}
|
|
}
|
|
|
|
if (attached_object_count > 0) {
|
|
add_int_to_int_array(attached_object_count, &n_ints_in_list,
|
|
&all_attached_object_count);
|
|
for (int jj = 0; jj < attached_object_count; jj++) {
|
|
add_tag_to_tag_array(deepcopydata_tags[jj], &n_tags_in_list,
|
|
&all_deepcopydata_tags);
|
|
}
|
|
}
|
|
if (deepcopydata_tags) MEM_free(deepcopydata_tags);
|
|
}
|
|
|
|
TCTYPE_revise_objects(num_target_objs, target_object_tags,
|
|
revise_input_tags, all_attached_object_count, all_deepcopydata_tags,
|
|
&target_copy_tags, &ifails);
|
|
|
|
printf("\nNew Revisions:\n");
|
|
for (int ii = 0; ii < num_target_objs; ii++) {
|
|
|
|
WSOM_ask_object_id_string(target_copy_tags[ii],
|
|
&id_string);
|
|
TCTYPE_ask_object_type(target_copy_tags[ii], &type_tag);
|
|
TCTYPE_ask_name(type_tag, type_name);
|
|
|
|
if (ifails[ii] == ITK_ok) {
|
|
printf("%s (%s)\n", id_string, type_name);
|
|
(*tags).push_back(target_copy_tags[ii]);
|
|
} else {
|
|
char *error_message_string;
|
|
EMH_get_error_string(NULLTAG, ifails[ii], &error_message_string);
|
|
printf("\t%d %s\n", ifails[ii], error_message_string);
|
|
if (error_message_string) MEM_free(error_message_string);
|
|
}
|
|
}
|
|
|
|
if (revise_input_tags) MEM_free(revise_input_tags);
|
|
if (all_attached_object_count) MEM_free(all_attached_object_count);
|
|
if (all_deepcopydata_tags) MEM_free(all_deepcopydata_tags);
|
|
if (attached_objs_tags) MEM_free(attached_objs_tags);
|
|
if (target_copy_tags) MEM_free(target_copy_tags);
|
|
if (ifails) MEM_free(ifails);
|
|
if (id_string) MEM_free(id_string);
|
|
}
|
|
|
|
int jd_auto_revise(EPM_action_message_t msg) {
|
|
int att_cnt;
|
|
tag_t root_task, *attachments;
|
|
EPM_ask_root_task(msg.task, &root_task);
|
|
EPM_ask_attachments(root_task, EPM_target_attachment, &att_cnt, &attachments);
|
|
vector<tag_t> revs;
|
|
vector<tag_t> tags;
|
|
POM_AM__set_application_bypass(true);
|
|
for (int i = 0;i < att_cnt;i++) {
|
|
if (isTypeOf(attachments[i], "ItemRevision")) {
|
|
revs.push_back(attachments[i]);
|
|
}
|
|
}
|
|
revise_item_revisions(revs.size(), &revs[0], &tags);
|
|
if (tags.size() > 0) {
|
|
tag_t owning_user, group;
|
|
char *name, **prefs;
|
|
int prefs_cnt = 0, tags_cnt = tags.size();
|
|
AOM_ask_value_tag(msg.task, "owning_user", &owning_user);
|
|
AOM_ask_value_string(owning_user, "object_string", &name);
|
|
cout << "owning_user:" << name << endl;
|
|
SA_ask_user_login_group(owning_user, &group);
|
|
char *group_name;
|
|
AOM_ask_value_string(group, "object_string", &group_name);
|
|
cout << "group name:" << group_name << endl;
|
|
PREF_ask_char_values("jd2_auto_revise_relations", &prefs_cnt, &prefs);
|
|
for (int i = 0;i < prefs_cnt;i++) {
|
|
cout << "relation:" << prefs[i] << endl;
|
|
for (int ii = 0;ii < tags_cnt;ii++) {
|
|
tag_t *temp;
|
|
int num = 0;
|
|
AOM_ask_value_tags(tags[ii], prefs[i], &num, &temp);
|
|
for (int iii = 0;iii < num;iii++) {
|
|
char *str;
|
|
AOM_ask_value_string(temp[iii], "object_string", &str);
|
|
cout << "add name:" << str << endl;
|
|
tags.push_back(temp[iii]);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0;i < tags.size();i++) {
|
|
AOM_lock(tags[i]);
|
|
int res = ITK_ok;
|
|
char *uid;
|
|
ITKCALL(AOM_set_ownership(tags[i], owning_user, group));
|
|
ITKCALL(res = AOM_save(tags[i]));
|
|
if (res != ITK_ok) {
|
|
ITK__convert_tag_to_uid(tags[i], &uid);
|
|
cout << uid << endl;
|
|
if (uid) MEM_free(uid);
|
|
}
|
|
AOM_unlock(tags[i]);
|
|
//if (isTypeOf(tags[i], "Dataset")) {
|
|
//int ref_cnt;
|
|
//tag_t *refs;
|
|
//AOM_ask_value_tags(tags[i], "ref_list", &ref_cnt, &refs);
|
|
//cout << "dataset ref cnt:" << ref_cnt << endl;
|
|
//for (int iiii = 0;iiii < ref_cnt;iiii++) {
|
|
// //tags.push_back(refs[iiii]);
|
|
// AOM_lock(refs[iiii]);
|
|
// ITKCALL(POM_set_owning_group(refs[iiii], group));
|
|
// ITKCALL(POM_set_owning_user(refs[iiii], owning_user));
|
|
// AOM_save(refs[iiii]);
|
|
// AOM_unlock(refs[iiii]);
|
|
//}
|
|
//tag_t latest_dataset;
|
|
//AE_ask_dataset_latest_rev(tags[i], &latest_dataset);
|
|
//AOM_lock(latest_dataset);
|
|
// ITKCALL(POM_set_owning_group(tags[i], group));
|
|
|
|
// ITKCALL(POM_set_owning_user(tags[i], owning_user));
|
|
// ITKCALL(POM_set_modification_user(tags[i], owning_user));
|
|
// ITKCALL(AE_save_myself(tags[i]));
|
|
|
|
//
|
|
|
|
// AOM_save(tags[i]);
|
|
// AOM_unlock(tags[i]);
|
|
//} else {
|
|
// ITKCALL(POM_set_owning_group(tags[i], group));
|
|
// ITKCALL(POM_set_owning_user(tags[i], owning_user));
|
|
// AOM_save(tags[i]);
|
|
// AOM_unlock(tags[i]);
|
|
//}
|
|
}
|
|
cout << "success" << endl;
|
|
} else {
|
|
cout << "revs cnt:0" << endl;
|
|
}
|
|
POM_AM__set_application_bypass(false);
|
|
return 0;
|
|
} |