private void insertMapping(String target, String source) { List<Function> targetQuery = parse(target); if (targetQuery != null) { final boolean isValid = validator.validate(targetQuery); if (isValid) { try { OBDAModel mapcon = obdaModel; URI sourceID = dataSource.getSourceID(); System.out.println(sourceID.toString() + " \n"); OBDASQLQuery body = dataFactory.getSQLQuery(source); System.out.println(body.toString() + " \n"); OBDAMappingAxiom newmapping = dataFactory.getRDBMSMappingAxiom(txtMappingID.getText().trim(), body, targetQuery); System.out.println(newmapping.toString() + " \n"); if (mapping == null) { // Case when we are creating a new mapping mapcon.addMapping(sourceID, newmapping); } else { // Case when we are updating an existing mapping mapcon.updateMappingsSourceQuery(sourceID, mapping.getId(), body); mapcon.updateTargetQueryMapping(sourceID, mapping.getId(), targetQuery); mapcon.updateMapping(sourceID, mapping.getId(), txtMappingID.getText().trim()); } } catch (DuplicateMappingException e) { JOptionPane.showMessageDialog( this, "Error while inserting mapping: " + e.getMessage() + " is already taken"); return; } parent.setVisible(false); parent.dispose(); } else { // List of invalid predicates that are found by the validator. Vector<String> invalidPredicates = validator.getInvalidPredicates(); String invalidList = ""; for (String predicate : invalidPredicates) { invalidList += "- " + predicate + "\n"; } JOptionPane.showMessageDialog( this, "This list of predicates is unknown by the ontology: \n" + invalidList, "New Mapping", JOptionPane.WARNING_MESSAGE); } } }
@Override public void actionPerformed(ActionEvent e) { currentOnto = owlManager.getActiveOntology(); currentModel = modelManager.getActiveOBDAModel(); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); JLabel dsource = new JLabel("Choose a datasource to bootstrap: "); dsource.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(dsource); List<String> options = new ArrayList<String>(); for (OBDADataSource source : currentModel.getSources()) options.add(source.getSourceID().toString()); JComboBox combo = new JComboBox(options.toArray()); combo.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(combo); Dimension minsize = new Dimension(10, 10); panel.add(new Box.Filler(minsize, minsize, minsize)); JLabel ouri = new JLabel("Base URI - the prefix to be used for all generated classes and properties: "); ouri.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(ouri); JTextField base_uri = new JTextField(); base_uri.setText(currentModel.getPrefixManager().getDefaultPrefix().replace("#", "/")); base_uri.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(base_uri); int res = JOptionPane.showOptionDialog( workspace, panel, "Bootstrapping", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (res == JOptionPane.OK_OPTION) { int index = combo.getSelectedIndex(); currentSource = currentModel.getSources().get(index); if (currentSource != null) { this.baseUri = base_uri.getText().trim(); if (baseUri.contains("#")) { JOptionPane.showMessageDialog(workspace, "Base Uri cannot contain the character '#'"); throw new RuntimeException("Base URI " + baseUri + " contains '#' character!"); } else { Thread th = new Thread( new Runnable() { @Override public void run() { try { OBDAProgessMonitor monitor = new OBDAProgessMonitor("Bootstrapping ontology and mappings..."); BootstrapperThread t = new BootstrapperThread(); monitor.addProgressListener(t); monitor.start(); t.run(baseUri, currentOnto, currentModel, currentSource); currentModel.fireSourceParametersUpdated(); monitor.stop(); JOptionPane.showMessageDialog( workspace, "Task is completed.", "Done", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { log.error(e.getMessage(), e); JOptionPane.showMessageDialog( null, "Error occured during bootstrapping data source."); } } }); th.start(); } } } }