Skip to content

Commit 62b845b

Browse files
committed
Added item in menu tools - Generate instance data from xls
1 parent 4ee8124 commit 62b845b

21 files changed

+1416
-1117
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>eu.griddigit</groupId>
1414
<artifactId>CimPal</artifactId>
15-
<version>2023.1</version>
15+
<version>2023.2</version>
1616

1717

1818
<build>

src/main/java/application/MainController.java

Lines changed: 132 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package application;
77

88
import core.*;
9+
import customWriter.CustomRDFFormat;
910
import gui.ComboBoxCell;
1011
import gui.GUIhelper;
1112
import gui.TableColumnsSetup;
@@ -24,6 +25,7 @@
2425
import javafx.scene.control.*;
2526
import javafx.scene.control.cell.PropertyValueFactory;
2627
import javafx.scene.input.MouseEvent;
28+
import javafx.scene.text.Font;
2729
import javafx.scene.text.Text;
2830
import javafx.stage.FileChooser;
2931
import javafx.stage.Modality;
@@ -59,6 +61,16 @@
5961

6062
public class MainController implements Initializable {
6163

64+
public TabPane tabPaneConstraintsDetails;
65+
public Tab tabCreateCompleteSM1;
66+
public Tab tabCreateCompleteSM11;
67+
public Button btnRunExcelShape;
68+
public Button btnResetExcelShape;
69+
public Tab tabCreateCompleteSM2;
70+
public Button fbtnRunRDFConvert;
71+
public Tab tabOutputWindow;
72+
public Button btnResetIDComp;
73+
public Font x3;
6274
@FXML
6375
private TextArea foutputWindow;
6476
@FXML
@@ -68,8 +80,6 @@ public class MainController implements Initializable {
6880
@FXML
6981
private TextField fPathRdffile2;
7082
@FXML
71-
private Button btnResetRDFComp;
72-
@FXML
7383
private Button btnRunRDFcompare;
7484
@FXML
7585
private TabPane tabPaneDown;
@@ -114,8 +124,6 @@ public class MainController implements Initializable {
114124
@FXML
115125
private TextField fNSexcelShape;
116126
@FXML
117-
private Button btnRunExcelShape;
118-
@FXML
119127
private TextField fPathXLSfileForShape;
120128
@FXML
121129
private TextField fsourcePathTextField;
@@ -124,8 +132,6 @@ public class MainController implements Initializable {
124132
@FXML
125133
private ChoiceBox ftargetFormatChoiceBox;
126134
@FXML
127-
private Button fbtnRunRDFConvert;
128-
@FXML
129135
private TextField frdfConvertXmlBase;
130136
@FXML
131137
private CheckBox fcbShowXMLDeclaration;
@@ -170,8 +176,6 @@ public class MainController implements Initializable {
170176
@FXML
171177
private ChoiceBox fcbIDformat;
172178
@FXML
173-
private Button btnResetIDComp;
174-
@FXML
175179
private Button btnRunIDcompare;
176180
@FXML
177181
private TextField fPathIDfile1;
@@ -255,6 +259,8 @@ public class MainController implements Initializable {
255259

256260
public static TextArea foutputWindowVar;
257261
public static boolean excludeMRID;
262+
public static List<File> inputXLS;
263+
public static List<File> rdfProfileFileList;
258264

259265

260266
public MainController() {
@@ -1055,7 +1061,124 @@ private void actionBtnRunRDFcompare() throws FileNotFoundException {
10551061

10561062
}
10571063

1064+
@FXML
1065+
// action on menu Generation of instance data based on xls template
1066+
private void actionMenuInstanceDataGenxls() throws IOException {
1067+
1068+
System.out.print("Conversion in progress.\n");
1069+
progressBar.setProgress(0);
1070+
shaclNodataMap = 1; // as this mapping should not be used for this task
1071+
//select file
1072+
FileChooser filechooser = new FileChooser();
1073+
filechooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Input template instance data XLS", "*.xlsx"));
1074+
filechooser.setInitialDirectory(new File(MainController.prefs.get("LastWorkingFolder","")));
1075+
List<File> fileLxml;
1076+
fileLxml = filechooser.showOpenMultipleDialog(null);
1077+
1078+
1079+
if (fileLxml != null ) {// the file is selected
1080+
MainController.prefs.put("LastWorkingFolder", fileLxml.get(0).getParent());
1081+
MainController.inputXLS = fileLxml;
10581082

1083+
//select file
1084+
FileChooser filechooser1 = new FileChooser();
1085+
filechooser1.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("RDF profile file", "*.rdf", "*.ttl"));
1086+
filechooser1.setInitialDirectory(new File(MainController.prefs.get("LastWorkingFolder","")));
1087+
List<File> fileL;
1088+
fileL = filechooser1.showOpenMultipleDialog(null);
1089+
1090+
1091+
if (fileL!=null) {// the file is selected
1092+
MainController.prefs.put("LastWorkingFolder", fileL.get(0).getParent());
1093+
MainController.rdfProfileFileList = fileL;
1094+
1095+
//String xmlBase = "http://entsoe.eu/ns/nc";
1096+
//String xmlBase = "http://iec.ch/TC57/CIM100";
1097+
String xmlBase = "";
1098+
1099+
//set properties for the export
1100+
String formatGeneratedModel = "61970-552 CIM XML (.xml)"; //fcbGenDataFormat.getSelectionModel().getSelectedItem().toString();
1101+
Map<String, Object> saveProperties = new HashMap<>();
1102+
if (formatGeneratedModel.equals("61970-552 CIM XML (.xml)")) {
1103+
saveProperties.put("filename", "test");
1104+
saveProperties.put("showXmlDeclaration", "true");
1105+
saveProperties.put("showDoctypeDeclaration", "false");
1106+
saveProperties.put("tab", "2");
1107+
saveProperties.put("relativeURIs", "same-document");
1108+
saveProperties.put("showXmlEncoding", "true");
1109+
saveProperties.put("xmlBase", xmlBase);
1110+
saveProperties.put("rdfFormat", CustomRDFFormat.RDFXML_CUSTOM_PLAIN_PRETTY);
1111+
saveProperties.put("useAboutRules", true); //switch to trigger file chooser and adding the property
1112+
saveProperties.put("useEnumRules", true); //switch to trigger special treatment when Enum is referenced
1113+
saveProperties.put("useFileDialog", true);
1114+
saveProperties.put("fileFolder", "C:");
1115+
saveProperties.put("dozip", false);
1116+
saveProperties.put("instanceData", "true"); //this is to only print the ID and not with namespace
1117+
saveProperties.put("showXmlBaseDeclaration", "false");
1118+
1119+
saveProperties.put("putHeaderOnTop", true);
1120+
saveProperties.put("headerClassResource", "http://iec.ch/TC57/61970-552/ModelDescription/1#FullModel");
1121+
saveProperties.put("extensionName", "RDF XML");
1122+
saveProperties.put("fileExtension", "*.xml");
1123+
saveProperties.put("fileDialogTitle", "Save RDF XML for");
1124+
//RDFFormat rdfFormat=RDFFormat.RDFXML;
1125+
//RDFFormat rdfFormat=RDFFormat.RDFXML_PLAIN;
1126+
//RDFFormat rdfFormat = RDFFormat.RDFXML_ABBREV;
1127+
//RDFFormat rdfFormat = CustomRDFFormat.RDFXML_CUSTOM_PLAIN_PRETTY;
1128+
//RDFFormat rdfFormat = CustomRDFFormat.RDFXML_CUSTOM_PLAIN;
1129+
1130+
} else if (formatGeneratedModel.equals("Custom RDF XML Plain (.xml)")) {
1131+
saveProperties.put("filename", "test");
1132+
saveProperties.put("showXmlDeclaration", "true");
1133+
saveProperties.put("showDoctypeDeclaration", "false");
1134+
saveProperties.put("tab", "2");
1135+
saveProperties.put("relativeURIs", "same-document");
1136+
saveProperties.put("showXmlEncoding", "true");
1137+
saveProperties.put("xmlBase", xmlBase);
1138+
saveProperties.put("rdfFormat", CustomRDFFormat.RDFXML_CUSTOM_PLAIN);
1139+
saveProperties.put("useAboutRules", true); //switch to trigger file chooser and adding the property
1140+
saveProperties.put("useEnumRules", true); //switch to trigger special treatment when Enum is referenced
1141+
saveProperties.put("useFileDialog", true);
1142+
saveProperties.put("fileFolder", "C:");
1143+
saveProperties.put("dozip", false);
1144+
saveProperties.put("instanceData", "true"); //this is to only print the ID and not with namespace
1145+
saveProperties.put("showXmlBaseDeclaration", "false");
1146+
1147+
saveProperties.put("putHeaderOnTop", true);
1148+
saveProperties.put("headerClassResource", "http://iec.ch/TC57/61970-552/ModelDescription/1#FullModel");
1149+
saveProperties.put("extensionName", "RDF XML");
1150+
saveProperties.put("fileExtension", "*.xml");
1151+
saveProperties.put("fileDialogTitle", "Save RDF XML for");
1152+
}
1153+
1154+
1155+
1156+
boolean profileModelUnionFlag = false;
1157+
boolean instanceModelUnionFlag = false;
1158+
boolean shaclModelUnionFlag = false;
1159+
String eqbdID = null;
1160+
String tpbdID = null;
1161+
boolean persistentEQflag = false;
1162+
1163+
1164+
Map<String, Boolean> inputData = new HashMap<>();
1165+
inputData.put("rdfs", true);
1166+
inputData.put("baseModel", false);
1167+
inputData.put("shacl", false);
1168+
1169+
progressBar.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);
1170+
1171+
ModelManipulationFactory.generateDataFromXls(xmlBase, profileModelUnionFlag, instanceModelUnionFlag, inputData, shaclModelUnionFlag,eqbdID,tpbdID,saveProperties,persistentEQflag);
1172+
1173+
progressBar.setProgress(1);
1174+
System.out.print("Conversion finished.\n");
1175+
}else{
1176+
System.out.print("Conversion terminated.\n");
1177+
}
1178+
}else{
1179+
System.out.print("Conversion terminated.\n");
1180+
}
1181+
}
10591182

10601183
@FXML
10611184
//This is the menu item "Create datatypes map" - loads RDFfile(s) and creates the map
@@ -2604,7 +2727,7 @@ private void actionBtnRunExcelShape(ActionEvent actionEvent) throws IOException
26042727

26052728
//if (file != null) {// the file is selected
26062729

2607-
dataExcel = ExcelTools.importXLSX(String.valueOf(MainController.xlsFileExcelShacl));
2730+
dataExcel = ExcelTools.importXLSX(String.valueOf(MainController.xlsFileExcelShacl),0);
26082731
//System.out.println(dataExcel);
26092732
// }
26102733
//TODO: this can be made with many additional options e.g. what to be added and in which model to be added. Now it is primitive to solve a simple task

src/main/java/application/rdfDiffResultController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
import javafx.event.ActionEvent;
1212
import javafx.fxml.FXML;
1313
import javafx.fxml.Initializable;
14-
import javafx.scene.control.Label;
15-
import javafx.scene.control.TableCell;
16-
import javafx.scene.control.TableColumn;
17-
import javafx.scene.control.TableView;
14+
import javafx.scene.control.*;
1815
import javafx.scene.control.cell.PropertyValueFactory;
1916
import javafx.stage.Stage;
2017
import javafx.util.Callback;
@@ -27,6 +24,8 @@
2724
import static gui.ExcelExportTableView.export;
2825

2926
public class rdfDiffResultController implements Initializable {
27+
public Button btnCancel;
28+
public Button btnExportResult;
3029
@FXML
3130
private TableView tableViewResults;
3231
@FXML

src/main/java/core/InstanceDataFactory.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,30 @@
88
import application.MainController;
99
import customWriter.CustomRDFFormat;
1010
import javafx.scene.control.Alert;
11-
import javafx.stage.DirectoryChooser;
1211
import javafx.stage.FileChooser;
1312
import org.apache.commons.io.FilenameUtils;
14-
import org.apache.commons.lang3.RandomStringUtils;
15-
import org.apache.jena.datatypes.RDFDatatype;
16-
import org.apache.jena.datatypes.xsd.XSDDatatype;
17-
import org.apache.jena.datatypes.xsd.impl.XSDBaseNumericType;
1813
import org.apache.jena.rdf.model.*;
1914
import org.apache.jena.riot.Lang;
2015
import org.apache.jena.riot.RDFDataMgr;
2116
import org.apache.jena.riot.RDFFormat;
2217
import org.apache.jena.riot.SysRIOT;
2318
import org.apache.jena.sparql.util.Context;
24-
import org.apache.jena.vocabulary.*;
25-
import org.topbraid.shacl.vocabulary.SH;
19+
import org.apache.jena.vocabulary.DCAT;
20+
import org.apache.jena.vocabulary.RDF;
2621

2722
import java.io.*;
28-
import java.math.BigDecimal;
2923
import java.nio.file.Path;
3024
import java.nio.file.Paths;
31-
import java.security.SecureRandom;
32-
import java.text.SimpleDateFormat;
3325
import java.util.*;
34-
import java.util.concurrent.ThreadLocalRandom;
35-
import java.util.concurrent.TimeUnit;
3626
import java.util.zip.ZipEntry;
3727
import java.util.zip.ZipFile;
3828
import java.util.zip.ZipOutputStream;
3929

4030
public class InstanceDataFactory {
4131

42-
public static Map<Property,Map> shaclConstraints;
43-
4432

4533
//Loads one or many models
46-
public static Map<String,Model> modelLoad(List<File> files, String xmlBase, Lang rdfSourceFormat) throws FileNotFoundException {
34+
public static Map<String,Model> modelLoad(List<File> files, String xmlBase, Lang rdfSourceFormat, boolean isSHACL) throws FileNotFoundException {
4735

4836
Map<String,Model> unionModelMap=new HashMap<>();
4937
Model modelUnion = org.apache.jena.rdf.model.ModelFactory.createDefaultModel();
@@ -86,11 +74,15 @@ public static Map<String,Model> modelLoad(List<File> files, String xmlBase, Lang
8674
modelUnion.setNsPrefixes(prefixMap);
8775
modelUnionWithoutHeader.setNsPrefixes(prefixMap);
8876

89-
90-
unionModelMap.put("unionModel",modelUnion);
91-
unionModelMap.put("modelUnionWithoutHeader",modelUnionWithoutHeader);
92-
return unionModelMap;
93-
77+
if (isSHACL){
78+
Model shaclModel= ShapeFactory.createShapeModelWithOwlImport(modelUnion);
79+
unionModelMap.put("shacl",shaclModel);
80+
return unionModelMap;
81+
}else {
82+
unionModelMap.put("unionModel",modelUnion);
83+
unionModelMap.put("modelUnionWithoutHeader",modelUnionWithoutHeader);
84+
return unionModelMap;
85+
}
9486
}
9587

9688
//get the keyword for the profile

0 commit comments

Comments
 (0)