Search in sources :

Example 36 with QueryPart

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

the class TestGetMaterials method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Get the appropriate deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        // Checkin the file
        bimServerClient.checkinSync(newProject.getOid(), "test", deserializer.getOid(), false, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // Refresh project info
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), false, false);
        Query query = new Query(model.getPackageMetaData());
        query.setDoubleBuffer(true);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addType(new TypeDef(model.getPackageMetaData().getEClass("IfcProduct"), true));
        Include include = queryPart.createInclude();
        include.addType(model.getPackageMetaData().getEClass("IfcObjectDefinition"), true);
        include.addField("HasAssociations");
        include.addInclude("ifc2x3tc1-stdlib:IfcRelAssociatesMaterial");
        JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(model.getPackageMetaData());
        model.query(converter.toJson(query), true);
        int nrMaterialsWithName = 0;
        for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
            Set<IfcMaterial> materials = getMaterials(ifcProduct);
            for (IfcMaterial ifcMaterial : materials) {
                if (ifcMaterial.getName() != null) {
                    System.out.println(ifcMaterial.getName());
                    nrMaterialsWithName++;
                }
            }
        }
        Assert.assertEquals(416, nrMaterialsWithName);
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) Query(org.bimserver.database.queries.om.Query) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) QueryPart(org.bimserver.database.queries.om.QueryPart) Include(org.bimserver.database.queries.om.Include) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) IfcMaterial(org.bimserver.models.ifc2x3tc1.IfcMaterial) TypeDef(org.bimserver.database.queries.om.Include.TypeDef) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) 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