Search in sources :

Example 36 with HashMapVirtualObject

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;
}
Also used : HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) SerializerException(org.bimserver.plugins.serializers.SerializerException)

Example 37 with HashMapVirtualObject

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);
    }
}
Also used : FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) Buffer(org.bimserver.models.geometry.Buffer) OldQuery(org.bimserver.database.OldQuery) Query(org.bimserver.database.queries.om.Query) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) Include(org.bimserver.database.queries.om.Include) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) UserException(org.bimserver.shared.exceptions.UserException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 38 with HashMapVirtualObject

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);
        }
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) ArrayList(java.util.ArrayList) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 39 with HashMapVirtualObject

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;
}
Also used : Query(org.bimserver.database.queries.om.Query) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider)

Example 40 with HashMapVirtualObject

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();
    }
}
Also used : Query(org.bimserver.database.queries.om.Query) HashMap(java.util.HashMap) QueryPart(org.bimserver.database.queries.om.QueryPart) Include(org.bimserver.database.queries.om.Include) EClass(org.eclipse.emf.ecore.EClass) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) QueryTypeStackFrame(org.bimserver.database.queries.QueryTypeStackFrame) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) ArrayList(java.util.ArrayList) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference) HashSet(java.util.HashSet)

Aggregations

HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)44 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)23 Query (org.bimserver.database.queries.om.Query)23 QueryPart (org.bimserver.database.queries.om.QueryPart)22 List (java.util.List)20 EClass (org.eclipse.emf.ecore.EClass)20 PackageMetaData (org.bimserver.emf.PackageMetaData)18 UserException (org.bimserver.shared.exceptions.UserException)17 EReference (org.eclipse.emf.ecore.EReference)15 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)13 HashMapWrappedVirtualObject (org.bimserver.shared.HashMapWrappedVirtualObject)12 OldQuery (org.bimserver.database.OldQuery)11 IOException (java.io.IOException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Include (org.bimserver.database.queries.om.Include)8 QueryException (org.bimserver.database.queries.om.QueryException)7 ByteBuffer (java.nio.ByteBuffer)6 Revision (org.bimserver.models.store.Revision)6 EAttribute (org.eclipse.emf.ecore.EAttribute)6