Search in sources :

Example 1 with ExtendedDataSchema

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

the class ServiceImpl method addExtendedDataSchema.

@Override
public Long addExtendedDataSchema(SExtendedDataSchema extendedDataSchema) throws ServerException, UserException {
    // requireAdminAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
    try {
        ExtendedDataSchema create = session.create(ExtendedDataSchema.class);
        ExtendedDataSchema convert = getBimServer().getSConverter().convertFromSObject(extendedDataSchema, create, session);
        return session.executeAndCommitAction(new AddExtendedDataSchemaDatabaseAction(session, getInternalAccessMethod(), convert));
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) SExtendedDataSchema(org.bimserver.interfaces.objects.SExtendedDataSchema) ExtendedDataSchema(org.bimserver.models.store.ExtendedDataSchema) AddExtendedDataSchemaDatabaseAction(org.bimserver.database.actions.AddExtendedDataSchemaDatabaseAction) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 2 with ExtendedDataSchema

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

the class BimServer method initDatabaseDependantItems.

private void initDatabaseDependantItems() throws BimserverDatabaseException {
    LOGGER.info("Initializing database dependant logic...");
    long start = System.nanoTime();
    notificationsManager.init();
    getSerializerFactory().init(pluginManager, bimDatabase, this);
    try {
        DatabaseSession session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE);
        try {
            updatePlugins(session);
            session.commit();
        } catch (ServiceException e) {
            LOGGER.error("", e);
        } finally {
            session.close();
        }
        int renderEngineProcesses = getServerSettingsCache().getServerSettings().getRenderEngineProcesses();
        RenderEnginePoolFactory renderEnginePoolFactory = new CommonsPoolingRenderEnginePoolFactory(renderEngineProcesses);
        renderEnginePools = new RenderEnginePools(this, renderEnginePoolFactory);
        session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE);
        // createDatabaseObjects(session);
        ServerSettings serverSettings = serverSettingsCache.getServerSettings();
        for (Entry<PluginContext, WebModulePlugin> entry : pluginManager.getAllWebPlugins(true).entrySet()) {
            WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), entry.getKey().getIdentifier());
            if (webPluginConfiguration == null) {
                webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
                serverSettings.getWebModules().add(webPluginConfiguration);
                PluginDescriptor pluginDescriptor = getPluginDescriptor(session, entry.getKey().getIdentifier());
                if (pluginDescriptor == null) {
                    throw new BimserverDatabaseException("No plugin descriptor found: " + entry.getKey().getIdentifier());
                }
                genericPluginConversion(entry.getKey(), session, webPluginConfiguration, pluginDescriptor);
            } else {
                if (webPluginConfiguration == serverSettings.getWebModule()) {
                    setDefaultWebModule(entry.getValue());
                }
            }
        }
        // Set the default
        // if (serverSettings.getWebModule() == null) {
        // WebModulePluginConfiguration bimviewsWebModule = findWebModule(serverSettings, "BIM Views");
        // if (bimviewsWebModule != null) {
        // serverSettings.setWebModule(bimviewsWebModule);
        // setDefaultWebModule(pluginManager.getWebModulePlugin(bimviewsWebModule.getPluginDescriptor().getPluginClassName(), true));
        // } else {
        // WebModulePluginConfiguration defaultWebModule = findWebModule(serverSettings, "org.bimserver.defaultwebmodule.DefaultWebModulePlugin");
        // if (defaultWebModule != null) {
        // serverSettings.setWebModule(defaultWebModule);
        // setDefaultWebModule(pluginManager.getWebModulePlugin(defaultWebModule.getPluginDescriptor().getPluginClassName(), true));
        // }
        // }
        // }
        session.store(serverSettings);
        Condition condition = new AttributeCondition(StorePackage.eINSTANCE.getUser_Username(), new StringLiteral("system"));
        User systemUser = session.querySingle(condition, User.class, OldQuery.getDefault());
        ServerStarted serverStarted = session.create(ServerStarted.class);
        serverStarted.setDate(new Date());
        serverStarted.setAccessMethod(AccessMethod.INTERNAL);
        serverStarted.setExecutor(systemUser);
        try {
            session.store(serverStarted);
            session.commit();
        } catch (BimserverLockConflictException e) {
            throw new BimserverDatabaseException(e);
        } catch (ServiceException e) {
            throw new BimserverDatabaseException(e);
        } finally {
            session.close();
        }
        webModules = new HashMap<String, WebModulePlugin>();
        List<WebModulePluginConfiguration> webModuleConfigurations = serverSettingsCache.getServerSettings().getWebModules();
        for (WebModulePluginConfiguration webModulePluginConfiguration : webModuleConfigurations) {
            String contextPath = "";
            for (Parameter parameter : webModulePluginConfiguration.getSettings().getParameters()) {
                if (parameter.getName().equals("contextPath")) {
                    contextPath = ((StringType) parameter.getValue()).getValue();
                }
            }
            String identifier = webModulePluginConfiguration.getPluginDescriptor().getIdentifier();
            webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(identifier, true));
        }
        try (DatabaseSession databaseSession = getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
            ExtendedDataSchema htmlSchema = (ExtendedDataSchema) databaseSession.querySingle(StorePackage.eINSTANCE.getExtendedDataSchema_Name(), "GEOMETRY_GENERATION_REPORT_HTML_1_1");
            ExtendedDataSchema jsonSchema = (ExtendedDataSchema) databaseSession.querySingle(StorePackage.eINSTANCE.getExtendedDataSchema_Name(), "GEOMETRY_GENERATION_REPORT_JSON_1_1");
            if (htmlSchema == null) {
                htmlSchema = createExtendedDataSchema(databaseSession, "GEOMETRY_GENERATION_REPORT_HTML_1_1", "text/html");
            }
            if (jsonSchema == null) {
                jsonSchema = createExtendedDataSchema(databaseSession, "GEOMETRY_GENERATION_REPORT_JSON_1_1", "application/json");
            }
            databaseSession.commit();
        } catch (ServiceException e) {
            LOGGER.error("", e);
        }
        Integer protocolBuffersPort = getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
        if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
            try {
                protocolBuffersMetaData = new ProtocolBuffersMetaData();
                protocolBuffersMetaData.load(servicesMap, ProtocolBuffersBimServerClientFactory.class);
                protocolBuffersServer = new ProtocolBuffersServer(protocolBuffersMetaData, serviceFactory, servicesMap, protocolBuffersPort);
                protocolBuffersServer.start();
            } catch (Exception e) {
                LOGGER.error("", e);
            }
        }
        bimServerClientFactory = new DirectBimServerClientFactory<ServiceInterface>(serverSettingsCache.getServerSettings().getSiteAddress(), serviceFactory, servicesMap, pluginManager, metaDataManager);
        pluginManager.setBimServerClientFactory(bimServerClientFactory);
        try (DatabaseSession session2 = bimDatabase.createSession(OperationType.READ_ONLY)) {
            IfcModelInterface pluginBundleVersions = session2.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
            for (PluginBundleVersion pluginBundleVersion : pluginBundleVersions.getAll(PluginBundleVersion.class)) {
                if (pluginBundleVersion.getType() == PluginBundleType.MAVEN || pluginBundleVersion.getType() == PluginBundleType.LOCAL) {
                    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(pluginBundleVersion.getGroupId(), pluginBundleVersion.getArtifactId(), pluginBundleVersion.getVersion());
                    IfcModelInterface pluginDescriptors = session2.getAllOfType(StorePackage.eINSTANCE.getPluginDescriptor(), OldQuery.getDefault());
                    List<SPluginInformation> plugins = new ArrayList<>();
                    for (PluginDescriptor pluginDescriptor : pluginDescriptors.getAll(PluginDescriptor.class)) {
                        if (pluginDescriptor.getPluginBundleVersion() == pluginBundleVersion && pluginDescriptor.getEnabled()) {
                            SPluginInformation sPluginInformation = new SPluginInformation();
                            sPluginInformation.setEnabled(true);
                            sPluginInformation.setDescription(pluginDescriptor.getDescription());
                            sPluginInformation.setIdentifier(pluginDescriptor.getIdentifier());
                            sPluginInformation.setInstallForAllUsers(pluginDescriptor.isInstallForNewUsers());
                            sPluginInformation.setInstallForNewUsers(pluginDescriptor.isInstallForNewUsers());
                            sPluginInformation.setName(pluginDescriptor.getName());
                            sPluginInformation.setType(pluginManager.getPluginTypeFromClass(pluginDescriptor.getPluginClassName()));
                            plugins.add(sPluginInformation);
                        }
                    }
                    try {
                        pluginBundleManager.loadFromPluginDir(pluginBundleVersionIdentifier, getSConverter().convertToSObject(pluginBundleVersion), plugins, serverSettingsCache.getServerSettings().isPluginStrictVersionChecking());
                    } catch (Exception e) {
                        LOGGER.error("", e);
                    }
                }
            }
        } catch (Exception e) {
            throw new BimserverDatabaseException(e);
        }
    } catch (BimserverLockConflictException e) {
        throw new BimserverDatabaseException(e);
    // } catch (PluginException e) {
    // throw new BimserverDatabaseException(e);
    } catch (RenderEngineException e) {
        throw new BimserverDatabaseException(e);
    }
    long end = System.nanoTime();
    LOGGER.info("Done initializing database dependant logic (" + ((end - start) / 1000000) + "ms)");
}
Also used : User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ArrayList(java.util.ArrayList) ProtocolBuffersMetaData(org.bimserver.shared.pb.ProtocolBuffersMetaData) PluginBundleVersionIdentifier(org.bimserver.plugins.PluginBundleVersionIdentifier) ServerSettings(org.bimserver.models.store.ServerSettings) CommonsPoolingRenderEnginePoolFactory(org.bimserver.renderengine.pooled.CommonsPoolingRenderEnginePoolFactory) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) ExtendedDataSchema(org.bimserver.models.store.ExtendedDataSchema) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) PluginBundleVersion(org.bimserver.models.store.PluginBundleVersion) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) Condition(org.bimserver.database.query.conditions.Condition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) PluginContext(org.bimserver.plugins.PluginContext) WebModulePluginConfiguration(org.bimserver.models.store.WebModulePluginConfiguration) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) RenderEnginePoolFactory(org.bimserver.renderengine.RenderEnginePoolFactory) CommonsPoolingRenderEnginePoolFactory(org.bimserver.renderengine.pooled.CommonsPoolingRenderEnginePoolFactory) Date(java.util.Date) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) QueryException(org.bimserver.database.queries.om.QueryException) InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) ProtocolBuffersServer(org.bimserver.pb.server.ProtocolBuffersServer) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) ServerStarted(org.bimserver.models.log.ServerStarted) ServiceException(org.bimserver.shared.exceptions.ServiceException) StringLiteral(org.bimserver.database.query.literals.StringLiteral) RenderEnginePools(org.bimserver.renderengine.RenderEnginePools) Parameter(org.bimserver.models.store.Parameter) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Example 3 with ExtendedDataSchema

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

the class BimServer method createExtendedDataSchema.

private ExtendedDataSchema createExtendedDataSchema(DatabaseSession databaseSession, String name, String contentType) throws BimserverDatabaseException {
    ExtendedDataSchema extendedDataSchema = databaseSession.create(ExtendedDataSchema.class);
    extendedDataSchema.setName(name);
    extendedDataSchema.setContentType(contentType);
    return extendedDataSchema;
}
Also used : ExtendedDataSchema(org.bimserver.models.store.ExtendedDataSchema)

Example 4 with ExtendedDataSchema

use of org.bimserver.models.store.ExtendedDataSchema 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 5 with ExtendedDataSchema

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

the class AddUserToExtendedDataSchemaDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), uoid, OldQuery.getDefault());
    if (user == null) {
        throw new UserException("User with oid " + uoid + " not found");
    }
    ExtendedDataSchema extendedDataSchema = getDatabaseSession().get(StorePackage.eINSTANCE.getExtendedDataSchema(), edsid, OldQuery.getDefault());
    if (extendedDataSchema == null) {
        throw new UserException("ExtendedDataSchema with oid " + edsid + " not found");
    }
    user.getSchemas().add(extendedDataSchema);
    getDatabaseSession().store(user);
    getDatabaseSession().store(extendedDataSchema);
    return null;
}
Also used : User(org.bimserver.models.store.User) ExtendedDataSchema(org.bimserver.models.store.ExtendedDataSchema) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

ExtendedDataSchema (org.bimserver.models.store.ExtendedDataSchema)7 User (org.bimserver.models.store.User)4 UserException (org.bimserver.shared.exceptions.UserException)4 IOException (java.io.IOException)3 DatabaseSession (org.bimserver.database.DatabaseSession)3 ServerException (org.bimserver.shared.exceptions.ServerException)3 Date (java.util.Date)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 QueryException (org.bimserver.database.queries.om.QueryException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 ArrayList (java.util.ArrayList)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1 GenerateGeometryResult (org.bimserver.GenerateGeometryResult)1 GeometryGeneratingException (org.bimserver.GeometryGeneratingException)1 SummaryMap (org.bimserver.SummaryMap)1 Change (org.bimserver.changes.Change)1 CreateObjectChange (org.bimserver.changes.CreateObjectChange)1