Search in sources :

Example 6 with DataObject

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

the class GetDataObjectsByTypeDatabaseAction method execute.

@Override
public List<DataObject> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    EClass eClass = getDatabaseSession().getEClassForName(packageName, className);
    Revision virtualRevision = getRevisionByRoid(roid);
    if (virtualRevision == null) {
        throw new UserException("No revision with roid " + roid + " found");
    }
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    IfcModelSet ifcModelSet = new IfcModelSet();
    pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
    PackageMetaData lastPackageMetaData = null;
    Project project = virtualRevision.getProject();
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        int highestStopId = findHighestStopRid(project, concreteRevision);
        OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), -1, null, Deep.NO, highestStopId);
        lastPackageMetaData = packageMetaData;
        IfcModelInterface subModel = getDatabaseSession().getAllOfType(packageMetaData.getEPackage().getName(), className, query);
        subModel.getModelMetaData().setDate(concreteRevision.getDate());
        ifcModelSet.add(subModel);
    }
    IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
    if (ifcModelSet.size() > 1) {
        try {
            ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
        } catch (MergeException e) {
            throw new UserException(e);
        }
    } else {
        ifcModel = ifcModelSet.iterator().next();
    }
    List<DataObject> dataObjects = new ArrayList<DataObject>();
    for (Long oid : new HashSet<>(ifcModel.keySet())) {
        EObject eObject = ifcModel.get(oid);
        if (eClass.isInstance(eObject)) {
            DataObject dataObject = StoreFactory.eINSTANCE.createDataObject();
            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.setGuid("");
                dataObject.setName("");
            }
            if (!flat) {
                GetDataObjectByOidDatabaseAction.fillDataObject(ifcModel.getObjects(), eObject, dataObject);
            }
            dataObjects.add(dataObject);
        }
    }
    return dataObjects;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ServerIfcModel(org.bimserver.ServerIfcModel) HashMap(java.util.HashMap) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) ArrayList(java.util.ArrayList) EClass(org.eclipse.emf.ecore.EClass) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) EObject(org.eclipse.emf.ecore.EObject) UserException(org.bimserver.shared.exceptions.UserException) HashSet(java.util.HashSet) ModelHelper(org.bimserver.plugins.ModelHelper) PackageMetaData(org.bimserver.emf.PackageMetaData) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) DataObject(org.bimserver.models.store.DataObject) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) IfcModelSet(org.bimserver.plugins.IfcModelSet)

Example 7 with DataObject

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

the class GetDataObjectsDatabaseAction method execute.

@Override
public List<DataObject> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision virtualRevision = getRevisionByRoid(roid);
    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()) {
        int highestStopId = findHighestStopRid(concreteRevision.getProject(), concreteRevision);
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        lastPackageMetaData = packageMetaData;
        IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
        OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.YES, highestStopId);
        getDatabaseSession().getMap(subModel, query);
        subModel.getModelMetaData().setDate(concreteRevision.getDate());
        ifcModelSet.add(subModel);
    }
    IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
    try {
        ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(virtualRevision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
    } catch (MergeException e) {
        throw new UserException(e);
    }
    List<DataObject> dataObjects = new ArrayList<DataObject>();
    for (Long oid : ifcModel.keySet()) {
        EObject eObject = ifcModel.get(oid);
        if (eObject.eClass().getEAnnotation("hidden") == null) {
            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.setGuid("");
                dataObject.setName("");
            }
            GetDataObjectByOidDatabaseAction.fillDataObject(ifcModel.getObjects(), eObject, dataObject);
            dataObjects.add(dataObject);
        }
    }
    return dataObjects;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ServerIfcModel(org.bimserver.ServerIfcModel) 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) ArrayList(java.util.ArrayList) OldQuery(org.bimserver.database.OldQuery) ServerIfcModel(org.bimserver.ServerIfcModel) 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) 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