Search in sources :

Example 6 with BimServerClientException

use of org.bimserver.shared.exceptions.BimServerClientException in project BIMserver by opensourceBIM.

the class BimServerClient method getGeometry.

@Override
public Geometry getGeometry(long roid, IdEObject ifcProduct) {
    try {
        SSerializerPluginConfiguration serializerByPluginClassName = getPluginInterface().getSerializerByPluginClassName("org.bimserver.serializers.binarygeometry.BinaryGeometrySerializerPlugin");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        download(roid, serializerByPluginClassName.getOid(), outputStream);
        Files.write(Paths.get("bin.bin"), outputStream.toByteArray());
        ByteArrayInputStream bain = new ByteArrayInputStream(outputStream.toByteArray());
        return new Geometry(bain, ifcProduct.getOid());
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Geometry(org.bimserver.plugins.services.Geometry) ServerException(org.bimserver.shared.exceptions.ServerException) ByteArrayInputStream(java.io.ByteArrayInputStream) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Example 7 with BimServerClientException

use of org.bimserver.shared.exceptions.BimServerClientException in project BIMserver by opensourceBIM.

the class AbstractService method register.

@Override
public void register(long uoid, SInternalServicePluginConfiguration internalService, final PluginConfiguration pluginConfiguration) {
    name = internalService.getName();
    ServiceDescriptor serviceDescriptor = StoreFactory.eINSTANCE.createServiceDescriptor();
    serviceDescriptor.setProviderName("BIMserver");
    serviceDescriptor.setIdentifier("" + internalService.getOid());
    serviceDescriptor.setName(internalService.getName());
    serviceDescriptor.setDescription(internalService.getDescription());
    serviceDescriptor.setNotificationProtocol(AccessMethod.INTERNAL);
    serviceDescriptor.setTrigger(Trigger.NEW_REVISION);
    addRequiredRights(serviceDescriptor);
    serviceDescriptor.setReadRevision(true);
    registerNewRevisionHandler(uoid, serviceDescriptor, new NewRevisionHandler() {

        @Override
        public void newRevision(BimServerClientInterface bimServerClientInterface, long poid, long roid, String userToken, long soid, SObjectType settings) throws ServerException, UserException {
            try {
                Long topicId = bimServerClientInterface.getRegistry().registerProgressOnRevisionTopic(SProgressTopicType.RUNNING_SERVICE, poid, roid, "Running " + name);
                RunningService runningService = new RunningService(topicId, bimServerClientInterface, pluginConfiguration);
                try {
                    SLongActionState state = new SLongActionState();
                    state.setProgress(getProgressType() == ProgressType.KNOWN ? 0 : -1);
                    state.setTitle(name);
                    state.setState(SActionState.STARTED);
                    state.setStart(runningService.getStartDate());
                    bimServerClientInterface.getRegistry().updateProgressTopic(topicId, state);
                    AbstractService.this.newRevision(runningService, bimServerClientInterface, poid, roid, userToken, soid, settings);
                    state = new SLongActionState();
                    state.setProgress(100);
                    state.setTitle(name);
                    state.setState(SActionState.FINISHED);
                    state.setStart(runningService.getStartDate());
                    state.setEnd(new Date());
                    bimServerClientInterface.getRegistry().updateProgressTopic(topicId, state);
                } catch (BimServerClientException e) {
                    LOGGER.error("", e);
                } catch (Exception e) {
                    LOGGER.error("", e);
                } finally {
                    bimServerClientInterface.getRegistry().unregisterProgressTopic(topicId);
                }
            } catch (PublicInterfaceNotFoundException e) {
                LOGGER.error("", e);
            }
        }
    });
}
Also used : SObjectType(org.bimserver.interfaces.objects.SObjectType) ServerException(org.bimserver.shared.exceptions.ServerException) SLongActionState(org.bimserver.interfaces.objects.SLongActionState) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) Date(java.util.Date) PluginException(org.bimserver.shared.exceptions.PluginException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) ServiceDescriptor(org.bimserver.models.store.ServiceDescriptor) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) UserException(org.bimserver.shared.exceptions.UserException)

Example 8 with BimServerClientException

use of org.bimserver.shared.exceptions.BimServerClientException in project BIMserver by opensourceBIM.

the class TestGuid method main.

public static void main(String[] args) {
    BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
    try {
        SProject project = client.getServiceInterface().addProject("testProject2", "ifc2x3tc1");
        Long tid = client.getLowLevelInterface().startTransaction(project.getOid());
        client.getLowLevelInterface().createObject(tid, "IfcWall", false);
        Long roid = client.getLowLevelInterface().commitTransaction(tid, "test commit");
        SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
        client.download(roid, serializer.getOid(), Paths.get("test2.ifc"));
    } catch (ServerException | UserException | PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Example 9 with BimServerClientException

use of org.bimserver.shared.exceptions.BimServerClientException in project BIMserver by opensourceBIM.

the class SharedJsonDeserializer method read.

@SuppressWarnings("rawtypes")
public IfcModelInterface read(InputStream in, IfcModelInterface model, boolean checkWaitingList) throws DeserializeException {
    if (model.getPackageMetaData().getSchemaDefinition() == null) {
        throw new DeserializeException("No SchemaDefinition available");
    }
    WaitingList<Long> waitingList = new WaitingList<Long>();
    final boolean log = false;
    if (log) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            IOUtils.copy(in, baos);
            File file = new File("debug.json");
            System.out.println(file.getAbsolutePath());
            FileUtils.writeByteArrayToFile(file, baos.toByteArray());
        } catch (IOException e) {
            e.printStackTrace();
        }
        in = new ByteArrayInputStream(baos.toByteArray());
    }
    JsonReader jsonReader = new JsonReader(new InputStreamReader(in, Charsets.UTF_8));
    int nrObjects = 0;
    try {
        JsonToken peek = jsonReader.peek();
        if (peek != null && peek == JsonToken.BEGIN_OBJECT) {
            jsonReader.beginObject();
            peek = jsonReader.peek();
            while (peek == JsonToken.NAME) {
                String nextName = jsonReader.nextName();
                if (nextName.equals("objects")) {
                    jsonReader.beginArray();
                    while (jsonReader.hasNext()) {
                        nrObjects++;
                        processObject(model, waitingList, jsonReader, null);
                    }
                    jsonReader.endArray();
                } else if (nextName.equals("header")) {
                    IfcHeader ifcHeader = (IfcHeader) processObject(model, waitingList, jsonReader, StorePackage.eINSTANCE.getIfcHeader());
                    model.getModelMetaData().setIfcHeader(ifcHeader);
                }
                peek = jsonReader.peek();
            }
            jsonReader.endObject();
        }
    } catch (IOException e) {
        LOGGER.error("", e);
    } catch (IfcModelInterfaceException e) {
        LOGGER.error("", e);
    } finally {
        LOGGER.debug("# Objects: " + nrObjects);
        try {
            jsonReader.close();
        } catch (IOException e) {
            LOGGER.error("", e);
        }
    }
    boolean checkUnique = false;
    if (checkUnique) {
        for (IdEObject idEObject : model.getValues()) {
            for (EStructuralFeature eStructuralFeature : idEObject.eClass().getEAllStructuralFeatures()) {
                Object value = idEObject.eGet(eStructuralFeature);
                if (eStructuralFeature instanceof EReference) {
                    if (eStructuralFeature.isMany()) {
                        List list = (List) value;
                        if (eStructuralFeature.isUnique()) {
                            Set<Object> t = new HashSet<>();
                            for (Object v : list) {
                                if (t.contains(v)) {
                                // LOGGER.error("NOT UNIQUE " + idEObject.eClass().getName() + "." + eStructuralFeature.getName());
                                }
                                t.add(v);
                            }
                        }
                    }
                }
            }
        }
    }
    if (checkWaitingList && waitingList.size() > 0) {
        try {
            waitingList.dumpIfNotEmpty();
        } catch (BimServerClientException e) {
            e.printStackTrace();
        }
        throw new DeserializeException("Waitinglist should be empty (" + waitingList.size() + ")");
    }
    return model;
}
Also used : InputStreamReader(java.io.InputStreamReader) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) IfcHeader(org.bimserver.models.store.IfcHeader) WaitingList(org.bimserver.shared.WaitingList) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonReader(com.google.gson.stream.JsonReader) JsonToken(com.google.gson.stream.JsonToken) ListWaitingObject(org.bimserver.shared.ListWaitingObject) EObject(org.eclipse.emf.ecore.EObject) AbstractEList(org.eclipse.emf.common.util.AbstractEList) WaitingList(org.bimserver.shared.WaitingList) List(java.util.List) File(java.io.File) EReference(org.eclipse.emf.ecore.EReference) HashSet(java.util.HashSet)

Example 10 with BimServerClientException

use of org.bimserver.shared.exceptions.BimServerClientException in project BIMserver by opensourceBIM.

the class BimServerClient method download.

public void download(long roid, long serializerOid, OutputStream outputStream) throws BimServerClientException {
    try {
        Long topicId = getServiceInterface().download(Collections.singleton(roid), DefaultQueries.allAsString(), serializerOid, false);
        SLongActionState progress = getNotificationRegistryInterface().getProgress(topicId);
        if (progress != null && progress.getState() == SActionState.AS_ERROR) {
            throw new BimServerClientException(Joiner.on(", ").join(progress.getErrors()));
        } else {
            InputStream inputStream = getDownloadData(topicId);
            try {
                IOUtils.copy(inputStream, outputStream);
                getServiceInterface().cleanupLongAction(topicId);
            } finally {
                inputStream.close();
            }
        }
    } catch (ServerException e) {
        LOGGER.error("", e);
    } catch (UserException e) {
        LOGGER.error("", e);
    } catch (IOException e) {
        LOGGER.error("", e);
    } catch (PublicInterfaceNotFoundException e) {
        LOGGER.error("", e);
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) SLongActionState(org.bimserver.interfaces.objects.SLongActionState) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Aggregations

BimServerClientException (org.bimserver.shared.exceptions.BimServerClientException)19 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)15 IOException (java.io.IOException)12 SProject (org.bimserver.interfaces.objects.SProject)12 ServiceException (org.bimserver.shared.exceptions.ServiceException)11 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)10 ServerException (org.bimserver.shared.exceptions.ServerException)10 UserException (org.bimserver.shared.exceptions.UserException)10 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)8 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)8 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)8 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)7 Path (java.nio.file.Path)6 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)5 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Date (java.util.Date)3 IfcModelInterface (org.bimserver.emf.IfcModelInterface)3 PluginException (org.bimserver.shared.exceptions.PluginException)3