Skip to content

Commit

Permalink
ISSUE-656: Delete schema metadata when invalid schema is added (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
joylyn authored and raju-saravanan committed Jan 27, 2020
1 parent e64e11d commit 47e73d8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class SchemaFormContainer extends Component {
}
}

handleSave(didVersionFailed) {
handleSave() {
let data = {};
let {name, type, schemaGroup, description, compatibility, evolve, schemaText} = this.state;
data = {
Expand All @@ -195,18 +195,14 @@ export default class SchemaFormContainer extends Component {
if (compatibility !== '') {
data.compatibility = compatibility;
}
if(didVersionFailed){
return SchemaREST.postVersion(name, {body: JSON.stringify(versionData)});
} else {
return SchemaREST.postSchema({body: JSON.stringify(data)})
.then((schemaResult)=>{
if(schemaResult.responseMessage !== undefined){
FSReactToastr.error(<CommonNotification flag="error" content={schemaResult.responseMessage}/>, '', toastOpt);
} else {
return SchemaREST.postVersion(name, {body: JSON.stringify(versionData)});
}
});
}
return SchemaREST.postSchema({body: JSON.stringify(data)})
.then((schemaResult)=>{
if(schemaResult.responseMessage !== undefined){
FSReactToastr.error(<CommonNotification flag="error" content={schemaResult.responseMessage}/>, '', toastOpt);
} else {
return SchemaREST.postVersion(name, {body: JSON.stringify(versionData)});
}
});
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,15 @@ export default class SchemaRegistryContainer extends Component {
}
handleSave() {
if (this.refs.addSchema.validateData()) {
this.refs.addSchema.handleSave(this.versionFailed).then((schemas) => {
this.refs.addSchema.handleSave().then((schemas) => {
if (schemas.responseMessage !== undefined) {
this.versionFailed = true;
FSReactToastr.error(<CommonNotification flag="error" content={schemas.responseMessage}/>, '', toastOpt);
let name = this.refs.addSchema.state.name;
let content = 'An exception was thrown while adding the schema version'+schemas.responseMessage.slice(schemas.responseMessage.indexOf('message') + 'message'.length);
SchemaREST.deleteSchemaMetadata(name)
.then(()=>{
FSReactToastr.error(<CommonNotification flag="error" content={content} />, '', toastOpt);
});
} else {
this.versionFailed = false;
this.refs.schemaModal.hide();
this.fetchData();
let msg = "Schema added successfully";
Expand Down
13 changes: 13 additions & 0 deletions webservice/src/main/resources/app/scripts/rest/SchemaREST.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ const SchemaREST = {
.then((res) => {
return checkStatus(res, 'DELETE');
});
},
deleteSchemaMetadata(name, options){
options = options || {};
options.method = options.method || 'DELETE';
options.headers = options.headers || {
'Content-Type': 'application/json',
'Accept': 'application/json'
};
options.credentials = 'same-origin';
return fetch(baseUrl + `schemaregistry/schemas/${name}`, options)
.then((res) => {
return checkStatus(res, 'DELETE');
});
}
};

Expand Down

0 comments on commit 47e73d8

Please sign in to comment.