Search in sources :

Example 61 with IdEObject

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

the class RevisionMerger method copyAttributesGuidObjectsAndAddNewObjects.

private void copyAttributesGuidObjectsAndAddNewObjects() throws IfcModelInterfaceException, ObjectAlreadyExistsException {
    for (IdEObject idEObject : newModel.getValues()) {
        if (idEObject instanceof IfcRoot) {
            IfcRoot ifcRoot = (IfcRoot) idEObject;
            String guid = ifcRoot.getGlobalId();
            if (resultModel.containsGuid(guid)) {
                // LOGGER.info("Updating attributes for object " + idEObject.eClass().getName() + " " + guid);
                IfcRoot oldObject = (IfcRoot) resultModel.getByGuid(guid);
                for (EAttribute eAttribute : idEObject.eClass().getEAllAttributes()) {
                    Object newValue = idEObject.eGet(eAttribute);
                    oldObject.eSet(eAttribute, newValue);
                }
            } else {
                // LOGGER.info("Adding new GUID object " + idEObject.eClass().getName() + " " + guid);
                IdEObject newObject = (IdEObject) idEObject.eClass().getEPackage().getEFactoryInstance().create(idEObject.eClass());
                ((IdEObjectImpl) newObject).setOid(idEObject.getOid());
                ((IfcRoot) newObject).setGlobalId(newGuid(guid));
                for (EAttribute eAttribute : newObject.eClass().getEAllAttributes()) {
                    newObject.eSet(eAttribute, idEObject.eGet(eAttribute));
                }
                resultModel.add(newObject.getOid(), 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) IdEObject(org.bimserver.emf.IdEObject)

Example 62 with IdEObject

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

the class RevisionMerger method cleanupUnmodified.

@SuppressWarnings("rawtypes")
public void cleanupUnmodified() {
    Iterator<Long> iterator = resultModel.keySet().iterator();
    while (iterator.hasNext()) {
        Long oid = iterator.next();
        IdEObject idEObject = resultModel.get(oid);
        IdEObject originalObject = oldModel.get(oid);
        if (originalObject != null) {
            boolean objectChanged = false;
            for (EAttribute eAttribute : idEObject.eClass().getEAllAttributes()) {
                Object value = idEObject.eGet(eAttribute);
                Object originalValue = originalObject.eGet(eAttribute);
                if (((value == null && originalValue != null) || (value != null && originalValue == null))) {
                    objectChanged = true;
                    continue;
                }
                if (!(value == null && originalValue == null) && !value.equals(originalValue)) {
                    objectChanged = true;
                    continue;
                }
            }
            if (!objectChanged) {
                for (EReference eReference : idEObject.eClass().getEAllReferences()) {
                    if (eReference.isMany()) {
                        List list = (List) idEObject.eGet(eReference);
                        List originalList = (List) originalObject.eGet(eReference);
                        if (list.size() != originalList.size()) {
                            objectChanged = true;
                            continue;
                        }
                        for (int i = 0; i < list.size(); i++) {
                            IdEObject referencedObject = (IdEObject) list.get(i);
                            IdEObject originalReferencedObject = (IdEObject) originalList.get(i);
                            if ((referencedObject == null && originalReferencedObject != null) || (referencedObject != null && originalReferencedObject == null)) {
                                objectChanged = true;
                                continue;
                            }
                            if (!(referencedObject == null && originalReferencedObject == null) && referencedObject.getOid() != originalReferencedObject.getOid()) {
                                objectChanged = true;
                                continue;
                            }
                        }
                    } else {
                        IdEObject referencedObject = (IdEObject) idEObject.eGet(eReference);
                        IdEObject originalReferencedObject = (IdEObject) originalObject.eGet(eReference);
                        if ((referencedObject == null && originalReferencedObject != null) || (referencedObject != null && originalReferencedObject == null)) {
                            objectChanged = true;
                            continue;
                        }
                        if (!(referencedObject == null && originalReferencedObject == null) && referencedObject.getOid() != originalReferencedObject.getOid()) {
                            objectChanged = true;
                            continue;
                        }
                    }
                }
            }
            if (!objectChanged) {
                iterator.remove();
            }
        }
    }
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) IdEObject(org.bimserver.emf.IdEObject) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 63 with IdEObject

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

the class RevisionMerger method updateReferences.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateReferences() {
    for (IdEObject idEObject : newModel.getValues()) {
        if (idEObject instanceof IfcRoot) {
            String guid = ((IfcRoot) idEObject).getGlobalId();
            IfcRoot oldObject = (IfcRoot) resultModel.getByGuid(guid);
            for (EReference eReference : idEObject.eClass().getEAllReferences()) {
                Object referencedObject = idEObject.eGet(eReference);
                if (referencedObject instanceof IfcRoot) {
                    String referencedGuid = ((IfcRoot) referencedObject).getGlobalId();
                    IfcRoot newObject = (IfcRoot) resultModel.getByGuid(referencedGuid);
                    oldObject.eSet(eReference, newObject);
                // LOGGER.info("Fixing reference from " + guid + " to " + referencedGuid);
                } else if (referencedObject instanceof List) {
                    List referencedList = (List) referencedObject;
                    List oldReferencedList = (List) oldObject.eGet(eReference);
                    for (Object object : referencedList) {
                        if (object instanceof IfcRoot) {
                            IfcRoot referencedItem = (IfcRoot) object;
                            String itemGuid = referencedItem.getGlobalId();
                            oldReferencedList.add(resultModel.getByGuid(itemGuid));
                        // LOGGER.info("Fixing list reference from " + guid + " to " + itemGuid);
                        }
                    }
                }
            }
        }
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 64 with IdEObject

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

the class RevisionMerger method fixExplicitNullReferences.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void fixExplicitNullReferences() {
    for (IdEObject idEObject : newModel.getValues()) {
        if (idEObject instanceof IfcRoot) {
            String guid = ((IfcRoot) idEObject).getGlobalId();
            for (EReference eReference : idEObject.eClass().getEAllReferences()) {
                if (eReference.isMany()) {
                    List list = (List) idEObject.eGet(eReference);
                    List oldList = (List) resultModel.getByGuid(guid).eGet(eReference);
                    Set<Object> guidsToRemove = new HashSet<Object>();
                    for (Object o : oldList) {
                        if (o instanceof IfcRoot) {
                            String referredGuid = ((IfcRoot) o).getGlobalId();
                            if (newModel.containsGuid(referredGuid)) {
                                boolean found = false;
                                for (Object q : list) {
                                    if (q instanceof IfcRoot) {
                                        String qGuid = ((IfcRoot) q).getGlobalId();
                                        if (qGuid.equals(referredGuid)) {
                                            found = true;
                                            break;
                                        }
                                    }
                                }
                                if (!found) {
                                    guidsToRemove.add(referredGuid);
                                }
                            }
                        }
                    }
                    if (!guidsToRemove.isEmpty()) {
                        // LOGGER.info("Removing list references");
                        oldList.removeAll(guidsToRemove);
                    }
                } else {
                    if (idEObject.eGet(eReference) == null) {
                        Object eGet = resultModel.getByGuid(guid).eGet(eReference);
                        if (eGet != null) {
                            if (eGet instanceof IfcRoot) {
                                String oldGuid = ((IfcRoot) eGet).getGlobalId();
                                if (newModel.containsGuid(oldGuid)) {
                                    // LOGGER.info("Settings explicit null reference");
                                    resultModel.getByGuid(guid).eSet(eReference, null);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) List(java.util.List) IdEObject(org.bimserver.emf.IdEObject) EReference(org.eclipse.emf.ecore.EReference) HashSet(java.util.HashSet)

Example 65 with IdEObject

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

the class ReferenceCounter method updateReferences.

@SuppressWarnings("rawtypes")
public void updateReferences() {
    references.clear();
    for (IdEObject idEObject : ifcModel.getValues()) {
        for (EReference eReference : idEObject.eClass().getEAllReferences()) {
            if (eReference.isMany()) {
                List list = (List) idEObject.eGet(eReference);
                for (Object o : list) {
                    if (!references.containsKey(o)) {
                        references.put((IdEObject) o, new HashSet<Reference>());
                    }
                    references.get(o).add(new MultiReference(idEObject, (IdEObject) o, eReference));
                }
            } else {
                Object o = idEObject.eGet(eReference);
                if (!references.containsKey(o)) {
                    references.put((IdEObject) o, new HashSet<Reference>());
                }
                references.get(o).add(new SingleReference(idEObject, (IdEObject) o, eReference));
            }
        }
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) EReference(org.eclipse.emf.ecore.EReference) List(java.util.List) AbstractEList(org.eclipse.emf.common.util.AbstractEList) IdEObject(org.bimserver.emf.IdEObject) 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