Пример #1
0
 private void process(Path directory, SProject parentProject)
     throws ServerException, UserException, PublicInterfaceNotFoundException, IOException {
   if (Files.isDirectory(directory)) {
     SProject project = null;
     if (parentProject == null) {
       project =
           client
               .getBimsie1ServiceInterface()
               .addProject(directory.getFileName().toString(), "ifc2x3tc1");
     } else {
       project =
           client
               .getBimsie1ServiceInterface()
               .addProjectAsSubProject(
                   directory.getFileName().toString(), parentProject.getOid(), "ifc2x3tc1");
     }
     for (Path file : PathUtils.list(directory)) {
       process(file, project);
     }
   } else {
     String lowerCase = directory.getFileName().toString().toLowerCase();
     if (lowerCase.endsWith("ifc")
         || lowerCase.endsWith("ifcxml")
         || lowerCase.endsWith("ifczip")) {
       SDeserializerPluginConfiguration deserializerForExtension =
           client
               .getBimsie1ServiceInterface()
               .getSuggestedDeserializerForExtension(
                   directory
                       .getFileName()
                       .toString()
                       .substring(directory.getFileName().toString().lastIndexOf(".") + 1),
                   parentProject.getOid());
       System.out.println(
           "Checking in "
               + directory.toString()
               + " - "
               + Formatters.bytesToString(directory.toFile().length()));
       try {
         client.checkin(
             parentProject.getOid(),
             "",
             deserializerForExtension.getOid(),
             false,
             true,
             directory);
       } catch (UserException e) {
         e.printStackTrace();
       }
     } else {
       System.out.println("Ignoring " + directory.toString());
     }
   }
 }
Пример #2
0
  @Test
  public void test() {
    try {
      // New client
      BimServerClientInterface bimServerClient =
          getFactory()
              .create(new UsernamePasswordAuthenticationInfo("*****@*****.**", "admin"));

      // Create a project
      SProject project =
          bimServerClient
              .getBimsie1ServiceInterface()
              .addProject("test" + Math.random(), "ifc2x3tc1");

      // Look for a deserializer
      SDeserializerPluginConfiguration deserializer =
          bimServerClient
              .getBimsie1ServiceInterface()
              .getSuggestedDeserializerForExtension("ifc", project.getOid());

      bimServerClient.checkin(
          project.getOid(),
          "test",
          deserializer.getOid(),
          false,
          true,
          new File("../TestData/data/AC11-Institute-Var-2-IFC.ifc"));

      // Refresh project
      project = bimServerClient.getBimsie1ServiceInterface().getProjectByPoid(project.getOid());

      // Load model without lazy loading (complete model at once)
      IfcModelInterface model =
          bimServerClient.getModel(project, project.getLastRevisionId(), true, false);

      String propertyName = "BooleanProperty";

      int nrWindowsFirst = 0;
      // Iterate over all projects, there should be 1
      for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
        nrWindowsFirst++;
        createProperty(window, model, propertyName, "Description of property", true);
      }

      model.commit("Added boolean properties to " + nrWindowsFirst + " windows");

      project = bimServerClient.getBimsie1ServiceInterface().getProjectByPoid(project.getOid());
      model = bimServerClient.getModel(project, project.getLastRevisionId(), true, false);
      int foundOke = 0;
      int nrWindowsSecond = 0;
      Set<Long> counted = new HashSet<Long>();
      for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
        nrWindowsSecond++;
        for (IfcRelDefines ifcRelDefines : window.getIsDefinedBy()) {
          if (ifcRelDefines instanceof IfcRelDefinesByProperties) {
            IfcRelDefinesByProperties ifcRelDefinesByProperties =
                (IfcRelDefinesByProperties) ifcRelDefines;
            IfcPropertySetDefinition relatingPropertyDefinition =
                ifcRelDefinesByProperties.getRelatingPropertyDefinition();
            if (relatingPropertyDefinition instanceof IfcPropertySet) {
              IfcPropertySet ifcPropertySet = (IfcPropertySet) relatingPropertyDefinition;
              for (IfcProperty ifcProperty : ifcPropertySet.getHasProperties()) {
                if (ifcProperty instanceof IfcPropertySingleValue) {
                  IfcPropertySingleValue ifcPropertySingleValue =
                      (IfcPropertySingleValue) ifcProperty;
                  if (ifcPropertySingleValue.getName().equals(propertyName)) {
                    IfcValue nominalValue = ifcPropertySingleValue.getNominalValue();
                    if (nominalValue instanceof IfcBoolean) {
                      if (((IfcBoolean) nominalValue).getWrappedValue() == Tristate.TRUE) {
                        if (!counted.contains(ifcPropertySingleValue.getOid())) {
                          foundOke++;
                          counted.add(ifcPropertySingleValue.getOid());
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      LOGGER.info("Windows first: " + nrWindowsFirst);
      LOGGER.info("Windows second: " + nrWindowsSecond);
      LOGGER.info("Found Oke: " + foundOke);
      if (foundOke != nrWindowsFirst) {
        fail(foundOke + " / " + nrWindowsFirst);
      }
    } catch (Throwable e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
  private void start() {
    BimServerConfig config = new BimServerConfig();
    Path homeDir = Paths.get("home");
    try {
      if (Files.isDirectory(homeDir)) {
        PathUtils.removeDirectoryWithContent(homeDir);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    config.setClassPath(System.getProperty("java.class.path"));
    config.setHomeDir(homeDir);
    config.setPort(8080);
    config.setStartEmbeddedWebServer(true);
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    final BimServer bimServer = new BimServer(config);
    try {
      LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null);
      bimServer.start();
      if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
        bimServer
            .getService(AdminInterface.class)
            .setup(
                "http://localhost",
                "localhost",
                "*****@*****.**",
                "Administrator",
                "*****@*****.**",
                "admin");
      }
    } catch (PluginException e2) {
      e2.printStackTrace();
    } catch (ServerException e) {
      e.printStackTrace();
    } catch (DatabaseInitException e) {
      e.printStackTrace();
    } catch (BimserverDatabaseException e) {
      e.printStackTrace();
    } catch (DatabaseRestartRequiredException e) {
      e.printStackTrace();
    } catch (UserException e) {
      e.printStackTrace();
    }

    try {
      final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL);
      ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class);
      SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class);
      final Bimsie1AuthInterface authInterface = serviceMap.get(Bimsie1AuthInterface.class);
      serviceInterface =
          bimServer
              .getServiceFactory()
              .get(authInterface.login("*****@*****.**", "admin"), AccessMethod.INTERNAL)
              .get(ServiceInterface.class);
      settingsInterface.setCacheOutputFiles(true);
      settingsInterface.setGenerateGeometryOnCheckin(false);
      final SProject project =
          serviceMap.getBimsie1ServiceInterface().addProject("test", "ifc2x3tc1");
      SDeserializerPluginConfiguration deserializerByName =
          serviceMap.getBimsie1ServiceInterface().getDeserializerByName("IfcStepDeserializer");
      Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
      serviceInterface.checkin(
          project.getOid(),
          "test",
          deserializerByName.getOid(),
          file.toFile().length(),
          file.getFileName().toString(),
          new DataHandler(new FileDataSource(file.toFile())),
          false,
          true);
      final SProject projectUpdate =
          serviceMap.getBimsie1ServiceInterface().getProjectByPoid(project.getOid());
      ThreadPoolExecutor executor =
          new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000));
      for (int i = 0; i < 20; i++) {
        executor.execute(
            new Runnable() {
              @Override
              public void run() {
                try {
                  ServiceMap serviceMap2 =
                      bimServer
                          .getServiceFactory()
                          .get(
                              authInterface.login("*****@*****.**", "admin"),
                              AccessMethod.INTERNAL);
                  SSerializerPluginConfiguration serializerPluginConfiguration =
                      serviceMap.getBimsie1ServiceInterface().getSerializerByName("Ifc2x3");
                  Long download =
                      serviceMap2
                          .getBimsie1ServiceInterface()
                          .download(
                              projectUpdate.getLastRevisionId(),
                              serializerPluginConfiguration.getOid(),
                              true,
                              true);
                  SDownloadResult downloadData =
                      serviceMap2.getBimsie1ServiceInterface().getDownloadData(download);
                  if (downloadData.getFile().getDataSource()
                      instanceof CacheStoringEmfSerializerDataSource) {
                    CacheStoringEmfSerializerDataSource c =
                        (CacheStoringEmfSerializerDataSource)
                            downloadData.getFile().getDataSource();
                    try {
                      ByteArrayOutputStream baos = new ByteArrayOutputStream();
                      c.writeToOutputStream(baos, null);
                      System.out.println(baos.size());
                    } catch (SerializerException e) {
                      e.printStackTrace();
                    }
                  } else {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    IOUtils.copy(downloadData.getFile().getInputStream(), baos);
                    System.out.println(baos.size());
                  }
                  serviceMap2.getServiceInterface().cleanupLongAction(download);
                } catch (ServerException e) {
                  e.printStackTrace();
                } catch (UserException e) {
                  e.printStackTrace();
                } catch (FileNotFoundException e) {
                  e.printStackTrace();
                } catch (IOException e) {
                  e.printStackTrace();
                } catch (PublicInterfaceNotFoundException e1) {
                  e1.printStackTrace();
                }
              }
            });
      }
      executor.shutdown();
      executor.awaitTermination(1, TimeUnit.HOURS);
      bimServer.stop();
    } catch (ServerException e1) {
      e1.printStackTrace();
    } catch (UserException e1) {
      e1.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
Пример #4
0
  @Test
  public void test() {
    try {
      // Create a new BimServerClient with authentication
      BimServerClientInterface bimServerClient =
          getFactory()
              .create(new UsernamePasswordAuthenticationInfo("*****@*****.**", "admin"));

      long s = System.nanoTime();
      // Create a new project
      SProject mainProject =
          bimServerClient.getBimsie1ServiceInterface().addProject("main" + Math.random());
      SProject sub1 =
          bimServerClient
              .getBimsie1ServiceInterface()
              .addProjectAsSubProject("Sub1" + Math.random(), mainProject.getOid());
      SProject sub2 =
          bimServerClient
              .getBimsie1ServiceInterface()
              .addProjectAsSubProject("Sub2" + Math.random(), mainProject.getOid());
      SProject sub3 =
          bimServerClient
              .getBimsie1ServiceInterface()
              .addProjectAsSubProject("Sub3" + Math.random(), mainProject.getOid());

      // This is the file we will be checking in
      File ifcFile1 = new File("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
      File ifcFile2 = new File("../TestData/data/AC90R1-niedriha-V2-2x3.ifc");
      File ifcFile3 = new File("../TestData/data/AC11-FZK-Haus-IFC.ifc");

      // Find a deserializer to use
      SDeserializerPluginConfiguration deserializer =
          bimServerClient.getBimsie1ServiceInterface().getSuggestedDeserializerForExtension("ifc");

      // Checkin
      bimServerClient.checkin(sub1.getOid(), "test", deserializer.getOid(), false, true, ifcFile1);
      bimServerClient.checkin(sub2.getOid(), "test", deserializer.getOid(), false, true, ifcFile2);
      bimServerClient.checkin(sub3.getOid(), "test", deserializer.getOid(), false, true, ifcFile3);

      // Find a serializer
      SSerializerPluginConfiguration serializer =
          bimServerClient
              .getBimsie1ServiceInterface()
              .getSerializerByContentType("application/ifc");

      // Get the project details
      mainProject =
          bimServerClient.getBimsie1ServiceInterface().getProjectByPoid(mainProject.getOid());

      // Download the latest revision (the one we just checked in)
      //			Long downloadId =
      // bimServerClient.getBimsie1ServiceInterface().downloadByTypes(Collections.singleton(mainProject.getLastRevisionId()),
      //					Collections.singleton("IfcWall"), serializer.getOid(), true, false, true, true);
      Long downloadId =
          bimServerClient
              .getBimsie1ServiceInterface()
              .download(mainProject.getLastRevisionId(), serializer.getOid(), true, true);
      IOUtils.copy(
          bimServerClient.getDownloadData(downloadId, serializer.getOid()),
          new FileOutputStream(new File("out.ifc")));
      long e = System.nanoTime();
      System.out.println(((e - s) / 1000000) + " ms");
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
Пример #5
0
  @Test
  public void test() {
    try {
      // Create a new BimServerClient with authentication
      BimServerClientInterface bimServerClient =
          getFactory()
              .create(new UsernamePasswordAuthenticationInfo("*****@*****.**", "admin"));

      // Create a new project
      SProject newProject =
          bimServerClient
              .getBimsie1ServiceInterface()
              .addProject("test" + Math.random(), "ifc2x3tc1");

      // Get the appropriate deserializer
      SDeserializerPluginConfiguration deserializer =
          bimServerClient
              .getBimsie1ServiceInterface()
              .getSuggestedDeserializerForExtension("ifc", newProject.getOid());

      // Checkin the file
      bimServerClient.checkin(
          newProject.getOid(),
          "test",
          deserializer.getOid(),
          false,
          true,
          new File("../TestData/data/AC11-Institute-Var-2-IFC.ifc"));

      // Refresh project info
      newProject =
          bimServerClient.getBimsie1ServiceInterface().getProjectByPoid(newProject.getOid());

      IfcModelInterface model =
          bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
      for (IfcFurnishingElement ifcFurnishingElement :
          model.getAllWithSubTypes(IfcFurnishingElement.class)) {
        IfcObjectPlacement objectPlacement = ifcFurnishingElement.getObjectPlacement();
        if (objectPlacement != null && objectPlacement instanceof IfcLocalPlacement) {
          IfcLocalPlacement localPlacement = (IfcLocalPlacement) objectPlacement;
          IfcAxis2Placement relativePlacement = localPlacement.getRelativePlacement();
          if (relativePlacement != null) {
            if (relativePlacement instanceof IfcAxis2Placement3D) {
              IfcAxis2Placement3D axis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
              IfcCartesianPoint location = axis2Placement3D.getLocation();
              double newValue = location.getCoordinates().get(2) + 50;
              System.out.println(
                  "Changing z value of "
                      + ifcFurnishingElement.getName()
                      + " from "
                      + location.getCoordinates().get(2)
                      + " to "
                      + newValue);
              location.getCoordinates().set(2, newValue);
            }
          }
        }
      }
      long newRoid = model.commit("Moved all furniture 50 meters up");
      SSerializerPluginConfiguration ifcSerializer =
          bimServerClient
              .getBimsie1ServiceInterface()
              .getSerializerByContentType("application/ifc");
      bimServerClient.download(newRoid, ifcSerializer.getOid(), new File("movedf.ifc"));
    } catch (Throwable e) {
      e.printStackTrace();
      if (e instanceof AssertionError) {
        throw (AssertionError) e;
      }
      fail(e.getMessage());
    }
  }