use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class ByteBufferVirtualObject method setListItem.
public void setListItem(EStructuralFeature feature, int index, Object value) throws BimserverDatabaseException {
if (currentListStart == -1) {
throw new BimserverDatabaseException("Not currently writing a list");
}
if (index + 1 > currentListSize) {
currentListSize = index + 1;
}
if (value instanceof ByteBufferWrappedVirtualObject) {
ByteBuffer otherBuffer = ((ByteBufferWrappedVirtualObject) value).write();
ensureCapacity(buffer.position(), otherBuffer.position());
buffer.put(otherBuffer.array(), 0, otherBuffer.position());
} else if (value instanceof ByteBufferList) {
ByteBuffer otherBuffer = ((ByteBufferList) value).write();
ensureCapacity(buffer.position(), otherBuffer.position());
buffer.put(otherBuffer.array(), 0, otherBuffer.position());
} else {
writePrimitiveValue(feature, value);
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class HashMapVirtualObject method writePrimitiveValue.
private void writePrimitiveValue(EStructuralFeature feature, Object value, ByteBuffer buffer) throws BimserverDatabaseException {
EClassifier type = feature.getEType();
if (type == EcorePackage.eINSTANCE.getEString()) {
if (value == null) {
buffer.putInt(-1);
} else {
String stringValue = (String) value;
byte[] bytes = stringValue.getBytes(Charsets.UTF_8);
if (bytes.length > Integer.MAX_VALUE) {
throw new BimserverDatabaseException("String value too long (max length is " + Integer.MAX_VALUE + ")");
}
buffer.putInt(bytes.length);
buffer.put(bytes);
}
} else if (type == EcorePackage.eINSTANCE.getEInt() || type == EcorePackage.eINSTANCE.getEIntegerObject()) {
if (value == null) {
buffer.putInt(0);
} else {
buffer.putInt((Integer) value);
}
} else if (type == EcorePackage.eINSTANCE.getEDouble() || type == EcorePackage.eINSTANCE.getEDoubleObject()) {
if (value == null) {
buffer.putDouble(0D);
} else {
buffer.putDouble((Double) value);
}
} else if (type == EcorePackage.eINSTANCE.getEFloat() || type == EcorePackage.eINSTANCE.getEFloatObject()) {
if (value == null) {
buffer.putFloat(0F);
} else {
buffer.putFloat((Float) value);
}
} else if (type == EcorePackage.eINSTANCE.getELong() || type == EcorePackage.eINSTANCE.getELongObject()) {
if (value == null) {
buffer.putLong(0L);
} else {
buffer.putLong((Long) value);
}
} else if (type == EcorePackage.eINSTANCE.getEBoolean() || type == EcorePackage.eINSTANCE.getEBooleanObject()) {
if (value == null) {
buffer.put((byte) 0);
} else {
buffer.put(((Boolean) value) ? (byte) 1 : (byte) 0);
}
} else if (type == EcorePackage.eINSTANCE.getEDate()) {
if (value == null) {
buffer.putLong(-1L);
} else {
buffer.putLong(((Date) value).getTime());
}
} else if (type.getName().equals("Tristate")) {
if (value == null) {
buffer.putInt(Tristate.UNDEFINED.getValue());
} else {
Enumerator eEnumLiteral = (Enumerator) value;
buffer.putInt(eEnumLiteral.getValue());
}
} else if (value instanceof Enumerator) {
Enumerator eEnumLiteral = (Enumerator) value;
buffer.putInt(eEnumLiteral.getValue());
} else if (type == EcorePackage.eINSTANCE.getEByteArray()) {
if (value == null) {
buffer.putInt(0);
} else {
byte[] bytes = (byte[]) value;
buffer.putInt(bytes.length);
buffer.put(bytes);
}
} else {
throw new RuntimeException("Unsupported type " + type.getName());
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class TestInOut method start.
private void start(String[] args) {
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("../")));
BimServer bimServer = new BimServer(config);
try {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), new OptionsParser(args).getPluginDirectories());
bimServer.start();
if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
AdminInterface adminInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(AdminInterface.class);
adminInterface.setup("http://localhost:8080", "Administrator", "admin@bimserver.org", "admin", null, null, null);
SettingsInterface settingsInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(SettingsInterface.class);
settingsInterface.setCacheOutputFiles(false);
}
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
SProject project = client.getServiceInterface().addProject("test", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
Path inputFile = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
client.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, inputFile);
project = client.getServiceInterface().getProjectByPoid(project.getOid());
SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
Path outputFile = Paths.get("output.ifc");
client.download(project.getLastRevisionId(), serializer.getOid(), outputFile);
Diff diff = new Diff(false, false, false, inputFile, outputFile);
diff.start();
} catch (ServerException e) {
e.printStackTrace();
} catch (DatabaseInitException e) {
e.printStackTrace();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (PluginException e) {
e.printStackTrace();
} catch (DatabaseRestartRequiredException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (CompareException e) {
e.printStackTrace();
} catch (BimServerClientException e) {
e.printStackTrace();
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class TestDatabase method checkLists3.
private void checkLists3() {
DatabaseSession session = database.createSession();
long xid = -1;
try {
User user = session.create(User.class);
UserSettings userSettings = session.create(UserSettings.class);
SerializerPluginConfiguration serializerPluginConfiguration1 = session.create(SerializerPluginConfiguration.class);
SerializerPluginConfiguration serializerPluginConfiguration2 = session.create(SerializerPluginConfiguration.class);
xid = serializerPluginConfiguration2.getOid();
user.setUserSettings(userSettings);
serializerPluginConfiguration1.setUserSettings(userSettings);
serializerPluginConfiguration2.setUserSettings(userSettings);
session.commit();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} finally {
session.close();
session = database.createSession();
try {
SerializerPluginConfiguration p1 = session.get(xid, OldQuery.getDefault());
UserSettings userSettings = p1.getUserSettings();
for (SerializerPluginConfiguration p2 : userSettings.getSerializers()) {
System.out.println(p2.getOid() + " - " + p2);
}
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} finally {
session.close();
}
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class TestDatabase method checkWithAllOfType.
private void checkWithAllOfType() {
DatabaseSession session = database.createSession();
try {
List<User> users = session.getAllOfType(StorePackage.eINSTANCE.getUser(), User.class, OldQuery.getDefault());
for (User user : users) {
if (user.getName().equals("testuser")) {
System.out.println(user.getName() + ": " + user.getHasRightsOn());
}
}
List<Project> projects = session.getAllOfType(StorePackage.eINSTANCE.getProject(), Project.class, OldQuery.getDefault());
for (Project project : projects) {
if (project.getName().equals("testproject")) {
System.out.println(project.getName() + ": " + project.getHasAuthorizedUsers());
}
}
session.commit();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} finally {
session.close();
}
}
Aggregations