Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #712 from BorisNen/hdbdd-parse
Browse files Browse the repository at this point in the history
Fix artifact parsing without making changes for HDBDD
  • Loading branch information
ThuF authored Oct 27, 2021
2 parents 3080543 + b6b7413 commit da7ae9b
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class XSKDataStructureModel {
@Transient
private transient XSKDBContentType dbContentType;

@Transient
private transient boolean createDataStructure = false;

/**
* Gets the location.
*
Expand Down Expand Up @@ -221,6 +224,14 @@ public void setDbContentType(XSKDBContentType dbContentType) {
this.dbContentType = dbContentType;
}

public boolean isCreateDataStructure() {
return createDataStructure;
}

public void setCreateDataStructure(boolean createDataStructure) {
this.createDataStructure = createDataStructure;
}

/**
* To json.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.sap.xsk.hdb.ds.model.hdbdd.XSKDataStructureCdsModel;
import com.sap.xsk.hdb.ds.model.hdbtable.XSKDataStructureHDBTableModel;
import com.sap.xsk.hdb.ds.model.hdbtabletype.XSKDataStructureHDBTableTypeModel;
import com.sap.xsk.hdb.ds.module.XSKHDBModule;
import com.sap.xsk.hdb.ds.parser.XSKDataStructureParser;
import com.sap.xsk.hdb.ds.transformer.hdbdd.HdbddTransformer;
import com.sap.xsk.parser.hdbdd.core.CdsLexer;
Expand Down Expand Up @@ -61,10 +62,16 @@ public class XSKHdbddParser implements XSKDataStructureParser {
private HdbddTransformer hdbddTransformer = new HdbddTransformer();
private IRepository repository = (IRepository) StaticObjects.get(StaticObjects.REPOSITORY);
private SymbolTable symbolTable = new SymbolTable();
private Map<String, Set<String>> usedFiles = new HashMap<>();
private Map<String, Set<String>> dependencyStructure = new HashMap<>();
private Set<String> parsedNodes = new HashSet<>();

@Override
public XSKDataStructureModel parse(String location, String content) throws XSKDataStructuresException, IOException {
XSKDataStructureCdsModel cdsModel = getCdsModelBaseData(location, content);
if (XSKHDBModule.getManagerServices().get(getType()).isParsed(cdsModel, dependencyStructure.get(location) != null)) {
return null;
}

for (String fileLocation : this.getFilesToProcess(location)) {
IResource loadedResource = this.repository.getResource("/registry/public/" + fileLocation);
String fileContent = new String(loadedResource.getContent());
Expand All @@ -77,9 +84,10 @@ public XSKDataStructureModel parse(String location, String content) throws XSKDa
}
}

XSKDataStructureCdsModel cdsModel = getCdsModel(location, content);
getCdsModelWithParsedData(cdsModel);
this.symbolTable.clearSymbolsByFullName();
this.symbolTable.clearEntityGraph();
parsedNodes.clear();

return cdsModel;
}
Expand Down Expand Up @@ -121,11 +129,15 @@ private void parseHdbdd(String location, String content) throws IOException, XSK

entityDefinitionListener.getPackagesUsed().forEach(p -> {
String fileLocation = getFileLocation(p);
addUsedFile(fileLocation, location);
addFileToDependencyTree(fileLocation, location);
if(!parsedNodes.isEmpty() && parsedNodes.contains(fileLocation)){
return;
}

try {
IResource loadedResource = this.repository.getResource("/registry/public/" + fileLocation);
parseHdbdd(fileLocation, new String(loadedResource.getContent()));
parsedNodes.add(fileLocation);
} catch (IOException | XSKArtifactParserException e) {
XSKCommonsUtils.logCustomErrors(location, XSKCommonsConstants.PARSER_ERROR, "", "", e.getMessage(),
"", XSKCommonsConstants.HDBDD_PARSER, XSKCommonsConstants.MODULE_PARSERS,
Expand All @@ -150,14 +162,14 @@ private void parseHdbdd(String location, String content) throws IOException, XSK
}
}

private void addUsedFile(String usedFile, String userFile) {
Set<String> userFiles = usedFiles.get(usedFile);
if (userFiles == null) {
userFiles = new HashSet<>();
private void addFileToDependencyTree(String nodeFile, String rootFile) {
Set<String> rootFiles = dependencyStructure.get(nodeFile);
if (rootFiles == null) {
rootFiles = new HashSet<>();
}

userFiles.add(userFile);
this.usedFiles.put(usedFile, userFiles);
rootFiles.add(rootFile);
this.dependencyStructure.put(nodeFile, rootFiles);
}

@Override
Expand All @@ -178,21 +190,32 @@ private List<String> getFilesToProcess(String fileLocation) {
}

private void getRootFiles(String usedFileName, List<String> rootFiles) {
Set<String> userFiles = usedFiles.get(usedFileName);
Set<String> userFiles = dependencyStructure.get(usedFileName);
if (userFiles == null) {
rootFiles.add(usedFileName);
return;
}

usedFiles.get(usedFileName).forEach(f -> {
dependencyStructure.get(usedFileName).forEach(f -> {
getRootFiles(f, rootFiles);
});
}

private XSKDataStructureCdsModel getCdsModel(String location, String content) {
List<EntitySymbol> parsedEntities = this.symbolTable.getSortedEntities();

private XSKDataStructureCdsModel getCdsModelBaseData(String location, String content) {
XSKDataStructureCdsModel cdsModel = new XSKDataStructureCdsModel();
cdsModel.setName(location);
cdsModel.setLocation(location);
cdsModel.setType(getType());
cdsModel.setCreatedBy(UserFacade.getName());
cdsModel.setCreatedAt(new Timestamp(new java.util.Date().getTime()));
cdsModel.setHash(DigestUtils.md5Hex(content));
cdsModel.setDbContentType(XSKDBContentType.XS_CLASSIC);

return cdsModel;
}

private void getCdsModelWithParsedData(XSKDataStructureCdsModel cdsModel) {
List<EntitySymbol> parsedEntities = this.symbolTable.getSortedEntities();

List<XSKDataStructureHDBTableModel> tableModels = new ArrayList<>();
parsedEntities.forEach(e -> {
Expand All @@ -210,14 +233,6 @@ private XSKDataStructureCdsModel getCdsModel(String location, String content) {

cdsModel.setTableModels(tableModels);
cdsModel.setTableTypeModels(hdbTableTypeModels);
cdsModel.setName(location);
cdsModel.setLocation(location);
cdsModel.setType(getType());
cdsModel.setCreatedBy(UserFacade.getName());
cdsModel.setCreatedAt(new Timestamp(new java.util.Date().getTime()));
cdsModel.setHash(DigestUtils.md5Hex(content));
cdsModel.setDbContentType(XSKDBContentType.XS_CLASSIC);
return cdsModel;
}

private String getFileLocation(String fullPackagePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ void updateDataStructure(Connection connection, T tableModel)
void cleanup() throws XSKDataStructuresException;

void clearCache();

boolean isParsed(T tableModel, boolean parsedByRoot) throws XSKDataStructuresException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,33 @@ public IXSKEntityManagerService() {
entitiesSynchronized = Collections.synchronizedList(new ArrayList<>());
}

public boolean isParsed(XSKDataStructureCdsModel entitiesModel, boolean parsedByRoot) throws XSKDataStructuresException {
XSKDataStructureCdsModel existingModel = getDataStructuresCoreService()
.getDataStructure(entitiesModel.getLocation(), entitiesModel.getType());
boolean isEmptyExistingModel = existingModel == null;

if (isEmptyExistingModel && parsedByRoot) {
getDataStructuresCoreService()
.createDataStructure(entitiesModel.getLocation(), entitiesModel.getName(), entitiesModel.getHash(), entitiesModel.getType());
return true;
}

entitiesModel.setCreateDataStructure(isEmptyExistingModel);
return !isEmptyExistingModel && existingModel.equals(entitiesModel);
}

@Override
public void synchronizeRuntimeMetadata(XSKDataStructureCdsModel entitiesModel) throws XSKDataStructuresException {
if (!getDataStructuresCoreService().existsDataStructure(entitiesModel.getLocation(), entitiesModel.getType())) {
if (entitiesModel.isCreateDataStructure()) {
getDataStructuresCoreService()
.createDataStructure(entitiesModel.getLocation(), entitiesModel.getName(), entitiesModel.getHash(), entitiesModel.getType());
dataStructureEntitiesModel.put(entitiesModel.getName(), entitiesModel);
logger.info("Synchronized a new Entities file [{}] from location: {}", entitiesModel.getName(), entitiesModel.getLocation());
} else {
XSKDataStructureCdsModel existing = getDataStructuresCoreService()
.getDataStructure(entitiesModel.getLocation(), entitiesModel.getType());
if (!entitiesModel.equals(existing)) {
getDataStructuresCoreService()
.updateDataStructure(entitiesModel.getLocation(), entitiesModel.getName(), entitiesModel.getHash(), entitiesModel.getType());
dataStructureEntitiesModel.put(entitiesModel.getName(), entitiesModel);
logger.info("Synchronized a modified Entities file [{}] from location: {}", entitiesModel.getName(), entitiesModel.getLocation());
}
getDataStructuresCoreService()
.updateDataStructure(entitiesModel.getLocation(), entitiesModel.getName(), entitiesModel.getHash(), entitiesModel.getType());
dataStructureEntitiesModel.put(entitiesModel.getName(), entitiesModel);
logger.info("Synchronized a modified Entities file [{}] from location: {}", entitiesModel.getName(), entitiesModel.getLocation());
}
if (!entitiesSynchronized.contains(entitiesModel.getLocation())) {
entitiesSynchronized.add(entitiesModel.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ public String getDataStructureType() {
public void clearCache() {
dataStructureSequenceModels.clear();
}

@Override
public boolean isParsed(XSKDataStructureHDBSequenceModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public void clearCache() {
dataStructureProceduresModels.clear();
}

@Override
public boolean isParsed(XSKDataStructureHDBProcedureModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException {
return false;
}

@Override
public Map<String, XSKDataStructureHDBProcedureModel> getDataStructureModels() {
return Collections.unmodifiableMap(this.dataStructureProceduresModels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public void clearCache() {
dataStructureSchemasModels.clear();
}

@Override
public boolean isParsed(XSKDataStructureHDBSchemaModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException {
return false;
}

@Override
public Map<String, XSKDataStructureHDBSchemaModel> getDataStructureModels() {
return Collections.unmodifiableMap(this.dataStructureSchemasModels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public String getDataStructureType() {
public void clearCache() {
dataStructureSynonymModels.clear();
}

@Override
public boolean isParsed(XSKDataStructureHDBSynonymModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public void clearCache() {
dataStructureTableFunctionsModels.clear();
}

@Override
public boolean isParsed(XSKDataStructureHDBTableFunctionModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException {
return false;
}

@Override
public Map<String, XSKDataStructureHDBTableFunctionModel> getDataStructureModels() {
return Collections.unmodifiableMap(this.dataStructureTableFunctionsModels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ public String getDataStructureType() {
public void clearCache() {
dataStructureTableModels.clear();
}

@Override
public boolean isParsed(XSKDataStructureHDBTableModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ public String getDataStructureType() {
public void clearCache() {
dataStructureHDBTableTypeModels.clear();
}

@Override
public boolean isParsed(XSKDataStructureHDBTableTypeModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ public String getDataStructureType() {
public void clearCache() {
dataStructureViewsModels.clear();
}

@Override
public boolean isParsed(XSKDataStructureHDBViewModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException {
return false;
}
}

0 comments on commit da7ae9b

Please sign in to comment.