Esempio n. 1
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());
     }
   }
 }
Esempio n. 2
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;
 }
Esempio n. 3
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());
 }
Esempio n. 4
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);
    }
  }
Esempio n. 5
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);
 }