Search in sources :

Example 1 with SCompareResult

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();
    }
}
Also used : EmailMessage(org.bimserver.mail.EmailMessage) InternetAddress(javax.mail.internet.InternetAddress) DatabaseSession(org.bimserver.database.DatabaseSession) MessagingException(javax.mail.MessagingException) SUser(org.bimserver.interfaces.objects.SUser) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) SRevision(org.bimserver.interfaces.objects.SRevision) Revision(org.bimserver.models.store.Revision) CheckinRevision(org.bimserver.models.store.CheckinRevision) SExtendedDataAddedToRevision(org.bimserver.interfaces.objects.SExtendedDataAddedToRevision) AddressException(javax.mail.internet.AddressException) SCompareResult(org.bimserver.interfaces.objects.SCompareResult) UserException(org.bimserver.shared.exceptions.UserException)

Example 2 with SCompareResult

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();
    }
}
Also used : CompareDatabaseAction(org.bimserver.database.actions.CompareDatabaseAction) DatabaseSession(org.bimserver.database.DatabaseSession) CompareResult(org.bimserver.models.store.CompareResult) SCompareResult(org.bimserver.interfaces.objects.SCompareResult) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

Aggregations

IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 MessagingException (javax.mail.MessagingException)2 AddressException (javax.mail.internet.AddressException)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 DatabaseSession (org.bimserver.database.DatabaseSession)2 SCompareResult (org.bimserver.interfaces.objects.SCompareResult)2 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)2 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)2 SerializerException (org.bimserver.plugins.serializers.SerializerException)2 ServerException (org.bimserver.shared.exceptions.ServerException)2 UserException (org.bimserver.shared.exceptions.UserException)2 BcfException (org.opensourcebim.bcf.BcfException)2 InternetAddress (javax.mail.internet.InternetAddress)1 CompareDatabaseAction (org.bimserver.database.actions.CompareDatabaseAction)1 SExtendedDataAddedToRevision (org.bimserver.interfaces.objects.SExtendedDataAddedToRevision)1 SRevision (org.bimserver.interfaces.objects.SRevision)1 SUser (org.bimserver.interfaces.objects.SUser)1 EmailMessage (org.bimserver.mail.EmailMessage)1