Search in sources :

Example 66 with IdEObject

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

the class TracingGarbageCollector method sweep.

public void sweep() {
    Map<Long, IdEObject> objects = ifcModel.getObjects();
    Iterator<Long> iterator = objects.keySet().iterator();
    while (iterator.hasNext()) {
        Long next = iterator.next();
        IdEObject idEObject = objects.get(next);
        if (!referencedObjects.contains(idEObject)) {
            iterator.remove();
        }
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject)

Example 67 with IdEObject

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

the class TracingGarbageCollector method mark.

@SuppressWarnings("rawtypes")
public void mark(Set<? extends IdEObject> rootObjects) {
    referencedObjects.addAll(rootObjects);
    SchemaDefinition schema = ifcModel.getPackageMetaData().getSchemaDefinition();
    for (IdEObject rootObject : rootObjects) {
        for (EReference eReference : rootObject.eClass().getEAllReferences()) {
            Attribute attributeBNWithSuper = null;
            if (schema != null) {
                EntityDefinition entityBN = schema.getEntityBN(rootObject.eClass().getName());
                if (entityBN == null) {
                    LOGGER.info(rootObject.eClass().getName() + " not found");
                } else {
                    attributeBNWithSuper = entityBN.getAttributeBNWithSuper(eReference.getName());
                    if (attributeBNWithSuper == null) {
                        LOGGER.info(eReference.getName() + " not found");
                    }
                }
            }
            if (schema == null || !(attributeBNWithSuper instanceof InverseAttribute)) {
                Object referredObject = rootObject.eGet(eReference);
                if (eReference.isMany()) {
                    List list = (List) referredObject;
                    for (Object o : list) {
                        if (!referencedObjects.contains(o)) {
                            mark(makeSet((IdEObject) o));
                        }
                    }
                } else {
                    IdEObject referredIdEObject = (IdEObject) referredObject;
                    if (referredIdEObject != null) {
                        if (!referencedObjects.contains(referredObject)) {
                            mark(makeSet(referredIdEObject));
                        }
                    }
                }
            }
        }
    }
}
Also used : EntityDefinition(nl.tue.buildingsmart.schema.EntityDefinition) SchemaDefinition(nl.tue.buildingsmart.schema.SchemaDefinition) IdEObject(org.bimserver.emf.IdEObject) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) Attribute(nl.tue.buildingsmart.schema.Attribute) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) EReference(org.eclipse.emf.ecore.EReference)

Example 68 with IdEObject

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

the class ServiceImpl method getUserRelatedLogs.

@Override
public List<SLogAction> getUserRelatedLogs(Long uoid) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        List<LogAction> logActions = new ArrayList<LogAction>();
        User user = session.get(getAuthorization().getUoid(), OldQuery.getDefault());
        IfcModelInterface projectsModel = session.getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
        logActions.addAll(user.getLogs());
        for (IdEObject idEObject : projectsModel.getValues()) {
            if (idEObject instanceof Project) {
                Project project = (Project) idEObject;
                if ((user.getUserType() == UserType.ADMIN || (project.getState() == ObjectState.ACTIVE) && getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project))) {
                    logActions.addAll(project.getLogs());
                }
            }
        }
        Collections.sort(logActions, new Comparator<LogAction>() {

            @Override
            public int compare(LogAction o1, LogAction o2) {
                return o1.getDate().compareTo(o2.getDate());
            }
        });
        return getBimServer().getSConverter().convertToSListLogAction(logActions);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) SProject(org.bimserver.interfaces.objects.SProject) LogAction(org.bimserver.models.log.LogAction) SLogAction(org.bimserver.interfaces.objects.SLogAction) SUser(org.bimserver.interfaces.objects.SUser) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) IdEObject(org.bimserver.emf.IdEObject) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

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