Skip to content

Commit 93ec40d

Browse files
fixing removeFromArchive integration issues caused by WRC not maintaining their own archive state (#225)
* fixing removeFromArchive integration issues caused by WRC not maintaining their own archive state * fixing recursion exit issue * changing i18n text
1 parent f123eb1 commit 93ec40d

File tree

9 files changed

+99
-48
lines changed

9 files changed

+99
-48
lines changed

electron/app/js/ipcRendererPreload.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const uuid = require('uuid');
99

1010
const k8sUtils = require('./k8sUtils');
1111
const fsUtils = require('./fsUtils');
12+
const errorUtils = require('./errorUtils');
1213
const WktApp = require('./wktApp');
1314
const osUtils = require('./osUtils');
1415
const i18n = require('./i18next.webui.config');
@@ -292,6 +293,7 @@ contextBridge.exposeInMainWorld(
292293
'utils': {
293294
generateUuid: () => uuid.v4(),
294295
compareVersions: (version, otherVersion) => compareVersions(version, otherVersion),
296+
getErrorMessage: (err) => errorUtils.getErrorMessage(err),
295297
mainModule: mainModule,
296298
wrcFrontendCompatibilityVersion: wrcFrontendCompatibilityVersion,
297299
}

electron/app/locales/en/webui.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@
12851285
"k8s-domain-undeployer-operator-installed-check-failed-error-message": "Unable to undeploy WebLogic domain because an error occurred while detecting if the WebLogic Kubernetes Operator {{operatorName}} is installed in Kubernetes namespace {{operatorNamespace}}: {{error}}.",
12861286
"k8s-domain-undeployer-update-operator-config-in-progress": "Updating WebLogic Kubernetes Operator {{operatorName}} in Kubernetes namespace {{operatorNamespace}} to stop managing WebLogic Domains in Kubernetes namespace {{domainNamespace}}",
12871287
"k8s-domain-undeployer-k8s-namespace-delete-failed-error-message": "Unable to undeploy the domain because an error occurred while trying to delete the Kubernetes namespace {{namespace}}: {{error}}.",
1288-
"k8s-domain-undeployer-k8s-object-delete-failed-error-message": "Unable to undeploy the domain because an error occurred while trying to delete the Kubernetes {{type}} object {{name}} from the Kubernetes namespace {{namespace}}: {{error}}.",
1288+
"k8s-domain-undeployer-k8s-object-delete-failed-error-message": "Unable to undeploy the domain because an error occurred while trying to delete the Kubernetes {{type}} {{name}} from the Kubernetes namespace {{namespace}}: {{error}}.",
12891289
"k8s-domain-undeployer-remove-domain-error-message": "Unable to update WebLogic Kubernetes Operator to remove Kubernetes namespace {{domainNamespace}} from its list of managed namespaces due to an error while upgrading the WebLogic Kubernetes Operator {{operatorName}} in namespace {{operatorNamespace}}: {{error}}.",
12901290
"k8s-domain-undeployer-undeploy-complete-title": "WebLogic Domain Undeployment from Kubernetes Complete",
12911291
"k8s-domain-undeployer-undeploy-domain-complete-message": "WebLogic domain {{domainName}} successfully undeployed from Kubernetes namespace {{domainNamespace}}.",
@@ -1854,9 +1854,8 @@
18541854
"quickstart-page5-list1-item-1": "Model - Defines the domain configuration.",
18551855
"quickstart-page5-list1-item-2": "Variables - Defines a set of tokens to be used in the model and their values.",
18561856
"quickstart-page5-list1-item-3": "Archive - Contains application-related and domain-related files and directories to be added to the domain.",
1857-
"quickstart-page5-paragraph-2-pre-url": "See the",
1858-
"quickstart-page5-wdt-url-label": "WebLogic Deploy Tooling documentation",
1859-
"quickstart-page5-paragraph-2-post-url": "for more information.",
1857+
"quickstart-page5-paragraph-2": "For more information, please see the documentation: ",
1858+
"quickstart-page5-wdt-url-label": "WebLogic Deploy Tooling",
18601859
"quickstart-page5-list2-heading": "The WKT UI application supports creating, discovering, importing, and editing WDT metadata models.",
18611860
"quickstart-page5-list2-item-1": "Use the File menu's Add Model menu to discover a model from a domain or import existing model files.",
18621861
"quickstart-page5-list2-item-2": "Use the Model section to create new or edit existing model-related files.",
@@ -1959,5 +1958,7 @@
19591958
"wrc-wdt-archive-add-bad-wrc-type-error": "Failed to add to archive because the WebLogic Remote Console entry type {{wrcType}} was not known.",
19601959
"wrc-wdt-archive-add-empty-file-path-error": "Failed to add to archive because WebLogic Remote Console entry type {{wrcType}} requires a non-empty file path.",
19611960
"wrc-wdt-archive-add-failed-error": "Failed to add WebLogic Remote Console entry type {{wrcType}} to archive: {{error}}",
1962-
"wrc-wdt-archive-remove-empty-path-error": "Failed to remove from archive because the archive path was empty."
1961+
"wrc-wdt-archive-remove-empty-path-error": "Failed to remove from archive because the archive path was empty.",
1962+
"wrc-wdt-archive-remove-failed-to-match-path-error": "Failed to remove {{archivePath}} from the archive because an error occurred while trying to match the path to its archive entry: {{error}}.",
1963+
"wrc-wdt-archive-remove-no-matching-node-error": "Failed to match WRC archive path {{archivePath}}'"
19631964
}

webui/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@oracle/oraclejet": "^13.1.7",
14-
"@oracle/wrc-jet-pack": "~2.4.2",
14+
"@oracle/wrc-jet-pack": "^2.4.3-develop",
1515
"ace-builds": "^1.15.0",
1616
"i18next": "^22.4.9",
1717
"jquery": "^3.6.3",

webui/src/js/utils/wdt-archive-helper.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* Returns a singleton.
1111
*/
1212

13-
define(['knockout', 'models/wkt-project'],
14-
function (ko, project) {
13+
define(['knockout', 'models/wkt-project', 'utils/wkt-logger'],
14+
function (ko, project, wktLogger) {
1515
function WdtArchiveHelper() {
1616

1717
this.project = project;
@@ -61,23 +61,31 @@ define(['knockout', 'models/wkt-project'],
6161

6262
this.addToArchive = async (archiveEntryTypeName, options) => {
6363
const result = await window.api.ipc.invoke('add-archive-entry', archiveEntryTypeName, options);
64+
wktLogger.debug('add-to-archive IPC call returned: %s', result);
6465
// no archivePath means selection was cancelled, no need to notify or continue
6566
if (!!result.archivePath) {
6667
this._addArchiveUpdate(result.filePath, result.archiveUpdatePath);
6768
this._addToArchiveModel(result.archivePath, options.fileType || 'emptyDir', result.childPaths);
6869
}
69-
return result.archivePath;
70+
return result ? result.archiveUpdatePath : result;
7071
};
7172

7273
this.removeFromArchive = (archivePath) => {
73-
this.project.wdtModel.addArchiveUpdate('remove', archivePath);
74+
if (archivePath) {
75+
this._removeFromArchiveModel(archivePath, this.project.wdtModel.archiveRoots);
76+
this._removeArchiveUpdate(archivePath);
77+
}
7478
};
7579

7680
// add an archive update that will be applied to the file on the next save.
7781
this._addArchiveUpdate = (filePath, archivePath) => {
7882
this.project.wdtModel.addArchiveUpdate('add', archivePath, filePath);
7983
};
8084

85+
this._removeArchiveUpdate = (archivePath) => {
86+
this.project.wdtModel.addArchiveUpdate('remove', archivePath);
87+
};
88+
8189
// add the archive entry to the model, so it will be displayed in the tree.
8290
this._addToArchiveModel = (archivePath, leafEntryFileType, leafChildPaths) => {
8391
const childList = this.project.wdtModel.archiveRoots;
@@ -150,6 +158,22 @@ define(['knockout', 'models/wkt-project'],
150158
}
151159
}
152160
};
161+
162+
this._removeFromArchiveModel = (archivePath, nodesObservable) => {
163+
for (const node of nodesObservable()) {
164+
if (node.id === archivePath) {
165+
nodesObservable.remove(node);
166+
167+
// this shouldn't be required, but resolves tree view problems with emptied lists
168+
nodesObservable.sort();
169+
break;
170+
}
171+
172+
if (node.children) {
173+
this._removeFromArchiveModel(archivePath, node.children);
174+
}
175+
}
176+
};
153177
}
154178

155179
return new WdtArchiveHelper();

webui/src/js/utils/wrc-wdt-archive.js

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
*/
66
'use strict';
77

8-
define(['models/wkt-project', 'utils/i18n', 'utils/wdt-archive-helper'],
9-
function(project, i18n, archiveHelper) {
8+
define(['models/wkt-project', 'utils/i18n', 'utils/wdt-archive-helper', 'utils/wkt-logger'],
9+
function(project, i18n, archiveHelper, wktLogger) {
1010
class WrcWdtArchive {
1111
constructor() {
1212
this.project = project;
1313
}
1414

1515
async addToArchive(wrcEntryTypeName, filePath, otherArgs={}) {
16+
wktLogger.debug('entering WRC API addToArchive(%s, %s, %s)', wrcEntryTypeName, filePath, otherArgs);
1617
const typeInfo = this._convertWrcType(wrcEntryTypeName);
1718
if (typeof typeInfo === 'undefined') {
1819
return Promise.reject(new Error(i18n.t('wrc-wdt-archive-add-empty-wrc-type-error')));
@@ -34,8 +35,11 @@ define(['models/wkt-project', 'utils/i18n', 'utils/wdt-archive-helper'],
3435
const options =
3536
archiveHelper.buildAddToArchiveOptions(archiveEntryTypeName, archiveEntry, filePath, filePathType, otherArgs);
3637

38+
wktLogger.debug('preparing to call archiveHelper.addToArchive(%s, %s)', archiveEntryTypeName, options);
3739
return new Promise((resolve, reject) => {
3840
archiveHelper.addToArchive(archiveEntryTypeName, options).then((archivePath) => {
41+
wktLogger.debug('WRC API addToArchive(%s, %s, %s) returned %s', wrcEntryTypeName, filePath,
42+
otherArgs, archivePath);
3943
resolve(archivePath);
4044
}).catch(err => {
4145
const errMessage = err instanceof Error ? err.message : err;
@@ -46,11 +50,27 @@ define(['models/wkt-project', 'utils/i18n', 'utils/wdt-archive-helper'],
4650
});
4751
}
4852

53+
// WRC does not have the ability to remember the archivePath returned from addToArchive().
54+
// This causes a problem for removing directories, where the underlying code depends on
55+
// directory entries having a trailing slash. As such, we have to go determine if the
56+
// archivePath argument is a directory and, if so, make sure it ends with a trailing slash
57+
// before passing it on.
58+
//
4959
async removeFromArchive(archivePath) {
60+
wktLogger.debug('entering WRC API removeFromToArchive(%s)', archivePath);
5061
return new Promise((resolve, reject) => {
5162
if (archivePath) {
52-
archiveHelper.removeFromArchive(archivePath);
53-
resolve();
63+
try {
64+
const updatedArchivePath = this._convertWrcArchivePath(archivePath);
65+
66+
wktLogger.debug('calling archiveHelper.removeFromArchive(%s)', updatedArchivePath);
67+
archiveHelper.removeFromArchive(updatedArchivePath);
68+
resolve();
69+
} catch (err) {
70+
const errorMessage = window.api.utils.getErrorMessage(err);
71+
reject(new Error(i18n.t('wrc-wdt-archive-remove-failed-to-match-path-error',
72+
{ archivePath, error: errorMessage})));
73+
}
5474
} else {
5575
reject(new Error(i18n.t('wrc-wdt-archive-remove-empty-path-error')));
5676
}
@@ -83,6 +103,35 @@ define(['models/wkt-project', 'utils/i18n', 'utils/wdt-archive-helper'],
83103

84104
return result;
85105
}
106+
107+
_convertWrcArchivePath(wrcArchivePath, nodesObservable = this.project.wdtModel.archiveRoots) {
108+
wktLogger.debug('Entering _convertWrcArchivePath(%s, %s)', wrcArchivePath, JSON.stringify(nodesObservable()));
109+
const wrcPath = wrcArchivePath.endsWith('/') ? wrcArchivePath.slice(0, -1) : wrcArchivePath;
110+
let result;
111+
for (const node of nodesObservable()) {
112+
if (wrcPath === node.id || wrcPath + '/' === node.id) {
113+
wktLogger.debug('Found matching node id = %s', node.id);
114+
return node.id;
115+
}
116+
117+
if (node.children) {
118+
wktLogger.debug('node %s has children', node.id);
119+
result = this._convertWrcArchivePath(wrcArchivePath, node.children);
120+
if (result) {
121+
wktLogger.debug('return nested _convertWrcArchivePath() call from node %s: %s', node.id, result);
122+
return result;
123+
}
124+
wktLogger.debug('No match found for %s in children of node %s', wrcArchivePath, node.id);
125+
}
126+
}
127+
128+
// If we are back at the topmost level and have no result, throw an error.
129+
if (nodesObservable === this.project.wdtModel.archiveRoots && !result) {
130+
throw new Error(i18n.t('wrc-wdt-archive-remove-no-matching-node-error', {archivePath: wrcArchivePath}));
131+
}
132+
wktLogger.debug('Exiting _convertWrcArchivePath() returning %s', result);
133+
return result;
134+
}
86135
}
87136

88137
return new WrcWdtArchive();

webui/src/js/viewModels/model-archive-view.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,8 @@ function(accUtils, ko, i18n, project, dialogHelper, archiveHelper, ArrayTreeData
4141

4242
this.deleteSelected = () => {
4343
const path = this.selectedItem();
44-
45-
// delete the path from the UI
46-
this._deleteArchiveNode(path, project.wdtModel.archiveRoots);
47-
48-
// add a 'remove' operation to be applied on save
4944
archiveHelper.removeFromArchive(path);
5045
};
51-
52-
// recursively search the archive tree for a node matching the ID,
53-
// then delete that element from its parent list.
54-
this._deleteArchiveNode = (id, list) => {
55-
for (let item of list()) {
56-
if(item.id === id) {
57-
list.remove(item);
58-
59-
// this shouldn't be required, but resolves tree view problems with emptied lists
60-
list.sort();
61-
break;
62-
}
63-
64-
const children = item['children'];
65-
if(children) {
66-
this._deleteArchiveNode(id, children);
67-
}
68-
}
69-
};
7046
}
7147

7248
/*

webui/src/js/viewModels/model-design-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function(accUtils, i18n, ko, project, urlCatalog, wrcArchiveHelper, viewHelper,
136136
// Set model properties provider option
137137
providerOptions['modelProperties'] = JSON.parse(JSON.stringify(this.project.wdtModel.getModelPropertiesObject().observable()));
138138
// Set model archive provider option
139-
providerOptions['modelArchive'] = this.project.wdtModel.archiveRoots;
139+
// providerOptions['modelArchive'] = this.project.wdtModel.archiveRoots;
140140

141141
return providerOptions;
142142
};

webui/src/js/views/quickstart/page5-view.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ <h6><oj-bind-text value="[[labelMapper('title')]]"></oj-bind-text></h6>
1818
</ul>
1919

2020
<p>
21-
<oj-bind-text value="[[labelMapper('paragraph-2-pre-url')]]"></oj-bind-text>
21+
<oj-bind-text value="[[labelMapper('paragraph-2')]]"></oj-bind-text>
2222
<a href="https://oracle.github.io/weblogic-deploy-tooling/concepts/model/">
2323
<oj-bind-text value="[[labelMapper('wdt-url-label')]]"></oj-bind-text>
2424
</a>
25-
<oj-bind-text value="[[labelMapper('paragraph-2-post-url')]]"></oj-bind-text>
2625
</p>
2726

2827
<p><oj-bind-text value="[[labelMapper('list2-heading')]]"></oj-bind-text></p>

0 commit comments

Comments
 (0)