Search in sources :

Example 1 with StreamingGeometryGenerator

use of org.bimserver.geometry.StreamingGeometryGenerator in project BIMserver by opensourceBIM.

the class CommitTransactionDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getProjectByPoid(longTransaction.getPoid());
    User user = getUserByUoid(authorization.getUoid());
    if (project == null) {
        throw new UserException("Project with poid " + longTransaction.getPoid() + " not found");
    }
    if (!authorization.hasRightsOnProjectOrSuperProjects(user, project)) {
        throw new UserException("User has no rights to checkin models to this project");
    }
    if (!MailSystem.isValidEmailAddress(user.getUsername())) {
        throw new UserException("Users must have a valid e-mail address to checkin");
    }
    long size = 0;
    Revision previousRevision = project.getLastRevision();
    ConcreteRevision previousConcreteRevision = null;
    if (previousRevision != null) {
        previousConcreteRevision = previousRevision.getConcreteRevisions().get(0);
    }
    if (project.getLastRevision() != null) {
        size += project.getLastRevision().getSize();
    }
    for (Change change : longTransaction.getChanges()) {
        if (change instanceof CreateObjectChange) {
            size++;
        } else if (change instanceof RemoveObjectChange) {
            size--;
        }
    }
    Revision oldLastRevision = project.getLastRevision();
    CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), size, project, user, comment.trim());
    ConcreteRevision concreteRevision = result.getConcreteRevision();
    if (previousConcreteRevision != null) {
        concreteRevision.setIfcHeader(previousConcreteRevision.getIfcHeader());
    }
    revision = concreteRevision.getRevisions().get(0);
    project.setLastRevision(revision);
    final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
    newRevisionAdded.setDate(new Date());
    newRevisionAdded.setExecutor(user);
    newRevisionAdded.setRevision(concreteRevision.getRevisions().get(0));
    newRevisionAdded.setProject(project);
    newRevisionAdded.setAccessMethod(getAccessMethod());
    OidCounters originalOidCounters = null;
    PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema());
    if (oldLastRevision != null) {
        int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(project, oldLastRevision.getLastConcreteRevision());
        OldQuery query = new OldQuery(longTransaction.getPackageMetaData(), project.getId(), oldLastRevision.getId(), -1, Deep.YES, highestStopId);
        originalOidCounters = query.updateOidCounters(oldLastRevision.getLastConcreteRevision(), getDatabaseSession());
    } else {
        originalOidCounters = new OidCounters();
    }
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            getBimServer().getNotificationsManager().notify(new SConverter().convertToSObject(newRevisionAdded));
            try {
                getBimServer().getLongTransactionManager().remove(longTransaction.getTid());
            } catch (NoTransactionException e) {
                LOGGER.error("", e);
            }
        }
    });
    SummaryMap summaryMap = null;
    if (oldLastRevision != null && oldLastRevision.getConcreteRevisions().size() == 1 && oldLastRevision.getConcreteRevisions().get(0).getSummary() != null) {
        summaryMap = new SummaryMap(packageMetaData, oldLastRevision.getConcreteRevisions().get(0).getSummary());
    } else {
        summaryMap = new SummaryMap(packageMetaData);
    }
    // First create all new objects
    Transaction transaction = new Transaction(getBimServer(), previousRevision, project, concreteRevision, getDatabaseSession());
    for (Change change : longTransaction.getChanges()) {
        if (change instanceof CreateObjectChange) {
            try {
                CreateObjectChange createObjectChange = (CreateObjectChange) change;
                change.execute(transaction);
                getDatabaseSession().addStartOid(createObjectChange.geteClass(), createObjectChange.getOid());
            } catch (IOException | QueryException e) {
                e.printStackTrace();
            }
            summaryMap.add(((CreateObjectChange) change).geteClass(), 1);
        }
    }
    // Then do the rest
    for (Change change : longTransaction.getChanges()) {
        if (!(change instanceof CreateObjectChange)) {
            if (change instanceof RemoveObjectChange) {
                summaryMap.remove(((RemoveObjectChange) change).geteClass(), 1);
            }
            try {
                change.execute(transaction);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (QueryException e) {
                e.printStackTrace();
            }
        }
    }
    for (HashMapVirtualObject object : transaction.getCreated()) {
        getDatabaseSession().save(object);
    }
    for (HashMapVirtualObject object : transaction.getUpdated()) {
        getDatabaseSession().save(object, concreteRevision.getId());
    }
    for (HashMapVirtualObject object : transaction.getDeleted()) {
        getDatabaseSession().delete(object, concreteRevision.getId());
    }
    setProgress("Generating inverses/opposites...", -1);
    Revision newRevision = result.getRevisions().get(0);
    long newRoid = newRevision.getOid();
    try {
        fixInverses(packageMetaData, newRoid, summaryMap.getSummaryMap());
    } catch (QueryException | IOException e1) {
        e1.printStackTrace();
    }
    int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(concreteRevision.getProject(), concreteRevision);
    QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, project.getId(), concreteRevision.getId(), concreteRevision.getRevisions().get(0).getOid(), concreteRevision.getOid(), highestStopId);
    Map<String, Long> startOids = getDatabaseSession().getStartOids();
    if (startOids == null) {
        throw new BimserverDatabaseException("No objects changed");
    }
    for (EClass eClass : packageMetaData.getEClasses()) {
        if (startOids.containsKey(eClass.getEPackage().getName() + "." + eClass.getName())) {
            long oid = startOids.get(eClass.getEPackage().getName() + "." + eClass.getName());
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                originalOidCounters.putIfAbsent(eClass, oid);
            }
        }
    }
    queryContext.setOidCounters(originalOidCounters);
    concreteRevision.setOidCounters(originalOidCounters == null ? null : originalOidCounters.getBytes());
    if (getBimServer().getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
        if (regenerateAllGeometry) {
            setProgress("Generating Geometry...", -1);
            try {
                GeometryGenerationReport report = new GeometryGenerationReport();
                report.setOriginalDeserializer("No deserializer, low level call");
                report.setOriginalIfcFileName("No file, low level call");
                report.setOriginalIfcFileSize(-1);
                StreamingGeometryGenerator streamingGeometryGenerator = new StreamingGeometryGenerator(getBimServer(), null, -1L, report);
                GenerateGeometryResult generateGeometry = streamingGeometryGenerator.generateGeometry(authorization.getUoid(), getDatabaseSession(), queryContext, summaryMap.count());
                concreteRevision.setMultiplierToMm(generateGeometry.getMultiplierToMm());
                concreteRevision.setBounds(generateGeometry.getBounds());
                concreteRevision.setBoundsUntransformed(generateGeometry.getBoundsUntransformed());
                generateDensityAndBounds(result, generateGeometry, concreteRevision);
                final GeometryGenerationReport finalReport = report;
                getDatabaseSession().addPostCommitAction(new PostCommitAction() {

                    @Override
                    public void execute() throws UserException {
                        if (finalReport != null) {
                            byte[] htmlBytes = finalReport.toHtml().getBytes(Charsets.UTF_8);
                            byte[] jsonBytes = finalReport.toJson().toString().getBytes(Charsets.UTF_8);
                            try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
                                AddGeometryReports addGeometryReports = new AddGeometryReports(tmpSession, AccessMethod.INTERNAL, htmlBytes, jsonBytes, finalReport.getTimeToGenerateMs(), authorization.getUoid(), revision.getOid());
                                try {
                                    tmpSession.executeAndCommitAction(addGeometryReports);
                                } catch (ServerException e1) {
                                    LOGGER.error("", e1);
                                }
                            } catch (BimserverDatabaseException e1) {
                                LOGGER.error("", e1);
                            }
                        }
                        getBimServer().getNotificationsManager().notify(new NewRevisionNotification(getBimServer(), project.getOid(), revision.getOid(), authorization));
                    }
                });
            } catch (GeometryGeneratingException e) {
                throw new UserException(e);
            }
            revision.setHasGeometry(true);
        } else {
            if (previousRevision != null) {
                byte[] htmlBytes = null;
                byte[] jsonBytes = null;
                long timeToGenerate = -1;
                for (ExtendedData previousExtendedData : previousRevision.getExtendedData()) {
                    ExtendedDataSchema previousSchema = previousExtendedData.getSchema();
                    if (previousSchema.getName().contentEquals("GEOMETRY_GENERATION_REPORT_HTML_1_1")) {
                        htmlBytes = previousExtendedData.getFile().getData();
                    } else if (previousSchema.getName().contentEquals("GEOMETRY_GENERATION_REPORT_JSON_1_1")) {
                        jsonBytes = previousExtendedData.getFile().getData();
                    }
                }
                byte[] finalHtmlBytes = htmlBytes;
                byte[] finalJsonBytes = jsonBytes;
                getDatabaseSession().addPostCommitAction(new PostCommitAction() {

                    public void execute() throws UserException {
                        try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
                            AddGeometryReports addGeometryReports = new AddGeometryReports(tmpSession, AccessMethod.INTERNAL, finalHtmlBytes, finalJsonBytes, timeToGenerate, authorization.getUoid(), revision.getOid());
                            try {
                                tmpSession.executeAndCommitAction(addGeometryReports);
                            } catch (ServerException e1) {
                                LOGGER.error("", e1);
                            }
                        } catch (BimserverDatabaseException e1) {
                            LOGGER.error("", e1);
                        }
                    }
                });
                concreteRevision.setMultiplierToMm(previousConcreteRevision.getMultiplierToMm());
                concreteRevision.setBounds(previousConcreteRevision.getBounds());
                concreteRevision.setBoundsUntransformed(previousConcreteRevision.getBoundsUntransformed());
                newRevision.setBounds(previousRevision.getBounds());
                newRevision.setBoundsUntransformed(previousRevision.getBoundsUntransformed());
                newRevision.setBoundsMm(previousRevision.getBoundsMm());
                newRevision.setBoundsUntransformedMm(previousRevision.getBoundsUntransformedMm());
                // TODO validate this, contains ids?
                newRevision.setDensityCollection(previousRevision.getDensityCollection());
                revision.setHasGeometry(true);
            }
        }
    }
    concreteRevision.setSummary(summaryMap.toRevisionSummary(getDatabaseSession()));
    getDatabaseSession().store(concreteRevision);
    getDatabaseSession().store(project);
    return concreteRevision;
}
Also used : User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) RemoveObjectChange(org.bimserver.changes.RemoveObjectChange) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) GeometryGenerationReport(org.bimserver.geometry.GeometryGenerationReport) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) CreateObjectChange(org.bimserver.changes.CreateObjectChange) ExtendedDataSchema(org.bimserver.models.store.ExtendedDataSchema) OidCounters(org.bimserver.database.OidCounters) UserException(org.bimserver.shared.exceptions.UserException) NewRevisionAdded(org.bimserver.models.log.NewRevisionAdded) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) SConverter(org.bimserver.interfaces.SConverter) ExtendedData(org.bimserver.models.store.ExtendedData) PackageMetaData(org.bimserver.emf.PackageMetaData) PostCommitAction(org.bimserver.database.PostCommitAction) StreamingGeometryGenerator(org.bimserver.geometry.StreamingGeometryGenerator) RemoveObjectChange(org.bimserver.changes.RemoveObjectChange) CreateObjectChange(org.bimserver.changes.CreateObjectChange) Change(org.bimserver.changes.Change) IOException(java.io.IOException) QueryContext(org.bimserver.shared.QueryContext) Date(java.util.Date) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) QueryException(org.bimserver.database.queries.om.QueryException) NewRevisionNotification(org.bimserver.notifications.NewRevisionNotification) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SummaryMap(org.bimserver.SummaryMap) LongTransaction(org.bimserver.webservices.LongTransaction) Transaction(org.bimserver.changes.Transaction) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) GenerateGeometryResult(org.bimserver.GenerateGeometryResult)

Example 2 with StreamingGeometryGenerator

use of org.bimserver.geometry.StreamingGeometryGenerator in project BIMserver by opensourceBIM.

the class StreamingCheckinDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
    try {
        if (inputStream instanceof RestartableInputStream) {
            ((RestartableInputStream) inputStream).restartIfAtEnd();
        }
        getDatabaseSession().clearPostCommitActions();
        if (fileSize == -1) {
        // setProgress("Deserializing IFC file...", -1);
        } else {
            setProgress("Deserializing IFC file...", 0);
        }
        authorization.canCheckin(poid);
        project = getProjectByPoid(poid);
        int nrConcreteRevisionsBefore = project.getConcreteRevisions().size();
        User user = getUserByUoid(authorization.getUoid());
        if (project == null) {
            throw new UserException("Project with poid " + poid + " not found");
        }
        if (!authorization.hasRightsOnProjectOrSuperProjects(user, project)) {
            throw new UserException("User has no rights to checkin models to this project");
        }
        if (!MailSystem.isValidEmailAddress(user.getUsername())) {
            throw new UserException("Users must have a valid e-mail address to checkin");
        }
        // if (getModel() != null) {
        // checkCheckSum(project);
        // }
        packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema());
        // TODO checksum
        // TODO modelcheckers
        // TODO test ifc4
        // long size = 0;
        // if (getModel() != null) {
        // for (IdEObject idEObject : getModel().getValues()) {
        // if (idEObject.eClass().getEAnnotation("hidden") == null) {
        // size++;
        // }
        // }
        // getModel().fixInverseMismatches();
        // }
        // for (ModelCheckerInstance modelCheckerInstance : project.getModelCheckers()) {
        // if (modelCheckerInstance.isValid()) {
        // ModelCheckerPlugin modelCheckerPlugin = bimServer.getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
        // if (modelCheckerPlugin != null) {
        // ModelChecker modelChecker = modelCheckerPlugin.createModelChecker(null);
        // ModelCheckerResult result = modelChecker.check(getModel(), modelCheckerInstance.getCompiled());
        // if (!result.isValid()) {
        // throw new UserException("Model is not valid according to " + modelCheckerInstance.getName());
        // }
        // }
        // }
        // }
        CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), -1, project, user, comment.trim());
        newRevision = result.getRevisions().get(0);
        long newRoid = newRevision.getOid();
        // TODO check
        QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, result.getConcreteRevision().getProject().getId(), result.getConcreteRevision().getId(), newRoid, result.getConcreteRevision().getOid(), -1);
        AtomicLong bytesRead = new AtomicLong();
        deserializer.setProgressReporter(new ByteProgressReporter() {

            @Override
            public void progress(long byteNumber) {
                bytesRead.set(byteNumber);
                if (fileSize != -1) {
                    int perc = (int) (100.0 * byteNumber / fileSize);
                    setProgress("Deserializing...", perc);
                }
            }
        });
        // This will read the full stream of objects and write to the database directly
        long size = deserializer.read(inputStream, fileName, fileSize, queryContext);
        Set<EClass> eClasses = deserializer.getSummaryMap().keySet();
        Map<String, Long> startOids = getDatabaseSession().getStartOids();
        if (startOids == null) {
            throw new BimserverDatabaseException("No objects changed");
        }
        OidCounters oidCounters = new OidCounters();
        for (EClass eClass : eClasses) {
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                oidCounters.put(eClass, startOids.get(fullname(eClass)));
            }
        }
        queryContext.setOidCounters(oidCounters);
        concreteRevision = result.getConcreteRevision();
        concreteRevision.setOidCounters(oidCounters.getBytes());
        setProgress("Generating inverses/opposites...", -1);
        fixInverses(packageMetaData, newRoid, deserializer.getSummaryMap());
        ProgressListener progressListener = new ProgressListener() {

            @Override
            public void updateProgress(String state, int percentage) {
                setProgress("Generating geometry...", percentage);
            }
        };
        GeometryGenerationReport report = null;
        if (getBimServer().getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
            report = new GeometryGenerationReport();
            report.setOriginalIfcFileName(fileName);
            report.setOriginalIfcFileSize(bytesRead.get());
            report.setNumberOfObjects(size);
            report.setOriginalDeserializer(pluginBundleVersion.getGroupId() + "." + pluginBundleVersion.getArtifactId() + ":" + pluginBundleVersion.getVersion());
            StreamingGeometryGenerator geometryGenerator = new StreamingGeometryGenerator(getBimServer(), progressListener, -1L, report);
            setProgress("Generating geometry...", 0);
            GenerateGeometryResult generateGeometry = geometryGenerator.generateGeometry(getActingUid(), getDatabaseSession(), queryContext, size);
            for (Revision other : concreteRevision.getRevisions()) {
                other.setHasGeometry(true);
            }
            concreteRevision.setMultiplierToMm(generateGeometry.getMultiplierToMm());
            concreteRevision.setBounds(generateGeometry.getBounds());
            concreteRevision.setBoundsUntransformed(generateGeometry.getBoundsUntransformed());
            // TODO terrible code, but had to get it going quickly, will cleanup later
            generateDensityAndBounds(result, generateGeometry, concreteRevision);
        }
        final GeometryGenerationReport finalReport = report;
        // float[] quantizationMatrix = createQuantizationMatrixFromBounds(newRevision.getBoundsMm());
        // generateQuantizedVertices(getDatabaseSession(), newRevision, quantizationMatrix, generateGeometry.getMultiplierToMm());
        setProgress("Doing other stuff...", -1);
        eClasses = deserializer.getSummaryMap().keySet();
        oidCounters = new OidCounters();
        for (EClass eClass : eClasses) {
            String fullname = fullname(eClass);
            Long oid = startOids.get(fullname);
            if (oid == null) {
                // This happens almost never, but it most certainly must be a bug, adding verbose logging to try and identify the problem
                LOGGER.info("");
                LOGGER.info("EClass " + eClass.getName() + " not found in startOids, please report");
                LOGGER.info("eClasses:");
                for (EClass eClass2 : eClasses) {
                    LOGGER.info(fullname(eClass2));
                }
                LOGGER.info("");
                LOGGER.info("startOids");
                for (String fullname2 : startOids.keySet()) {
                    LOGGER.info(fullname2 + ": " + startOids.get(fullname2));
                }
                throw new UserException("EClass " + eClass.getName() + " not found in startOids, please report");
            }
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                oidCounters.put(eClass, oid);
            }
        }
        if (startOids.containsKey(fullname(GeometryPackage.eINSTANCE.getGeometryInfo())) && startOids.containsKey(fullname(GeometryPackage.eINSTANCE.getGeometryData()))) {
            oidCounters.put(GeometryPackage.eINSTANCE.getGeometryInfo(), startOids.get(fullname(GeometryPackage.eINSTANCE.getGeometryInfo())));
            oidCounters.put(GeometryPackage.eINSTANCE.getGeometryData(), startOids.get(fullname(GeometryPackage.eINSTANCE.getGeometryData())));
            oidCounters.put(GeometryPackage.eINSTANCE.getBuffer(), startOids.get(fullname(GeometryPackage.eINSTANCE.getBuffer())));
        }
        concreteRevision = result.getConcreteRevision();
        concreteRevision.setOidCounters(oidCounters.getBytes());
        // Clear the cache, we don't want it to cache incomplete oidcounters
        ConcreteRevisionStackFrame.clearCache(concreteRevision.getOid());
        result.getConcreteRevision().setSize(size);
        for (Revision revision : result.getRevisions()) {
            revision.setSize(((revision.getSize() == null || revision.getSize() == -1) ? 0 : revision.getSize()) + concreteRevision.getSize());
        }
        IfcHeader ifcHeader = deserializer.getIfcHeader();
        if (ifcHeader != null) {
            getDatabaseSession().store(ifcHeader);
            concreteRevision.setIfcHeader(ifcHeader);
        }
        project.getConcreteRevisions().add(concreteRevision);
        // if (getModel() != null) {
        // concreteRevision.setChecksum(getModel().getModelMetaData().getChecksum());
        // }
        final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
        newRevisionAdded.setDate(new Date());
        newRevisionAdded.setExecutor(user);
        final Revision revision = concreteRevision.getRevisions().get(0);
        if (newServiceId != -1) {
            NewService newService = getDatabaseSession().get(newServiceId, OldQuery.getDefault());
            revision.getServicesLinked().add(newService);
        }
        concreteRevision.setSummary(new SummaryMap(packageMetaData, deserializer.getSummaryMap()).toRevisionSummary(getDatabaseSession()));
        // If this revision is being created by an external service, store a link to the service in the revision
        if (authorization instanceof ExplicitRightsAuthorization) {
            ExplicitRightsAuthorization explicitRightsAuthorization = (ExplicitRightsAuthorization) authorization;
            if (explicitRightsAuthorization.getSoid() != -1) {
                Service service = getDatabaseSession().get(explicitRightsAuthorization.getSoid(), org.bimserver.database.OldQuery.getDefault());
                revision.setService(service);
            }
        }
        newRevisionAdded.setRevision(revision);
        newRevisionAdded.setProject(project);
        newRevisionAdded.setAccessMethod(getAccessMethod());
        if (nrConcreteRevisionsBefore != 0) {
            // There already was a revision, lets delete it (only when not merging)
            concreteRevision.setClear(true);
        }
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
                    Project project = tmpSession.get(poid, OldQuery.getDefault());
                    project.setCheckinInProgress(0);
                    tmpSession.store(project);
                    tmpSession.commit();
                } catch (BimserverDatabaseException e) {
                    LOGGER.error("", e);
                } catch (ServiceException e) {
                    LOGGER.error("", e);
                }
                if (finalReport != null) {
                    byte[] htmlBytes = finalReport.toHtml().getBytes(Charsets.UTF_8);
                    byte[] jsonBytes = finalReport.toJson().toString().getBytes(Charsets.UTF_8);
                    try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
                        AddGeometryReports addGeometryReports = new AddGeometryReports(tmpSession, AccessMethod.INTERNAL, htmlBytes, jsonBytes, finalReport.getTimeToGenerateMs(), authorization.getUoid(), revision.getOid());
                        try {
                            tmpSession.executeAndCommitAction(addGeometryReports);
                        } catch (ServerException e1) {
                            LOGGER.error("", e1);
                        }
                    } catch (BimserverDatabaseException e1) {
                        LOGGER.error("", e1);
                    }
                }
                getBimServer().getNotificationsManager().notify(new NewRevisionNotification(getBimServer(), project.getOid(), revision.getOid(), authorization));
            }
        });
        getDatabaseSession().store(concreteRevision);
        getDatabaseSession().store(project);
    } catch (Throwable e) {
        try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
            Project project = tmpSession.get(poid, OldQuery.getDefault());
            project.setCheckinInProgress(0);
            tmpSession.store(project);
            try {
                tmpSession.commit();
            } catch (ServiceException e2) {
                LOGGER.error("", e2);
            }
        } catch (BimserverDatabaseException e1) {
            LOGGER.error("", e1);
        }
        if (e instanceof BimserverDatabaseException) {
            throw (BimserverDatabaseException) e;
        }
        if (e instanceof UserException) {
            throw (UserException) e;
        }
        throw new UserException("[" + fileName + "] " + e.getMessage(), e);
    }
    return concreteRevision;
}
Also used : User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) RestartableInputStream(org.bimserver.webservices.impl.RestartableInputStream) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) GeometryGenerationReport(org.bimserver.geometry.GeometryGenerationReport) ExplicitRightsAuthorization(org.bimserver.webservices.authorization.ExplicitRightsAuthorization) OidCounters(org.bimserver.database.OidCounters) UserException(org.bimserver.shared.exceptions.UserException) NewRevisionAdded(org.bimserver.models.log.NewRevisionAdded) NewService(org.bimserver.models.store.NewService) ServerException(org.bimserver.shared.exceptions.ServerException) PostCommitAction(org.bimserver.database.PostCommitAction) StreamingGeometryGenerator(org.bimserver.geometry.StreamingGeometryGenerator) Service(org.bimserver.models.store.Service) NewService(org.bimserver.models.store.NewService) QueryContext(org.bimserver.shared.QueryContext) IfcHeader(org.bimserver.models.store.IfcHeader) Date(java.util.Date) Project(org.bimserver.models.store.Project) AtomicLong(java.util.concurrent.atomic.AtomicLong) ByteProgressReporter(org.bimserver.plugins.deserializers.ByteProgressReporter) NewRevisionNotification(org.bimserver.notifications.NewRevisionNotification) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SummaryMap(org.bimserver.SummaryMap) ServiceException(org.bimserver.shared.exceptions.ServiceException) GenerateGeometryResult(org.bimserver.GenerateGeometryResult) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 3 with StreamingGeometryGenerator

use of org.bimserver.geometry.StreamingGeometryGenerator in project BIMserver by opensourceBIM.

the class RegenerateGeometryDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    ProgressListener progressListener = new ProgressListener() {

        @Override
        public void updateProgress(String state, int percentage) {
            setProgress("Generating geometry...", percentage);
        }
    };
    GeometryGenerationReport report = new GeometryGenerationReport();
    report.setOriginalIfcFileName("rerun");
    report.setOriginalIfcFileSize(-1);
    report.setOriginalDeserializer("rerun");
    StreamingGeometryGenerator streamingGeometryGenerator = new StreamingGeometryGenerator(bimServer, progressListener, eoid, report);
    Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
    ConcreteRevision concreteRevision = revision.getConcreteRevisions().get(0);
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
    int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(concreteRevision.getProject(), concreteRevision);
    QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, revision.getProject().getId(), revision.getId(), roid, concreteRevision.getOid(), highestStopId);
    try {
        // TODO get the actual amount of products
        GenerateGeometryResult generateGeometry = streamingGeometryGenerator.generateGeometry(uoid, getDatabaseSession(), queryContext, 1000);
        for (Revision other : concreteRevision.getRevisions()) {
            other.setHasGeometry(true);
        }
        concreteRevision.setMultiplierToMm(generateGeometry.getMultiplierToMm());
        concreteRevision.setBounds(generateGeometry.getBounds());
        concreteRevision.setBoundsUntransformed(generateGeometry.getBoundsUntransformed());
        byte[] htmlBytes = report.toHtml().getBytes(Charsets.UTF_8);
        byte[] jsonBytes = report.toJson().toString().getBytes(Charsets.UTF_8);
        storeExtendedData(htmlBytes, "text/html", "html", revision);
        storeExtendedData(jsonBytes, "application/json", "json", revision);
        getDatabaseSession().store(revision);
        getDatabaseSession().store(concreteRevision);
        renderEngineName = streamingGeometryGenerator.getRenderEngineName();
    } catch (GeometryGeneratingException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : GeometryGenerationReport(org.bimserver.geometry.GeometryGenerationReport) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) GenerateGeometryResult(org.bimserver.GenerateGeometryResult) PackageMetaData(org.bimserver.emf.PackageMetaData) StreamingGeometryGenerator(org.bimserver.geometry.StreamingGeometryGenerator) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) QueryContext(org.bimserver.shared.QueryContext)

Aggregations

GenerateGeometryResult (org.bimserver.GenerateGeometryResult)3 GeometryGenerationReport (org.bimserver.geometry.GeometryGenerationReport)3 StreamingGeometryGenerator (org.bimserver.geometry.StreamingGeometryGenerator)3 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)3 Revision (org.bimserver.models.store.Revision)3 QueryContext (org.bimserver.shared.QueryContext)3 Date (java.util.Date)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 GeometryGeneratingException (org.bimserver.GeometryGeneratingException)2 SummaryMap (org.bimserver.SummaryMap)2 DatabaseSession (org.bimserver.database.DatabaseSession)2 OidCounters (org.bimserver.database.OidCounters)2 PostCommitAction (org.bimserver.database.PostCommitAction)2 PackageMetaData (org.bimserver.emf.PackageMetaData)2 NewRevisionAdded (org.bimserver.models.log.NewRevisionAdded)2 Project (org.bimserver.models.store.Project)2 User (org.bimserver.models.store.User)2 NewRevisionNotification (org.bimserver.notifications.NewRevisionNotification)2 ServerException (org.bimserver.shared.exceptions.ServerException)2 UserException (org.bimserver.shared.exceptions.UserException)2