Search in sources :

Example 31 with PackageMetaData

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

the class RemoveAttributeChange method execute.

@SuppressWarnings("rawtypes")
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    if (transaction.getDatabaseSession().getEClassForOid(oid).getName().equals("IfcFurnishingElement")) {
        System.out.println();
    }
    HashMapVirtualObject object = transaction.get(oid);
    if (object == null) {
        Query query = new Query(packageMetaData);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addOid(oid);
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
        object = queryObjectProvider.next();
        transaction.updated(object);
    }
    EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
    if (!ChangeHelper.canBeChanged(eClass)) {
        throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
    }
    if (object == null) {
        throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
    }
    EAttribute eAttribute = packageMetaData.getEAttribute(eClass.getName(), attributeName);
    if (eAttribute == null) {
        throw new UserException("No attribute with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
    }
    if (eAttribute.isMany()) {
        List list = (List) object.get(eAttribute.getName());
        list.remove(index);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) Query(org.bimserver.database.queries.om.Query) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException)

Example 32 with PackageMetaData

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

the class SetAttributeChange method execute.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    HashMapVirtualObject object = transaction.get(oid);
    if (object == null) {
        Query query = new Query(packageMetaData);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addOid(oid);
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
        object = queryObjectProvider.next();
        transaction.updated(object);
    }
    EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
    if (object == null) {
        throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
    }
    if (!ChangeHelper.canBeChanged(eClass)) {
        throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
    }
    EAttribute eAttribute = packageMetaData.getEAttribute(eClass.getName(), attributeName);
    if (eAttribute == null) {
        throw new UserException("No attribute with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
    }
    if (value instanceof List && eAttribute.isMany()) {
        List sourceList = (List) value;
        if (!eAttribute.isMany()) {
            throw new UserException("Attribute is not of type 'many'");
        }
        List list = (List) object.eGet(eAttribute);
        list.clear();
        List asStringList = null;
        if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
            asStringList = (List) object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString"));
            asStringList.clear();
        }
        for (Object o : sourceList) {
            if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                asStringList.add(String.valueOf(o));
            }
            list.add(o);
        }
    } else {
        if (eAttribute.isMany()) {
            throw new UserException("Attribute is not of type 'single'");
        }
        if (eAttribute.getEType() instanceof EEnum) {
            EEnum eEnum = (EEnum) eAttribute.getEType();
            object.set(eAttribute.getName(), eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance());
        } else {
            object.set(eAttribute.getName(), value);
        }
        if (value instanceof Double) {
            object.set(object.eClass().getEStructuralFeature(attributeName + "AsString").getName(), String.valueOf((Double) value));
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) Query(org.bimserver.database.queries.om.Query) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) List(java.util.List) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) UserException(org.bimserver.shared.exceptions.UserException) EEnum(org.eclipse.emf.ecore.EEnum)

Example 33 with PackageMetaData

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

the class SetReferenceChange method execute.

@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    Query query = new Query(packageMetaData);
    QueryPart queryPart = query.createQueryPart();
    queryPart.addOid(oid);
    HashMapVirtualObject object = transaction.get(oid);
    if (object == null) {
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
        object = queryObjectProvider.next();
        transaction.updated(object);
    }
    EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
    if (!ChangeHelper.canBeChanged(eClass)) {
        throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
    }
    if (object == null) {
        throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
    }
    EReference eReference = packageMetaData.getEReference(eClass.getName(), referenceName);
    if (eReference == null) {
        throw new UserException("No reference with the name \"" + referenceName + "\" found in class \"" + eClass.getName() + "\"");
    }
    if (eReference.isMany()) {
        throw new UserException("Attribute is not of type 'single'");
    }
    object.setReference(eReference, referenceOid, 0);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) Query(org.bimserver.database.queries.om.Query) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference)

Example 34 with PackageMetaData

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

the class SetWrappedAttributeChange method execute.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    Query query = new Query(packageMetaData);
    QueryPart queryPart = query.createQueryPart();
    queryPart.addOid(oid);
    HashMapVirtualObject object = transaction.get(oid);
    if (object == null) {
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
        object = queryObjectProvider.next();
        transaction.updated(object);
    }
    EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
    if (!ChangeHelper.canBeChanged(eClass)) {
        throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
    }
    if (object == null) {
        throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
    }
    EReference eReference = packageMetaData.getEReference(eClass.getName(), attributeName);
    if (eReference == null) {
        throw new UserException("No reference with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
    }
    if (value instanceof List && eReference.isMany()) {
        List sourceList = (List) value;
        if (!eReference.isMany()) {
            throw new UserException("Attribute is not of type 'many'");
        }
        List list = (List) object.eGet(eReference);
        for (Object o : sourceList) {
            if (eReference.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                List asStringList = (List) object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString"));
                asStringList.add(String.valueOf(o));
            }
            list.add(o);
        }
    } else {
        if (eReference.isMany()) {
            throw new UserException("Attribute is not of type 'single'");
        }
        if (eReference.getEType() instanceof EEnum) {
            EEnum eEnum = (EEnum) eReference.getEType();
            object.set(eReference.getName(), eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance());
        } else {
            EClass typeEClass = (EClass) packageMetaData.getEClassifier(type);
            if (typeEClass.getEAnnotation("wrapped") == null) {
                throw new UserException("Not a wrapped type");
            }
            HashMapWrappedVirtualObject wrappedObject = new HashMapWrappedVirtualObject(typeEClass);
            if (typeEClass == Ifc2x3tc1Package.eINSTANCE.getIfcBoolean()) {
                if ((Boolean) value == true) {
                    value = Tristate.TRUE;
                } else {
                    value = Tristate.FALSE;
                }
            }
            wrappedObject.set(wrappedObject.eClass().getEStructuralFeature("wrappedValue").getName(), value);
            object.set(eReference.getName(), wrappedObject);
        }
    // if (value instanceof Double) {
    // idEObject.eSet(idEObject.eClass().getEStructuralFeature(attributeName + "AsString"), String.valueOf((Double)value));
    // }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) Query(org.bimserver.database.queries.om.Query) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) List(java.util.List) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) UserException(org.bimserver.shared.exceptions.UserException) EEnum(org.eclipse.emf.ecore.EEnum) EReference(org.eclipse.emf.ecore.EReference)

Example 35 with PackageMetaData

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

the class DatabaseSession method extractFeatureBytes.

public byte[] extractFeatureBytes(DatabaseSession databaseSession, ByteBuffer buffer, EClass eClass, EStructuralFeature eStructuralFeature) throws BimserverDatabaseException {
    PackageMetaData packageMetaData = getMetaDataManager().getPackageMetaData(eClass.getEPackage().getName());
    buffer.position(0);
    int fieldCounter = 0;
    for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
        if (packageMetaData.useForDatabaseStorage(eClass, feature)) {
            fieldCounter++;
        }
    }
    int unsettedLength = (int) Math.ceil(fieldCounter / 8.0);
    byte[] unsetted = new byte[unsettedLength];
    buffer.get(unsetted);
    fieldCounter = 0;
    for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
        boolean isUnsetted = (unsetted[fieldCounter / 8] & (1 << (fieldCounter % 8))) != 0;
        if (isUnsetted) {
        } else {
            if (eStructuralFeature == feature) {
                if (feature instanceof EReference) {
                    return BinUtils.longToByteArrayLittleEndian(buffer.getLong());
                } else {
                    return databaseSession.readPrimitiveBytes(feature.getEType(), buffer, OldQuery.getDefault());
                }
            } else {
                databaseSession.fakeRead(buffer, feature);
            }
        }
        fieldCounter++;
    }
    return null;
}
Also used : PackageMetaData(org.bimserver.emf.PackageMetaData) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

PackageMetaData (org.bimserver.emf.PackageMetaData)43 UserException (org.bimserver.shared.exceptions.UserException)30 Revision (org.bimserver.models.store.Revision)22 OldQuery (org.bimserver.database.OldQuery)17 EClass (org.eclipse.emf.ecore.EClass)17 IfcModelInterface (org.bimserver.emf.IfcModelInterface)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)14 Query (org.bimserver.database.queries.om.Query)13 Project (org.bimserver.models.store.Project)13 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)12 ModelHelper (org.bimserver.plugins.ModelHelper)12 QueryPart (org.bimserver.database.queries.om.QueryPart)11 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)11 IfcModelSet (org.bimserver.plugins.IfcModelSet)10 MergeException (org.bimserver.plugins.modelmerger.MergeException)10 User (org.bimserver.models.store.User)9 HashMap (java.util.HashMap)8 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)8 List (java.util.List)7 ServerIfcModel (org.bimserver.ServerIfcModel)7