import org.simantics.db.exception.RuntimeDatabaseException;
import org.simantics.db.exception.ValidationException;
import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
+import org.simantics.db.layer0.util.ConsistsOfProcess.InternalEntry;
import org.simantics.db.layer0.util.TransferableGraphConfiguration2.RootSpec;
import org.simantics.db.service.SerialisationSupport;
import org.simantics.graph.db.TransferableGraphSource;
import org.simantics.graph.representation.External;
import org.simantics.graph.representation.Identity;
+import org.simantics.graph.representation.Internal;
import org.simantics.graph.representation.Root;
import org.simantics.graph.representation.Value;
import org.simantics.layer0.Layer0;
import gnu.trove.list.array.TIntArrayList;
+import gnu.trove.map.TIntObjectMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.procedure.TIntIntProcedure;
public class ModelTransferableGraphSource implements TransferableGraphSource {
private volatile boolean closed = false;
TIntArrayList externalParents = new TIntArrayList();
- ArrayList<String> externalNames = new ArrayList<String>();
+ ArrayList<String> externalNames = new ArrayList<>();
TreeMap<String,String> downloads = new TreeMap<String,String>();
public ModelTransferableGraphSource(final ReadGraph graph, TransferableGraphConfiguration2 configuration, final DomainProcessorState state, File ... fs) throws DatabaseException {
this.externalBase = state.id;
- final Collection<String> errors = new HashSet<String>();
+ final Collection<String> errors = new HashSet<>();
// All resource considered as not internal by domain processor. Can also contain roots.
int[] externals = state.externals.toArray();
});
if(!errors.isEmpty()) {
- ArrayList<String> sorted = new ArrayList<String>(errors);
+ ArrayList<String> sorted = new ArrayList<>(errors);
Collections.sort(sorted);
StringBuilder message = new StringBuilder();
message.append("Errors in exported model:\n");
// TODO: this should be Root with name ""
procedure.execute(getRootIdentity(state, support, graph.getRootLibrary()));
+ TIntObjectMap<Identity> internalMap = new TIntObjectHashMap<>(100, 0.5f, Integer.MIN_VALUE);
+
// Declare internal and external roots
for(RootSpec r : configuration.roots) {
Resource type = graph.getPossibleType(r.resource, L0.Entity);
if(type == null) type = L0.Entity;
- procedure.execute(new Identity(
- state.ids.get(support.getTransientId(r.resource)),
- new Root(r.name, graph.getURI(type))));
+ int id = state.ids.get(support.getTransientId(r.resource));
+ Root root = new Root(r.name, graph.getURI(type));
+ Identity rootId = new Identity(id,root);
+ internalMap.put(id, rootId);
+ procedure.execute(rootId);
}
for(int i = 0; i < state.externals.size() ; i++) {
String name = externalNames.get(i);
procedure.execute(new Identity(externalBase + i, new External(parent,name)));
}
+
+ if(state.internalEntries != null) {
+ for(InternalEntry ie : state.internalEntries) {
+ if(ie.parent != null && ie.name != null) {
+ procedure.execute(resolveInternal(graph, support, ie, internalMap));
+ }
+ }
+ }
}
+
+ private Identity resolveInternal(ReadGraph graph, SerialisationSupport ss, InternalEntry entry, TIntObjectMap<Identity> internalMap) throws DatabaseException {
+ int id = state.ids.get(ss.getTransientId(entry.resource));
+ Identity existing = internalMap.get(id);
+ if(existing != null) return existing;
+ Identity parent = resolveInternal(graph, ss, entry.parent, internalMap);
+ Identity result = new Identity(id,
+ new Internal(parent.resource, entry.name));
+ internalMap.put(id, result);
+ return result;
+ }
@Override
public TreeMap<String, Variant> getExtensions() {