Skip to content

Commit

Permalink
Solved cycle SchemaEvolution and ModelUtilities
Browse files Browse the repository at this point in the history
  • Loading branch information
suarezgpablo committed Oct 14, 2024
1 parent 6613c01 commit d48772a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package giis.modevo.model;

import java.io.File;
import java.io.IOException;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class DocumentUtilities {
public Document readDocumentGeneric (String path) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document doc = null;
// optional, but recommended
// process XML securely, avoid attacks like XML External Entities (XXE)
try {
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
// parse XML file
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(new File(path));
// optional, but recommended
doc.getDocumentElement().normalize();
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new DocumentException("A model could not be opened:" + e);
}
return doc;
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
package giis.modevo.model;

import java.io.File;
import java.io.IOException;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import giis.modevo.model.schema.Column;
import giis.modevo.model.schema.Schema;
import giis.modevo.model.schema.Table;
import giis.modevo.model.schemaevolution.SchemaEvolution;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ModelUtilities {
public Document readDocumentGeneric (String path) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document doc = null;
// optional, but recommended
// process XML securely, avoid attacks like XML External Entities (XXE)
try {
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
// parse XML file
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(new File(path));
// optional, but recommended
doc.getDocumentElement().normalize();
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new DocumentException("A model could not be opened:" + e);
}
return doc;
}

/**
* Returns the table object from either the Schema or the Schema Evolution model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import giis.modevo.model.ModelUtilities;
import giis.modevo.model.DocumentUtilities;
import giis.modevo.model.schema.Column;
import giis.modevo.model.schema.Schema;
import giis.modevo.model.schema.Table;
Expand Down Expand Up @@ -48,8 +48,7 @@ public void addTable(MigrationTable t) {
*/
public DataMigration readDataMigrationModel(String dataMigrationPath, SchemaEvolution schemaEvolution, Schema schema) {
DataMigration dataMigration = new DataMigration();
ModelUtilities mu = new ModelUtilities();
Document doc = mu.readDocumentGeneric(dataMigrationPath);
Document doc = new DocumentUtilities().readDocumentGeneric(dataMigrationPath);
NodeList list = doc.getElementsByTagName("MigrationTable");
for (int temp = 0; temp < list.getLength(); temp++) {
Node node = list.item(temp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import giis.modevo.model.ModelUtilities;
import giis.modevo.model.DocumentUtilities;
import lombok.Getter;
import lombok.Setter;

Expand Down Expand Up @@ -48,8 +48,7 @@ public Table getTable(String name) {
*/
public Schema loadSchemaIntoApp(String fileSchema) {
Schema schema = new Schema(new ArrayList<>());
ModelUtilities mu = new ModelUtilities();
Document doc = mu.readDocumentGeneric(fileSchema);
Document doc = new DocumentUtilities().readDocumentGeneric(fileSchema);
NodeList list = doc.getElementsByTagName("Table");
for (int temp = 0; temp < list.getLength(); temp++) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import giis.modevo.model.ModelUtilities;
import giis.modevo.model.DocumentUtilities;
import giis.modevo.model.schema.Table;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -60,8 +60,7 @@ public Table getTable(String name) {
*/
public SchemaEvolution readSchemaEvolutionModel(String pathSchemaEvolutionModel) {
SchemaEvolution se = new SchemaEvolution();
ModelUtilities mu = new ModelUtilities();
Document doc = mu.readDocumentGeneric(pathSchemaEvolutionModel);
Document doc = new DocumentUtilities().readDocumentGeneric(pathSchemaEvolutionModel);
NodeList xmi = doc.getElementsByTagName("xmi:XMI");
Node xmiNode = xmi.item(0); // There is only just one
NodeList list = xmiNode.getChildNodes();
Expand Down

0 comments on commit d48772a

Please sign in to comment.