Search in sources :

Example 11 with IdEObjectImpl

use of org.bimserver.emf.IdEObjectImpl 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 12 with IdEObjectImpl

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

the class ClientIfcModel method loadExplicit.

public void loadExplicit(long oid) {
    try {
        IdEObjectImpl idEObjectImpl = (IdEObjectImpl) super.get(oid);
        if (idEObjectImpl != null && !idEObjectImpl.isLoadedOrLoading()) {
            idEObjectImpl.setLoadingState(State.LOADING);
            modelState = ModelState.LOADING;
            Query query = new Query(getPackageMetaData());
            QueryPart queryPart = query.createQueryPart();
            queryPart.addOid(oid);
            JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(getPackageMetaData());
            long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(roid), converter.toJson(query).toString(), getJsonSerializerOid(), false);
            waitForDonePreparing(topicId);
            processDownload(topicId);
            bimServerClient.getServiceInterface().cleanupLongAction(topicId);
            idEObjectImpl.setLoadingState(State.LOADED);
            modelState = ModelState.NONE;
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) Query(org.bimserver.database.queries.om.Query) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryException(org.bimserver.database.queries.om.QueryException) EOFException(java.io.EOFException) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) UserException(org.bimserver.shared.exceptions.UserException) ServiceException(org.bimserver.shared.exceptions.ServiceException) ObjectAlreadyExistsException(org.bimserver.plugins.ObjectAlreadyExistsException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IOException(java.io.IOException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException)

Example 13 with IdEObjectImpl

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

the class DatabaseSession method createInternal.

private IdEObjectImpl createInternal(EClass eClass, QueryInterface queryInterface) {
    IdEObjectImpl object = (IdEObjectImpl) eClass.getEPackage().getEFactoryInstance().create(eClass);
    object.setQueryInterface(queryInterface);
    return object;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl)

Example 14 with IdEObjectImpl

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

the class DatabaseSession method readWrappedValue.

private IdEObject readWrappedValue(EStructuralFeature feature, ByteBuffer buffer, EClass eClass, QueryInterface query) {
    EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature("wrappedValue");
    Object primitiveValue = readPrimitiveValue(eStructuralFeature.getEType(), buffer, query);
    IdEObject eObject = createInternal(eClass, query);
    // We don't want to go lazy load
    ((IdEObjectImpl) eObject).setLoaded();
    // this
    eObject.eSet(eStructuralFeature, primitiveValue);
    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
        EStructuralFeature strFeature = eClass.getEStructuralFeature("wrappedValueAsString");
        Object stringVal = readPrimitiveValue(EcorePackage.eINSTANCE.getEString(), buffer, query);
        eObject.eSet(strFeature, stringVal);
    }
    return eObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject)

Example 15 with IdEObjectImpl

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

the class DownloadByNewJsonQueryDatabaseAction method convertWrapped.

private IdEObject convertWrapped(Revision revision, IfcModelInterface ifcModel, HashMapWrappedVirtualObject hashMapWrappedVirtualObject) throws IfcModelInterfaceException {
    IdEObject embeddedObject = ifcModel.create(hashMapWrappedVirtualObject.eClass());
    ((IdEObjectImpl) embeddedObject).setOid(-1);
    ((IdEObjectImpl) embeddedObject).setPid(revision.getProject().getId());
    for (EAttribute eAttribute : hashMapWrappedVirtualObject.eClass().getEAllAttributes()) {
        embeddedObject.eSet(eAttribute, hashMapWrappedVirtualObject.eGet(eAttribute));
    }
    return embeddedObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) EAttribute(org.eclipse.emf.ecore.EAttribute) IdEObject(org.bimserver.emf.IdEObject)

Aggregations

IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)23 IdEObject (org.bimserver.emf.IdEObject)16 EObject (org.eclipse.emf.ecore.EObject)10 EClass (org.eclipse.emf.ecore.EClass)8 UserException (org.bimserver.shared.exceptions.UserException)7 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)7 HashMap (java.util.HashMap)6 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)6 EAttribute (org.eclipse.emf.ecore.EAttribute)6 EReference (org.eclipse.emf.ecore.EReference)6 IfcModelInterface (org.bimserver.emf.IfcModelInterface)5 IfcRoot (org.bimserver.models.ifc2x3tc1.IfcRoot)5 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)5 AbstractEList (org.eclipse.emf.common.util.AbstractEList)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 OldQuery (org.bimserver.database.OldQuery)4 QueryException (org.bimserver.database.queries.om.QueryException)4 PackageMetaData (org.bimserver.emf.PackageMetaData)4