Skip to content

Commit 0ddf56b

Browse files
authored
Merge pull request #93 from oracle-samples/92-clone-activity-improvement
Version working
2 parents fda3fb5 + 21dc79a commit 0ddf56b

File tree

6 files changed

+133
-430
lines changed

6 files changed

+133
-430
lines changed

samples/013-CloneActivity/assets/css/jsonviewer.scss

Lines changed: 0 additions & 86 deletions
This file was deleted.

samples/013-CloneActivity/assets/js/custom.ts

Lines changed: 110 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,124 @@
44
*/
55

66
import { OFSPlugin, OFSMessage, OFSOpenMessage } from "@ofs-users/plugin";
7-
import { JSONTree } from "./utils/jsonview";
7+
import {
8+
OFSActivityResponse,
9+
ActivityResponse,
10+
OFSBulkUpdateRequest,
11+
OFSResponse,
12+
} from "@ofs-users/proxy";
13+
14+
// Create a ActivityResponseCustom object to be able to use apptNumber property
15+
export interface ActivityResponseCustom extends ActivityResponse {
16+
apptNumber: string;
17+
}
818
class OFSCustomOpenMessage extends OFSOpenMessage {
919
activity: any;
1020
openParams: any;
1121
resource: any;
1222
}
1323

24+
const keysToRemove: string[] = [
25+
"aid",
26+
"activityId",
27+
"date",
28+
"status",
29+
"createdBy",
30+
"createdDate",
31+
"resourceInternalId",
32+
"linkedActivities",
33+
"startTime",
34+
"endTime",
35+
"resouceTimeZone",
36+
"resourceTimeZoneIANA",
37+
"resourceTimeZoneDiff",
38+
"requiredInventories",
39+
"resourcePreferences",
40+
"workSkills",
41+
"timeZone",
42+
"workZone",
43+
"capacityCategories",
44+
"links",
45+
];
1446
export class CustomPlugin extends OFSPlugin {
1547
open(data: OFSCustomOpenMessage) {
16-
var activityData = data.activity;
17-
delete activityData["aid"];
18-
delete activityData["astatus"];
19-
delete activityData["date"];
20-
//activityData.appt_number = `CLONE_${activityData.appt_number}`;
21-
// activityData.appt_number = activityData.appt_number;
22-
var properties = activityData;
23-
var activityEntity = {
24-
entity: "activity",
25-
action: "create",
26-
activityType: activityData.aworktype,
27-
scheduled: false,
28-
properties,
48+
if (this.proxy) {
49+
this.createActivity(data);
50+
} else {
51+
console.debug(
52+
`${this.tag} : Proxy not available. The plugin framework option will be implemented instead`
53+
);
54+
var activityData = data.activity;
55+
keysToRemove.forEach((key) => {
56+
if (key in activityData) {
57+
delete activityData[key];
58+
}
59+
});
60+
var properties = activityData;
61+
var activityEntity = {
62+
entity: "activity",
63+
action: "create",
64+
activityType: activityData.aworktype,
65+
scheduled: false,
66+
properties,
67+
};
68+
var dataToSend: any = { actions: [activityEntity] };
69+
this.close(dataToSend);
70+
}
71+
}
72+
async createActivity(data: any) {
73+
var activityResponse: OFSActivityResponse =
74+
await this.proxy.getActivityDetails(data.activity.aid);
75+
console.debug(
76+
`${this.tag} : Activity data to create: ${JSON.stringify(
77+
activityResponse
78+
)}`
79+
);
80+
keysToRemove.forEach((key) => {
81+
if (key in activityResponse.data) {
82+
delete (activityResponse.data as any)[key];
83+
}
84+
});
85+
86+
var bulkUpdateData: OFSBulkUpdateRequest = {
87+
activities: [activityResponse.data],
88+
updateParameters: {
89+
identifyActivityBy: "apptNumber",
90+
ifExistsThenDoNotUpdateFields: [],
91+
ifInFinalStatusThen: "doNothing",
92+
},
2993
};
30-
var dataToSend: any = { actions: [activityEntity] };
31-
this.close(dataToSend);
94+
console.debug(
95+
`${
96+
this.tag
97+
} : Activity will be created with this information : ${JSON.stringify(
98+
bulkUpdateData
99+
)}`
100+
);
101+
var response: OFSResponse = await this.proxy.bulkUpdateActivity(
102+
bulkUpdateData
103+
);
104+
if (response.status >= 400 || response.status === -1) {
105+
var errorMessage =
106+
`${response.data.results || ""}` ||
107+
`Technical error with description {${response.description}} retrieving activities` ||
108+
`Technical error with status {${response.status}} retrieving activities`;
109+
alert(`Problems creating the activity ${errorMessage}`);
110+
console.error(
111+
`${this.tag} : Error Received ${JSON.stringify(response)}`
112+
);
113+
this.close();
114+
} else {
115+
// Cast data as ActivityResponseCustom
116+
alert(`Activity cloned or updated successfully`);
117+
console.debug(
118+
`${
119+
this.tag
120+
} : Activity cloned or updated successfully ${JSON.stringify(
121+
response
122+
)}`
123+
);
124+
this.close();
125+
}
32126
}
33127
}

0 commit comments

Comments
 (0)