Search in sources :

Example 6 with QueryPart

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

the class SetAttributeChangeAtIndex method execute.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    Query query = new Query(packageMetaData);
    QueryPart queryPart = query.createQueryPart();
    queryPart.addOid(oid);
    HashMapVirtualObject object = transaction.get(oid);
    if (object == null) {
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
        object = queryObjectProvider.next();
        transaction.updated(object);
    }
    EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
    if (!ChangeHelper.canBeChanged(eClass)) {
        throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
    }
    object = transaction.get(oid);
    if (object == null) {
        throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
    }
    EAttribute eAttribute = packageMetaData.getEAttribute(eClass.getName(), attributeName);
    if (eAttribute == null) {
        throw new UserException("No attribute with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
    }
    if (value instanceof List && eAttribute.isMany()) {
        List sourceList = (List) value;
        if (!eAttribute.isMany()) {
            throw new UserException("Attribute is not of type 'many'");
        }
        List list = (List) object.eGet(eAttribute);
        list.clear();
        List asStringList = null;
        if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
            asStringList = (List) object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString"));
            asStringList.clear();
        }
        for (Object o : sourceList) {
            if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                asStringList.add(String.valueOf(o));
            }
            list.add(o);
        }
    } else {
        if (eAttribute.isMany()) {
            throw new UserException("Attribute is not of type 'single'");
        }
        if (eAttribute.getEType() instanceof EEnum) {
            EEnum eEnum = (EEnum) eAttribute.getEType();
            object.setListItem(eAttribute, index, eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance());
        } else {
            object.setListItem(eAttribute, index, value);
        }
        if (value instanceof Double) {
            EStructuralFeature asStringAttribute = object.eClass().getEStructuralFeature(attributeName + "AsString");
            object.setListItem(asStringAttribute, index, String.valueOf((Double) value));
        }
    }
}
Also used : Query(org.bimserver.database.queries.om.Query) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EEnum(org.eclipse.emf.ecore.EEnum) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) List(java.util.List) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) UserException(org.bimserver.shared.exceptions.UserException)

Example 7 with QueryPart

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

the class ClientIfcModel method loadGeometry.

private void loadGeometry() throws QueryException, ServerException, UserException, PublicInterfaceNotFoundException, IOException, GeometryException, IfcModelInterfaceException {
    if (includeGeometry) {
        getModelMetaData().setMinBounds(getBimServerClient().getServiceInterface().getModelMinBounds(roid));
        getModelMetaData().setMaxBounds(getBimServerClient().getServiceInterface().getModelMaxBounds(roid));
        Query query = new Query("test", getPackageMetaData());
        QueryPart queryPart = query.createQueryPart();
        Map<Long, Long> geometryInfoOidToOid = new HashMap<>();
        EClass ifcProductClass = getPackageMetaData().getEClass("IfcProduct");
        EStructuralFeature geometryFeature = ifcProductClass.getEStructuralFeature("geometry");
        List<IdEObject> allWithSubTypes = new ArrayList<>(super.getAllWithSubTypes(ifcProductClass));
        for (IdEObject ifcProduct : allWithSubTypes) {
            GeometryInfo geometry = (GeometryInfo) ifcProduct.eGet(geometryFeature);
            if (geometry != null) {
                if (geometry.getData() == null || geometry.getData().getIndices() == null) {
                    queryPart.addOid(geometry.getOid());
                    geometryInfoOidToOid.put(geometry.getOid(), ifcProduct.getOid());
                }
            }
        }
        if (queryPart.getOids() == null) {
            return;
        }
        EClass geometryInfoClass = getPackageMetaData().getEClassIncludingDependencies("GeometryInfo");
        Include include = queryPart.createInclude();
        include.addType(geometryInfoClass, false);
        include.addField("data");
        long serializerOid = bimServerClient.getBinaryGeometryMessagingStreamingSerializerOid();
        long topicId = bimServerClient.query(query, roid, serializerOid);
        // TODO use websocket notifications
        waitForDonePreparing(topicId);
        InputStream inputStream = bimServerClient.getDownloadData(topicId);
        try {
            // ByteArrayOutputStream byteArrayOutputStream = new
            // ByteArrayOutputStream();
            // IOUtils.copy(inputStream, byteArrayOutputStream);
            processGeometryInputStream(inputStream, geometryInfoOidToOid);
        } catch (Throwable e) {
            e.printStackTrace();
        } finally {
            bimServerClient.getServiceInterface().cleanupLongAction(topicId);
        }
    }
}
Also used : Query(org.bimserver.database.queries.om.Query) HashMap(java.util.HashMap) IdEObject(org.bimserver.emf.IdEObject) QueryPart(org.bimserver.database.queries.om.QueryPart) LittleEndianDataInputStream(com.google.common.io.LittleEndianDataInputStream) InputStream(java.io.InputStream) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ArrayList(java.util.ArrayList) Include(org.bimserver.database.queries.om.Include) EClass(org.eclipse.emf.ecore.EClass) GeometryInfo(org.bimserver.models.geometry.GeometryInfo)

Example 8 with QueryPart

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

the class QueryStackFrame method process.

@Override
public boolean process() throws BimserverDatabaseException, QueryException {
    QueryPart next = queryIterator.next();
    queryObjectProvider.push(new QueryPartStackFrame(queryObjectProvider, next, reusable));
    if (queryIterator.hasNext()) {
        return false;
    }
    return true;
}
Also used : QueryPart(org.bimserver.database.queries.om.QueryPart)

Example 9 with QueryPart

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

the class GetNrPrimitivesDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
    if (packageMetaData == null) {
        throw new UserException("Schema not fond");
    }
    try {
        Query query = new Query("test", packageMetaData);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addType(packageMetaData.getEClassIncludingDependencies("GeometryInfo"), true);
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), bimServer, query, java.util.Collections.singleton(roid), packageMetaData);
        HashMapVirtualObject next = queryObjectProvider.next();
        long totalPrimitives = 0;
        while (next != null) {
            int nrPrimitives = (int) next.get("primitiveCount");
            totalPrimitives += nrPrimitives;
            next = queryObjectProvider.next();
        }
        return totalPrimitives;
    } catch (QueryException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : OldQuery(org.bimserver.database.OldQuery) Query(org.bimserver.database.queries.om.Query) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) QueryException(org.bimserver.database.queries.om.QueryException) Revision(org.bimserver.models.store.Revision) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) UserException(org.bimserver.shared.exceptions.UserException)

Example 10 with QueryPart

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

the class StreamingCheckinDatabaseAction 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 : OldQuery(org.bimserver.database.OldQuery) 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)

Aggregations

QueryPart (org.bimserver.database.queries.om.QueryPart)23 Query (org.bimserver.database.queries.om.Query)22 UserException (org.bimserver.shared.exceptions.UserException)16 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)15 EClass (org.eclipse.emf.ecore.EClass)13 PackageMetaData (org.bimserver.emf.PackageMetaData)11 IOException (java.io.IOException)9 List (java.util.List)8 QueryException (org.bimserver.database.queries.om.QueryException)7 JsonQueryObjectModelConverter (org.bimserver.database.queries.om.JsonQueryObjectModelConverter)6 EReference (org.eclipse.emf.ecore.EReference)6 Include (org.bimserver.database.queries.om.Include)5 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)5 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)5 ServiceException (org.bimserver.shared.exceptions.ServiceException)5 EOFException (java.io.EOFException)4 HashMap (java.util.HashMap)4 EAttribute (org.eclipse.emf.ecore.EAttribute)4 HashSet (java.util.HashSet)3