Search in sources :

Example 6 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class AddReferenceChange method execute.

@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 (!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("Reference is not of type 'many'");
    }
    EClass eClassForOid = transaction.getDatabaseSession().getEClassForOid(referenceOid);
    object.addReference(eReference, eClassForOid, referenceOid);
    EReference inverseOrOpposite = packageMetaData.getInverseOrOpposite(eClassForOid, eReference);
    if (inverseOrOpposite != null) {
        HashMapVirtualObject referencedObject = transaction.get(referenceOid);
        if (referencedObject == null) {
            Query query = new Query(packageMetaData);
            QueryPart queryPart = query.createQueryPart();
            queryPart.addOid(referenceOid);
            QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
            referencedObject = queryObjectProvider.next();
        }
        if (inverseOrOpposite.isMany()) {
            referencedObject.addReference(inverseOrOpposite, eClassForOid, oid);
        } else {
            referencedObject.setReference(inverseOrOpposite, oid);
        }
        transaction.updated(referencedObject);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) 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) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference)

Example 7 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class RemoveAllReferencesChange 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());
    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("Reference is not of type 'many'");
    }
    List list = (List) object.get(eReference.getName());
    while (!list.isEmpty()) {
        list.remove(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) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference)

Example 8 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class AddAttributeChange method execute.

@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 (!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()) {
        throw new UserException("Attribute is not of type 'many'");
    }
    object.addListItem(eAttribute, 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) UserException(org.bimserver.shared.exceptions.UserException)

Example 9 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class CreateObjectChange method execute.

@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    // TODO
    QueryContext queryContext = new QueryContext(transaction.getDatabaseSession(), packageMetaData, transaction.getConcreteRevision().getProject().getId(), transaction.getNewRid(), -1, -1, 0);
    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");
    }
    HashMapVirtualObject object = new HashMapVirtualObject(queryContext, eClass, oid, uuid);
    if (generateGuid) {
        EAttribute globalIdFeature = (EAttribute) object.eClass().getEStructuralFeature("GlobalId");
        if (globalIdFeature != null) {
            object.setAttribute(globalIdFeature, GuidCompressor.getNewIfcGloballyUniqueId());
        } else {
            throw new UserException("Cannot generate GUID for " + object.eClass().getName() + ", no GlobalId property");
        }
    }
    transaction.created(object);
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryContext(org.bimserver.shared.QueryContext) UserException(org.bimserver.shared.exceptions.UserException)

Example 10 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class RemoveReferenceChange 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());
    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 (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");
    }
    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("Reference is not of type 'many'");
    }
    List list = (List) object.get(eReference.getName());
    if (referencedOid != -1) {
        list.remove((Object) referencedOid);
    }
    if (index != -1) {
        list.remove(index);
    }
}
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) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)44 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)23 Query (org.bimserver.database.queries.om.Query)23 QueryPart (org.bimserver.database.queries.om.QueryPart)22 List (java.util.List)20 EClass (org.eclipse.emf.ecore.EClass)20 PackageMetaData (org.bimserver.emf.PackageMetaData)18 UserException (org.bimserver.shared.exceptions.UserException)17 EReference (org.eclipse.emf.ecore.EReference)15 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)13 HashMapWrappedVirtualObject (org.bimserver.shared.HashMapWrappedVirtualObject)12 OldQuery (org.bimserver.database.OldQuery)11 IOException (java.io.IOException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Include (org.bimserver.database.queries.om.Include)8 QueryException (org.bimserver.database.queries.om.QueryException)7 ByteBuffer (java.nio.ByteBuffer)6 Revision (org.bimserver.models.store.Revision)6 EAttribute (org.eclipse.emf.ecore.EAttribute)6