use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.
the class ServiceImpl method checkinFromUrlSync.
@Override
public SLongCheckinActionState checkinFromUrlSync(Long poid, String comment, Long deserializerOid, String fileName, String urlString, Boolean merge) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
final DatabaseSession readOnlySession = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
String username = "Unknown";
String userUsername = "Unknown";
try {
Long topicId = initiateCheckin(poid, deserializerOid);
User user = (User) readOnlySession.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
username = user.getName();
userUsername = user.getUsername();
Project project = readOnlySession.get(poid, OldQuery.getDefault());
if (project == null) {
throw new UserException("No project found with poid " + poid);
}
URL url = new URL(urlString);
URLConnection openConnection = url.openConnection();
InputStream input = openConnection.getInputStream();
Path incomingFile = getIncomingFileName(fileName, urlString, userUsername);
return checkinInternal(topicId, poid, comment, deserializerOid, (long) openConnection.getContentLength(), fileName, input, merge, true, readOnlySession, username, userUsername, project, incomingFile, -1);
// DeserializerPluginConfiguration deserializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getDeserializerPluginConfiguration(), deserializerOid, OldQuery.getDefault());
// if (deserializerPluginConfiguration == null) {
// throw new UserException("Deserializer with oid " + deserializerOid + " not found");
// }
// OutputStream outputStream = Files.newOutputStream(file);
// InputStream inputStream = new MultiplexingInputStream(input, outputStream);
// DeserializerPlugin deserializerPlugin = (DeserializerPlugin) getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
// ObjectType settings = deserializerPluginConfiguration.getSettings();
//
// Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration(settings));
// deserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
//
// IfcModelInterface model = deserializer.read(inputStream, fileName, 0, null);
//
// CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), model, comment, fileName, merge);
// LongCheckinAction longAction = new LongCheckinAction(-1L, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
// getBimServer().getLongActionManager().start(longAction);
// if (sync) {
// longAction.waitForCompletion();
// }
// return longAction.getProgressTopic().getKey().getId();
} catch (UserException e) {
throw e;
} catch (Throwable e) {
LOGGER.error("", e);
throw new ServerException(e);
} finally {
readOnlySession.close();
}
}
use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.
the class ServiceImpl method getVolume.
@Override
public Double getVolume(Long roid, Long oid) throws UserException, ServerException {
requireAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
BimDatabaseAction<Double> action = new GetVolumeDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, oid, getAuthorization());
return session.executeAndCommitAction(action);
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.
the class ServiceImpl method clone.
@Override
public Long clone(Long roid, String projectName, String comment, Boolean sync) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
try {
CloneToNewProjectDatabaseAction action = new CloneToNewProjectDatabaseAction(session, getInternalAccessMethod(), getBimServer(), getAuthorization(), roid, projectName, comment);
User user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
String username = user.getName();
String userUsername = user.getUsername();
LongCopyAction longAction = new LongCopyAction(getBimServer(), username, userUsername, getAuthorization(), action);
getBimServer().getLongActionManager().start(longAction);
if (sync) {
longAction.waitForCompletion();
}
return longAction.getProgressTopic().getKey().getId();
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.
the class ServiceImpl method uploadFile.
@Override
public Long uploadFile(SFile file) throws ServerException, UserException {
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
try {
File convertFromSObject = getBimServer().getSConverter().convertFromSObject(file, session.create(File.class), session);
UploadFileDatabaseAction action = new UploadFileDatabaseAction(session, getInternalAccessMethod(), convertFromSObject);
return session.executeAndCommitAction(action);
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.shared.exceptions.ServerException in project BIMserver by opensourceBIM.
the class ServiceImpl method getIfcHeader.
@Override
public SIfcHeader getIfcHeader(Long croid) throws UserException, ServerException {
requireAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
BimDatabaseAction<SIfcHeader> action = new GetIfcHeaderDatabaseAction(getBimServer(), session, getInternalAccessMethod(), croid, getAuthorization());
return session.executeAndCommitAction(action);
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
Aggregations