Search in sources :

Example 31 with IdEObject

use of org.bimserver.emf.IdEObject 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 32 with IdEObject

use of org.bimserver.emf.IdEObject 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 33 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class AbstractSchemaConverter method copy.

@SuppressWarnings("unchecked")
protected IdEObject copy(IdEObject original) throws IfcModelInterfaceException, ObjectAlreadyExistsException {
    if (!((IdEObjectImpl) original).isLoadedOrLoading()) {
        return null;
    }
    if (converted.containsKey(original)) {
        return converted.get(original);
    }
    if (original.eClass().getName().equals("GeometryInfo") || original.eClass().getName().equals("GeometryData") || original.eClass().getName().equals("Vector3f")) {
        return null;
    }
    EClass eClass = (EClass) target.getPackageMetaData().getEPackage().getEClassifier(original.eClass().getName());
    if (eClass == null) {
        LOGGER.info("No class " + original.eClass().getName() + " in " + target.getPackageMetaData().getEPackage().getName());
        return null;
    }
    IdEObject newObject = (IdEObject) eClass.getEPackage().getEFactoryInstance().create(eClass);
    ((IdEObjectImpl) newObject).setOid(original.getOid());
    converted.put(original, newObject);
    if (newObject.eClass().getEAnnotation("wrapped") == null) {
        target.add(newObject.getOid(), newObject);
    }
    for (EStructuralFeature eStructuralFeature : original.eClass().getEAllStructuralFeatures()) {
        EStructuralFeature targetFeature = newObject.eClass().getEStructuralFeature(eStructuralFeature.getName());
        if (targetFeature == null) {
            continue;
        }
        Object get = original.eGet(eStructuralFeature);
        if (eStructuralFeature instanceof EAttribute) {
            if (get instanceof Double) {
                EStructuralFeature doubleStringFeature = original.eClass().getEStructuralFeature("wrappedValueAsString");
                EStructuralFeature targetDoubleStringFeature = newObject.eClass().getEStructuralFeature("wrappedValueAsString");
                if (doubleStringFeature != null && targetDoubleStringFeature != null) {
                    Object doubleString = original.eGet(doubleStringFeature);
                    newObject.eSet(targetDoubleStringFeature, doubleString);
                } else {
                    newObject.eSet(targetFeature, get);
                }
            } else {
                if (eStructuralFeature.getEType() instanceof EEnum) {
                    EEnum targetEnum = (EEnum) targetFeature.getEType();
                    EEnumLiteral newLiteral = targetEnum.getEEnumLiteral(get.toString());
                    if (newLiteral != null) {
                        newObject.eSet(targetFeature, newLiteral.getInstance());
                    }
                } else {
                    if (targetFeature instanceof EAttribute) {
                        newObject.eSet(targetFeature, get);
                    }
                }
            }
        } else if (eStructuralFeature instanceof EReference) {
            if (get == null) {
            } else {
                if (eStructuralFeature.isMany()) {
                    EList<EObject> list = (EList<EObject>) get;
                    AbstractEList<EObject> toList = (AbstractEList<EObject>) newObject.eGet(targetFeature);
                    if (toList != null) {
                        for (Object o : list) {
                            IdEObject ref = (IdEObject) o;
                            if (targetFeature.getEType().isInstance(ref)) {
                                if (converted.containsKey(o)) {
                                    toList.addUnique(converted.get(o));
                                } else {
                                    IdEObject result = copy((IdEObject) o);
                                    if (result != null) {
                                        toList.addUnique(result);
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if (targetFeature.isMany()) {
                        LOGGER.info("Different multiplicity");
                    } else {
                        if (converted.containsKey(get)) {
                            newObject.eSet(targetFeature, converted.get(get));
                        } else {
                            newObject.eSet(targetFeature, copy((IdEObject) get));
                        }
                    }
                }
            }
        }
    }
    return newObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) AbstractEList(org.eclipse.emf.common.util.AbstractEList) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EEnum(org.eclipse.emf.ecore.EEnum) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) EList(org.eclipse.emf.common.util.EList) AbstractEList(org.eclipse.emf.common.util.AbstractEList) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) EReference(org.eclipse.emf.ecore.EReference)

Example 34 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class GetAllWritableProjectsDatabaseAction method execute.

@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getUserByUoid(authorization.getUoid());
    IfcModelInterface projectsModel = getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
    Set<Project> result = new HashSet<Project>();
    for (IdEObject idEObject : projectsModel.getValues()) {
        if (idEObject instanceof Project) {
            Project project = (Project) idEObject;
            if (!project.getName().equals("INT-Store")) {
                if ((user.getUserType() == UserType.ADMIN || (project.getState() == ObjectState.ACTIVE) && authorization.hasRightsOnProjectOrSuperProjects(user, project))) {
                    result.add(project);
                }
            }
        }
    }
    return result;
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) IdEObject(org.bimserver.emf.IdEObject) IfcModelInterface(org.bimserver.emf.IfcModelInterface) HashSet(java.util.HashSet)

Example 35 with IdEObject

use of org.bimserver.emf.IdEObject 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)

Aggregations

IdEObject (org.bimserver.emf.IdEObject)68 List (java.util.List)25 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)25 EClass (org.eclipse.emf.ecore.EClass)20 EReference (org.eclipse.emf.ecore.EReference)18 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)15 UserException (org.bimserver.shared.exceptions.UserException)15 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)14 EList (org.eclipse.emf.common.util.EList)14 EObject (org.eclipse.emf.ecore.EObject)14 ArrayList (java.util.ArrayList)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)12 HashSet (java.util.HashSet)10 IfcModelInterface (org.bimserver.emf.IfcModelInterface)10 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)10 OldQuery (org.bimserver.database.OldQuery)9 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)9 VirtualObject (org.bimserver.shared.VirtualObject)9 EAttribute (org.eclipse.emf.ecore.EAttribute)9 Project (org.bimserver.models.store.Project)8