use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class SharedJsonStreamingSerializer method write.
public boolean write(OutputStream outputStream, ProgressReporter progressReporter) throws SerializerException {
this.outputStream = outputStream;
try {
if (mode == Mode.HEADER) {
if (this.emfJsonSerializer == null) {
this.emfJsonSerializer = new EmfJsonSerializer(outputStream, includeHidden, SERIALIZE_EMPTY_LISTS);
}
print("{");
if (!minimal) {
if (ifcHeader != null) {
print("\"header\":");
this.emfJsonSerializer.writeObject(ifcHeader);
print("\n,");
}
}
print("\"objects\":[");
mode = Mode.BODY;
return true;
} else if (mode == Mode.BODY) {
HashMapVirtualObject object = objectProvider.next();
if (object != null) {
if (object.getOid() == -1) {
throw new SerializerException("Object cannot have oid -1 " + object.eClass().getName());
}
if (object.eClass().getEAnnotation("hidden") == null || includeHidden) {
if (!firstObject) {
print(",");
} else {
firstObject = false;
}
if (minimal) {
print("" + object.getOid());
} else {
writeObject(object);
}
}
return true;
} else {
print("]");
print("}");
mode = Mode.FOOTER;
return true;
}
} else if (mode == Mode.FOOTER) {
mode = Mode.DONE;
return false;
}
} catch (Throwable e) {
throw new SerializerException(e);
}
return false;
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class StreamingCheckinDatabaseAction method generateQuantizedVertices.
private void generateQuantizedVertices(DatabaseSession databaseSession, Revision revision, float[] quantizationMatrix, float multiplierToMm) {
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
Query query = new Query(packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addType(GeometryPackage.eINSTANCE.getGeometryData(), false);
Include geometryDataInclude = queryPart.createInclude();
try {
geometryDataInclude.addType(GeometryPackage.eINSTANCE.getGeometryData(), false);
geometryDataInclude.addFieldDirect("vertices");
QueryObjectProvider objectProvider = new QueryObjectProvider(getDatabaseSession(), getBimServer(), query, Collections.singleton(revision.getOid()), packageMetaData);
HashMapVirtualObject next = objectProvider.next();
while (next != null) {
HashMapVirtualObject verticesBuffer = (HashMapVirtualObject) next.get("vertices");
ByteBuffer verticesData = ByteBuffer.wrap((byte[]) verticesBuffer.get("data"));
verticesData.order(ByteOrder.LITTLE_ENDIAN);
FloatBuffer vertices = verticesData.asFloatBuffer();
ByteBuffer verticesQuantized = quantizeVertices(vertices.array(), quantizationMatrix, multiplierToMm);
Buffer buffer = getDatabaseSession().create(Buffer.class);
buffer.setData(verticesQuantized.array());
next.setReference(GeometryPackage.eINSTANCE.getGeometryData_VerticesQuantized(), buffer.getOid(), -1);
next.saveOverwrite();
next = objectProvider.next();
System.out.println("Generating quantized vertices");
}
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class GenericCheckinDatabaseAction method fixInverses.
private void fixInverses(PackageMetaData packageMetaData, long newRoid, Map<Long, HashMapVirtualObject> cache, HashMapVirtualObject next, EReference eReference, long refOid) throws JsonParseException, JsonMappingException, IOException, QueryException, BimserverDatabaseException {
HashMapVirtualObject referencedObject = cache.get(refOid);
if (referencedObject == null) {
referencedObject = getByOid(packageMetaData, getDatabaseSession(), newRoid, refOid);
if (referencedObject == null) {
throw new BimserverDatabaseException("Referenced object with oid " + refOid + " (" + getDatabaseSession().getEClassForOid(refOid).getName() + ")" + ", referenced from " + next.eClass().getName() + " not found");
}
cache.put(refOid, referencedObject);
}
EReference oppositeReference = packageMetaData.getInverseOrOpposite(referencedObject.eClass(), eReference);
if (oppositeReference == null) {
if (eReference.getName().equals("RelatedElements") && referencedObject.eClass().getName().equals("IfcSpace")) {
// Ignore, IfcSpace should have a field called RelatedElements, but it doesn't.
} else {
// LOGGER.error("No opposite " + eReference.getName() + " found");
}
} else {
if (oppositeReference.isMany()) {
Object existingList = referencedObject.eGet(oppositeReference);
if (existingList != null) {
int currentSize = ((List<?>) existingList).size();
referencedObject.setListItemReference(oppositeReference, currentSize, next.eClass(), next.getOid(), 0);
} else {
referencedObject.setListItemReference(oppositeReference, 0, next.eClass(), next.getOid(), 0);
}
} else {
referencedObject.setReference(oppositeReference, next.getOid(), 0);
}
}
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class GenericCheckinDatabaseAction method getByOid.
public HashMapVirtualObject getByOid(PackageMetaData packageMetaData, DatabaseSession databaseSession, long roid, long oid) throws JsonParseException, JsonMappingException, IOException, QueryException, BimserverDatabaseException {
Query query = new Query("test", packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addOid(oid);
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(databaseSession, bimServer, query, Collections.singleton(roid), packageMetaData);
HashMapVirtualObject first = queryObjectProvider.next();
return first;
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class GenericCheckinDatabaseAction method fixInverses.
@SuppressWarnings("unchecked")
protected void fixInverses(PackageMetaData packageMetaData, long newRoid, Map<EClass, Integer> summaryMap) throws QueryException, JsonParseException, JsonMappingException, IOException, BimserverDatabaseException {
// TODO remove cache, this is essentially a big part of the model in memory again
Map<Long, HashMapVirtualObject> cache = new HashMap<Long, HashMapVirtualObject>();
Query query = new Query("Inverses fixer", packageMetaData);
int nrTypes = 0;
Set<EClass> uniqueTypes = new HashSet<>();
for (EClass eClass : summaryMap.keySet()) {
if (packageMetaData.hasInverses(eClass)) {
QueryPart queryPart = query.createQueryPart();
queryPart.addType(eClass, true);
uniqueTypes.add(eClass);
nrTypes++;
for (EReference eReference : packageMetaData.getAllHasInverseReferences(eClass)) {
Include include = queryPart.createInclude();
include.addType(eClass, true);
include.addField(eReference.getName());
}
}
}
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), bimServer, query, Collections.singleton(newRoid), packageMetaData);
HashMapVirtualObject next = queryObjectProvider.next();
EClass lastEClass = null;
int currentType = 0;
while (next != null) {
if (next.eClass() != lastEClass && uniqueTypes.contains(next.eClass()) && queryObjectProvider.getStackFrame() instanceof QueryTypeStackFrame) {
lastEClass = next.eClass();
currentType++;
setProgress("Generating inverses", (100 * currentType / nrTypes));
}
if (packageMetaData.hasInverses(next.eClass())) {
for (EReference eReference : packageMetaData.getAllHasInverseReferences(next.eClass())) {
Object reference = next.eGet(eReference);
if (reference != null) {
if (eReference.isMany()) {
List<Long> references = (List<Long>) reference;
for (Long refOid : references) {
fixInverses(packageMetaData, newRoid, cache, next, eReference, refOid);
}
} else {
fixInverses(packageMetaData, newRoid, cache, next, eReference, (Long) reference);
}
}
}
}
next = queryObjectProvider.next();
}
setProgress("Storing data", -1);
for (HashMapVirtualObject referencedObject : cache.values()) {
referencedObject.saveOverwrite();
}
}
Aggregations