use of org.bimserver.database.DatabaseSession in project BIMserver by opensourceBIM.
the class ServiceImpl method checkout.
@Override
public Long checkout(Long roid, Long serializerOid, Boolean sync) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
getAuthorization().canDownload(roid);
DatabaseSession session = getBimServer().getDatabase().createSession();
User user = null;
try {
SerializerPluginConfiguration serializerPluginConfiguration = (SerializerPluginConfiguration) session.get(serializerOid, OldQuery.getDefault());
// org.bimserver.plugins.serializers.Serializer serializer = getBimServer().getEmfSerializerFactory().get(serializerOid).createSerializer(new org.bimserver.plugins.serializers.PluginConfiguration());
if (serializerPluginConfiguration == null) {
throw new UserException("No serializer with id " + serializerOid + " could be found");
}
if (!serializerPluginConfiguration.getPluginDescriptor().getPluginClassName().equals("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin") && !serializerPluginConfiguration.getPluginDescriptor().getPluginClassName().equals("org.bimserver.ifc.xml.serializer.IfcXmlSerializerPlugin")) {
throw new UserException("Only IFC or IFCXML allowed when checking out");
}
DownloadParameters downloadParameters = new DownloadParameters(getBimServer(), DownloadType.DOWNLOAD_PROJECTS);
downloadParameters.setRoid(roid);
downloadParameters.setSerializerOid(serializerOid);
user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
LongDownloadOrCheckoutAction longDownloadAction = new LongCheckoutAction(getBimServer(), user.getName(), user.getUsername(), downloadParameters, getAuthorization(), getInternalAccessMethod());
try {
getBimServer().getLongActionManager().start(longDownloadAction);
} catch (CannotBeScheduledException e) {
LOGGER.error("", e);
}
if (sync) {
longDownloadAction.waitForCompletion();
}
return longDownloadAction.getProgressTopic().getKey().getId();
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.database.DatabaseSession in project BIMserver by opensourceBIM.
the class ServiceImpl method branchToExistingProject.
@Override
public Long branchToExistingProject(Long roid, Long destPoid, String comment, Boolean sync) throws UserException, ServerException {
requireRealUserAuthentication();
final DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BranchToExistingProjectDatabaseAction action = new BranchToExistingProjectDatabaseAction(session, getInternalAccessMethod(), getBimServer(), getAuthorization(), roid, destPoid, comment);
User user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
String username = user.getName();
String userUsername = user.getUsername();
LongBranchAction longBranchAction = new LongBranchAction(getBimServer(), username, userUsername, getAuthorization(), action);
getBimServer().getLongActionManager().start(longBranchAction);
if (sync) {
longBranchAction.waitForCompletion();
}
return longBranchAction.getProgressTopic().getKey().getId();
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.database.DatabaseSession in project BIMserver by opensourceBIM.
the class ServiceImpl method getOidByGuid.
public Long getOidByGuid(Long roid, String guid) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BimDatabaseAction<Long> action = new GetOidByGuidDatabaseAction(session, getInternalAccessMethod(), roid, guid);
return session.executeAndCommitAction(action);
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.database.DatabaseSession in project BIMserver by opensourceBIM.
the class ServiceImpl method validateModelChecker.
@Override
public void validateModelChecker(Long oid) throws UserException, ServerException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BimDatabaseAction<Void> action = new ValidateModelCheckerDatabaseAction(getBimServer(), session, getInternalAccessMethod(), oid);
session.executeAndCommitAction(action);
} catch (Exception e) {
handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.database.DatabaseSession in project BIMserver by opensourceBIM.
the class ServiceImpl method sendCompareEmail.
@Override
public void sendCompareEmail(SCompareType sCompareType, Long mcid, Long poid, Long roid1, Long roid2, String address) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
SUser currentUser = getCurrentUser(session);
Revision revision1 = session.get(StorePackage.eINSTANCE.getRevision(), roid1, OldQuery.getDefault());
Revision revision2 = session.get(StorePackage.eINSTANCE.getRevision(), roid2, OldQuery.getDefault());
String senderName = currentUser.getName();
String senderAddress = currentUser.getUsername();
if (!senderAddress.contains("@") || !senderAddress.contains(".")) {
senderAddress = getBimServer().getServerSettingsCache().getServerSettings().getEmailSenderAddress();
}
EmailMessage message = getBimServer().getMailSystem().createMessage();
try {
InternetAddress addressFrom = new InternetAddress(senderAddress);
addressFrom.setPersonal(senderName);
message.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[1];
addressTo[0] = new InternetAddress(address);
message.setRecipients(Message.RecipientType.TO, addressTo);
message.setSubject("BIMserver Model Comparator");
SCompareResult compareResult = compare(roid1, roid2, sCompareType, mcid);
String html = CompareWriter.writeCompareResult(compareResult, revision1.getId(), revision2.getId(), sCompareType, getServiceMap().getServiceInterface().getProjectByPoid(poid), false);
message.setContent(html, "text/html");
message.send();
} catch (AddressException e) {
throw new UserException(e);
} catch (UnsupportedEncodingException e) {
throw new UserException(e);
} catch (MessagingException e) {
throw new UserException(e);
}
} catch (Exception e) {
handleException(e);
} finally {
session.close();
}
}
Aggregations