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;
}
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);
}
}
});
}
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();
}
}
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;
}
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);
}
}
Aggregations