X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fbase%2FUpdateComponentUids.java;fp=bundles%2Forg.simantics.structural.synchronization.client%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fbase%2FUpdateComponentUids.java;h=840d9ec4c7dc5bd688f382939d04734e8c1fa998;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java new file mode 100644 index 000000000..840d9ec4c --- /dev/null +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java @@ -0,0 +1,27 @@ +package org.simantics.structural.synchronization.base; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; + +/** + * Utility for updating UIDs in the given component to correspond + * the RVIs of the given variable. This operation is needed when + * the mapping is part of a model that is imported to a new database + * and resource ids have been changed. + * + * @author Hannu Niemistö + */ +public class UpdateComponentUids { + + public static > void update(ReadGraph graph, T component, Variable variable) throws DatabaseException { + component.uid = variable.getRVI(graph).toString(); + for(Variable childVariable : variable.getChildren(graph)) { + String childName = childVariable.getName(graph); + T childComponent = component.getChild(childName); + if(childComponent != null) + update(graph, childComponent, childVariable); + } + } + +}