Search in sources :

Example 11 with PluginConfiguration

use of org.bimserver.plugins.PluginConfiguration in project BIMserver by opensourceBIM.

the class DownloadQueryDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        SerializerPluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), serializerOid, OldQuery.getDefault());
        BimDatabaseAction<IfcModelInterface> action = new DownloadDatabaseAction(getBimServer(), session, AccessMethod.INTERNAL, roid, -1, serializerPluginConfiguration.getOid(), getAuthorization(), null);
        IfcModelInterface ifcModel = session.executeAndCommitAction(action);
        QueryEnginePluginConfiguration queryEngineObject = session.get(StorePackage.eINSTANCE.getQueryEnginePluginConfiguration(), qeid, OldQuery.getDefault());
        Revision revision = session.get(roid, OldQuery.getDefault());
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
        if (objectIDM == null) {
            objectIDM = new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), packageMetaData);
        }
        if (queryEngineObject != null) {
            QueryEnginePlugin queryEnginePlugin = getBimServer().getPluginManager().getQueryEngine(queryEngineObject.getPluginDescriptor().getPluginClassName(), true);
            if (queryEnginePlugin != null) {
                QueryEngine queryEngine = queryEnginePlugin.getQueryEngine(new PluginConfiguration(queryEngineObject.getSettings()));
                final IfcModelInterface result = new ServerIfcModel(packageMetaData, null, getDatabaseSession());
                ModelHelper modelHelper = new ModelHelper(getBimServer().getMetaDataManager(), objectIDM, result);
                modelHelper.setOidProvider(new OidProvider() {

                    private long oid = 1000000;

                    @Override
                    public long newOid(EClass eClass) {
                        return oid++;
                    }
                });
                IfcModelInterface finalResult = queryEngine.query(ifcModel, code, new Reporter() {

                    @Override
                    public void error(Throwable error) {
                    }

                    @Override
                    public void warning(String warning) {
                    }

                    @Override
                    public void info(String info) {
                    }
                }, modelHelper);
                return finalResult;
            } else {
                throw new UserException("No Query Engine found " + queryEngineObject.getPluginDescriptor().getPluginClassName());
            }
        } else {
            throw new UserException("No configured query engine found with qeid " + qeid);
        }
    } catch (BimserverDatabaseException e) {
        throw new UserException(e);
    } catch (QueryEngineException e) {
        throw new UserException(e);
    } catch (PluginException e) {
        throw new UserException(e);
    } finally {
        session.close();
    }
}
Also used : ServerIfcModel(org.bimserver.ServerIfcModel) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) QueryEngine(org.bimserver.plugins.queryengine.QueryEngine) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) OidProvider(org.bimserver.emf.OidProvider) QueryEngineException(org.bimserver.plugins.queryengine.QueryEngineException) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) QueryEnginePluginConfiguration(org.bimserver.models.store.QueryEnginePluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) QueryEnginePluginConfiguration(org.bimserver.models.store.QueryEnginePluginConfiguration) ModelHelper(org.bimserver.plugins.ModelHelper) PackageMetaData(org.bimserver.emf.PackageMetaData) Reporter(org.bimserver.plugins.Reporter) PluginException(org.bimserver.shared.exceptions.PluginException) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) Revision(org.bimserver.models.store.Revision) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration)

Example 12 with PluginConfiguration

use of org.bimserver.plugins.PluginConfiguration in project BIMserver by opensourceBIM.

the class SerializerFactory method create.

public Serializer create(Project project, String username, IfcModelInterface model, RenderEnginePlugin renderEnginePlugin, DownloadParameters downloadParameters) throws SerializerException {
    DatabaseSession session = bimDatabase.createSession();
    try {
        SerializerPluginConfiguration serializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
        if (serializerPluginConfiguration != null) {
            SerializerPlugin serializerPlugin = (SerializerPlugin) pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
            if (serializerPlugin != null) {
                ObjectType settings = serializerPluginConfiguration.getSettings();
                Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration(settings));
                if (!serializerPlugin.getSupportedSchemas().contains(model.getPackageMetaData().getSchema())) {
                    SchemaConverterFactory converterFactory = null;
                    for (Schema schema : serializerPlugin.getSupportedSchemas()) {
                        converterFactory = bimServer.getSchemaConverterManager().getSchemaConverterFactory(model.getPackageMetaData().getSchema(), schema);
                        if (converterFactory != null) {
                            break;
                        }
                    }
                    if (converterFactory == null) {
                        throw new SerializerException("No usable converter found for schema " + model.getPackageMetaData().getSchema() + " for serializer " + serializerPlugin.getClass().getName());
                    }
                    try {
                        IfcModel targetModel = new BasicIfcModel(bimServer.getMetaDataManager().getPackageMetaData(converterFactory.getTargetSchema().getEPackageName()), new HashMap<Integer, Long>(), (int) model.size());
                        SchemaConverter converter = converterFactory.create(model, targetModel);
                        converter.convert();
                        model = targetModel;
                    } catch (SchemaConverterException e) {
                        throw new SerializerException(e);
                    } catch (IfcModelInterfaceException e) {
                        throw new SerializerException(e);
                    }
                }
                if (serializer != null) {
                    try {
                        ProjectInfo projectInfo = new ProjectInfo();
                        projectInfo.setName(project.getName());
                        projectInfo.setDescription(project.getDescription());
                        GeoTag geoTag = project.getGeoTag();
                        if (geoTag != null && geoTag.getEnabled()) {
                            projectInfo.setX(geoTag.getX());
                            projectInfo.setY(geoTag.getY());
                            projectInfo.setZ(geoTag.getZ());
                            projectInfo.setDirectionAngle(geoTag.getDirectionAngle());
                        } else {
                            projectInfo.setX(4.8900);
                            projectInfo.setY(52.3700);
                        }
                        projectInfo.setAuthorName(username);
                        serializer.init(model, projectInfo, true);
                        return serializer;
                    } catch (NullPointerException e) {
                        LOGGER.error("", e);
                    }
                }
            }
        }
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } finally {
        session.close();
    }
    return null;
}
Also used : GeoTag(org.bimserver.models.store.GeoTag) DatabaseSession(org.bimserver.database.DatabaseSession) Schema(org.bimserver.emf.Schema) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) SerializerException(org.bimserver.plugins.serializers.SerializerException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) ObjectType(org.bimserver.models.store.ObjectType) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) IfcModel(org.bimserver.ifc.IfcModel) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SchemaConverterException(org.bimserver.schemaconverter.SchemaConverterException) ProjectInfo(org.bimserver.plugins.serializers.ProjectInfo) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SchemaConverter(org.bimserver.schemaconverter.SchemaConverter) MessagingSerializer(org.bimserver.plugins.serializers.MessagingSerializer) Serializer(org.bimserver.plugins.serializers.Serializer) SchemaConverterFactory(org.bimserver.schemaconverter.SchemaConverterFactory)

Example 13 with PluginConfiguration

use of org.bimserver.plugins.PluginConfiguration in project BIMserver by opensourceBIM.

the class DownloadServlet method service.

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        String acceptEncoding = request.getHeader("Accept-Encoding");
        boolean useGzip = false;
        if (acceptEncoding != null && acceptEncoding.contains("gzip")) {
            useGzip = true;
        }
        OutputStream outputStream = response.getOutputStream();
        boolean zip = request.getParameter("zip") != null && request.getParameter("zip").equals("on");
        if (useGzip && !zip) {
            response.setHeader("Content-Encoding", "gzip");
            outputStream = new GZIPOutputStream(response.getOutputStream());
        }
        String token = (String) request.getSession().getAttribute("token");
        if (token == null) {
            token = request.getParameter("token");
        }
        long topicId = -1;
        if (request.getParameter("topicId") != null) {
            topicId = Long.parseLong(request.getParameter("topicId"));
        }
        ServiceMap serviceMap = getBimServer().getServiceFactory().get(token, AccessMethod.INTERNAL);
        String action = request.getParameter("action");
        if (action != null) {
            if (action.equals("extendeddata")) {
                SExtendedData sExtendedData = serviceMap.getServiceInterface().getExtendedData(Long.parseLong(request.getParameter("edid")));
                SFile file = serviceMap.getServiceInterface().getFile(sExtendedData.getFileId());
                if (file.getMime() != null) {
                    response.setContentType(file.getMime());
                }
                if (file.getFilename() != null) {
                    response.setHeader("Content-Disposition", "inline; filename=\"" + file.getFilename() + "\"");
                }
                outputStream.write(file.getData());
                if (outputStream instanceof GZIPOutputStream) {
                    ((GZIPOutputStream) outputStream).finish();
                }
                outputStream.flush();
                return;
            } else if (action.equals("getfile")) {
                String type = request.getParameter("type");
                if (type.equals("proto")) {
                    try {
                        String protocolBuffersFile = serviceMap.getAdminInterface().getProtocolBuffersFile(request.getParameter("name"));
                        outputStream.write(protocolBuffersFile.getBytes(Charsets.UTF_8));
                        outputStream.flush();
                    } catch (ServiceException e) {
                        LOGGER.error("", e);
                    }
                } else if (type.equals("serverlog")) {
                    try {
                        OutputStreamWriter writer = new OutputStreamWriter(outputStream);
                        writer.write(serviceMap.getAdminInterface().getServerLog());
                        writer.flush();
                    } catch (ServerException e) {
                        LOGGER.error("", e);
                    } catch (UserException e) {
                        LOGGER.error("", e);
                    }
                }
            } else if (action.equals("getBcfImage")) {
                long extendedDataId = Long.parseLong(request.getParameter("extendedDataId"));
                String topicGuid = request.getParameter("topicGuid");
                String name = request.getParameter("name");
                BcfFile bcfFile = BcfCache.INSTANCE.get(extendedDataId);
                if (bcfFile == null) {
                    SExtendedData extendedData = serviceMap.getServiceInterface().getExtendedData(extendedDataId);
                    long fileId = extendedData.getFileId();
                    SFile file = serviceMap.getServiceInterface().getFile(fileId);
                    try {
                        bcfFile = BcfFile.read(new ByteArrayInputStream(file.getData()), new ReadOptions(false));
                        BcfCache.INSTANCE.put(extendedDataId, bcfFile);
                    } catch (BcfException e) {
                        e.printStackTrace();
                    }
                }
                TopicFolder topicFolder = bcfFile.getTopicFolder(topicGuid);
                if (topicFolder != null) {
                    byte[] data = topicFolder.getSnapshot(topicGuid + "/" + name);
                    if (data != null) {
                        response.setContentType("image/png");
                        IOUtils.write(data, outputStream);
                        if (outputStream instanceof GZIPOutputStream) {
                            ((GZIPOutputStream) outputStream).finish();
                        }
                        outputStream.flush();
                        return;
                    }
                }
            }
        } else {
            if (request.getParameter("topicId") != null) {
                topicId = Long.parseLong(request.getParameter("topicId"));
            }
            if (topicId == -1) {
                response.getWriter().println("No valid topicId");
                return;
            }
            SDownloadResult checkoutResult = serviceMap.getServiceInterface().getDownloadData(topicId);
            if (checkoutResult == null) {
                LOGGER.error("Invalid topicId: " + topicId);
            } else {
                DataSource dataSource = checkoutResult.getFile().getDataSource();
                PluginConfiguration pluginConfiguration = new PluginConfiguration(serviceMap.getPluginInterface().getPluginSettings(checkoutResult.getSerializerOid()));
                final ProgressTopic progressTopic = getBimServer().getNotificationsManager().getProgressTopic(topicId);
                ProgressReporter progressReporter = new ProgressReporter() {

                    private long lastMax;

                    private long lastProgress;

                    private int stage = 3;

                    private Date start = new Date();

                    private String title = "Downloading...";

                    @Override
                    public void update(long progress, long max) {
                        if (progressTopic != null) {
                            LongActionState ds = StoreFactory.eINSTANCE.createLongActionState();
                            ds.setStart(start);
                            ds.setState(progress == max ? ActionState.FINISHED : ActionState.STARTED);
                            ds.setTitle(title);
                            ds.setStage(stage);
                            ds.setProgress((int) Math.round(100.0 * progress / max));
                            progressTopic.stageProgressUpdate(ds);
                            this.lastMax = max;
                            this.lastProgress = progress;
                        }
                    }

                    @Override
                    public void setTitle(String title) {
                        if (progressTopic != null) {
                            stage++;
                            this.title = title;
                            LongActionState ds = StoreFactory.eINSTANCE.createLongActionState();
                            ds.setStart(new Date());
                            ds.setState(lastProgress == lastMax ? ActionState.FINISHED : ActionState.STARTED);
                            ds.setTitle(title);
                            ds.setStage(stage);
                            ds.setProgress((int) Math.round(100.0 * lastProgress / lastMax));
                            progressTopic.stageProgressUpdate(ds);
                        }
                    }
                };
                try {
                    if (zip) {
                        if (pluginConfiguration.getString("ZipExtension") != null) {
                            response.setHeader("Content-Disposition", "inline; filename=\"" + dataSource.getName() + "." + pluginConfiguration.getString(SerializerPlugin.ZIP_EXTENSION) + "\"");
                        } else {
                            response.setHeader("Content-Disposition", "inline; filename=\"" + dataSource.getName() + ".zip" + "\"");
                        }
                        response.setContentType("application/zip");
                        String nameInZip = dataSource.getName() + "." + pluginConfiguration.getString(SerializerPlugin.EXTENSION);
                        ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
                        zipOutputStream.putNextEntry(new ZipEntry(nameInZip));
                        processDataSource(zipOutputStream, dataSource, progressReporter);
                        try {
                            zipOutputStream.finish();
                        } catch (IOException e) {
                        // Sometimes it's already closed, that's no problem
                        }
                    } else {
                        if (request.getParameter("mime") == null) {
                            response.setContentType(pluginConfiguration.getString(SerializerPlugin.CONTENT_TYPE));
                            response.setHeader("Content-Disposition", "inline; filename=\"" + dataSource.getName() + "." + pluginConfiguration.getString(SerializerPlugin.EXTENSION) + "\"");
                        } else {
                            response.setContentType(request.getParameter("mime"));
                        }
                        processDataSource(outputStream, dataSource, progressReporter);
                    }
                } catch (SerializerException s) {
                    if (s.getCause() != null && s.getCause() instanceof IOException) {
                    } else {
                        LOGGER.error("", s);
                    }
                    LongActionState ds = StoreFactory.eINSTANCE.createLongActionState();
                    ds.setStart(new Date());
                    ds.setState(ActionState.AS_ERROR);
                    ds.setTitle("Serialization Error");
                    ds.setProgress(-1);
                    ds.setStage(3);
                    ds.getErrors().add(s.getMessage());
                    progressTopic.stageProgressUpdate(ds);
                }
            }
        }
        if (outputStream instanceof GZIPOutputStream) {
            ((GZIPOutputStream) outputStream).finish();
        }
        outputStream.flush();
    } catch (NumberFormatException e) {
        LOGGER.error("", e);
        response.getWriter().println("Some number was incorrectly formatted");
    } catch (ServiceException e) {
        LOGGER.error("", e);
        response.getWriter().println(e.getUserMessage());
    } catch (EOFException e) {
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : ServiceMap(org.bimserver.webservices.ServiceMap) LongActionState(org.bimserver.models.store.LongActionState) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipEntry(java.util.zip.ZipEntry) BcfFile(org.opensourcebim.bcf.BcfFile) GZIPOutputStream(java.util.zip.GZIPOutputStream) ReadOptions(org.opensourcebim.bcf.ReadOptions) EOFException(java.io.EOFException) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) SFile(org.bimserver.interfaces.objects.SFile) ServerException(org.bimserver.shared.exceptions.ServerException) TopicFolder(org.opensourcebim.bcf.TopicFolder) BcfException(org.opensourcebim.bcf.BcfException) SDownloadResult(org.bimserver.interfaces.objects.SDownloadResult) ProgressReporter(org.bimserver.plugins.serializers.ProgressReporter) IOException(java.io.IOException) SerializerException(org.bimserver.plugins.serializers.SerializerException) Date(java.util.Date) ServletException(javax.servlet.ServletException) ServiceException(org.bimserver.shared.exceptions.ServiceException) SerializerException(org.bimserver.plugins.serializers.SerializerException) IOException(java.io.IOException) EOFException(java.io.EOFException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) ExtendedDataSource(org.bimserver.plugins.serializers.ExtendedDataSource) DataSource(javax.activation.DataSource) ProgressTopic(org.bimserver.notifications.ProgressTopic) SExtendedData(org.bimserver.interfaces.objects.SExtendedData) ServiceException(org.bimserver.shared.exceptions.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStreamWriter(java.io.OutputStreamWriter)

Example 14 with PluginConfiguration

use of org.bimserver.plugins.PluginConfiguration in project BIMserver by opensourceBIM.

the class ServiceRunnerServlet method service.

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (request.getRequestURI().endsWith("/servicelist")) {
        processServiceList(request, response);
        return;
    }
    String token = null;
    if (request.getHeader("Authorization") != null) {
        String a = request.getHeader("Authorization");
        if (a.startsWith("Bearer")) {
            token = a.substring(7);
        }
    }
    if (token == null) {
        token = request.getHeader("Token");
    }
    LOGGER.info("Token: " + token);
    String serviceName = request.getHeader("ServiceName");
    if (serviceName == null) {
        serviceName = request.getRequestURI();
        if (serviceName.startsWith("/services/")) {
            serviceName = serviceName.substring(10);
        }
    }
    LOGGER.info("ServiceName: " + serviceName);
    long serviceOid = Long.parseLong(serviceName);
    String inputType = request.getHeader("Input-Type");
    LOGGER.info("Input-Type: " + inputType);
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        Authorization authorization = Authorization.fromToken(getBimServer().getEncryptionKey(), token);
        User user = session.get(authorization.getUoid(), OldQuery.getDefault());
        if (user == null) {
            LOGGER.error("Service \"" + serviceName + "\" not found for this user");
            throw new UserException("No user found with uoid " + authorization.getUoid());
        }
        if (user.getState() == ObjectState.DELETED) {
            LOGGER.error("User has been deleted");
            throw new UserException("User has been deleted");
        }
        InternalServicePluginConfiguration foundService = null;
        UserSettings userSettings = user.getUserSettings();
        for (InternalServicePluginConfiguration internalServicePluginConfiguration : userSettings.getServices()) {
            if (internalServicePluginConfiguration.getOid() == serviceOid) {
                foundService = internalServicePluginConfiguration;
                break;
            }
        }
        if (foundService == null) {
            LOGGER.info("Service \"" + serviceName + "\" not found for this user");
            throw new ServletException("Service \"" + serviceName + "\" not found for this user");
        }
        PluginDescriptor pluginDescriptor = foundService.getPluginDescriptor();
        ServicePlugin servicePlugin = getBimServer().getPluginManager().getServicePlugin(pluginDescriptor.getPluginClassName(), true);
        if (servicePlugin instanceof BimBotsServiceInterface) {
            LOGGER.info("Found service " + servicePlugin);
            BimBotsServiceInterface bimBotsServiceInterface = (BimBotsServiceInterface) servicePlugin;
            try {
                if (getBimServer().getServerSettingsCache().getServerSettings().isStoreServiceRuns()) {
                    LOGGER.info("Storing intermediate results");
                    // When we store service runs, we can just use the streaming deserializer to stream directly to the database, after that we'll trigger the actual service
                    // Create or find project and link user and service to project
                    // Checkin stream into project
                    // Trigger service
                    ServiceInterface serviceInterface = getBimServer().getServiceFactory().get(authorization, AccessMethod.INTERNAL).get(ServiceInterface.class);
                    SProject project = serviceInterface.addProject("tmp-" + new Random().nextInt(), "ifc2x3tc1");
                    SDeserializerPluginConfiguration deserializer = serviceInterface.getSuggestedDeserializerForExtension("ifc", project.getOid());
                    if (deserializer == null) {
                        throw new BimBotsException("No deserializer found");
                    }
                    serviceInterface.checkin(project.getOid(), "Auto checkin", deserializer.getOid(), -1L, "s", new DataHandler(new InputStreamDataSource(request.getInputStream())), false, true);
                    project = serviceInterface.getProjectByPoid(project.getOid());
                    PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema());
                    IfcModelInterface model = new BasicIfcModel(packageMetaData, null);
                    try {
                        Revision revision = session.get(project.getLastRevisionId(), OldQuery.getDefault());
                        session.getMap(model, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid(), null, Deep.NO));
                    } catch (BimserverDatabaseException e) {
                        e.printStackTrace();
                    }
                    BimServerBimBotsInput input = new BimServerBimBotsInput(getBimServer(), authorization.getUoid(), null, null, model);
                    BimBotsOutput output = bimBotsServiceInterface.runBimBot(input, getBimServer().getSConverter().convertToSObject(foundService.getSettings()));
                    SExtendedData extendedData = new SExtendedData();
                    SFile file = new SFile();
                    file.setData(output.getData());
                    file.setFilename(output.getContentDisposition());
                    file.setMime(output.getContentType());
                    file.setSize(output.getData().length);
                    Long fileId = serviceInterface.uploadFile(file);
                    extendedData.setFileId(fileId);
                    extendedData.setTitle(output.getTitle());
                    SExtendedDataSchema extendedDataSchema = null;
                    try {
                        extendedDataSchema = serviceInterface.getExtendedDataSchemaByName(output.getSchemaName());
                    } catch (UserException e) {
                        extendedDataSchema = new SExtendedDataSchema();
                        extendedDataSchema.setContentType(output.getContentType());
                        extendedDataSchema.setName(output.getSchemaName());
                        serviceInterface.addExtendedDataSchema(extendedDataSchema);
                    }
                    extendedData.setSchemaId(extendedDataSchema.getOid());
                    serviceInterface.addExtendedDataToRevision(project.getLastRevisionId(), extendedData);
                    response.setHeader("Output-Type", output.getSchemaName());
                    response.setHeader("Data-Title", output.getTitle());
                    response.setHeader("Data-Identifier", "" + project.getOid());
                    response.setHeader("Content-Type", output.getContentType());
                    response.setHeader("Content-Disposition", output.getContentDisposition());
                    response.getOutputStream().write(output.getData());
                } else {
                    // When we don't store the service runs, there is no other way than to just use the old deserializer and run the service from the EMF model
                    LOGGER.info("NOT Storing intermediate results");
                    DeserializerPlugin deserializerPlugin = getBimServer().getPluginManager().getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
                    if (deserializerPlugin == null) {
                        throw new BimBotsException("No deserializer plugin found");
                    }
                    byte[] data = IOUtils.toByteArray(request.getInputStream());
                    SchemaName schema = SchemaName.valueOf(inputType);
                    Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
                    PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData("ifc2x3tc1");
                    deserializer.init(packageMetaData);
                    IfcModelInterface model = deserializer.read(new ByteArrayInputStream(data), schema.name(), data.length, null);
                    BimServerBimBotsInput input = new BimServerBimBotsInput(getBimServer(), authorization.getUoid(), schema, data, model);
                    BimBotsOutput output = bimBotsServiceInterface.runBimBot(input, getBimServer().getSConverter().convertToSObject(foundService.getSettings()));
                    response.setHeader("Output-Type", output.getSchemaName());
                    response.setHeader("Data-Title", output.getTitle());
                    response.setHeader("Content-Type", output.getContentType());
                    response.setHeader("Content-Disposition", output.getContentDisposition());
                    response.getOutputStream().write(output.getData());
                }
            } catch (BimBotsException e) {
                LOGGER.error("", e);
            } catch (DeserializeException e) {
                LOGGER.error("", e);
            } catch (PluginException e) {
                LOGGER.error("", e);
            } catch (ServerException e) {
                LOGGER.error("", e);
            }
        } else {
            throw new ServletException("Service \"" + serviceName + "\" does not implement the BimBotsServiceInterface");
        }
    } catch (AuthenticationException e) {
        LOGGER.error("", e);
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } catch (UserException e) {
        LOGGER.error("", e);
    }
}
Also used : ServicePlugin(org.bimserver.plugins.services.ServicePlugin) User(org.bimserver.models.store.User) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) DatabaseSession(org.bimserver.database.DatabaseSession) AuthenticationException(org.bimserver.webservices.authorization.AuthenticationException) IfcModelInterface(org.bimserver.emf.IfcModelInterface) DataHandler(javax.activation.DataHandler) BimBotsServiceInterface(org.bimserver.bimbots.BimBotsServiceInterface) SProject(org.bimserver.interfaces.objects.SProject) SExtendedDataSchema(org.bimserver.interfaces.objects.SExtendedDataSchema) Authorization(org.bimserver.webservices.authorization.Authorization) ServletException(javax.servlet.ServletException) InputStreamDataSource(org.bimserver.utils.InputStreamDataSource) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Random(java.util.Random) BimBotsServiceInterface(org.bimserver.bimbots.BimBotsServiceInterface) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) SFile(org.bimserver.interfaces.objects.SFile) ServerException(org.bimserver.shared.exceptions.ServerException) UserSettings(org.bimserver.models.store.UserSettings) PackageMetaData(org.bimserver.emf.PackageMetaData) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) BimBotsException(org.bimserver.bimbots.BimBotsException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) BimServerBimBotsInput(org.bimserver.bimbots.BimServerBimBotsInput) OldQuery(org.bimserver.database.OldQuery) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) Revision(org.bimserver.models.store.Revision) SExtendedData(org.bimserver.interfaces.objects.SExtendedData) ByteArrayInputStream(java.io.ByteArrayInputStream) Deserializer(org.bimserver.plugins.deserializers.Deserializer) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) BimBotsOutput(org.bimserver.bimbots.BimBotsOutput) SchemaName(org.bimserver.plugins.SchemaName)

Example 15 with PluginConfiguration

use of org.bimserver.plugins.PluginConfiguration in project BIMserver by opensourceBIM.

the class AdminServiceImpl method regenerateGeometry.

@Override
public void regenerateGeometry(Long croid) throws ServerException, UserException {
    LOGGER.info("Regenerating geometry for concrete revision" + croid);
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        // Normally we wouldn't be allowed to change existing data
        session.setOverwriteEnabled(true);
        ConcreteRevision concreteRevision = session.get(StorePackage.eINSTANCE.getConcreteRevision(), croid, OldQuery.getDefault());
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        IfcModelInterface model = new BasicIfcModel(packageMetaData, null);
        session.getMap(model, new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), -1));
        User user = session.get(getAuthorization().getUoid(), OldQuery.getDefault());
        UserSettings userSettings = user.getUserSettings();
        RenderEnginePluginConfiguration defaultRenderEngine = userSettings.getDefaultRenderEngine();
        if (defaultRenderEngine == null) {
            throw new BimBotsException("No default render engine has been selected for this user");
        }
        RenderEnginePool pool = getBimServer().getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), new PluginConfiguration(defaultRenderEngine.getSettings()));
        new GeometryGenerator(getBimServer()).generateGeometry(pool, getBimServer().getPluginManager(), session, model, concreteRevision.getProject().getId(), concreteRevision.getId(), true, null);
        session.commit();
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : User(org.bimserver.models.store.User) RenderEnginePool(org.bimserver.renderengine.RenderEnginePool) DatabaseSession(org.bimserver.database.DatabaseSession) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) UserSettings(org.bimserver.models.store.UserSettings) GeometryGenerator(org.bimserver.GeometryGenerator) BimBotsException(org.bimserver.bimbots.BimBotsException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) UserException(org.bimserver.shared.exceptions.UserException) BimBotsException(org.bimserver.bimbots.BimBotsException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) OldQuery(org.bimserver.database.OldQuery) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration)

Aggregations

PluginConfiguration (org.bimserver.plugins.PluginConfiguration)18 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)9 IfcModelInterface (org.bimserver.emf.IfcModelInterface)7 UserException (org.bimserver.shared.exceptions.UserException)7 IOException (java.io.IOException)6 DatabaseSession (org.bimserver.database.DatabaseSession)6 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)6 PackageMetaData (org.bimserver.emf.PackageMetaData)5 Revision (org.bimserver.models.store.Revision)5 User (org.bimserver.models.store.User)5 UserSettings (org.bimserver.models.store.UserSettings)5 PluginException (org.bimserver.shared.exceptions.PluginException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Deserializer (org.bimserver.plugins.deserializers.Deserializer)4 DeserializerPlugin (org.bimserver.plugins.deserializers.DeserializerPlugin)4 FileNotFoundException (java.io.FileNotFoundException)3 OldQuery (org.bimserver.database.OldQuery)3 BasicIfcModel (org.bimserver.ifc.BasicIfcModel)3 PluginManager (org.bimserver.plugins.PluginManager)3 ServerException (org.bimserver.shared.exceptions.ServerException)3