Search in sources :

Example 1 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.

the class RevisionMerger method fixNonGuidObjects.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void fixNonGuidObjects() throws IfcModelInterfaceException {
    Set<List> clearedLists = new HashSet<List>();
    for (IdEObject idEObject : newModel.getValues()) {
        if (idEObject instanceof IfcRoot) {
            String guid = ((IfcRoot) idEObject).getGlobalId();
            for (EReference eReference : idEObject.eClass().getEAllReferences()) {
                Object referencedObject = idEObject.eGet(eReference);
                if (eReference.isMany()) {
                    List list = (List) referencedObject;
                    List newList = (List) resultModel.getByGuid(guid).eGet(eReference);
                    boolean listIsCleared = false;
                    for (Object o : list) {
                        if (!(o instanceof IfcRoot) && !(o instanceof IfcGloballyUniqueId)) {
                            if (!listIsCleared) {
                                newList.clear();
                                listIsCleared = true;
                            }
                            IdEObject referencedIDEObject = (IdEObject) o;
                            if (resultModel.contains(referencedIDEObject.getOid())) {
                                newList.add(resultModel.get(referencedIDEObject.getOid()));
                            } else {
                                IdEObject smartCopy = copy(resultModel, referencedIDEObject, true);
                                newList.add(smartCopy);
                            }
                        }
                    }
                } else {
                    if (referencedObject == null) {
                        if (resultModel.getByGuid(guid).eGet(eReference) != null && eReference.getEOpposite() != null) {
                            IdEObject x = (IdEObject) resultModel.getByGuid(guid).eGet(eReference);
                            if (eReference.getEOpposite().isMany()) {
                                List l = (List) x.eGet(eReference.getEOpposite());
                                if (!clearedLists.contains(l)) {
                                    clearedLists.add(l);
                                    l.clear();
                                }
                            } else {
                                x.eSet(eReference.getEOpposite(), null);
                            }
                        }
                        resultModel.getByGuid(guid).eSet(eReference, null);
                    } else {
                        if (!(referencedObject instanceof IfcRoot) && !(referencedObject instanceof IfcGloballyUniqueId)) {
                            IdEObject referencedIDEObject = (IdEObject) referencedObject;
                            if (resultModel.contains(referencedIDEObject.getOid())) {
                                if (resultModel.getByGuid(guid).eGet(eReference) != null && eReference.getEOpposite() != null) {
                                    IdEObject x = (IdEObject) resultModel.getByGuid(guid).eGet(eReference);
                                    if (eReference.getEOpposite().isMany()) {
                                        List l = (List) x.eGet(eReference.getEOpposite());
                                        if (!clearedLists.contains(l)) {
                                            clearedLists.add(l);
                                            l.clear();
                                        }
                                    } else {
                                        x.eSet(eReference.getEOpposite(), null);
                                    }
                                }
                                resultModel.getByGuid(guid).eSet(eReference, resultModel.get(referencedIDEObject.getOid()));
                            } else {
                                IdEObject smartCopy = copy(resultModel, referencedIDEObject, true);
                                if (resultModel.getByGuid(guid).eGet(eReference) != null && eReference.getEOpposite() != null) {
                                    IdEObject re = (IdEObject) resultModel.getByGuid(guid).eGet(eReference);
                                    if (eReference.getEOpposite().isMany()) {
                                        List l = (List) re.eGet(eReference.getEOpposite());
                                        if (!clearedLists.contains(l)) {
                                            clearedLists.add(l);
                                            l.clear();
                                        }
                                    } else {
                                        re.eSet(eReference.getEOpposite(), null);
                                    }
                                }
                                resultModel.getByGuid(guid).eSet(eReference, smartCopy);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) IfcGloballyUniqueId(org.bimserver.models.ifc2x3tc1.IfcGloballyUniqueId) List(java.util.List) IdEObject(org.bimserver.emf.IdEObject) EReference(org.eclipse.emf.ecore.EReference) HashSet(java.util.HashSet)

Example 2 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot in project BIMserver by opensourceBIM.

the class RevisionMerger method copy.

@SuppressWarnings({ "unchecked", "rawtypes" })
private IdEObject copy(IfcModel target, IdEObject idEObject, boolean limitToNonGuids) throws IfcModelInterfaceException {
    if (target.contains(idEObject.getOid())) {
        return target.get(idEObject.getOid());
    }
    IdEObject newObject = (IdEObject) idEObject.eClass().getEPackage().getEFactoryInstance().create(idEObject.eClass());
    ((IdEObjectImpl) newObject).setOid(idEObject.getOid());
    if (newObject.getOid() != -1) {
        target.add(newObject.getOid(), newObject);
    }
    for (EAttribute eAttribute : newObject.eClass().getEAllAttributes()) {
        newObject.eSet(eAttribute, idEObject.eGet(eAttribute));
    }
    for (EReference eReference : newObject.eClass().getEAllReferences()) {
        Object referencedObject = idEObject.eGet(eReference);
        if (referencedObject instanceof IdEObject) {
            IdEObject refEObject = (IdEObject) referencedObject;
            if (!limitToNonGuids || !(referencedObject instanceof IfcRoot) && !(referencedObject instanceof IfcGloballyUniqueId)) {
                newObject.eSet(eReference, copy(target, refEObject, limitToNonGuids));
            }
        } else if (referencedObject instanceof List) {
            List list = (List) referencedObject;
            List newList = (List) newObject.eGet(eReference);
            for (Object o : list) {
                if (!limitToNonGuids || !(o instanceof IfcRoot) && !(o instanceof IfcGloballyUniqueId)) {
                    IdEObject listObject = (IdEObject) o;
                    IdEObject smartCopy = copy(target, listObject, limitToNonGuids);
                    if (!newList.contains(smartCopy)) {
                        newList.add(smartCopy);
                    }
                }
            }
        }
    }
    return newObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) EAttribute(org.eclipse.emf.ecore.EAttribute) IdEObject(org.bimserver.emf.IdEObject) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) IfcGloballyUniqueId(org.bimserver.models.ifc2x3tc1.IfcGloballyUniqueId) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 3 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot 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 4 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot 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)

Example 5 with IfcRoot

use of org.bimserver.models.ifc2x3tc1.IfcRoot 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)

Aggregations

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