Skip to content

Commit 6d40d0d

Browse files
committed
Added DeleteAllExtensionsCommand
1 parent 4b7fb2d commit 6d40d0d

File tree

10 files changed

+78
-98
lines changed

10 files changed

+78
-98
lines changed

src/main/java/io/apicurio/datamodels/cmd/commands/AbstractSchemaInhCommand.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
* Copyright 2019 JBoss Inc
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
package io.apicurio.datamodels.cmd.commands;
182

193
import com.fasterxml.jackson.databind.node.ObjectNode;

src/main/java/io/apicurio/datamodels/cmd/commands/ChangeContactCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package io.apicurio.datamodels.cmd.commands;
32

43
import com.fasterxml.jackson.databind.node.ObjectNode;

src/main/java/io/apicurio/datamodels/cmd/commands/ChangeDescriptionCommand.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
* Copyright 2019 Red Hat
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
package io.apicurio.datamodels.cmd.commands;
182

193
import io.apicurio.datamodels.cmd.AbstractCommand;

src/main/java/io/apicurio/datamodels/cmd/commands/ChangeVersionCommand.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
* Copyright 2019 Red Hat
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
package io.apicurio.datamodels.cmd.commands;
182

193
import io.apicurio.datamodels.cmd.AbstractCommand;

src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllChildSchemasCommand.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
* Copyright 2019 Red Hat
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
package io.apicurio.datamodels.cmd.commands;
182

193
import com.fasterxml.jackson.databind.node.ObjectNode;

src/main/java/io/apicurio/datamodels/cmd/commands/DeleteAllExamplesCommand.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
* Copyright 2019 Red Hat
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
package io.apicurio.datamodels.cmd.commands;
182

193
import com.fasterxml.jackson.databind.node.ObjectNode;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package io.apicurio.datamodels.cmd.commands;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import io.apicurio.datamodels.Library;
5+
import io.apicurio.datamodels.cmd.AbstractCommand;
6+
import io.apicurio.datamodels.models.Document;
7+
import io.apicurio.datamodels.models.Extensible;
8+
import io.apicurio.datamodels.models.Node;
9+
import io.apicurio.datamodels.paths.NodePath;
10+
import io.apicurio.datamodels.paths.NodePathUtil;
11+
import io.apicurio.datamodels.util.LoggerUtil;
12+
13+
import java.util.LinkedHashMap;
14+
import java.util.Map;
15+
16+
/**
17+
* A command used to delete all extensions from a node.
18+
* @author eric.wittmann@gmail.com
19+
*/
20+
public class DeleteAllExtensionsCommand extends AbstractCommand {
21+
22+
public NodePath _parentPath;
23+
24+
public Map<String, JsonNode> _oldExtensions;
25+
26+
public DeleteAllExtensionsCommand() {
27+
}
28+
29+
public DeleteAllExtensionsCommand(Extensible parent) {
30+
this._parentPath = Library.createNodePath((Node) parent);
31+
}
32+
33+
/**
34+
* @see io.apicurio.datamodels.cmd.ICommand#execute(Document)
35+
*/
36+
@Override
37+
public void execute(Document document) {
38+
LoggerUtil.info("[DeleteAllExtensionsCommand] Executing.");
39+
this._oldExtensions = new LinkedHashMap<>();
40+
41+
Extensible parent = (Extensible) NodePathUtil.resolveNodePath(this._parentPath, document);
42+
43+
Map<String, JsonNode> extensions = parent.getExtensions();
44+
45+
// Save the old extensions (if any)
46+
if (!this.isNullOrUndefined(extensions)) {
47+
extensions.keySet().forEach(k -> {
48+
JsonNode value = extensions.get(k);
49+
this._oldExtensions.put(k, value);
50+
});
51+
}
52+
53+
// Remove all extensions
54+
parent.clearExtensions();
55+
}
56+
57+
/**
58+
* @see io.apicurio.datamodels.cmd.ICommand#undo(Document)
59+
*/
60+
@Override
61+
public void undo(Document document) {
62+
LoggerUtil.info("[DeleteAllExtensionsCommand] Reverting.");
63+
if (this._oldExtensions.size() == 0) {
64+
return;
65+
}
66+
67+
Extensible parent = (Extensible) NodePathUtil.resolveNodePath(this._parentPath, document);
68+
69+
this._oldExtensions.keySet().forEach(k -> {
70+
JsonNode value = _oldExtensions.get(k);
71+
parent.addExtension(k, value);
72+
});
73+
}
74+
}

src/main/java/io/apicurio/datamodels/cmd/commands/DeleteLicenseCommand.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
* Copyright 2019 Red Hat
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
171
package io.apicurio.datamodels.cmd.commands;
182

193
import com.fasterxml.jackson.databind.node.ObjectNode;

src/main/ts/src/io/apicurio/datamodels/util/CommandUtil.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {ChangeLicenseCommand} from "../cmd/commands/ChangeLicenseCommand";
1313

1414
import {DeleteAllChildSchemasCommand} from "../cmd/commands/DeleteAllChildSchemasCommand";
1515
import {DeleteAllExamplesCommand} from "../cmd/commands/DeleteAllExamplesCommand";
16+
import {DeleteAllExtensionsCommand} from "../cmd/commands/DeleteAllExtensionsCommand";
1617
import {DeleteContactCommand} from "../cmd/commands/DeleteContactCommand";
1718
import {DeleteExtensionCommand} from "../cmd/commands/DeleteExtensionCommand";
1819
import {DeleteLicenseCommand} from "../cmd/commands/DeleteLicenseCommand";
@@ -42,6 +43,7 @@ const commandSuppliers: { [key: string]: Supplier } = {
4243

4344
"DeleteAllChildSchemasCommand": () => { return new DeleteAllChildSchemasCommand(); },
4445
"DeleteAllExamplesCommand": () => { return new DeleteAllExamplesCommand(); },
46+
"DeleteAllExtensionsCommand": () => { return new DeleteAllExtensionsCommand(); },
4547
"DeleteContactCommand": () => { return new DeleteContactCommand(); },
4648
"DeleteExtensionCommand": () => { return new DeleteExtensionCommand(); },
4749
"DeleteLicenseCommand": () => { return new DeleteLicenseCommand(); },

src/test/resources/fixtures/cmd/tests.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@
3434
{ "name": "[OpenAPI 3] {Delete Media Type} - Delete Media Type Request Body", "test": "commands/delete-media-type/openapi-3/delete-media-type-requestBody" },
3535
{ "name": "[OpenAPI 3] {Delete Media Type} - Delete Media Type Response", "test": "commands/delete-media-type/openapi-3/delete-media-type-response" },
3636
{ "name": "[OpenAPI 3] {Delete All Child Schemas} - All Of", "test": "commands/delete-all-child-schemas/openapi-3/delete-all-schemas" },
37-
{ "name": "[OpenAPI 3] {Delete All Examples} - Delete All Examples", "test": "commands/delete-all-examples/openapi-3/delete-all-examples" }
37+
{ "name": "[OpenAPI 3] {Delete All Examples} - Delete All Examples", "test": "commands/delete-all-examples/openapi-3/delete-all-examples" },
38+
{ "name": "[OpenAPI 3] {Delete All Extensions} - Delete All Extensions", "test": "commands/delete-all-extensions/openapi-3/delete-all-extensions" }
3839
]

0 commit comments

Comments
 (0)