Search in sources :

Example 1 with DataObject

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

the class LowLevelServiceImpl method getDataObjectByGuid.

@Override
public SDataObject getDataObjectByGuid(Long roid, String guid) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        BimDatabaseAction<DataObject> action = new GetDataObjectByGuidDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, guid, getAuthorization());
        SDataObject dataObject = getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
        return dataObject;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) DatabaseSession(org.bimserver.database.DatabaseSession) GetDataObjectByGuidDatabaseAction(org.bimserver.database.actions.GetDataObjectByGuidDatabaseAction) SDataObject(org.bimserver.interfaces.objects.SDataObject) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 2 with DataObject

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

the class LowLevelServiceImpl method getDataObjectByOid.

@Override
public SDataObject getDataObjectByOid(Long roid, Long oid) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        BimDatabaseAction<DataObject> action = new GetDataObjectByOidDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, oid, getAuthorization());
        SDataObject dataObject = getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
        return dataObject;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : GetDataObjectByOidDatabaseAction(org.bimserver.database.actions.GetDataObjectByOidDatabaseAction) SDataObject(org.bimserver.interfaces.objects.SDataObject) DataObject(org.bimserver.models.store.DataObject) DatabaseSession(org.bimserver.database.DatabaseSession) SDataObject(org.bimserver.interfaces.objects.SDataObject) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 3 with DataObject

use of org.bimserver.models.store.DataObject 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(), null).execute();
        IfcModelInterface model2 = new DownloadDatabaseAction(getBimServer(), getDatabaseSession(), getAccessMethod(), roid2, -1, -1, getAuthorization(), null).execute();
        try {
            compareResults = getModelCompare().compare(model1, model2, compareType);
        } catch (ModelCompareException e) {
            throw new UserException(e);
        }
        // bimServer.getCompareCache().storeResults(roid1, roid2,
        // compareType, compareIdentifier, compareResults);
        ModelMerger merger = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid());
        PackageMetaData packageMetaData = model1.getPackageMetaData();
        IfcModelInterface mergedModel = new ServerIfcModel(packageMetaData, null, getDatabaseSession());
        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 : ServerIfcModel(org.bimserver.ServerIfcModel) 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 4 with DataObject

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

the class GetDataObjectByOidDatabaseAction method fillDataObject.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void fillDataObject(BiMap<? extends Long, ? extends EObject> mapResult, EObject eObject, DataObject dataObject) {
    for (EStructuralFeature eStructuralFeature : eObject.eClass().getEAllStructuralFeatures()) {
        Object eGet = eObject.eGet(eStructuralFeature);
        if (eStructuralFeature.getEAnnotation("hidden") == null) {
            if (eStructuralFeature instanceof EAttribute) {
                if (eStructuralFeature.isMany()) {
                    ListDataValue listDataValue = StoreFactory.eINSTANCE.createListDataValue();
                    listDataValue.setFieldName(eStructuralFeature.getName());
                    dataObject.getValues().add(listDataValue);
                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                        EStructuralFeature asStringFeature = eObject.eClass().getEStructuralFeature(eStructuralFeature.getName() + "AsString");
                        List list = (List) eObject.eGet(asStringFeature);
                        for (Object o : list) {
                            SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                            dataValue.setStringValue(o.toString());
                            listDataValue.getValues().add(dataValue);
                        }
                    } else {
                        if (eGet != null) {
                            List list = (List) eGet;
                            for (Object o : list) {
                                SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                                if (eGet != null) {
                                    dataValue.setStringValue(o.toString());
                                } else {
                                    dataValue.setStringValue(null);
                                }
                                listDataValue.getValues().add(dataValue);
                            }
                        }
                    }
                } else {
                    SimpleDataValue dataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                    if (eObject.eIsSet(eStructuralFeature)) {
                        if (eGet instanceof byte[]) {
                            dataValue.setStringValue(new String(((byte[]) eGet), Charsets.UTF_8));
                        } else {
                            dataValue.setStringValue(eGet.toString());
                        }
                    } else {
                        dataValue.setStringValue(null);
                    }
                    dataValue.setFieldName(eStructuralFeature.getName());
                    dataObject.getValues().add(dataValue);
                }
            } else if (eStructuralFeature instanceof EReference) {
                if (eStructuralFeature.isMany()) {
                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
                        List list = (List) eObject.eGet(eObject.eClass().getEStructuralFeature(eStructuralFeature.getName() + "AsString"));
                        ListDataValue dataValue = StoreFactory.eINSTANCE.createListDataValue();
                        dataValue.setFieldName(eStructuralFeature.getName());
                        dataObject.getValues().add(dataValue);
                        for (Object o : list) {
                            SimpleDataValue simpleDataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                            simpleDataValue.setStringValue(o.toString());
                            dataValue.getValues().add(simpleDataValue);
                        }
                    } else {
                        EList<? extends EObject> list = (EList<EObject>) eGet;
                        ListDataValue dataValue = StoreFactory.eINSTANCE.createListDataValue();
                        dataObject.getValues().add(dataValue);
                        dataValue.setFieldName(eStructuralFeature.getName());
                        for (EObject item : list) {
                            if (item.eClass().getEAnnotation("wrapped") != null) {
                                EObject referenceEObject = item;
                                SimpleDataValue simpleDataValue = StoreFactory.eINSTANCE.createSimpleDataValue();
                                simpleDataValue.setStringValue(referenceEObject.eGet(referenceEObject.eClass().getEStructuralFeature("wrappedValue")).toString());
                                dataValue.getValues().add(simpleDataValue);
                            } else {
                                Long oid = ((IdEObject) item).getOid();
                                ReferenceDataValue referenceDataValue = StoreFactory.eINSTANCE.createReferenceDataValue();
                                if (item instanceof IfcRoot) {
                                    IfcRoot ifcRoot = (IfcRoot) item;
                                    String guid = ifcRoot.getGlobalId();
                                    referenceDataValue.setGuid(guid);
                                }
                                referenceDataValue.setTypeName(item.eClass().getName());
                                ((IdEObjectImpl) referenceDataValue).setOid(oid);
                                dataValue.getValues().add(referenceDataValue);
                            }
                        }
                    }
                } else {
                    EObject eObject2 = (EObject) eGet;
                    if (eObject2 != null) {
                        if (eObject2.eClass().getEAnnotation("wrapped") != null) {
                            EObject referenceEObject = (EObject) eGet;
                            SimpleDataValue e = StoreFactory.eINSTANCE.createSimpleDataValue();
                            EStructuralFeature wrappedValueFeature = referenceEObject.eClass().getEStructuralFeature("wrappedValue");
                            Object eGet2 = referenceEObject.eGet(wrappedValueFeature);
                            // } else {
                            if (eGet2 != null) {
                                e.setStringValue(eGet2.toString());
                            } else {
                                e.setStringValue(null);
                            }
                            // }
                            e.setFieldName(eStructuralFeature.getName());
                            dataObject.getValues().add(e);
                        } else {
                            Long oid = ((IdEObject) eObject2).getOid();
                            ReferenceDataValue reference = StoreFactory.eINSTANCE.createReferenceDataValue();
                            if (eObject2 instanceof IfcRoot) {
                                IfcRoot ifcRoot = (IfcRoot) eObject2;
                                String guid = ifcRoot.getGlobalId();
                                reference.setGuid(guid);
                            }
                            reference.setTypeName(eObject2.eClass().getName());
                            ((IdEObjectImpl) reference).setOid(oid);
                            reference.setFieldName(eStructuralFeature.getName());
                            dataObject.getValues().add(reference);
                        }
                    }
                }
            }
        }
    }
}
Also used : ListDataValue(org.bimserver.models.store.ListDataValue) SimpleDataValue(org.bimserver.models.store.SimpleDataValue) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EAttribute(org.eclipse.emf.ecore.EAttribute) EList(org.eclipse.emf.common.util.EList) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) ReferenceDataValue(org.bimserver.models.store.ReferenceDataValue) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) DataObject(org.bimserver.models.store.DataObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 5 with DataObject

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

the class GetDataObjectByOidDatabaseAction method execute.

@Override
public DataObject execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision virtualRevision = getRevisionByRoid(roid);
    EObject eObject = null;
    IfcModelSet ifcModelSet = new IfcModelSet();
    PackageMetaData lastPackageMetaData = null;
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        lastPackageMetaData = packageMetaData;
        IfcModel subModel = new BasicIfcModel(packageMetaData, pidRoidMap);
        int highestStopId = findHighestStopRid(concreteRevision.getProject(), concreteRevision);
        OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.NO, highestStopId);
        eObject = getDatabaseSession().get(null, oid, subModel, query);
        subModel.getModelMetaData().setDate(concreteRevision.getDate());
        ifcModelSet.add(subModel);
        if (eObject != null) {
            break;
        }
    }
    IfcModelInterface ifcModel = new BasicIfcModel(lastPackageMetaData, pidRoidMap);
    if (ifcModelSet.size() > 1) {
        try {
            ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(virtualRevision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
        } catch (MergeException e) {
            throw new UserException(e);
        }
    } else {
        ifcModel = ifcModelSet.iterator().next();
    }
    if (eObject == null) {
        throw new UserException("Object not found in this project/revision");
    }
    DataObject dataObject = null;
    if (eObject instanceof IfcRoot) {
        IfcRoot ifcRoot = (IfcRoot) eObject;
        String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
        String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
        dataObject = StoreFactory.eINSTANCE.createDataObject();
        dataObject.setType(eObject.eClass().getName());
        ((IdEObjectImpl) dataObject).setOid(oid);
        dataObject.setGuid(guid);
        dataObject.setName(name);
    } else {
        dataObject = StoreFactory.eINSTANCE.createDataObject();
        dataObject.setType(eObject.eClass().getName());
        ((IdEObjectImpl) dataObject).setOid(oid);
        dataObject.setName("");
        dataObject.setGuid("");
    }
    fillDataObject(ifcModel.getObjects(), eObject, dataObject);
    return dataObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ModelHelper(org.bimserver.plugins.ModelHelper) HashMap(java.util.HashMap) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) OldQuery(org.bimserver.database.OldQuery) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) IfcModel(org.bimserver.ifc.IfcModel) DataObject(org.bimserver.models.store.DataObject) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) IfcModelSet(org.bimserver.plugins.IfcModelSet) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

DataObject (org.bimserver.models.store.DataObject)7 UserException (org.bimserver.shared.exceptions.UserException)6 IfcModelInterface (org.bimserver.emf.IfcModelInterface)4 PackageMetaData (org.bimserver.emf.PackageMetaData)4 IfcRoot (org.bimserver.models.ifc2x3tc1.IfcRoot)4 Revision (org.bimserver.models.store.Revision)4 IfcModelSet (org.bimserver.plugins.IfcModelSet)4 ModelHelper (org.bimserver.plugins.ModelHelper)4 MergeException (org.bimserver.plugins.modelmerger.MergeException)4 EObject (org.eclipse.emf.ecore.EObject)4 HashMap (java.util.HashMap)3 ServerIfcModel (org.bimserver.ServerIfcModel)3 OldQuery (org.bimserver.database.OldQuery)3 IdEObject (org.bimserver.emf.IdEObject)3 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)3 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 DatabaseSession (org.bimserver.database.DatabaseSession)2