@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;
  }
  @SuppressWarnings("unchecked")
  @Override
  public Set<T> execute()
      throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Map<Long, Revision> oidToRoidMap = new HashMap<Long, Revision>();

    // Look in the cache
    Set<EidClash> clashDetections =
        bimServer.getClashDetectionCache().getClashDetection(clashDetectionSettings);
    if (clashDetections != null) {
      return (Set<T>) clashDetections;
    }

    Project project = null;
    IfcModelSet ifcModelSet = new IfcModelSet();
    for (Revision revision : clashDetectionSettings.getRevisions()) {
      project = revision.getProject();
      for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) {
        IfcModel source = new IfcModel();
        getDatabaseSession()
            .getMap(
                source,
                concreteRevision.getProject().getId(),
                concreteRevision.getId(),
                true,
                null);
        source.setDate(concreteRevision.getDate());
        ifcModelSet.add(source);
        for (Long oid : source.keySet()) {
          oidToRoidMap.put(oid, revision);
        }
      }
    }
    IfcModelInterface ifcModel =
        bimServer.getMergerFactory().createMerger().merge(project, ifcModelSet, false);
    IfcModel newModel = new IfcModel();
    Map<IdEObject, IdEObject> converted = new HashMap<IdEObject, IdEObject>();
    for (IdEObject idEObject : ifcModel.getValues()) {
      if (!clashDetectionSettings.getIgnoredClasses().contains(idEObject.eClass().getName())) {
        cleanupModel(idEObject.eClass(), idEObject, newModel, ifcModel, converted);
      }
    }
    Collection<SerializerPlugin> allSerializerPlugins =
        bimServer.getPluginManager().getAllSerializerPlugins("application/ifc", true);
    if (!allSerializerPlugins.isEmpty()) {
      SerializerPlugin serializerPlugin = allSerializerPlugins.iterator().next();
      EmfSerializer ifcSerializer = serializerPlugin.createSerializer();
      try {
        try {
          ifcSerializer.init(
              newModel,
              null,
              bimServer.getPluginManager(),
              bimServer.getPluginManager().requireIfcEngine().createIfcEngine());
          byte[] bytes = ifcSerializer.getBytes();
          Plugin plugin =
              bimServer
                  .getPluginManager()
                  .getPlugin("org.bimserver.ifcengine.TNOIfcEnginePlugin", true);
          if (plugin != null && plugin instanceof IfcEnginePlugin) {
            IfcEnginePlugin ifcEnginePlugin = (IfcEnginePlugin) plugin;
            IfcEngine ifcEngine = ifcEnginePlugin.createIfcEngine();
            ifcEngine.init();
            IfcEngineModel ifcEngineModel = ifcEngine.openModel(bytes);
            try {
              Set<IfcEngineClash> clashes =
                  ifcEngineModel.findClashesWithEids(clashDetectionSettings.getMargin());

              Set<EidClash> eidClashes = new HashSet<EidClash>();
              for (IfcEngineClash clash : clashes) {
                EidClash eidClash = StoreFactory.eINSTANCE.createEidClash();
                eidClash.setEid1(clash.getEid1());
                eidClash.setEid2(clash.getEid2());
                eidClash.setName1(clash.getName1());
                eidClash.setName2(clash.getName2());
                eidClash.setType1(clash.getType1());
                eidClash.setType2(clash.getType2());
                eidClashes.add(eidClash);
              }

              // Store in cache
              bimServer
                  .getClashDetectionCache()
                  .storeClashDetection(clashDetectionSettings, eidClashes);

              for (EidClash clash : eidClashes) {
                IfcRoot object1 = (IfcRoot) newModel.get(clash.getEid1());
                clash.setName1(object1.getName());
                clash.setType1(object1.eClass().getName());
                clash.setRevision1(oidToRoidMap.get(clash.getEid1()));
                IfcRoot object2 = (IfcRoot) newModel.get(clash.getEid2());
                clash.setName2(object2.getName());
                clash.setType2(object2.eClass().getName());
                clash.setRevision2(oidToRoidMap.get(clash.getEid2()));
              }
              return (Set<T>) eidClashes;
            } finally {
              ifcEngineModel.close();
              ifcEngine.close();
            }
          }
        } catch (PluginException e) {
          LOGGER.error("", e);
        }
      } catch (SerializerException e) {
        LOGGER.error("", e);
      }
    }
    return null;
  }