use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class LowLevelServiceImpl method createObject.
@Override
public Long createObject(Long tid, String className, Boolean generateGuid) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
LongTransaction longTransaction = getBimServer().getLongTransactionManager().get(tid);
if (longTransaction == null) {
throw new UserException("No transaction with tid " + tid + " was found");
}
try {
EClass eClass = ((Database) getBimServer().getDatabase()).getEClass(longTransaction.getPackageMetaData().getEPackage().getName(), className);
Long oid = getBimServer().getDatabase().newOid(eClass);
CreateObjectChange createObject = new CreateObjectChange(className, oid, eClass, generateGuid);
longTransaction.add(createObject);
return oid;
} catch (BimserverDatabaseException e) {
throw new UserException("Unknown type: \"" + className + "\"");
}
} catch (Exception e) {
return handleException(e);
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class LowLevelServiceImpl method commitTransaction.
@Override
public Long commitTransaction(Long tid, String comment) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
LongTransaction longTransaction = getBimServer().getLongTransactionManager().get(tid);
if (longTransaction == null) {
throw new UserException("No transaction with tid " + tid + " was found");
}
CommitTransactionDatabaseAction action = new CommitTransactionDatabaseAction(getBimServer(), session, getInternalAccessMethod(), getAuthorization(), longTransaction, comment);
try {
session.executeAndCommitAction(action);
return action.getRevision().getOid();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
session.close();
}
} catch (NoTransactionException e) {
LOGGER.error("", e);
}
return -1L;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class NewServicesImpl method listAvailableOutputFormats.
@Override
public List<SFormatSerializerMap> listAvailableOutputFormats(Long poid) throws ServerException, UserException {
Map<String, SFormatSerializerMap> outputs = new HashMap<>();
try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
Project project = session.get(poid, OldQuery.getDefault());
try {
List<SSerializerPluginConfiguration> allSerializersForPoids = getServiceMap().get(PluginInterface.class).getAllSerializersForPoids(true, Collections.singleton(poid));
for (SSerializerPluginConfiguration pluginConfiguration : allSerializersForPoids) {
PluginDescriptor pluginDescriptor = session.get(pluginConfiguration.getPluginDescriptorId(), OldQuery.getDefault());
Plugin plugin = getBimServer().getPluginManager().getPlugin(pluginDescriptor.getIdentifier(), true);
String outputFormat = null;
// TODO For now only streaming serializers
if (plugin instanceof StreamingSerializerPlugin) {
outputFormat = ((StreamingSerializerPlugin) plugin).getOutputFormat(Schema.valueOf(project.getSchema().toUpperCase()));
}
if (outputFormat != null) {
SFormatSerializerMap map = outputs.get(outputFormat);
if (map == null) {
map = new SFormatSerializerMap();
map.setFormat(outputFormat);
outputs.put(outputFormat, map);
}
map.getSerializers().add(pluginConfiguration);
}
}
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
}
return new ArrayList<>(outputs.values());
} catch (BimserverDatabaseException e) {
return handleException(e);
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class OAuthServiceImpl method listRegisteredServersLocal.
@Override
public List<SOAuthServer> listRegisteredServersLocal() throws ServerException, UserException {
try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
List<OAuthServer> allOfType = session.getAllOfType(StorePackage.eINSTANCE.getOAuthServer(), OAuthServer.class, OldQuery.getDefault());
Iterator<OAuthServer> iterator = allOfType.iterator();
while (iterator.hasNext()) {
OAuthServer next = iterator.next();
if (!next.isIncoming()) {
iterator.remove();
}
}
return getBimServer().getSConverter().convertToSListOAuthServer(allOfType);
} catch (BimserverDatabaseException e) {
return handleException(e);
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class OAuthServiceImpl method listRegisteredServers.
@Override
public List<SOAuthServer> listRegisteredServers() throws ServerException, UserException {
try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
List<OAuthServer> allOfType = session.getAllOfType(StorePackage.eINSTANCE.getOAuthServer(), OAuthServer.class, OldQuery.getDefault());
Iterator<OAuthServer> iterator = allOfType.iterator();
while (iterator.hasNext()) {
OAuthServer next = iterator.next();
if (next.isIncoming()) {
iterator.remove();
}
}
return getBimServer().getSConverter().convertToSListOAuthServer(allOfType);
} catch (BimserverDatabaseException e) {
return handleException(e);
}
}
Aggregations