Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
fix(dv) ENTESB-14057 addressing scenarios that can build invalid
Browse files Browse the repository at this point in the history
metadata
  • Loading branch information
shawkins committed Jun 19, 2020
1 parent a37f3e4 commit f10a4ff
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,8 @@ ViewDefinition upsertViewEditorState(final ViewDefinition restViewDefn) {
}

boolean pathsSame = false;
boolean updateDv = false;
// Add a new ViewDefinition
if (viewDefn == null) {
updateDv = true;
viewDefn = getWorkspaceManager().createViewDefiniton(restViewDefn.getDataVirtualizationName(), restViewDefn.getName());
} else {
if (!restViewDefn.getName().equals(viewDefn.getName()) || !restViewDefn.getDataVirtualizationName().equals(viewDefn.getDataVirtualizationName())) {
Expand All @@ -272,21 +270,26 @@ ViewDefinition upsertViewEditorState(final ViewDefinition restViewDefn) {
for (String restSourcePath: restViewDefn.getSourcePaths()) {
viewDefn.addSourcePath(restSourcePath);
}
viewDefn.setComplete(restViewDefn.isComplete());
viewDefn.setUserDefined(restViewDefn.isUserDefined());

boolean wasParsable = viewDefn.isParsable();
boolean wasComplete = viewDefn.isComplete();

viewDefn.setComplete(restViewDefn.isComplete());
boolean updateDv = false;

if (viewDefn.isComplete()) {
if (!viewDefn.isUserDefined()) {
//regenerate if needed
if (viewDefn.getDdl() == null || !pathsSame || !viewDefn.isParsable()) {
if (viewDefn.getDdl() == null || !pathsSame || !wasParsable) {
String ddl = new ServiceVdbGenerator(metadataService).getODataViewDdl(viewDefn);
viewDefn.setDdl(ddl);
viewDefn.setParsable(true);
updateDv = true;
}
// else we're trusting the ui
} else if (viewDefn.getDdl() != null && !Objects.equals(oldDdl, viewDefn.getDdl())) {

} else if (viewDefn.getDdl() != null && (!Objects.equals(oldDdl, viewDefn.getDdl()) || !wasComplete)) {
viewDefn.setParsable(false);
//TODO: could pro-actively validate if we're in a good state
viewDefn.getSourcePaths().clear();
ValidationResult result = metadataInstance.parse(viewDefn.getDdl());
Expand All @@ -306,19 +309,17 @@ ViewDefinition upsertViewEditorState(final ViewDefinition restViewDefn) {
//for now we'll redo everything
updateDv = true;
}
} else {
//not actually usable - perhaps come other ddl statement
if (viewDefn.isParsable()) {
updateDv = true;
}
viewDefn.setParsable(false);
}
}
} else {
//could be anything, so also toggle the parsable flag
viewDefn.setParsable(false);
}

if (updateDv) {
DataVirtualization dv = getWorkspaceManager().findDataVirtualization(viewDefn.getDataVirtualizationName());
dv.touch();
}
//if there was a change that may have affected the metadata, we need to update the preview vdb
if (updateDv || (viewDefn.isComplete() ^ wasComplete) || (viewDefn.isParsable() ^ wasParsable)) {
DataVirtualization dv = getWorkspaceManager().findDataVirtualization(viewDefn.getDataVirtualizationName());
dv.touch();
}

return viewDefn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@

package io.syndesis.dv.server.endpoint;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import io.syndesis.dv.metadata.internal.DefaultMetadataInstance;
import io.syndesis.dv.model.ViewDefinition;
import io.syndesis.dv.repository.RepositoryConfiguration;
import io.syndesis.dv.repository.RepositoryManagerImpl;
import java.util.Arrays;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -35,13 +39,6 @@
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import io.syndesis.dv.metadata.internal.DefaultMetadataInstance;
import io.syndesis.dv.model.ViewDefinition;
import io.syndesis.dv.repository.RepositoryConfiguration;
import io.syndesis.dv.repository.RepositoryManagerImpl;

@SuppressWarnings("nls")
@RunWith(SpringRunner.class)
@DataJpaTest
Expand Down Expand Up @@ -125,6 +122,22 @@ public class EditorServiceTest {
for (ViewListing vl : dvService.getViewList("x")) {
assertTrue(vl.isValid());
}

//invalid
vd.setDdl("create view y as * from dummy.v");
vd.setComplete(false);
saved = utilService.upsertViewEditorState(vd);
assertFalse(saved.isParsable());

//still invalid
vd.setComplete(true);
saved = utilService.upsertViewEditorState(vd);
assertFalse(saved.isParsable());

//still invalid - parse error after main ddl
vd.setDdl("create view y as select * from dummy.v abc 123");
saved = utilService.upsertViewEditorState(vd);
assertFalse(saved.isParsable());
}

static VDBMetaData dummyPreviewVdb(boolean hidden) {
Expand Down

0 comments on commit f10a4ff

Please sign in to comment.