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));
}
}
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations