Search in sources :

Example 1 with NewService

use of org.bimserver.models.store.NewService in project BIMserver by opensourceBIM.

the class CheckinDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
    try {
        bimServer.getCheckinsInProgress().put(poid, getActingUid());
        if (fileSize == -1) {
            setProgress("Deserializing IFC file...", -1);
        } else {
            setProgress("Deserializing IFC file...", 0);
        }
        if (getModel().size() == 0) {
            throw new DeserializeException("Cannot checkin empty model");
        }
        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, getModel());
        }
        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(), size, project, user, comment.trim());
        concreteRevision = result.getConcreteRevision();
        IfcHeader ifcHeader = getModel().getModelMetaData().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(getModel()).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(), OldQuery.getDefault());
                revision.setService(service);
            }
        }
        newRevisionAdded.setRevision(revision);
        newRevisionAdded.setProject(project);
        newRevisionAdded.setAccessMethod(getAccessMethod());
        Revision lastRevision = project.getLastRevision();
        IfcModelInterface ifcModel = null;
        if (merge && lastRevision != null) {
            ifcModel = checkinMerge(lastRevision);
        } else {
            ifcModel = getModel();
        }
        ifcModel.fixOidsFlat(getDatabaseSession());
        if (bimServer.getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
            setProgress("Generating Geometry...", -1);
            UserSettings userSettings = user.getUserSettings();
            RenderEnginePluginConfiguration defaultRenderEngine = userSettings.getDefaultRenderEngine();
            if (defaultRenderEngine == null) {
                throw new UserException("No default render engine has been selected for this user");
            }
            RenderEnginePool pool = bimServer.getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), new PluginConfiguration(defaultRenderEngine.getSettings()));
            GenerateGeometryResult generateGeometry = new GeometryGenerator(bimServer).generateGeometry(pool, bimServer.getPluginManager(), getDatabaseSession(), ifcModel, project.getId(), concreteRevision.getId(), true, geometryCache);
            concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
            concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
            for (Revision other : concreteRevision.getRevisions()) {
                other.setHasGeometry(true);
            }
        }
        if (nrConcreteRevisionsBefore != 0 && !merge) {
            // There already was a revision, lets delete it (only when not merging)
            concreteRevision.setClear(true);
        }
        Set<EClass> eClasses = ifcModel.getUsedClasses();
        Map<EClass, Long> startOids = getDatabaseSession().getStartOids();
        if (startOids == null) {
            throw new BimserverDatabaseException("No objects changed");
        }
        int s = 0;
        for (EClass eClass : eClasses) {
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                s++;
            }
        }
        ByteBuffer buffer = ByteBuffer.allocate(8 * s);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        for (EClass eClass : eClasses) {
            long oid = startOids.get(eClass);
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                buffer.putLong(oid);
            }
        }
        concreteRevision.setOidCounters(buffer.array());
        if (ifcModel != null) {
            getDatabaseSession().store(ifcModel.getValues(), project.getId(), concreteRevision.getId());
        }
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getCheckinsInProgress().remove(poid);
                bimServer.getNotificationsManager().notify(new NewRevisionNotification(bimServer, project.getOid(), revision.getOid(), authorization));
            }
        });
        getDatabaseSession().store(concreteRevision);
        getDatabaseSession().store(project);
    } catch (Throwable e) {
        if (e instanceof BimserverDatabaseException) {
            throw (BimserverDatabaseException) e;
        }
        if (e instanceof UserException) {
            throw (UserException) e;
        }
        LOGGER.error("", e);
        throw new UserException(e);
    }
    return concreteRevision;
}
Also used : User(org.bimserver.models.store.User) RenderEnginePool(org.bimserver.renderengine.RenderEnginePool) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ModelCheckerResult(org.bimserver.models.store.ModelCheckerResult) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ModelChecker(org.bimserver.plugins.modelchecker.ModelChecker) EClass(org.eclipse.emf.ecore.EClass) ExplicitRightsAuthorization(org.bimserver.webservices.authorization.ExplicitRightsAuthorization) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) NewRevisionAdded(org.bimserver.models.log.NewRevisionAdded) NewService(org.bimserver.models.store.NewService) ModelCheckerInstance(org.bimserver.models.store.ModelCheckerInstance) ModelCheckerPlugin(org.bimserver.plugins.modelchecker.ModelCheckerPlugin) IdEObject(org.bimserver.emf.IdEObject) UserSettings(org.bimserver.models.store.UserSettings) PostCommitAction(org.bimserver.database.PostCommitAction) GeometryGenerator(org.bimserver.GeometryGenerator) Service(org.bimserver.models.store.Service) NewService(org.bimserver.models.store.NewService) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IfcHeader(org.bimserver.models.store.IfcHeader) ByteBuffer(java.nio.ByteBuffer) Date(java.util.Date) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) NewRevisionNotification(org.bimserver.notifications.NewRevisionNotification) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SummaryMap(org.bimserver.SummaryMap) GenerateGeometryResult(org.bimserver.GenerateGeometryResult)

Example 2 with NewService

use of org.bimserver.models.store.NewService in project BIMserver by opensourceBIM.

the class NewRevisionNotification method process.

@Override
public void process() throws BimserverDatabaseException, UserException, ServerException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        Project project = session.get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
        if (project == null) {
            LOGGER.error("Project with oid " + poid + " not found");
            return;
        }
        Revision revision = session.get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
        if (revision == null) {
            LOGGER.error("Revision with roid " + roid + " not found");
            return;
        }
        if (project.isSendEmailOnNewRevision() && sendEmail) {
            sendEmail(session, project, revision);
        }
        for (NewService newService : project.getNewServices()) {
            if (soid == -1 || newService.getOid() == soid) {
                triggerNewRevision(session, getBimServer().getNotificationsManager(), getBimServer(), getBimServer().getNotificationsManager().getSiteAddress(), project, roid, Trigger.NEW_REVISION, newService);
            }
        }
        for (Service service : project.getServices()) {
            if (soid == -1 || service.getOid() == soid) {
                triggerNewRevision(session, getBimServer().getNotificationsManager(), getBimServer(), getBimServer().getNotificationsManager().getSiteAddress(), project, roid, Trigger.NEW_REVISION, service);
            }
        }
        if (soid == -1) {
            // Only execute if we are not triggering a specific service with this notification
            NewRevisionTopic newRevisionTopic = getBimServer().getNotificationsManager().getNewRevisionTopic();
            if (newRevisionTopic != null) {
                newRevisionTopic.process(session, poid, roid, this);
            }
            NewRevisionOnSpecificProjectTopic newRevisionOnSpecificProjectTopic = getBimServer().getNotificationsManager().getNewRevisionOnSpecificProjectTopic(new NewRevisionOnSpecificProjectTopicKey(poid));
            if (newRevisionOnSpecificProjectTopic != null) {
                newRevisionOnSpecificProjectTopic.process(session, poid, roid, this);
            }
        }
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) Revision(org.bimserver.models.store.Revision) DatabaseSession(org.bimserver.database.DatabaseSession) Service(org.bimserver.models.store.Service) NewService(org.bimserver.models.store.NewService) NewService(org.bimserver.models.store.NewService)

Example 3 with NewService

use of org.bimserver.models.store.NewService in project BIMserver by opensourceBIM.

the class OAuthServiceImpl method getRemoteToken.

@Override
public String getRemoteToken(Long soid, String code, Long serverId) throws ServerException, UserException {
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        NewService newService = session.get(soid, OldQuery.getDefault());
        ObjectNode objectNode = OBJECT_MAPPER.createObjectNode();
        objectNode.put("grant_type", "authorization_code");
        objectNode.put("code", code);
        OAuthServer oAuthServer = session.get(serverId, OldQuery.getDefault());
        objectNode.put("client_id", oAuthServer.getClientId());
        objectNode.put("client_secret", oAuthServer.getClientSecret());
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try {
            HttpPost post = new HttpPost(newService.getTokenUrl());
            post.setHeader("Content-Type", "application/x-www-form-urlencoded");
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("grant_type", "authorization_code"));
            nvps.add(new BasicNameValuePair("code", code));
            nvps.add(new BasicNameValuePair("client_id", oAuthServer.getClientId()));
            nvps.add(new BasicNameValuePair("client_secret", oAuthServer.getClientSecret()));
            nvps.add(new BasicNameValuePair("redirect_uri", "crap"));
            post.setEntity(new UrlEncodedFormEntity(nvps));
            CloseableHttpResponse httpResponse = httpclient.execute(post);
            ObjectNode response = OBJECT_MAPPER.readValue(httpResponse.getEntity().getContent(), ObjectNode.class);
            if (response.has("access_token")) {
                String accessToken = response.get("access_token").asText();
                newService.setAccessToken(accessToken);
                newService.setStatus(ServiceStatus.AUTHENTICATED);
                newService.setResourceUrl(response.get("resource_url").asText());
                session.store(newService);
                session.commit();
                return accessToken;
            } else {
                throw new UserException("No access_token received from oauth server");
            }
        } finally {
            httpclient.close();
        }
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DatabaseSession(org.bimserver.database.DatabaseSession) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) SOAuthServer(org.bimserver.interfaces.objects.SOAuthServer) OAuthServer(org.bimserver.models.store.OAuthServer) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) UserException(org.bimserver.shared.exceptions.UserException) NewService(org.bimserver.models.store.NewService)

Example 4 with NewService

use of org.bimserver.models.store.NewService in project BIMserver by opensourceBIM.

the class RemoveNewServiceFromProjectDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    NewService service = getDatabaseSession().get(soid, OldQuery.getDefault());
    Project project = getDatabaseSession().get(poid, OldQuery.getDefault());
    project.getNewServices().remove(service);
    getDatabaseSession().store(project);
    return true;
}
Also used : Project(org.bimserver.models.store.Project) NewService(org.bimserver.models.store.NewService)

Example 5 with NewService

use of org.bimserver.models.store.NewService in project BIMserver by opensourceBIM.

the class StreamingCheckinDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
    try {
        bimServer.getCheckinsInProgress().put(poid, getActingUid());
        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 = bimServer.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, -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<EClass, Long> startOids = getDatabaseSession().getStartOids();
        if (startOids == null) {
            throw new BimserverDatabaseException("No objects changed");
        }
        Map<EClass, Long> oidCounters = new HashMap<>();
        int s = 0;
        for (EClass eClass : eClasses) {
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                s++;
            }
        }
        ByteBuffer buffer = ByteBuffer.allocate(8 * s);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        for (EClass eClass : eClasses) {
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                long oid = startOids.get(eClass);
                oidCounters.put(eClass, oid);
                buffer.putLong(oid);
            }
        }
        queryContext.setOidCounters(oidCounters);
        concreteRevision = result.getConcreteRevision();
        concreteRevision.setOidCounters(buffer.array());
        setProgress("Generating inverses/opposites...", -1);
        fixInverses(packageMetaData, newRoid);
        ProgressListener progressListener = new ProgressListener() {

            @Override
            public void updateProgress(String state, int percentage) {
                setProgress("Generating geometry...", percentage);
            }
        };
        GeometryGenerationReport 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(bimServer, progressListener, -1L, report);
        setProgress("Generating geometry...", 0);
        GenerateGeometryResult generateGeometry = geometryGenerator.generateGeometry(getActingUid(), getDatabaseSession(), queryContext);
        for (Revision other : concreteRevision.getRevisions()) {
            other.setHasGeometry(true);
        }
        concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
        concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
        setProgress("Doing other stuff...", -1);
        eClasses = deserializer.getSummaryMap().keySet();
        s = (startOids.containsKey(GeometryPackage.eINSTANCE.getGeometryInfo()) && startOids.containsKey(GeometryPackage.eINSTANCE.getGeometryData())) ? 2 : 0;
        for (EClass eClass : eClasses) {
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                s++;
            }
        }
        buffer = ByteBuffer.allocate(8 * s);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        for (EClass eClass : eClasses) {
            long oid = startOids.get(eClass);
            if (!DatabaseSession.perRecordVersioning(eClass)) {
                buffer.putLong(oid);
            }
        }
        if (startOids.containsKey(GeometryPackage.eINSTANCE.getGeometryInfo()) && startOids.containsKey(GeometryPackage.eINSTANCE.getGeometryData())) {
            buffer.putLong(startOids.get(GeometryPackage.eINSTANCE.getGeometryInfo()));
            buffer.putLong(startOids.get(GeometryPackage.eINSTANCE.getGeometryData()));
        }
        concreteRevision = result.getConcreteRevision();
        concreteRevision.setOidCounters(buffer.array());
        // 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 ? 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);
        }
        ExtendedData extendedData = getDatabaseSession().create(ExtendedData.class);
        File file = getDatabaseSession().create(File.class);
        byte[] bytes = report.toHtml().getBytes(Charsets.UTF_8);
        file.setData(bytes);
        file.setFilename("geometrygenerationreport.html");
        file.setMime("text/html");
        file.setSize(bytes.length);
        User actingUser = getUserByUoid(authorization.getUoid());
        extendedData.setUser(actingUser);
        extendedData.setTitle("Geometry generation report");
        extendedData.setAdded(new Date());
        extendedData.setSize(file.getData().length);
        extendedData.setFile(file);
        revision.getExtendedData().add(extendedData);
        extendedData.setProject(revision.getProject());
        extendedData.setRevision(revision);
        getDatabaseSession().store(file);
        getDatabaseSession().store(extendedData);
        if (extendedData.getSchema() != null) {
            getDatabaseSession().store(extendedData.getSchema());
        }
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getNotificationsManager().notify(new NewRevisionNotification(bimServer, project.getOid(), revision.getOid(), authorization));
            }
        });
        getDatabaseSession().store(concreteRevision);
        getDatabaseSession().store(project);
    } catch (Throwable e) {
        if (e instanceof BimserverDatabaseException) {
            throw (BimserverDatabaseException) e;
        }
        if (e instanceof UserException) {
            throw (UserException) e;
        }
        throw new UserException(e);
    } finally {
        bimServer.getCheckinsInProgress().remove(poid);
    }
    return concreteRevision;
}
Also used : User(org.bimserver.models.store.User) HashMap(java.util.HashMap) 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) UserException(org.bimserver.shared.exceptions.UserException) NewRevisionAdded(org.bimserver.models.log.NewRevisionAdded) NewService(org.bimserver.models.store.NewService) ExtendedData(org.bimserver.models.store.ExtendedData) 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) ByteBuffer(java.nio.ByteBuffer) IfcHeader(org.bimserver.models.store.IfcHeader) Date(java.util.Date) 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) GenerateGeometryResult(org.bimserver.GenerateGeometryResult) AtomicLong(java.util.concurrent.atomic.AtomicLong) File(org.bimserver.models.store.File)

Aggregations

NewService (org.bimserver.models.store.NewService)7 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)5 UserException (org.bimserver.shared.exceptions.UserException)5 DatabaseSession (org.bimserver.database.DatabaseSession)4 Revision (org.bimserver.models.store.Revision)4 Date (java.util.Date)3 Project (org.bimserver.models.store.Project)3 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)3 ServerException (org.bimserver.shared.exceptions.ServerException)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 ByteBuffer (java.nio.ByteBuffer)2 MessagingException (javax.mail.MessagingException)2 AddressException (javax.mail.internet.AddressException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 GenerateGeometryResult (org.bimserver.GenerateGeometryResult)2 SummaryMap (org.bimserver.SummaryMap)2