|
14 | 14 | package io.openmanufacturing.sds.aspectmodel.versionupdate.migrator;
|
15 | 15 |
|
16 | 16 | import java.util.AbstractMap;
|
| 17 | +import java.util.HashMap; |
17 | 18 | import java.util.Map;
|
18 | 19 | import java.util.Optional;
|
19 | 20 | import java.util.stream.Collectors;
|
@@ -63,17 +64,19 @@ protected RDFNode updateRdfNode( final RDFNode rdfNode, final Map<String, String
|
63 | 64 | public Model migrate( final Model sourceModel ) {
|
64 | 65 | final Model targetModel = ModelFactory.createDefaultModel();
|
65 | 66 |
|
66 |
| - final Map<String, String> targetPrefixes; |
67 |
| - targetPrefixes = Namespace.createPrefixMap( getTargetKnownVersion() ); |
68 |
| - |
69 |
| - final Map<String, String> oldToNewNamespaces = |
70 |
| - Namespace.createPrefixMap( getSourceKnownVersion() ) |
71 |
| - .keySet() |
72 |
| - .stream() |
73 |
| - .filter( prefix -> sourceModel.getNsPrefixURI( prefix ) != null ) |
74 |
| - .map( prefix -> new AbstractMap.SimpleEntry<>( sourceModel.getNsPrefixURI( prefix ), targetPrefixes.get( prefix ) ) ) |
75 |
| - .filter( entry -> !entry.getKey().equals( entry.getValue() ) ) |
76 |
| - .collect( Collectors.toMap( AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue ) ); |
| 67 | + final Map<String, String> targetPrefixes = Namespace.createPrefixMap( getTargetKnownVersion() ); |
| 68 | + |
| 69 | + final Map<String, String> sourcePrefixes = Namespace.createPrefixMap( getSourceKnownVersion() ); |
| 70 | + final Map<String, String> oldToNewNamespaces = new HashMap<>(); |
| 71 | + for ( final Map.Entry<String, String> targetEntry : targetPrefixes.entrySet() ) { |
| 72 | + final String prefix = targetEntry.getKey(); |
| 73 | + if ( prefix != null ) { |
| 74 | + final String sourceUri = sourcePrefixes.get( prefix ); |
| 75 | + if ( sourceUri != null && !sourceUri.equals( targetEntry.getValue() )) { |
| 76 | + oldToNewNamespaces.put( sourceUri, targetEntry.getValue() ); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
77 | 80 |
|
78 | 81 | Streams.stream( sourceModel.listStatements() ).map( statement -> targetModel
|
79 | 82 | .createStatement(
|
|
0 commit comments