Search in sources :

Example 1 with CompareResult

use of org.bimserver.models.store.CompareResult in project BIMserver by opensourceBIM.

the class CompareDatabaseAction method execute.

@Override
public CompareResult execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    // bimServer.getCompareCache().getCompareResults(roid1,
    CompareResult compareResults = null;
    // sCompareIdentifier);
    if (compareResults == null) {
        IfcModelInterface model1 = new DownloadDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), roid1, -1, serializerOid, authorization, null).execute();
        IfcModelInterface model2 = new DownloadDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), roid2, -1, serializerOid, authorization, null).execute();
        try {
            compareResults = getModelCompare().compare(model1, model2, sCompareType);
        } catch (ModelCompareException e) {
            LOGGER.error("", e);
            throw new UserException(e);
        }
    // bimServer.getCompareCache().storeResults(roid1, roid2, sCompareType, sCompareIdentifier, compareResults);
    }
    return compareResults;
}
Also used : IfcModelInterface(org.bimserver.emf.IfcModelInterface) ModelCompareException(org.bimserver.plugins.modelcompare.ModelCompareException) UserException(org.bimserver.shared.exceptions.UserException) CompareResult(org.bimserver.models.store.CompareResult)

Example 2 with CompareResult

use of org.bimserver.models.store.CompareResult in project BIMserver by opensourceBIM.

the class DownloadCompareDatabaseAction method execute.

@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    try {
        Revision revision1 = getRevisionByRoid(roid1);
        Revision revision2 = getRevisionByRoid(roid2);
        Project project = revision1.getProject();
        // bimServer.getCompareCache().getCompareResults(roid1,
        CompareResult compareResults = null;
        // roid2, compareType,
        // compareIdentifier);
        IfcModelInterface model1 = new DownloadDatabaseAction(getBimServer(), getDatabaseSession(), getAccessMethod(), roid1, -1, -1, getAuthorization()).execute();
        ModelMerger merger = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid());
        PackageMetaData packageMetaData = model1.getPackageMetaData();
        IfcModelInterface mergedModel = getDatabaseSession().createServerModel(packageMetaData, null);
        try (DatabaseSession secondSession = getBimServer().getDatabase().createSession(OperationType.READ_ONLY)) {
            IfcModelInterface model2 = new DownloadDatabaseAction(getBimServer(), secondSession, getAccessMethod(), roid2, -1, -1, getAuthorization()).execute();
            try {
                compareResults = getModelCompare().compare(model1, model2, compareType);
            } catch (ModelCompareException e) {
                throw new UserException(e);
            }
            // bimServer.getCompareCache().storeResults(roid1, roid2,
            // compareType, compareIdentifier, compareResults);
            mergedModel = merger.merge(project, new IfcModelSet(model1, model2), new ModelHelper(getBimServer().getMetaDataManager(), mergedModel));
        }
        mergedModel.getModelMetaData().setName(project.getName() + "." + revision1.getId() + "." + revision2.getId());
        Set<Long> added = new HashSet<Long>();
        Set<Long> modified = new HashSet<Long>();
        Set<Long> deleted = new HashSet<Long>();
        for (CompareContainer compareContainer : compareResults.getItems()) {
            for (CompareItem compareItem : compareContainer.getItems()) {
                DataObject dataObject = compareItem.getDataObject();
                if (compareItem instanceof ObjectAdded) {
                    added.add(dataObject.getOid());
                } else if (compareItem instanceof ObjectModified) {
                    modified.add(dataObject.getOid());
                } else if (compareItem instanceof ObjectRemoved) {
                    deleted.add(dataObject.getOid());
                }
            }
        }
        EClass ifcColourRgbClass = packageMetaData.getEClass("IfcColourRgb");
        EStructuralFeature nameFeature = ifcColourRgbClass.getEStructuralFeature("Name");
        EStructuralFeature redFeature = ifcColourRgbClass.getEStructuralFeature("Red");
        EStructuralFeature greenFeature = ifcColourRgbClass.getEStructuralFeature("Green");
        EStructuralFeature blueFeature = ifcColourRgbClass.getEStructuralFeature("Blue");
        IdEObject red = mergedModel.createAndAdd(ifcColourRgbClass);
        red.eSet(nameFeature, "red");
        red.eSet(redFeature, 0.5D);
        red.eSet(greenFeature, 0.0D);
        red.eSet(blueFeature, 0.0D);
        IdEObject green = mergedModel.createAndAdd(ifcColourRgbClass);
        green.eSet(nameFeature, "green");
        green.eSet(redFeature, 0D);
        green.eSet(greenFeature, 0.5D);
        green.eSet(blueFeature, 0D);
        IdEObject blue = mergedModel.createAndAdd(ifcColourRgbClass);
        blue.eSet(nameFeature, "blue");
        blue.eSet(redFeature, 0D);
        blue.eSet(greenFeature, 0D);
        blue.eSet(blueFeature, 0.5D);
        for (IdEObject product : mergedModel.getAllWithSubTypes(packageMetaData.getEClass("IfcProduct"))) {
            IdEObject color = null;
            if (added.contains(product.getOid())) {
                color = green;
            } else if (deleted.contains(product.getOid())) {
                color = red;
            } else if (modified.contains(product.getOid())) {
                color = blue;
            }
            if (color != null) {
                setColor(mergedModel, product, color);
            }
        }
        mergedModel.fixOidCounter();
        return mergedModel;
    } catch (IfcModelInterfaceException e) {
        throw new UserException(e);
    } catch (MergeException e) {
        throw new UserException(e);
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) CompareResult(org.bimserver.models.store.CompareResult) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) EClass(org.eclipse.emf.ecore.EClass) MergeException(org.bimserver.plugins.modelmerger.MergeException) CompareContainer(org.bimserver.models.store.CompareContainer) UserException(org.bimserver.shared.exceptions.UserException) ModelMerger(org.bimserver.plugins.modelmerger.ModelMerger) HashSet(java.util.HashSet) ModelHelper(org.bimserver.plugins.ModelHelper) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) ObjectRemoved(org.bimserver.models.store.ObjectRemoved) CompareItem(org.bimserver.models.store.CompareItem) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Project(org.bimserver.models.store.Project) DataObject(org.bimserver.models.store.DataObject) Revision(org.bimserver.models.store.Revision) IfcModelSet(org.bimserver.plugins.IfcModelSet) ObjectAdded(org.bimserver.models.store.ObjectAdded) ModelCompareException(org.bimserver.plugins.modelcompare.ModelCompareException) ObjectModified(org.bimserver.models.store.ObjectModified)

Example 3 with CompareResult

use of org.bimserver.models.store.CompareResult 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(OperationType.READ_ONLY);
    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) ServiceException(org.bimserver.shared.exceptions.ServiceException) 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) PluginException(org.bimserver.shared.exceptions.PluginException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Aggregations

CompareResult (org.bimserver.models.store.CompareResult)3 UserException (org.bimserver.shared.exceptions.UserException)3 DatabaseSession (org.bimserver.database.DatabaseSession)2 IfcModelInterface (org.bimserver.emf.IfcModelInterface)2 ModelCompareException (org.bimserver.plugins.modelcompare.ModelCompareException)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 HashSet (java.util.HashSet)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 CompareDatabaseAction (org.bimserver.database.actions.CompareDatabaseAction)1 IdEObject (org.bimserver.emf.IdEObject)1 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)1 PackageMetaData (org.bimserver.emf.PackageMetaData)1 SCompareResult (org.bimserver.interfaces.objects.SCompareResult)1 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)1 CompareContainer (org.bimserver.models.store.CompareContainer)1