Search in sources :

Example 31 with QueryPart

use of org.bimserver.database.queries.om.QueryPart 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)

Example 32 with QueryPart

use of org.bimserver.database.queries.om.QueryPart 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 33 with QueryPart

use of org.bimserver.database.queries.om.QueryPart in project BIMserver by opensourceBIM.

the class ClientIfcModel method getAllWithSubTypes.

@Override
public <T extends IdEObject> List<T> getAllWithSubTypes(EClass eClass) {
    if (!loadedClasses.contains(eClass.getName()) && modelState != ModelState.FULLY_LOADED && !assumeCompletePreload) {
        try {
            modelState = ModelState.LOADING;
            Query query = new Query(getPackageMetaData());
            QueryPart queryPart = query.createQueryPart();
            queryPart.addType(eClass, true);
            if (includeGeometry && getPackageMetaData().getEClass("IfcProduct").isSuperTypeOf(eClass)) {
                Include include = queryPart.createInclude();
                include.addType(eClass, true);
                include.addField("geometry");
                Include include2 = include.createInclude();
                include2.addType(new TypeDef(GeometryPackage.eINSTANCE.getGeometryInfo(), false));
                include2.addField("data");
            }
            JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(getPackageMetaData());
            long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(roid), converter.toJson(query).toString(), bimServerClient.getJsonSerializerOid(), false);
            bimServerClient.waitForDonePreparing(topicId);
            processDownload(topicId);
            clientDebugInfo.incrementGetAll();
            bimServerClient.getServiceInterface().cleanupLongAction(topicId);
            for (EClass subClass : bimServerClient.getMetaDataManager().getPackageMetaData(eClass.getEPackage().getName()).getAllSubClasses(eClass)) {
                loadedClasses.add(subClass.getName());
                rebuildIndexPerClass(eClass);
            }
            loadedClasses.add(eClass.getName());
            modelState = ModelState.NONE;
            loadGeometry();
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    }
    return super.getAllWithSubTypes(eClass);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) Query(org.bimserver.database.queries.om.Query) TypeDef(org.bimserver.database.queries.om.Include.TypeDef) QueryPart(org.bimserver.database.queries.om.QueryPart) Include(org.bimserver.database.queries.om.Include) QueryException(org.bimserver.database.queries.om.QueryException) SerializerException(org.bimserver.plugins.serializers.SerializerException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) UserException(org.bimserver.shared.exceptions.UserException) ServiceException(org.bimserver.shared.exceptions.ServiceException) ObjectAlreadyExistsException(org.bimserver.plugins.ObjectAlreadyExistsException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IOException(java.io.IOException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException)

Example 34 with QueryPart

use of org.bimserver.database.queries.om.QueryPart in project BIMserver by opensourceBIM.

the class ClientIfcModel method loadDeep.

private void loadDeep() throws ServerException, UserException, PublicInterfaceNotFoundException, QueryException {
    long start = System.nanoTime();
    if (modelState != ModelState.FULLY_LOADED && modelState != ModelState.LOADING) {
        modelState = ModelState.LOADING;
        Query query = new Query("test", getPackageMetaData());
        QueryPart queryPart = query.createQueryPart();
        queryPart.setIncludeAllFields(true);
        ObjectNode queryNode = new JsonQueryObjectModelConverter(query.getPackageMetaData()).toJson(query);
        Long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(roid), queryNode.toString(), bimServerClient.getJsonSerializerOid(), false);
        bimServerClient.waitForDonePreparing(topicId);
        try {
            processDownload(topicId);
            bimServerClient.getServiceInterface().cleanupLongAction(topicId);
            buildIndex();
            loadGeometry();
            modelState = ModelState.FULLY_LOADED;
        } catch (IfcModelInterfaceException | IOException e) {
            LOGGER.error("", e);
        } catch (QueryException e) {
            LOGGER.error("", e);
        } catch (GeometryException e) {
            LOGGER.error("", e);
        }
    }
    long end = System.nanoTime();
// LOGGER.info((((end - start) / 1000000) + " ms"));
}
Also used : IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) QueryException(org.bimserver.database.queries.om.QueryException) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) Query(org.bimserver.database.queries.om.Query) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) QueryPart(org.bimserver.database.queries.om.QueryPart) IOException(java.io.IOException)

Example 35 with QueryPart

use of org.bimserver.database.queries.om.QueryPart in project BIMserver by opensourceBIM.

the class TestCheckinAndGeometryDownload method test.

@Test
public void test() throws Exception {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8080")) {
        for (int i = 0; i < 100; i++) {
            try (BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"))) {
                SProject project = client.getServiceInterface().addProject(RandomStringUtils.randomAlphanumeric(10), "ifc2x3tc1");
                SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
                Path path = Paths.get("../../TestFiles/TestData/data/export1.ifc");
                SLongCheckinActionState checkinSync = client.checkinSync(project.getOid(), "test", deserializer.getOid(), path, (title, progress) -> {
                });
                PackageMetaData packageMetaData = client.getMetaDataManager().getPackageMetaData("ifc2x3tc1");
                Query query = new Query(packageMetaData);
                QueryPart queryPart = query.createQueryPart();
                queryPart.addType(packageMetaData.getEClass("IfcProduct"), true);
                Tiles tiles = new Tiles();
                tiles.add(0);
                tiles.setMaximumThreshold(1000);
                tiles.setMaxDepth(0);
                queryPart.setTiles(tiles);
                Include include1 = queryPart.createInclude();
                include1.addType(packageMetaData.getEClass("IfcProduct"), true);
                include1.addField("geometry");
                Include include2 = include1.createInclude();
                include2.addType(GeometryPackage.eINSTANCE.getGeometryInfo(), false);
                include2.addField("data");
                Include include3 = include2.createInclude();
                include3.addType(GeometryPackage.eINSTANCE.getGeometryData(), false);
                include3.addFieldDirect("indices");
                include3.addFieldDirect("normals");
                include3.addFieldDirect("normalsQuantized");
                include3.addFieldDirect("vertices");
                include3.addFieldDirect("verticesQuantized");
                include3.addFieldDirect("colorsQuantized");
                include3.addFieldDirect("colorPack");
                SSerializerPluginConfiguration serializer = client.getPluginInterface().getSerializerByPluginClassName("org.bimserver.serializers.binarygeometry.BinaryGeometryMessagingStreamingSerializerPlugin");
                ObjectNode queryJson = new JsonQueryObjectModelConverter(packageMetaData).toJson(query);
                queryJson.set("loaderSettings", generateLoaderSettings());
                String queryString = queryJson.toString();
                Long topicId = client.getServiceInterface().download(Collections.singleton(checkinSync.getRoid()), queryString, serializer.getOid(), false);
                ObjectNode downloadMessage = OBJECT_MAPPER.createObjectNode();
                downloadMessage.put("action", "download");
                downloadMessage.put("token", client.getToken());
                downloadMessage.put("topicId", topicId);
                CountDownLatch doneCountdown = new CountDownLatch(1);
                client.getNotificationsManager().setBinaryMessageListener(topicId, new BinaryMessageListener() {

                    @Override
                    public void newData(byte[] bytes, int start, int length) {
                        ByteBuffer buffer = ByteBuffer.wrap(bytes, start, length).order(ByteOrder.LITTLE_ENDIAN);
                        // TopicId
                        buffer.getLong();
                        int type = buffer.getInt();
                        if (type == 0) {
                        } else if (type == 1) {
                            doneCountdown.countDown();
                        }
                    }
                });
                client.getNotificationsManager().send(downloadMessage);
                if (!doneCountdown.await(5, TimeUnit.MINUTES)) {
                    LOGGER.error("Not finished after 5 minutes!");
                }
                LOGGER.info("Done");
                client.getServiceInterface().cleanupLongAction(topicId);
            }
        }
    }
    Thread.sleep(30000);
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) Query(org.bimserver.database.queries.om.Query) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SLongCheckinActionState(org.bimserver.interfaces.objects.SLongCheckinActionState) Include(org.bimserver.database.queries.om.Include) SProject(org.bimserver.interfaces.objects.SProject) CountDownLatch(java.util.concurrent.CountDownLatch) BinaryMessageListener(org.bimserver.client.notifications.BinaryMessageListener) ByteBuffer(java.nio.ByteBuffer) BimServerClient(org.bimserver.client.BimServerClient) Tiles(org.bimserver.database.queries.om.Tiles) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) Test(org.junit.Test)

Aggregations

QueryPart (org.bimserver.database.queries.om.QueryPart)36 Query (org.bimserver.database.queries.om.Query)33 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)23 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)22 UserException (org.bimserver.shared.exceptions.UserException)18 EClass (org.eclipse.emf.ecore.EClass)17 Include (org.bimserver.database.queries.om.Include)16 PackageMetaData (org.bimserver.emf.PackageMetaData)16 IOException (java.io.IOException)12 List (java.util.List)10 JsonQueryObjectModelConverter (org.bimserver.database.queries.om.JsonQueryObjectModelConverter)10 OldQuery (org.bimserver.database.OldQuery)9 QueryException (org.bimserver.database.queries.om.QueryException)9 EReference (org.eclipse.emf.ecore.EReference)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)6 ServiceException (org.bimserver.shared.exceptions.ServiceException)6 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)5