@Deprecated public void addTriplesMap(URI sourceID, SQLPPTriplesMap triplesMap, boolean disableFiringMappingInsertedEvent) throws DuplicateMappingException { String mapId = triplesMap.getId(); if (triplesMapMap.containsKey(mapId)) throw new DuplicateMappingException("ID " + mapId); triplesMapMap.put(mapId, triplesMap); if (!disableFiringMappingInsertedEvent) fireMappingInserted(sourceID); }
@Override public SQLPPMapping clone() { try { return new SQLPPMappingImpl(triplesMaps, mappingMetadata); } catch (DuplicateMappingException e) { throw new RuntimeException("Unexpected error (inconsistent cloning): " + e.getMessage()); } }
public void run(File file) throws Exception { /** * Uses the predefined data source for creating the OBDAModel. */ OBDADataSource dataSource = obdaModelController.getSources().get(0); OntopMappingSQLAllConfiguration configuration = OntopMappingSQLAllConfiguration.defaultBuilder() .properties(DataSource2PropertiesConvertor.convert(dataSource)) .r2rmlMappingFile(file) .build(); SQLPPMapping parsedModel = configuration.loadProvidedPPMapping(); try{ /** * TODO: improve this inefficient method (batch processing, not one by one) */ for (SQLPPTriplesMap mapping : parsedModel.getTripleMaps()) { if (mapping.getTargetAtoms().toString().contains("BNODE")) { JOptionPane.showMessageDialog(getWorkspace(), "The mapping " + mapping.getId() + " contains BNode. -ontoPro- does not support it yet."); } else { obdaModelController.addTriplesMap(mapping, false); } } } catch (DuplicateMappingException dm) { JOptionPane.showMessageDialog(getWorkspace(), "Duplicate mapping id found. Please correct the Resource node name: " + dm.getLocalizedMessage()); throw new RuntimeException("Duplicate mapping found: " + dm.getMessage()); } }
/** * the method that gives the obda model based on the given graph * @param sourceUri - the uri of the datasource of the model * @return the read obda model */ public OBDAModel readModel(URI sourceUri){ try { //add to the model the mappings retrieved from the manager obdaModel.addMappings(sourceUri, manager.getMappings(m)); } catch (DuplicateMappingException e) { e.printStackTrace(); } return obdaModel; }
/** * the method that gives the obda model based on the given graph * @param dataSource - the datasource of the model * @return the read obda model */ public OBDAModel readModel(OBDADataSource dataSource){ try { obdaModel.addSource(dataSource); URI sourceUri = dataSource.getSourceID(); //add to the model the mappings retrieved from the manager obdaModel.addMappings(sourceUri, manager.getMappings(m)); } catch (DuplicateMappingException e) { e.printStackTrace(); } return obdaModel; }
@Override public void addMappings(URI datasource_uri, Collection<OBDAMappingAxiom> mappings) throws DuplicateMappingException { List<String> duplicates = new ArrayList<String>(); for (OBDAMappingAxiom map : mappings) { try { addMapping(datasource_uri, map, true); } catch (DuplicateMappingException e) { duplicates.add(map.getId()); } } fireMappigUpdated(datasource_uri); if (duplicates.size() > 0) { String msg = String.format("Found %d duplicates in the following ids: %s", duplicates.size(), duplicates.toString()); throw new DuplicateMappingException(msg); } }
@Override public SQLPPMapping clone() { try { return new SQLPPMappingImpl(triplesMaps, mappingMetadata); } catch (DuplicateMappingException e) { throw new RuntimeException("Unexpected error (inconsistent cloning): " + e.getMessage()); } }
throw new DuplicateMappingException(String.format("Found %d duplicates in the following ids: %s", duplicateCount, duplicateIds.toString()));
public SQLPPMapping generatePPMapping() { ImmutableList<SQLPPTriplesMap> triplesMaps = ImmutableList.copyOf(triplesMapMap.values()); try { UriTemplateMatcher uriTemplateMatcher = UriTemplateMatcher.create( triplesMaps.stream() .flatMap(ax -> ax.getTargetAtoms().stream()) .flatMap(targetAtom -> targetAtom.getSubstitution().getImmutableMap().values().stream()) .filter(t -> t instanceof ImmutableFunctionalTerm) .map(t -> (ImmutableFunctionalTerm) t), termFactory); return ppMappingFactory.createSQLPreProcessedMapping(triplesMaps, // TODO: give an immutable prefix manager!! specificationFactory.createMetadata(prefixManager, uriTemplateMatcher)); /** * No mapping so should never happen */ } catch(DuplicateMappingException e) { throw new RuntimeException("A DuplicateMappingException has been thrown while no mapping has been given." + "What is going on? Message: " + e.getMessage()); } }
public void addTriplesMap(SQLPPTriplesMap triplesMap, boolean disableFiringMappingInsertedEvent) throws DuplicateMappingException { String mapId = triplesMap.getId(); if (triplesMapMap.containsKey(mapId)) throw new DuplicateMappingException("ID " + mapId); triplesMapMap.put(mapId, triplesMap); if (!disableFiringMappingInsertedEvent) fireMappingInserted(source.getSourceID()); }
public SQLPPMapping createMappings() { OntopMappingConfiguration defaultConfiguration = OntopMappingConfiguration.defaultBuilder() .build(); SpecificationFactory specificationFactory = defaultConfiguration.getInjector().getInstance(SpecificationFactory.class); PrefixManager prefixManager = specificationFactory.createPrefixManager(ImmutableMap.of()); ImmutableList<SQLPPTriplesMap> mappingAxioms = dataRepository.getMappings(); UriTemplateMatcher uriTemplateMatcher = UriTemplateMatcher.create( mappingAxioms.stream() .flatMap(ax -> ax.getTargetAtoms().stream()) .flatMap(atom -> atom.getSubstitution().getImmutableMap().values().stream()) .filter(t -> t instanceof ImmutableFunctionalTerm) .map(t -> (ImmutableFunctionalTerm) t), termFactory); try { return new SQLPPMappingImpl(mappingAxioms, specificationFactory.createMetadata(prefixManager, uriTemplateMatcher)); } catch (DuplicateMappingException e) { throw new IllegalStateException(e.getMessage()); } } }
throw new DuplicateMappingException(String.format("Found %d duplicates in the following ids: %s", duplicateCount, duplicateIds.toString()));
JOptionPane.showMessageDialog(this, "Error while inserting mapping: " + e.getMessage() + " is already taken"); return;
@Override public void addMapping(URI datasource_uri, OBDAMappingAxiom mapping, boolean disableFiringMappingInsertedEvent) throws DuplicateMappingException { int index = indexOf(datasource_uri, mapping.getId()); if (index != -1) { throw new DuplicateMappingException("ID " + mapping.getId()); } mappings.get(datasource_uri).add(mapping); if(!disableFiringMappingInsertedEvent) { fireMappingInserted(datasource_uri); } }
@Override public int updateMapping(URI datasource_uri, String mapping_id, String new_mappingid) throws DuplicateMappingException { OBDAMappingAxiom mapping = getMapping(datasource_uri, mapping_id); // adds a new mapping if (!containsMapping(datasource_uri, new_mappingid)) { mapping.setId(new_mappingid); fireMappigUpdated(datasource_uri); return 0; } // updates an existing mapping else { // updates the mapping without changing the mapping id if (new_mappingid.equals(mapping_id)) { return -1; } // changes the mapping id to an existing one else { throw new DuplicateMappingException(new_mappingid); } } }