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.layer0.util.ConsistsOfProcess.ConsistsOfProcessEntry;
+import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec;
+import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec.SeedSpecType;
import org.simantics.db.service.SerialisationSupport;
import org.simantics.graph.db.TransferableGraphSource;
import org.simantics.graph.representation.External;
SerialisationSupport ss = graph.getService(SerialisationSupport.class);
// At this point ids contains all internal resources. Now add roots and externals.
-
+
// Root Library
state.ids.put(ss.getTransientId(graph.getRootLibrary()), state.id++);
-
+
// External roots - internal roots were already processed as internal resources by domain processor
- for(RootSpec rs : configuration.roots) {
- if(!rs.internal) {
- int resourceId = ss.getTransientId(rs.resource);
+ for(SeedSpec spec : configuration.seeds) {
+ if(SeedSpecType.SPECIAL_ROOT.equals(spec.specType)) {
+ int resourceId = ss.getTransientId(spec.resource);
state.ids.put(resourceId, state.id++);
// The fixed roots have been seen as externals by domain processor. Now remove them from external set.
state.externals.remove(resourceId);
}
}
-
+
this.externalBase = state.id;
final Collection<String> errors = new HashSet<>();
// All resource considered as not internal by domain processor. Can also contain roots.
int[] externals = state.externals.toArray();
-
+
// Build up the state.externals, externalNames and externalParents
for(int i=0;i<externals.length;i++) {
getId(graph, externals[i], errors);
}
-
+
state.inverses.forEachEntry(new TIntIntProcedure() {
-
+
@Override
public boolean execute(int predicate, int inverse) {
try {
}
return true;
}
-
+
});
-
+
if(!errors.isEmpty()) {
ArrayList<String> sorted = new ArrayList<>(errors);
Collections.sort(sorted);
}
throw new DatabaseException(message.toString());
}
-
+
this.resourceCount = state.id;
-
+
state.extensions.put(ExternalDownloadBean.EXTENSION_KEY, new Variant(ExternalDownloadBean.BINDING, new ExternalDownloadBean(downloads)));
-
+
}
int indent = 0;
-
+
public boolean validateExternal(Resource ext) {
if(configuration.validate) {
ExtentStatus status = configuration.preStatus.get(ext);
}
return true;
}
-
+
private Resource getResource(ReadGraph graph, int r) throws DatabaseException {
SerialisationSupport ss = graph.getService(SerialisationSupport.class);
return ss.getResource(r);
}
-
+
final public int getExistingId(ReadGraph graph, int r) throws DatabaseException {
-
+
int ret = state.ids.get(r);
if(ret != -1) {
return ret;
}
}
-
+
/*
*
* @return -2 if r is not really external and the statement should be excluded
// // First external is root library
// if(r == rootId) return internalCount;
-
+
SerialisationSupport ss = graph.getService(SerialisationSupport.class);
Layer0 L0 = Layer0.getInstance(graph);
-
+
if(state.ids.containsKey(r)) {
int ret = state.ids.get(r);
if(ret == -1) {
errors.add("Illegal reference to " + graph.getPossibleURI(getResource(graph, r)));
return -2;
}
- Collection<Resource> parents = graph.getObjects(res, L0.PartOf);
+ Collection<Resource> parents = graph.getObjects(res, L0.PartOf);
if(parents.size() != 1) {
throw new ValidationException("Reference to external resource "
+ NameUtils.getSafeName(graph, getResource(graph, r), true) + " without unique uri (" + parents.size() + " parents).");
return state.id++;
}
}
-
+
@Override
public DataContainer getHeader() throws Exception {
return null;
}
-
+
@Override
public int getResourceCount() {
return resourceCount;
}
-
+
+ private int countRootSeeds() {
+ int result = 0;
+ for(SeedSpec spec : configuration.seeds) {
+ if(SeedSpecType.INTERNAL.equals(spec.specType)) continue;
+ result++;
+ }
+ return result;
+ }
+
@Override
public int getIdentityCount() {
- return configuration.roots.size() + state.externals.size() + state.internalEntries.size() + 1;
+ return countRootSeeds() + state.externals.size() + state.internalEntries.size() + 1;
}
-
+
@Override
public int getStatementCount() {
return state.statementCount;
}
-
+
@Override
public int getValueCount() {
return state.valueCount;
@Override
public void forStatements(ReadGraph graph, TransferableGraphSourceProcedure<int[]> procedure) throws Exception {
-
+
int[] value = new int[4];
long length = state.otherStatementsInput.length();
state.otherStatementsInput.position(0);
-
+
while(state.otherStatementsInput.position() < length && !state.monitor.isCanceled()) {
-
+
int s = state.otherStatementsInput.readInt();
int subjectId = state.ids.get(s);
-
+
boolean exclude = subjectId == -1;
-
+
int size = state.otherStatementsInput.readInt();
for(int i=0;i<size;i++) {
int p = state.otherStatementsInput.readInt();
} else if(state.excludedShared.contains(o)) {
System.err.println("excluding shared " + s + " " + p + " " + o);
} else {
-
+
int objectId = getExistingId(graph, o);
// The statement can be denied still
if(objectId != -2) {
value[3] = objectId;
procedure.execute(value);
-
+
} else {
System.err.println("Denied (" + NameUtils.getSafeName(graph, getResource(graph, s)) + ", " + NameUtils.getSafeName(graph, getResource(graph, p)) + "," + NameUtils.getSafeName(graph, getResource(graph, o)) + ")");
- }
-
+ }
+
}
} else {
System.err.println("excluding shared " + s);
@Override
public void forIdentities(ReadGraph graph, TransferableGraphSourceProcedure<Identity> procedure) throws Exception {
-
+
SerialisationSupport support = graph.getService(SerialisationSupport.class);
Layer0 L0 = Layer0.getInstance(graph);
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;
+ for(SeedSpec r : configuration.seeds) {
+ if(SeedSpecType.INTERNAL.equals(r.specType)) continue;
+ String typeId = r.type;
+ if (typeId == null) {
+ Resource type = graph.getPossibleType(r.resource, L0.Entity);
+ typeId = type != null ? graph.getURI(type) : Layer0.URIs.Entity;
+ }
int id = state.ids.get(support.getTransientId(r.resource));
- Root root = new Root(r.name, graph.getURI(type));
+ Root root = new Root(r.name, typeId);
Identity rootId = new Identity(id,root);
internalMap.put(id, rootId);
procedure.execute(rootId);
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));
+ for(ConsistsOfProcessEntry ie : state.internalEntries) {
+ if(ie.parent != null) {
+ if(ie.name != null) {
+ procedure.execute(resolveInternal(graph, support, ie, internalMap));
+ } else {
+ // In this case there is a child that has no HasName => this should be treated as a blank
+ }
} else {
- throw new DatabaseException("Invalid internal entry " + ie);
+ procedure.execute(resolveInternal(graph, support, ie, internalMap));
}
}
}
-
+
}
-
- private Identity resolveInternal(ReadGraph graph, SerialisationSupport ss, InternalEntry entry, TIntObjectMap<Identity> internalMap) throws DatabaseException {
+
+ private Identity resolveInternal(ReadGraph graph, SerialisationSupport ss, ConsistsOfProcessEntry 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;
+
+ if(entry.parent == null) {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource possibleParent = graph.getPossibleObject(entry.resource, L0.PartOf);
+ if(possibleParent == null) throw new DatabaseException("Invalid root or internal parent path: " + entry.resource);
+ int externalId = state.ids.get(ss.getTransientId(possibleParent));
+ Identity result = new Identity(id,
+ new Internal(externalId, entry.name));
+ internalMap.put(id, result);
+ return result;
+ } else {
+ 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 void reset() throws Exception {
throw new UnsupportedOperationException();
}
-
+
public long[] getResourceArray(ReadGraph graph) throws DatabaseException {
final SerialisationSupport ss = graph.getService(SerialisationSupport.class);
final long[] result = new long[state.ids.size()];
@Override
public boolean execute(int a, int b) {
-
+
try {
Resource r = ss.getResource(a);
result[b] = r.getResourceId();
} catch (DatabaseException e) {
e.printStackTrace();
}
-
+
return true;
-
+
}
});
return result;
}
-
+
public DomainProcessorState getState() {
return state;
}
-
+
public void forResourceStatements(ReadGraph graph, TransferableGraphSourceProcedure<int[]> procedure) throws Exception {
-
+
int[] value = new int[4];
long length = state.otherStatementsInput.length();
state.otherStatementsInput.position(0);
-
+
while(state.otherStatementsInput.position() < length) {
-
+
int s = state.otherStatementsInput.readInt();
int subjectId = state.ids.get(s);
-
+
boolean exclude = subjectId == -1;
-
+
int size = state.otherStatementsInput.readInt();
for(int i=0;i<size;i++) {
int p = state.otherStatementsInput.readInt();
if(state.excludedShared.contains(o)) {
System.err.println("excluding shared " + s + " " + p + " " + o);
} else {
-
+
int objectId = getExistingId(graph, o);
// The statement can be denied still
if(objectId != -2) {
value[3] = o;
procedure.execute(value);
-
+
} else {
System.err.println("Denied (" + NameUtils.getSafeName(graph, getResource(graph, s)) + ", " + NameUtils.getSafeName(graph, getResource(graph, p)) + "," + NameUtils.getSafeName(graph, getResource(graph, o)) + ")");
}
-
+
}
} else {
System.err.println("excluding shared " + s);