use of org.bimserver.interfaces.objects.SCompareResult 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();
}
}
use of org.bimserver.interfaces.objects.SCompareResult in project BIMserver by opensourceBIM.
the class ServiceImpl method compare.
@Override
public SCompareResult compare(Long roid1, Long roid2, SCompareType sCompareType, Long mcid) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BimDatabaseAction<CompareResult> action = new CompareDatabaseAction(getBimServer(), session, getInternalAccessMethod(), getAuthorization(), -1, roid1, roid2, getBimServer().getSConverter().convertFromSObject(sCompareType), mcid);
return getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
Aggregations