Search in sources :

Example 1 with BimBotsInput

use of org.bimserver.bimbots.BimBotsInput in project BIMserver by opensourceBIM.

the class BimBotClient method main.

public static void main(String[] args) {
    try (BimBotClient bimBotCaller = new BimBotClient("http://localhost:8080/services", "a70abb752c5a04f5ccce7ea1b79b85c045c594c3d7fb23d6f28e8e8ad04f2750477ec5706013f2bc07be2b9555fd44df")) {
        BimBotsInput bimBotsInput = new BimBotsInput(SchemaName.IFC_STEP_2X3TC1, Files.toByteArray(new File("C:\\Git\\TestFiles\\TestData\\data\\export3.ifc")));
        BimBotsOutput bimBotsOutput = bimBotCaller.call("3866702", bimBotsInput);
        ObjectNode readValue = new ObjectMapper().readValue(bimBotsOutput.getData(), ObjectNode.class);
        System.out.println(readValue.toString());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BimBotExecutionException e) {
        e.printStackTrace();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BimBotsInput(org.bimserver.bimbots.BimBotsInput) BimBotsOutput(org.bimserver.bimbots.BimBotsOutput) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with BimBotsInput

use of org.bimserver.bimbots.BimBotsInput in project BIMserver by opensourceBIM.

the class BimBotAbstractService method newRevision.

@Override
public void newRevision(RunningService runningService, BimServerClientInterface bimServerClientInterface, long poid, long roid, String userToken, long soid, SObjectType settings) throws Exception {
    try {
        long start = System.nanoTime();
        byte[] data = null;
        if (needsRawInput()) {
            // We need to generate some, by serializing the current model
            SSerializerPluginConfiguration serializerByContentType = bimServerClientInterface.getServiceInterface().getSerializerByContentType("application/ifc");
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            bimServerClientInterface.download(roid, serializerByContentType.getOid(), outputStream);
            data = outputStream.toByteArray();
        }
        BimBotsInput input = new BimBotsInput(SchemaName.IFC_STEP_2X3TC1, data);
        SProject project = bimServerClientInterface.getServiceInterface().getProjectByPoid(poid);
        String contextId = project.getUuid().toString();
        IfcModelInterface model = bimServerClientInterface.getModel(project, roid, preloadCompleteModel(), false, requiresGeometry());
        input.setIfcModel(model);
        BimBotContext bimBotContext = new BimBotContext() {

            @Override
            public void updateProgress(String label, int percentage) {
            }

            @Override
            public String getCurrentUser() {
                return runningService.getCurrentUser();
            }

            @Override
            public String getContextId() {
                return contextId;
            }
        };
        BimBotsOutput output = runBimBot(input, bimBotContext, new PluginConfiguration(settings));
        long end = System.nanoTime();
        if (output.getSchemaName().contentEquals(SchemaName.IFC_STEP_2X3TC1.name()) || output.getSchemaName().contentEquals(SchemaName.IFC_STEP_4.name())) {
            // There is no point in storing the retuned model as extended data, lets make a new revision
            output.getModel().checkin(poid, output.getTitle());
        } else {
            SFile file = new SFile();
            SExtendedData extendedData = new SExtendedData();
            extendedData.setTimeToGenerate((end - start) / 1000000);
            extendedData.setTitle(output.getTitle());
            extendedData.setSize(output.getData().length);
            file.setFilename(output.getContentDisposition());
            SExtendedDataSchema extendedDataSchemaByName = null;
            try {
                extendedDataSchemaByName = bimServerClientInterface.getServiceInterface().getExtendedDataSchemaByName(output.getSchemaName());
            } catch (Exception e) {
                extendedDataSchemaByName = new SExtendedDataSchema();
                extendedDataSchemaByName.setContentType(output.getContentType());
                extendedDataSchemaByName.setName(output.getSchemaName());
                bimServerClientInterface.getServiceInterface().addExtendedDataSchema(extendedDataSchemaByName);
            }
            extendedData.setSchemaId(extendedDataSchemaByName.getOid());
            file.setData(output.getData());
            file.setSize(output.getData().length);
            file.setMime(output.getContentType());
            long fileId = bimServerClientInterface.getServiceInterface().uploadFile(file);
            extendedData.setFileId(fileId);
            bimServerClientInterface.getServiceInterface().addExtendedDataToRevision(roid, extendedData);
        }
    } catch (BimBotsException e) {
        LOGGER.error("", e);
    } catch (Throwable e) {
        LOGGER.error("", e);
    }
}
Also used : IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimBotsException(org.bimserver.bimbots.BimBotsException) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) SProject(org.bimserver.interfaces.objects.SProject) SExtendedDataSchema(org.bimserver.interfaces.objects.SExtendedDataSchema) BimBotsException(org.bimserver.bimbots.BimBotsException) SExtendedData(org.bimserver.interfaces.objects.SExtendedData) BimBotsInput(org.bimserver.bimbots.BimBotsInput) BimBotContext(org.bimserver.bimbots.BimBotContext) BimBotsOutput(org.bimserver.bimbots.BimBotsOutput) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) SFile(org.bimserver.interfaces.objects.SFile)

Aggregations

BimBotsInput (org.bimserver.bimbots.BimBotsInput)2 BimBotsOutput (org.bimserver.bimbots.BimBotsOutput)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 File (java.io.File)1 IOException (java.io.IOException)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 BimBotContext (org.bimserver.bimbots.BimBotContext)1 BimBotsException (org.bimserver.bimbots.BimBotsException)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 SExtendedData (org.bimserver.interfaces.objects.SExtendedData)1 SExtendedDataSchema (org.bimserver.interfaces.objects.SExtendedDataSchema)1 SFile (org.bimserver.interfaces.objects.SFile)1 SProject (org.bimserver.interfaces.objects.SProject)1 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)1 PluginConfiguration (org.bimserver.plugins.PluginConfiguration)1