@Override
 public Boolean execute()
     throws UserException, BimserverLockConflictException, BimserverDatabaseException {
   User user = getUserByUoid(uoid);
   if (!MailSystem.isValidEmailAddress(user.getUsername())) {
     return false;
   }
   return authorization.hasRightsOnProject(user, getProjectByPoid(poid));
 }
예제 #2
0
 public boolean hasRightsOnProject(User user, Project project) {
   if (user.getUserType() == UserType.ADMIN || user.getUserType() == UserType.SYSTEM) {
     return true;
   }
   for (User authorizedUser : project.getHasAuthorizedUsers()) {
     if (authorizedUser == user) {
       return true;
     }
   }
   return false;
 }
예제 #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();
     }
   }
 }
예제 #4
0
 public boolean hasRightsOnProjectOrSubProjects(User user, Project project) {
   if (user.getUserType() == UserType.ADMIN || user.getUserType() == UserType.SYSTEM) {
     return true;
   }
   if (hasRightsOnProject(user, project)) {
     return true;
   }
   for (Project subProject : project.getSubProjects()) {
     if (hasRightsOnProjectOrSubProjects(user, subProject)) {
       return true;
     }
   }
   return false;
 }
예제 #5
0
 public boolean hasRightsOnProjectOrSuperProjects(User user, Project project) {
   if (user.getUserType() == UserType.ADMIN || user.getUserType() == UserType.SYSTEM) {
     return true;
   }
   if (hasRightsOnProject(user, project)) {
     return true;
   }
   if (project.getParent() != null) {
     if (hasRightsOnProjectOrSuperProjects(user, project.getParent())) {
       return true;
     }
   }
   return false;
 }
 @Override
 public IfcModel execute()
     throws UserException, BimserverDatabaseException, BimserverLockConflictException {
   DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");
   User user = getUserByUoid(getAuthorization().getUoid());
   Revision revision = getRevisionByRoid(roid);
   Project project = revision.getProject();
   if (user.getHasRightsOn().contains(project)) {
     for (Checkout checkout : revision.getCheckouts()) {
       if (checkout.getRevision() == revision
           && checkout.getUser() == user
           && checkout.getActive()) {
         throw new UserException(
             "This revision has already been checked out by you on "
                 + dateFormat.format(checkout.getDate()));
       }
     }
     for (Checkout checkout : project.getCheckouts()) {
       if (checkout.getUser() == user && checkout.getActive()) {
         checkout.setActive(false);
         Checkout newCheckout = getDatabaseSession().create(Checkout.class);
         newCheckout.setActive(true);
         newCheckout.setDate(new Date());
         newCheckout.setUser(user);
         newCheckout.setProject(project);
         newCheckout.setRevision(revision);
         getDatabaseSession().store(checkout);
         getDatabaseSession().store(newCheckout);
         getDatabaseSession().store(project);
         return realCheckout(project, revision, getDatabaseSession(), user);
       }
     }
     Checkout checkout = getDatabaseSession().create(Checkout.class);
     checkout.setActive(true);
     checkout.setDate(new Date());
     checkout.setUser(user);
     checkout.setProject(project);
     checkout.setRevision(revision);
     getDatabaseSession().store(checkout);
     getDatabaseSession().store(project);
     return realCheckout(project, revision, getDatabaseSession(), user);
   } else {
     throw new UserException("Insufficient rights to checkout this project");
   }
 }
 @Override
 public Set<User> execute()
     throws UserException, BimserverLockConflictException, BimserverDatabaseException {
   User actingUser = getUserByUoid(authorization.getUoid());
   Condition condition = new IsOfTypeCondition(StorePackage.eINSTANCE.getUser());
   condition =
       condition.and(
           new Not(
               new AttributeCondition(
                   StorePackage.eINSTANCE.getUser_UserType(), new EnumLiteral(UserType.SYSTEM))));
   if (actingUser.getUserType() != UserType.ADMIN) {
     condition =
         condition.and(
             new AttributeCondition(
                 StorePackage.eINSTANCE.getUser_State(), new EnumLiteral(ObjectState.ACTIVE)));
   }
   return CollectionUtils.mapToSet(
       getDatabaseSession().query(condition, User.class, OldQuery.getDefault()));
 }
  @Override
  public Long execute()
      throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Long execute = super.execute();
    // Make sure the backreferences are stored as well, someday this should be automatic
    if (getIdEObject().getRenderEngine() != null) {
      getDatabaseSession().store(getIdEObject().getRenderEngine());
    }
    if (getIdEObject().getObjectIDM() != null) {
      getDatabaseSession().store(getIdEObject().getObjectIDM());
    }
    User user =
        getDatabaseSession()
            .get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), Query.getDefault());
    user.getUserSettings().getSerializers().add(getIdEObject());
    getDatabaseSession().store(user.getUserSettings());

    return execute;
  }
  private IfcModel realCheckout(
      Project project, Revision revision, DatabaseSession databaseSession, User user)
      throws BimserverLockConflictException, BimserverDatabaseException, UserException {
    SerializerPluginConfiguration serializerPluginConfiguration =
        getDatabaseSession()
            .get(
                StorePackage.eINSTANCE.getSerializerPluginConfiguration(),
                serializerOid,
                Query.getDefault());
    final long totalSize = revision.getSize();
    final AtomicLong total = new AtomicLong();

    IfcModelSet ifcModelSet = new IfcModelSet();
    for (ConcreteRevision subRevision : revision.getConcreteRevisions()) {
      IfcModel subModel = new IfcModel();
      int highestStopId = findHighestStopRid(project, subRevision);
      Query query =
          new Query(
              subRevision.getProject().getId(), subRevision.getId(), null, Deep.YES, highestStopId);
      subModel.addChangeListener(
          new IfcModelChangeListener() {
            @Override
            public void objectAdded() {
              total.incrementAndGet();
              if (totalSize == 0) {
                setProgress("Preparing checkout...", 0);
              } else {
                setProgress(
                    "Preparing checkout...", (int) Math.round(100.0 * total.get() / totalSize));
              }
            }
          });
      getDatabaseSession().getMap(subModel, query);
      try {
        checkGeometry(
            serializerPluginConfiguration,
            getBimServer().getPluginManager(),
            subModel,
            project,
            subRevision,
            revision);
      } catch (GeometryGeneratingException e) {
        throw new UserException(e);
      }
      subModel.getModelMetaData().setDate(subRevision.getDate());
      ifcModelSet.add(subModel);
    }

    IfcModelInterface ifcModel = new IfcModel();
    if (ifcModelSet.size() > 1) {
      try {
        ifcModel =
            getBimServer()
                .getMergerFactory()
                .createMerger(getDatabaseSession(), getAuthorization().getUoid())
                .merge(revision.getProject(), ifcModelSet, new ModelHelper(ifcModel));
      } catch (MergeException e) {
        throw new UserException(e);
      }
    } else {
      ifcModel = ifcModelSet.iterator().next();
    }

    ifcModel.getModelMetaData().setName(project.getName() + "." + revision.getId());
    ifcModel.getModelMetaData().setRevisionId(project.getRevisions().indexOf(revision) + 1);
    ifcModel.getModelMetaData().setAuthorizedUser(user.getName());
    ifcModel.getModelMetaData().setDate(new Date());
    return (IfcModel) ifcModel;
  }
예제 #10
0
  @Override
  public Project execute()
      throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    User actingUser = getUserByUoid(owningUoid);
    String trimmedName = name.trim();
    if (trimmedName.equals("")) {
      throw new UserException("Invalid project name");
    }
    final Project project = StoreFactory.eINSTANCE.createProject();
    Project parentProject = null;
    if (parentPoid != -1) {
      parentProject = getProjectByPoid(parentPoid);
      project.setParent(parentProject);
      parentProject.getSubProjects().add(project);
      getDatabaseSession().store(parentProject);
    }
    if (actingUser.getUserType() != UserType.SYSTEM) {
      if (parentPoid == -1
          && actingUser.getUserType() != UserType.ADMIN
          && !bimServer.getSettingsManager().getSettings().isAllowUsersToCreateTopLevelProjects()) {
        throw new UserException("Only administrators can create new projects");
      }
    }
    if (project.getParent() == null) {
      for (Project p : getProjectsByName(trimmedName)) {
        if (p.getParent() == null) {
          throw new UserException("Project name must be unique");
        }
      }
    } else {
      Project parent = project.getParent();
      for (Project subProject : parent.getSubProjects()) {
        if (subProject != project && subProject.getName().equals(trimmedName)) {
          throw new UserException(
              "Project name must be unique within parent project (" + parent.getName() + ")");
        }
      }
      project.setClashDetectionSettings(parent.getClashDetectionSettings());
      project.setGeoTag(parent.getGeoTag());
    }
    final NewProjectAdded newProjectAdded = LogFactory.eINSTANCE.createNewProjectAdded();
    newProjectAdded.setDate(new Date());
    newProjectAdded.setExecutor(actingUser);
    newProjectAdded.setParentProject(parentProject);
    newProjectAdded.setProject(project);
    newProjectAdded.setAccessMethod(getAccessMethod());
    getDatabaseSession()
        .addPostCommitAction(
            new PostCommitAction() {
              @Override
              public void execute() throws UserException {
                NewProjectNotification newProjectNotification =
                    StoreFactory.eINSTANCE.createNewProjectNotification();
                newProjectNotification.setProject(project);
                bimServer.getNotificationsManager().notify(newProjectNotification);
              }
            });
    project.setId(getDatabaseSession().newPid());
    project.setName(trimmedName);
    //		project.getHasAuthorizedUsers().add(getAdminUser());
    project.getHasAuthorizedUsers().add(actingUser);
    project.setCreatedBy(actingUser);
    project.setCreatedDate(new Date());
    project.setDescription("");
    project.setExportLengthMeasurePrefix(SIPrefix.METER);
    if (project.getParent() == null) {
      GeoTag geoTag = StoreFactory.eINSTANCE.createGeoTag();
      geoTag.setEnabled(false);
      project.setGeoTag(geoTag);
      ClashDetectionSettings clashDetectionSettings =
          StoreFactory.eINSTANCE.createClashDetectionSettings();
      clashDetectionSettings.setEnabled(false);
      project.setClashDetectionSettings(clashDetectionSettings);
      getDatabaseSession().store(geoTag);
      getDatabaseSession().store(clashDetectionSettings);
    } else {
      ClashDetectionSettings clashDetectionSettings = parentProject.getClashDetectionSettings();
      project.setClashDetectionSettings(clashDetectionSettings);
      getDatabaseSession().store(clashDetectionSettings);

      GeoTag geoTag = parentProject.getGeoTag();
      project.setGeoTag(geoTag);
      getDatabaseSession().store(geoTag);
    }
    getDatabaseSession().store(project);
    getDatabaseSession().store(actingUser);
    getDatabaseSession().store(newProjectAdded);
    return project;
  }
예제 #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);
 }