Ejemplo n.º 1
0
 public Deserializer createDeserializer(long deserializerOid)
     throws PluginException, UserException {
   DatabaseSession session = bimDatabase.createSession();
   try {
     DeserializerPluginConfiguration deserializerPluginConfiguration =
         session.get(
             StorePackage.eINSTANCE.getDeserializerPluginConfiguration(),
             deserializerOid,
             Query.getDefault());
     if (deserializerPluginConfiguration != null) {
       DeserializerPlugin deserializerPlugin =
           (DeserializerPlugin)
               pluginManager.getPlugin(
                   deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(),
                   true);
       if (deserializerPlugin != null) {
         ObjectType settings = deserializerPluginConfiguration.getSettings();
         return deserializerPlugin.createDeserializer(new PluginConfiguration(settings));
       } else {
         throw new UserException("No (enabled) deserializer found with oid " + deserializerOid);
       }
     }
   } catch (BimserverDatabaseException e) {
     LOGGER.error("", e);
   } finally {
     session.close();
   }
   return null;
 }
Ejemplo n.º 2
0
 private void updatePlugins(DatabaseSession session) throws BimserverDatabaseException {
   Collection<Plugin> allPlugins = pluginManager.getAllPlugins(false);
   for (Plugin plugin : allPlugins) {
     Condition pluginCondition =
         new AttributeCondition(
             StorePackage.eINSTANCE.getPluginDescriptor_PluginClassName(),
             new StringLiteral(plugin.getClass().getName()));
     Map<Long, PluginDescriptor> results =
         session.query(pluginCondition, PluginDescriptor.class, Query.getDefault());
     if (results.size() == 0) {
       PluginContext pluginContext = pluginManager.getPluginContext(plugin);
       PluginDescriptor pluginDescriptor = session.create(PluginDescriptor.class);
       pluginDescriptor.setPluginClassName(plugin.getClass().getName());
       pluginDescriptor.setSimpleName(plugin.getClass().getSimpleName());
       pluginDescriptor.setDescription(plugin.getDescription() + " " + plugin.getVersion());
       pluginDescriptor.setLocation(pluginContext.getLocation().toString());
       pluginDescriptor.setPluginInterfaceClassName(getPluginInterfaceClass(plugin).getName());
       pluginDescriptor.setEnabled(true); // New plugins are enabled by default
     } else if (results.size() == 1) {
       PluginContext pluginContext = pluginManager.getPluginContext(plugin);
       PluginDescriptor pluginDescriptor = results.values().iterator().next();
       pluginDescriptor.setPluginClassName(plugin.getClass().getName());
       pluginDescriptor.setSimpleName(plugin.getClass().getSimpleName());
       pluginDescriptor.setDescription(plugin.getDescription() + " " + plugin.getVersion());
       pluginDescriptor.setLocation(pluginContext.getLocation().toString());
       pluginDescriptor.setPluginInterfaceClassName(getPluginInterfaceClass(plugin).getName());
       session.store(pluginDescriptor);
       pluginManager.getPluginContext(plugin).setEnabled(pluginDescriptor.getEnabled(), false);
     } else {
       LOGGER.error(
           "Multiple plugin descriptor objects found with the same name: "
               + plugin.getClass().getName());
     }
   }
 }
Ejemplo n.º 3
0
 public void update() {
   try {
     serverInfo.setVersion(
         bimServer
             .getSConverter()
             .convertFromSObject(bimServer.getVersionChecker().getLocalVersion(), null));
   } catch (BimserverDatabaseException e) {
     LOGGER.error("", e);
   }
   if (bimServer.getDatabase().getMigrator().migrationRequired()) {
     setServerState(ServerState.MIGRATION_REQUIRED);
     if (bimServer.getConfig().isAutoMigrate()) {
       try {
         bimServer.getDatabase().getMigrator().migrate();
         setServerState(ServerState.RUNNING);
       } catch (MigrationException | InconsistentModelsException e) {
         LOGGER.error("", e);
       }
     }
   } else if (bimServer.getDatabase().getMigrator().migrationImpossible()) {
     setServerState(ServerState.MIGRATION_IMPOSSIBLE);
   } else {
     DatabaseSession session = bimServer.getDatabase().createSession();
     try {
       boolean adminFound = false;
       ServerSettings settings = bimServer.getServerSettingsCache().getServerSettings();
       IfcModelInterface users =
           session.getAllOfType(StorePackage.eINSTANCE.getUser(), Query.getDefault());
       for (IdEObject idEObject : users.getValues()) {
         if (idEObject instanceof User) {
           User user = (User) idEObject;
           if (user.getUserType() == UserType.ADMIN) {
             adminFound = true;
             break;
           }
         }
       }
       if (settings.getSiteAddress().isEmpty()
           || settings.getSmtpServer().isEmpty()
           || !adminFound) {
         setServerState(ServerState.NOT_SETUP);
       } else {
         setServerState(ServerState.RUNNING);
       }
     } catch (BimserverDatabaseException e) {
       LOGGER.error("", e);
     } finally {
       session.close();
     }
   }
 }
Ejemplo n.º 4
0
 private ObjectType convertSettings(DatabaseSession session, Plugin plugin)
     throws BimserverDatabaseException {
   ObjectType settings = session.create(ObjectType.class);
   ObjectDefinition settingsDefinition = plugin.getSettingsDefinition();
   if (plugin.getSettingsDefinition() != null) {
     for (ParameterDefinition parameterDefinition : settingsDefinition.getParameters()) {
       Parameter parameter = session.create(Parameter.class);
       parameter.setName(parameterDefinition.getName());
       if (parameterDefinition.getDefaultValue() != null) {
         Type value = cloneAndAdd(session, parameterDefinition.getDefaultValue());
         parameter.setValue(value);
       }
       settings.getParameters().add(parameter);
     }
   }
   return settings;
 }
Ejemplo n.º 5
0
 /*
  * Serializers, deserializers, renderengines etc... all have counterparts as
  * objects in the database for configuration purposes, this methods syncs
  * both versions
  */
 private void createDatabaseObjects(DatabaseSession session)
     throws BimserverLockConflictException, BimserverDatabaseException, PluginException,
         BimserverConcurrentModificationDatabaseException {
   IfcModelInterface allOfType =
       session.getAllOfType(StorePackage.eINSTANCE.getUser(), Query.getDefault());
   for (User user : allOfType.getAll(User.class)) {
     updateUserSettings(session, user);
   }
 }
Ejemplo n.º 6
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 @Override
 public void execute(
     IfcModelInterface model,
     Project project,
     ConcreteRevision concreteRevision,
     DatabaseSession databaseSession,
     Map<Long, IdEObject> created,
     Map<Long, IdEObject> deleted)
     throws UserException, BimserverLockConflictException, BimserverDatabaseException {
   PackageMetaData packageMetaData =
       databaseSession.getMetaDataManager().getPackageMetaData(project.getSchema());
   IdEObject idEObject =
       databaseSession.get(
           model, oid, new Query(packageMetaData, project.getId(), concreteRevision.getId(), -1));
   EClass eClass = databaseSession.getEClassForOid(oid);
   if (idEObject == null) {
     idEObject = created.get(oid);
   }
   if (idEObject == null) {
     throw new UserException(
         "No object of type + "
             + eClass.getName()
             + " with oid "
             + oid
             + " found in project with pid "
             + project.getId());
   }
   EAttribute eAttribute = packageMetaData.getEAttribute(eClass.getName(), attributeName);
   if (eAttribute == null) {
     throw new UserException(
         "No attribute with the name " + attributeName + " found in class " + eClass.getName());
   }
   if (!eAttribute.isMany()) {
     throw new UserException("Attribute is not of type 'many'");
   }
   List list = (List) idEObject.eGet(eAttribute);
   list.add(value);
   databaseSession.store(idEObject, project.getId(), concreteRevision.getId());
 }
 public String getFileNameWithoutExtension() {
   switch (downloadType) {
     case DOWNLOAD_REVISION:
       return getRoidsString();
     case DOWNLOAD_BY_GUIDS:
       return getRoidsString() + "-" + getGuidsString();
     case DOWNLOAD_BY_NAMES:
       return getRoidsString() + "-" + getNamesString();
     case DOWNLOAD_BY_OIDS:
       return getRoidsString() + "-" + getOidsString();
     case DOWNLOAD_OF_TYPE:
       return getRoidsString() + "-" + classNames;
     case DOWNLOAD_PROJECTS:
       DatabaseSession session = bimServer.getDatabase().createSession();
       StringBuilder fileName = new StringBuilder();
       for (long roid : roids) {
         Revision revision;
         try {
           revision =
               session.get(
                   session.getEClassForName("store", "Revision"), roid, Query.getDefault());
           for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) {
             fileName.append(concreteRevision.getProject().getName() + "-");
           }
         } catch (BimserverDatabaseException e) {
           e.printStackTrace();
         }
       }
       fileName.delete(fileName.length() - 1, fileName.length());
       return fileName.toString();
     case DOWNLOAD_COMPARE:
       return "compare";
     case DOWNLOAD_JSON_QUERY:
       return getRoidsString();
     case DOWNLOAD_QUERY:
       return "query";
   }
   return "unknown";
 }
Ejemplo n.º 8
0
 private Type cloneAndAdd(DatabaseSession session, Type input) throws BimserverDatabaseException {
   if (input instanceof BooleanType) {
     BooleanType booleanType = session.create(BooleanType.class);
     booleanType.setValue(((BooleanType) input).isValue());
     session.store(booleanType);
     return booleanType;
   } else if (input instanceof StringType) {
     StringType stringType = session.create(StringType.class);
     stringType.setValue(((StringType) input).getValue());
     session.store(stringType);
     return stringType;
   } else if (input instanceof DoubleType) {
     DoubleType doubleType = session.create(DoubleType.class);
     doubleType.setValue(((DoubleType) input).getValue());
     session.store(doubleType);
     return doubleType;
   } else if (input instanceof LongType) {
     LongType longType = session.create(LongType.class);
     longType.setValue(((LongType) input).getValue());
     session.store(longType);
     return longType;
   }
   return null;
 }
Ejemplo n.º 9
0
  @Override
  public void run() {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    running = true;
    while (running) {
      try {
        String line = reader.readLine();
        if (line == null) {
          try {
            Thread.sleep(50);
          } catch (InterruptedException e) {
            LOGGER.error("", e);
          }
          continue;
        }
        if (line.equalsIgnoreCase("exit")) {
          bimServer.stop();
          return;
        } else if (line.startsWith("dumpmodel")) {
          try {
            long roid = Long.parseLong(line.substring(9).trim());
            DatabaseSession databaseSession = bimServer.getDatabase().createSession();
            try {
              DownloadDatabaseAction downloadDatabaseAction =
                  new DownloadDatabaseAction(
                      bimServer,
                      databaseSession,
                      AccessMethod.INTERNAL,
                      roid,
                      -1,
                      -1,
                      new SystemAuthorization(1, TimeUnit.HOURS),
                      null,
                      new Reporter() {
                        @Override
                        public void error(String error) {}

                        @Override
                        public void info(String info) {}

                        @Override
                        public void warning(String warning) {}
                      });
              IfcModelInterface model = downloadDatabaseAction.execute();
              LOGGER.info("Model size: " + model.size());

              List<IfcWall> walls = model.getAll(IfcWall.class);
              List<IfcProject> projects = model.getAll(IfcProject.class);
              List<IfcSlab> slabs = model.getAll(IfcSlab.class);
              List<IfcWindow> windows = model.getAll(IfcWindow.class);

              LOGGER.info("Walls: " + walls.size());
              LOGGER.info("Windows: " + windows.size());
              LOGGER.info("Projects: " + projects.size());
              LOGGER.info("Slabs: " + slabs.size());
            } catch (UserException e) {
              LOGGER.error("", e);
            } catch (BimserverLockConflictException e) {
              LOGGER.error("", e);
            } catch (BimserverDatabaseException e) {
              LOGGER.error("", e);
            } finally {
              databaseSession.close();
            }
          } catch (Exception e) {
            LOGGER.error("", e);
          }
        } else if (line.equalsIgnoreCase("dump")) {
          LOGGER.info("Dumping all thread's track traces...");
          LOGGER.info("");
          Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
          for (Thread t : allStackTraces.keySet()) {
            LOGGER.info(t.getName());
            StackTraceElement[] stackTraceElements = allStackTraces.get(t);
            for (StackTraceElement stackTraceElement : stackTraceElements) {
              LOGGER.info(
                  "\t"
                      + stackTraceElement.getClassName()
                      + ":"
                      + stackTraceElement.getLineNumber()
                      + "."
                      + stackTraceElement.getMethodName());
            }
            LOGGER.info("");
          }
          LOGGER.info("Done printing stack traces");
          LOGGER.info("");
          try {
            Thread.sleep(10000);
          } catch (InterruptedException e) {
            LOGGER.error("", e);
          }
        } else if (line.equals("migrate")) {
          try {
            bimServer.getDatabase().getMigrator().migrate();
            bimServer.getServerInfoManager().update();
          } catch (MigrationException e) {
            LOGGER.error("", e);
          } catch (InconsistentModelsException e) {
            LOGGER.error("", e);
          }
        } else if (line.equals("clearendpoints")) {
          bimServer.getEndPointManager().clear();
        } else if (line.startsWith("showall")) {
          KeyValueStore keyValueStore = ((Database) bimServer.getDatabase()).getKeyValueStore();
          Set<String> allTableNames = keyValueStore.getAllTableNames();
          long total = 0;
          for (String tableName : allTableNames) {
            long size = keyValueStore.count(tableName);
            total += size;
            if (size != 0) {
              LOGGER.info(tableName + " " + size);
            }
          }
          LOGGER.info("total: " + total);
        } else {
          LOGGER.info("Unknown command");
        }
      } catch (IOException e) {
        LOGGER.error("", e);
      }
    }
  }
Ejemplo n.º 10
0
  private void initDatabaseDependantItems() throws BimserverDatabaseException {
    serverSettingsCache.init();
    notificationsManager.init();

    getSerializerFactory().init(pluginManager, bimDatabase, this);
    getDeserializerFactory().init(pluginManager, bimDatabase);
    try {
      DatabaseSession session = bimDatabase.createSession();
      try {
        updatePlugins(session);
        session.commit();
      } catch (ServiceException e) {
        LOGGER.error("", e);
      } finally {
        session.close();
      }

      session = bimDatabase.createSession();
      createDatabaseObjects(session);

      ServerSettings serverSettings = serverSettingsCache.getServerSettings();

      for (WebModulePlugin webModulePlugin : pluginManager.getAllWebPlugins(true)) {
        WebModulePluginConfiguration webPluginConfiguration =
            find(serverSettings.getWebModules(), webModulePlugin.getClass().getName());
        if (webPluginConfiguration == null) {
          webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
          serverSettings.getWebModules().add(webPluginConfiguration);
          genericPluginConversion(
              session,
              webModulePlugin,
              webPluginConfiguration,
              getPluginDescriptor(session, webModulePlugin.getClass().getName()));
        } else {
          if (webPluginConfiguration == serverSettings.getWebModule()) {
            setDefaultWebModule(webModulePlugin);
          }
        }
      }

      // Set the default
      if (serverSettings.getWebModule() == null) {
        WebModulePluginConfiguration bimviewsWebModule =
            findWebModule(serverSettings, "org.bimserver.bimviews.BimViewsWebModulePlugin");
        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, Query.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>();
      DatabaseSession ses = bimDatabase.createSession();
      try {
        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();
            }
          }
          webModules.put(
              contextPath,
              (WebModulePlugin)
                  pluginManager.getPlugin(
                      webModulePluginConfiguration.getPluginDescriptor().getPluginClassName(),
                      true));
        }
        //				if (serverSettingsCache.getServerSettings().getWebModule() != null) {
        //					defaultWebModule = (WebModulePlugin)
        // pluginManager.getPlugin(serverSettingsCache.getServerSettings().getWebModule().getPluginDescriptor().getPluginClassName(), true);
        //				}
      } finally {
        ses.close();
      }

      Integer protocolBuffersPort =
          getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
      if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
        try {
          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);
    } catch (BimserverLockConflictException e) {
      throw new BimserverDatabaseException(e);
    } catch (PluginException e) {
      throw new BimserverDatabaseException(e);
    }
  }
Ejemplo n.º 11
0
 public void updateUserSettings(DatabaseSession session, User user)
     throws BimserverLockConflictException, BimserverDatabaseException {
   UserSettings userSettings = user.getUserSettings();
   if (userSettings == null) {
     userSettings = session.create(UserSettings.class);
     user.setUserSettings(userSettings);
     session.store(user);
   }
   for (ObjectIDMPlugin objectIDMPlugin : pluginManager.getAllObjectIDMPlugins(true)) {
     ObjectIDMPluginConfiguration objectIdmPluginConfiguration =
         find(userSettings.getObjectIDMs(), objectIDMPlugin.getClass().getName());
     if (objectIdmPluginConfiguration == null) {
       objectIdmPluginConfiguration = session.create(ObjectIDMPluginConfiguration.class);
       userSettings.getObjectIDMs().add(objectIdmPluginConfiguration);
       genericPluginConversion(
           session,
           objectIDMPlugin,
           objectIdmPluginConfiguration,
           getPluginDescriptor(session, objectIDMPlugin.getClass().getName()));
     }
     if (userSettings.getDefaultObjectIDM() == null
         && objectIDMPlugin.getClass() == SchemaFieldObjectIDMPlugin.class) {
       userSettings.setDefaultObjectIDM(objectIdmPluginConfiguration);
     }
   }
   if (userSettings.getDefaultObjectIDM() == null && !userSettings.getObjectIDMs().isEmpty()) {
     userSettings.setDefaultObjectIDM(userSettings.getObjectIDMs().get(0));
   }
   for (RenderEnginePlugin ifcEnginePlugin : pluginManager.getAllRenderEnginePlugins(true)) {
     RenderEnginePluginConfiguration ifcEnginePluginConfiguration =
         find(userSettings.getRenderEngines(), ifcEnginePlugin.getClass().getName());
     if (ifcEnginePluginConfiguration == null) {
       ifcEnginePluginConfiguration = session.create(RenderEnginePluginConfiguration.class);
       userSettings.getRenderEngines().add(ifcEnginePluginConfiguration);
       genericPluginConversion(
           session,
           ifcEnginePlugin,
           ifcEnginePluginConfiguration,
           getPluginDescriptor(session, ifcEnginePlugin.getClass().getName()));
     }
     if (userSettings.getDefaultRenderEngine() != null
         && userSettings
             .getDefaultRenderEngine()
             .getPluginDescriptor()
             .getPluginClassName()
             .equals("org.bimserver.ifcengine.TNOJvmRenderEnginePlugin")
         && ifcEnginePlugin
             .getClass()
             .getName()
             .equals("org.ifcopenshell.IfcOpenShellEnginePlugin")) {
       userSettings.setDefaultRenderEngine(ifcEnginePluginConfiguration);
     }
     if (userSettings.getDefaultRenderEngine() == null
         && ifcEnginePlugin
             .getClass()
             .getName()
             .equals("org.ifcopenshell.IfcOpenShellEnginePlugin")) {
       userSettings.setDefaultRenderEngine(ifcEnginePluginConfiguration);
     }
   }
   if (userSettings.getDefaultRenderEngine() == null
       && !userSettings.getRenderEngines().isEmpty()) {
     userSettings.setDefaultRenderEngine(userSettings.getRenderEngines().get(0));
   }
   Iterator<RenderEnginePluginConfiguration> iterator = userSettings.getRenderEngines().iterator();
   while (iterator.hasNext()) {
     RenderEnginePluginConfiguration next = iterator.next();
     PluginDescriptor pluginDescriptor = next.getPluginDescriptor();
     if (pluginDescriptor
         .getPluginClassName()
         .equals("org.bimserver.ifcengine.TNOJvmRenderEnginePlugin")) {
       iterator.remove();
     }
   }
   for (QueryEnginePlugin queryEnginePlugin : pluginManager.getAllQueryEnginePlugins(true)) {
     QueryEnginePluginConfiguration queryEnginePluginConfiguration =
         find(userSettings.getQueryengines(), queryEnginePlugin.getClass().getName());
     if (queryEnginePluginConfiguration == null) {
       queryEnginePluginConfiguration = session.create(QueryEnginePluginConfiguration.class);
       userSettings.getQueryengines().add(queryEnginePluginConfiguration);
       genericPluginConversion(
           session,
           queryEnginePlugin,
           queryEnginePluginConfiguration,
           getPluginDescriptor(session, queryEnginePlugin.getClass().getName()));
     }
     if (userSettings.getDefaultQueryEngine() == null
         && queryEnginePlugin
             .getClass()
             .getName()
             .equals("nl.wietmazairac.bimql.BimQLQueryEnginePlugin")) {
       userSettings.setDefaultQueryEngine(queryEnginePluginConfiguration);
     }
   }
   if (userSettings.getDefaultQueryEngine() == null && !userSettings.getQueryengines().isEmpty()) {
     userSettings.setDefaultQueryEngine(userSettings.getQueryengines().get(0));
   }
   for (ModelMergerPlugin modelMergerPlugin : pluginManager.getAllModelMergerPlugins(true)) {
     ModelMergerPluginConfiguration modelMergerPluginConfiguration =
         find(userSettings.getModelmergers(), modelMergerPlugin.getClass().getName());
     if (modelMergerPluginConfiguration == null) {
       modelMergerPluginConfiguration = session.create(ModelMergerPluginConfiguration.class);
       userSettings.getModelmergers().add(modelMergerPluginConfiguration);
       genericPluginConversion(
           session,
           modelMergerPlugin,
           modelMergerPluginConfiguration,
           getPluginDescriptor(session, modelMergerPlugin.getClass().getName()));
     }
     if (userSettings.getDefaultModelMerger() == null
         && modelMergerPlugin
             .getClass()
             .getName()
             .equals("org.bimserver.merging.BasicModelMergerPlugin")) {
       userSettings.setDefaultModelMerger(modelMergerPluginConfiguration);
     }
   }
   if (userSettings.getDefaultModelMerger() == null && !userSettings.getModelmergers().isEmpty()) {
     userSettings.setDefaultModelMerger(userSettings.getModelmergers().get(0));
   }
   for (ModelComparePlugin modelComparePlugin : pluginManager.getAllModelComparePlugins(true)) {
     ModelComparePluginConfiguration modelComparePluginConfiguration =
         find(userSettings.getModelcompares(), modelComparePlugin.getClass().getName());
     if (modelComparePluginConfiguration == null) {
       modelComparePluginConfiguration = session.create(ModelComparePluginConfiguration.class);
       userSettings.getModelcompares().add(modelComparePluginConfiguration);
       genericPluginConversion(
           session,
           modelComparePlugin,
           modelComparePluginConfiguration,
           getPluginDescriptor(session, modelComparePlugin.getClass().getName()));
     }
     if (userSettings.getDefaultModelCompare() == null
         && modelComparePlugin
             .getClass()
             .getName()
             .equals("org.bimserver.ifc.compare.GuidBasedModelComparePlugin")) {
       userSettings.setDefaultModelCompare(modelComparePluginConfiguration);
     }
   }
   if (userSettings.getDefaultModelCompare() == null
       && !userSettings.getModelcompares().isEmpty()) {
     userSettings.setDefaultModelCompare(userSettings.getModelcompares().get(0));
   }
   for (SerializerPlugin serializerPlugin : pluginManager.getAllSerializerPlugins(true)) {
     SerializerPluginConfiguration serializerPluginConfiguration =
         find(userSettings.getSerializers(), serializerPlugin.getClass().getName());
     if (serializerPluginConfiguration == null) {
       serializerPluginConfiguration = session.create(SerializerPluginConfiguration.class);
       userSettings.getSerializers().add(serializerPluginConfiguration);
       genericPluginConversion(
           session,
           serializerPlugin,
           serializerPluginConfiguration,
           getPluginDescriptor(session, serializerPlugin.getClass().getName()));
       serializerPluginConfiguration.setObjectIDM(userSettings.getDefaultObjectIDM());
       serializerPluginConfiguration.setRenderEngine(userSettings.getDefaultRenderEngine());
     }
     if (userSettings.getDefaultSerializer() == null
         && serializerPlugin
             .getClass()
             .getName()
             .equals("org.bimserver.ifc.step.serializer.Ifc2x3tc1StepSerializerPlugin")) {
       userSettings.setDefaultSerializer(serializerPluginConfiguration);
     }
   }
   for (MessagingSerializerPlugin serializerPlugin :
       pluginManager.getAllMessagingSerializerPlugins(true)) {
     MessagingSerializerPluginConfiguration serializerPluginConfiguration =
         find(userSettings.getMessagingSerializerPlugins(), serializerPlugin.getClass().getName());
     if (serializerPluginConfiguration == null) {
       serializerPluginConfiguration =
           session.create(MessagingSerializerPluginConfiguration.class);
       userSettings.getMessagingSerializerPlugins().add(serializerPluginConfiguration);
       genericPluginConversion(
           session,
           serializerPlugin,
           serializerPluginConfiguration,
           getPluginDescriptor(session, serializerPlugin.getClass().getName()));
     }
   }
   if (userSettings.getDefaultSerializer() == null && !userSettings.getSerializers().isEmpty()) {
     userSettings.setDefaultSerializer(userSettings.getSerializers().get(0));
   }
   for (ServicePlugin servicePlugin : pluginManager.getAllServicePlugins(true)) {
     InternalServicePluginConfiguration internalServicePluginConfiguration =
         find(userSettings.getServices(), servicePlugin.getClass().getName());
     if (internalServicePluginConfiguration == null) {
       internalServicePluginConfiguration =
           session.create(InternalServicePluginConfiguration.class);
       userSettings.getServices().add(internalServicePluginConfiguration);
       genericPluginConversion(
           session,
           servicePlugin,
           internalServicePluginConfiguration,
           getPluginDescriptor(session, servicePlugin.getClass().getName()));
     }
     ObjectType settings = internalServicePluginConfiguration.getSettings();
     SInternalServicePluginConfiguration sInternalService =
         getSConverter().convertToSObject(internalServicePluginConfiguration);
     servicePlugin.register(
         user.getOid(), sInternalService, new org.bimserver.plugins.PluginConfiguration(settings));
   }
   for (DeserializerPlugin deserializerPlugin : pluginManager.getAllDeserializerPlugins(true)) {
     DeserializerPluginConfiguration deserializerPluginConfiguration =
         find(userSettings.getDeserializers(), deserializerPlugin.getClass().getName());
     if (deserializerPluginConfiguration == null) {
       deserializerPluginConfiguration = session.create(DeserializerPluginConfiguration.class);
       userSettings.getDeserializers().add(deserializerPluginConfiguration);
       genericPluginConversion(
           session,
           deserializerPlugin,
           deserializerPluginConfiguration,
           getPluginDescriptor(session, deserializerPlugin.getClass().getName()));
     }
   }
   session.store(userSettings);
 }
Ejemplo n.º 12
0
 private PluginDescriptor getPluginDescriptor(DatabaseSession session, String pluginClassName)
     throws BimserverDatabaseException {
   return session.querySingle(
       StorePackage.eINSTANCE.getPluginDescriptor_PluginClassName(), pluginClassName);
 }
Ejemplo n.º 13
0
  public void start()
      throws DatabaseInitException, BimserverDatabaseException, PluginException,
          DatabaseRestartRequiredException, ServerException {
    try {
      LOGGER.debug("Starting BIMserver");
      SVersion localVersion = versionChecker.getLocalVersion();
      if (localVersion != null) {
        LOGGER.info(
            "Version: "
                + localVersion.getMajor()
                + "."
                + localVersion.getMinor()
                + "."
                + localVersion.getRevision()
                + " - "
                + localVersion.getDate());
      } else {
        LOGGER.info("Unknown version");
      }

      try {
        pluginManager.addPluginChangeListener(
            new PluginChangeListener() {
              @Override
              public void pluginStateChanged(PluginContext pluginContext, boolean enabled) {
                // Reflect this change also in the database
                Condition pluginCondition =
                    new AttributeCondition(
                        StorePackage.eINSTANCE.getPluginDescriptor_PluginClassName(),
                        new StringLiteral(pluginContext.getPlugin().getClass().getName()));
                DatabaseSession session = bimDatabase.createSession();
                try {
                  Map<Long, PluginDescriptor> pluginsFound =
                      session.query(pluginCondition, PluginDescriptor.class, Query.getDefault());
                  if (pluginsFound.size() == 0) {
                    LOGGER.error(
                        "Error changing plugin-state in database, plugin "
                            + pluginContext.getPlugin().getClass().getName()
                            + " not found");
                  } else if (pluginsFound.size() == 1) {
                    PluginDescriptor pluginConfiguration = pluginsFound.values().iterator().next();
                    pluginConfiguration.setEnabled(pluginContext.isEnabled());
                    session.store(pluginConfiguration);
                  } else {
                    LOGGER.error(
                        "Error, too many plugin-objects found in database for name "
                            + pluginContext.getPlugin().getClass().getName());
                  }
                  session.commit();
                } catch (BimserverDatabaseException e) {
                  LOGGER.error("", e);
                } catch (ServiceException e) {
                  LOGGER.error("", e);
                } finally {
                  session.close();
                }
              }
            });
        pluginManager.loadPlugin(
            ObjectIDMPlugin.class,
            new File(".").toURI(),
            "Internal",
            new SchemaFieldObjectIDMPlugin(),
            getClass().getClassLoader(),
            PluginSourceType.INTERNAL,
            null);
      } catch (Exception e) {
        LOGGER.error("", e);
      }

      try {
        metaDataManager.init();
        pluginManager.initAllLoadedPlugins();
      } catch (PluginException e) {
        LOGGER.error("", e);
      }
      serverStartTime = new GregorianCalendar();

      longActionManager = new LongActionManager();

      Set<EPackage> packages = new LinkedHashSet<>();
      packages.add(Ifc2x3tc1Package.eINSTANCE);
      packages.add(Ifc4Package.eINSTANCE);
      templateEngine = new TemplateEngine();
      templateEngine.init(config.getResourceFetcher().getResource("templates/"));
      Path databaseDir = config.getHomeDir().resolve("database");
      BerkeleyKeyValueStore keyValueStore = new BerkeleyKeyValueStore(databaseDir);

      schemaConverterManager.registerConverter(new Ifc2x3tc1ToIfc4SchemaConverterFactory());
      schemaConverterManager.registerConverter(new Ifc4ToIfc2x3tc1SchemaConverterFactory());

      metricsRegistry = new MetricsRegistry();

      Query.setPackageMetaDataForDefaultQuery(metaDataManager.getPackageMetaData("store"));

      bimDatabase = new Database(this, packages, keyValueStore, metaDataManager);
      try {
        bimDatabase.init();
      } catch (DatabaseRestartRequiredException e) {
        bimDatabase.close();
        keyValueStore = new BerkeleyKeyValueStore(databaseDir);
        bimDatabase = new Database(this, packages, keyValueStore, metaDataManager);
        try {
          bimDatabase.init();
        } catch (InconsistentModelsException e1) {
          LOGGER.error("", e);
          serverInfoManager.setServerState(ServerState.FATAL_ERROR);
          serverInfoManager.setErrorMessage("Inconsistent models");
        }
      } catch (InconsistentModelsException e) {
        LOGGER.error("", e);
        serverInfoManager.setServerState(ServerState.FATAL_ERROR);
        serverInfoManager.setErrorMessage("Inconsistent models");
      }

      DatabaseSession encsession = bimDatabase.createSession();
      try {
        byte[] encryptionkeyBytes = null;
        if (!bimDatabase.getRegistry().has(ENCRYPTIONKEY, encsession)) {
          encryptionkeyBytes = new byte[16];
          new SecureRandom().nextBytes(encryptionkeyBytes);
          bimDatabase.getRegistry().save(ENCRYPTIONKEY, encryptionkeyBytes, encsession);
          encsession.commit();
        } else {
          encryptionkeyBytes = bimDatabase.getRegistry().readByteArray(ENCRYPTIONKEY, encsession);
        }
        encryptionkey = new SecretKeySpec(encryptionkeyBytes, "AES");
      } finally {
        encsession.close();
      }

      protocolBuffersMetaData = new ProtocolBuffersMetaData();
      protocolBuffersMetaData.load(servicesMap, ProtocolBuffersBimServerClientFactory.class);

      serverInfoManager.init(this);

      webModuleManager = new WebModuleManager(this);

      jsonHandler = new JsonHandler(this);

      serializerFactory = new SerializerFactory();
      deserializerFactory = new DeserializerFactory();

      serverSettingsCache = new ServerSettingsCache(bimDatabase);

      serverInfoManager.update();

      if (serverInfoManager.getServerState() == ServerState.MIGRATION_REQUIRED) {
        serverInfoManager.registerStateChangeListener(
            new StateChangeListener() {
              @Override
              public void stateChanged(ServerState oldState, ServerState newState) {
                if (oldState == ServerState.MIGRATION_REQUIRED && newState == ServerState.RUNNING) {
                  try {
                    initDatabaseDependantItems();
                  } catch (BimserverDatabaseException e) {
                    LOGGER.error("", e);
                  }
                }
              }
            });
      } else {
        initDatabaseDependantItems();
      }

      mailSystem = new MailSystem(this);

      diskCacheManager = new DiskCacheManager(this, config.getHomeDir().resolve("cache"));

      mergerFactory = new MergerFactory(this);

      FileBasedReflectorFactoryBuilder factoryBuilder = new FileBasedReflectorFactoryBuilder();
      reflectorFactory = factoryBuilder.newReflectorFactory();
      if (reflectorFactory == null) {
        throw new RuntimeException("No reflector factory!");
      }
      servicesMap.setReflectorFactory(reflectorFactory);

      bimScheduler = new JobScheduler(this);
      bimScheduler.start();

      if (config.isStartEmbeddedWebServer()) {
        embeddedWebServer.start();
      }

      if (config.isStartCommandLine()) {
        commandLine = new CommandLine(this);
        commandLine.start();
      }
    } catch (Throwable e) {
      LOGGER.error("", e);
      serverInfoManager.setErrorMessage(e.getMessage());
    }
  }