Search in sources :

Example 1 with RenderEnginePluginConfiguration

use of org.bimserver.models.store.RenderEnginePluginConfiguration 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 RenderEnginePluginConfiguration

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

the class DeleteRenderEngineDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    RenderEnginePluginConfiguration object = getDatabaseSession().get(geteClass(), getOid(), OldQuery.getDefault());
    UserSettings settings = object.getUserSettings();
    settings.getRenderEngines().remove(object);
    getDatabaseSession().store(settings);
    return super.execute();
}
Also used : RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) UserSettings(org.bimserver.models.store.UserSettings)

Example 3 with RenderEnginePluginConfiguration

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

the class PluginServiceImpl method updateRenderEngine.

@Override
public void updateRenderEngine(SRenderEnginePluginConfiguration renderEngine) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        RenderEnginePluginConfiguration convert = session.get(renderEngine.getOid(), OldQuery.getDefault());
        getBimServer().getSConverter().convertFromSObject(renderEngine, convert, session);
        session.executeAndCommitAction(new UpdateRenderEngineDatabaseAction(session, getInternalAccessMethod(), convert));
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : SRenderEnginePluginConfiguration(org.bimserver.interfaces.objects.SRenderEnginePluginConfiguration) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) UpdateRenderEngineDatabaseAction(org.bimserver.database.actions.UpdateRenderEngineDatabaseAction) DatabaseSession(org.bimserver.database.DatabaseSession) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException)

Example 4 with RenderEnginePluginConfiguration

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

the class LongDownloadOrCheckoutAction method executeAction.

protected void executeAction(BimDatabaseAction<? extends IfcModelInterface> action, DownloadParameters downloadParameters, DatabaseSession session, boolean commit) throws BimserverDatabaseException, UserException, NoSerializerFoundException, ServerException {
    try {
        if (action == null) {
            checkoutResult = new SCheckoutResult();
            checkoutResult.setFile(new CachingDataHandler(getBimServer().getDiskCacheManager(), downloadParameters));
            checkoutResult.setSerializerOid(downloadParameters.getSerializerOid());
        } else {
            Revision revision = session.get(StorePackage.eINSTANCE.getRevision(), downloadParameters.getRoid(), OldQuery.getDefault());
            if (revision == null) {
                throw new UserException("Revision with roid " + downloadParameters.getRoid() + " not found");
            }
            // Little hack to make
            revision.getProject().getGeoTag().load();
            // sure this is
            // lazily loaded,
            // because after the
            // executeAndCommitAction
            // the session won't
            // be usable
            IfcModelInterface ifcModel = session.executeAndCommitAction(action);
            // Session is closed after this
            DatabaseSession newSession = getBimServer().getDatabase().createSession();
            RenderEnginePlugin renderEnginePlugin = null;
            try {
                PluginConfiguration serializerPluginConfiguration = newSession.get(StorePackage.eINSTANCE.getPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
                if (serializerPluginConfiguration != null) {
                    if (serializerPluginConfiguration instanceof MessagingSerializerPluginConfiguration) {
                        try {
                            messagingSerializer = getBimServer().getSerializerFactory().createMessagingSerializer(getUserName(), ifcModel, downloadParameters);
                        } catch (SerializerException e) {
                            e.printStackTrace();
                        }
                    } else if (serializerPluginConfiguration instanceof SerializerPluginConfiguration) {
                        RenderEnginePluginConfiguration renderEngine = ((SerializerPluginConfiguration) serializerPluginConfiguration).getRenderEngine();
                        if (renderEngine != null) {
                            renderEnginePlugin = getBimServer().getPluginManager().getRenderEnginePlugin(renderEngine.getPluginDescriptor().getPluginClassName(), true);
                        }
                        checkoutResult = convertModelToCheckoutResult(revision.getProject(), getUserName(), ifcModel, renderEnginePlugin, downloadParameters);
                    }
                }
            } catch (BimserverDatabaseException e) {
                LOGGER.error("", e);
            } finally {
                newSession.close();
            }
        }
    } finally {
        done();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SCheckoutResult(org.bimserver.interfaces.objects.SCheckoutResult) RenderEnginePlugin(org.bimserver.plugins.renderengine.RenderEnginePlugin) SerializerException(org.bimserver.plugins.serializers.SerializerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) Revision(org.bimserver.models.store.Revision) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) PluginConfiguration(org.bimserver.models.store.PluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException)

Example 5 with RenderEnginePluginConfiguration

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

the class PluginServiceImpl method addRenderEngine.

@Override
public Long addRenderEngine(SRenderEnginePluginConfiguration renderEngine) throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        RenderEnginePluginConfiguration convert = getBimServer().getSConverter().convertFromSObject(renderEngine, session);
        return session.executeAndCommitAction(new AddRenderEngineDatabaseAction(session, getInternalAccessMethod(), getAuthorization(), convert));
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : SRenderEnginePluginConfiguration(org.bimserver.interfaces.objects.SRenderEnginePluginConfiguration) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) DatabaseSession(org.bimserver.database.DatabaseSession) AddRenderEngineDatabaseAction(org.bimserver.database.actions.AddRenderEngineDatabaseAction) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

RenderEnginePluginConfiguration (org.bimserver.models.store.RenderEnginePluginConfiguration)8 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)6 UserException (org.bimserver.shared.exceptions.UserException)6 IOException (java.io.IOException)4 DatabaseSession (org.bimserver.database.DatabaseSession)4 UserSettings (org.bimserver.models.store.UserSettings)4 IfcModelInterface (org.bimserver.emf.IfcModelInterface)3 User (org.bimserver.models.store.User)3 PluginConfiguration (org.bimserver.plugins.PluginConfiguration)3 RenderEnginePool (org.bimserver.renderengine.RenderEnginePool)3 ServerException (org.bimserver.shared.exceptions.ServerException)3 GenerateGeometryResult (org.bimserver.GenerateGeometryResult)2 GeometryGenerator (org.bimserver.GeometryGenerator)2 OldQuery (org.bimserver.database.OldQuery)2 SRenderEnginePluginConfiguration (org.bimserver.interfaces.objects.SRenderEnginePluginConfiguration)2 Revision (org.bimserver.models.store.Revision)2 ByteBuffer (java.nio.ByteBuffer)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1