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