Search in sources :

Example 76 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class BimServerClient method getGeometry.

@Override
public Geometry getGeometry(long roid, IdEObject ifcProduct) {
    try {
        SSerializerPluginConfiguration serializerByPluginClassName = getPluginInterface().getSerializerByPluginClassName("org.bimserver.serializers.binarygeometry.BinaryGeometrySerializerPlugin");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        download(roid, serializerByPluginClassName.getOid(), outputStream);
        Files.write(Paths.get("bin.bin"), outputStream.toByteArray());
        ByteArrayInputStream bain = new ByteArrayInputStream(outputStream.toByteArray());
        return new Geometry(bain, ifcProduct.getOid());
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Geometry(org.bimserver.plugins.services.Geometry) ServerException(org.bimserver.shared.exceptions.ServerException) ByteArrayInputStream(java.io.ByteArrayInputStream) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException)

Example 77 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class ClientIfcModel method branch.

@SuppressWarnings({ "unchecked", "rawtypes" })
public ClientIfcModel branch(long poid, boolean recordChanges) {
    // TODO this should of course be done server side, without any copying
    ClientIfcModel branch = new ClientIfcModel(bimServerClient, getPackageMetaData(), poid, recordChanges);
    try {
        loadDeep();
    } catch (ServerException e) {
        LOGGER.error("", e);
    } catch (UserException e) {
        LOGGER.error("", e);
    } catch (PublicInterfaceNotFoundException e) {
        LOGGER.error("", e);
    } catch (QueryException e) {
        LOGGER.error("", e);
    }
    Map<IdEObject, IdEObject> map = new HashMap<IdEObject, IdEObject>();
    for (IdEObject sourceObject : getValues()) {
        try {
            IdEObjectImpl targetObject = branch.create(sourceObject.eClass());
            targetObject.setLoadingState(State.LOADED);
            map.put(sourceObject, targetObject);
        } catch (IfcModelInterfaceException e) {
            LOGGER.error("", e);
        }
    }
    for (IdEObject sourceObject : getObjects().values()) {
        IdEObject targetObject = map.get(sourceObject);
        for (EStructuralFeature eStructuralFeature : sourceObject.eClass().getEAllStructuralFeatures()) {
            Object sourceValue = sourceObject.eGet(eStructuralFeature);
            if (eStructuralFeature instanceof EReference) {
                if (eStructuralFeature.isMany()) {
                    List sourceList = (List) sourceValue;
                    List targetList = (List) targetObject.eGet(eStructuralFeature);
                    for (Object sourceItem : sourceList) {
                        IdEObject e = map.get(sourceItem);
                        if (e != null) {
                            targetList.add(e);
                        }
                    }
                } else {
                    targetObject.eSet(eStructuralFeature, map.get(sourceValue));
                }
            } else {
                if (eStructuralFeature.isMany()) {
                    List sourceList = (List) sourceValue;
                    List targetList = (List) targetObject.eGet(eStructuralFeature);
                    for (Object sourceItem : sourceList) {
                        targetList.add(sourceItem);
                    }
                } else {
                    targetObject.eSet(eStructuralFeature, sourceValue);
                }
            }
        }
    }
    branch.setModelState(ModelState.FULLY_LOADED);
    return branch;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ServerException(org.bimserver.shared.exceptions.ServerException) IdEObject(org.bimserver.emf.IdEObject) HashMap(java.util.HashMap) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) QueryException(org.bimserver.database.queries.om.QueryException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) ArrayList(java.util.ArrayList) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference)

Example 78 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class AddExtendedDataToProjectDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    super.execute();
    User actingUser = getUserByUoid(authorization.getUoid());
    Project project = getProjectByPoid(poid);
    if (project == null) {
        throw new UserException("Project with poid " + poid + " not found");
    }
    project.getExtendedData().add(getIdEObject());
    getDatabaseSession().store(project);
    final ExtendedDataAddedToProject extendedDataAddedToProject = getDatabaseSession().create(ExtendedDataAddedToProject.class);
    extendedDataAddedToProject.setAccessMethod(getAccessMethod());
    extendedDataAddedToProject.setDate(new Date());
    extendedDataAddedToProject.setExecutor(actingUser);
    extendedDataAddedToProject.setExtendedData(getIdEObject());
    extendedDataAddedToProject.setProject(project);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(extendedDataAddedToProject));
        }
    });
    return null;
}
Also used : ExtendedDataAddedToProject(org.bimserver.models.log.ExtendedDataAddedToProject) Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) ExtendedDataAddedToProject(org.bimserver.models.log.ExtendedDataAddedToProject) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date)

Example 79 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class AddNewServiceToProjectDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getDatabaseSession().get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
    // service.setUser(user);
    for (org.bimserver.models.store.Service existing : project.getServices()) {
        if (existing.getName().equals(service.getName())) {
            throw new UserException("Service name \"" + service.getName() + "\" already used in this project");
        }
    }
    service.setAction(action);
    service.setStatus(ServiceStatus.NEW);
    if (service.getAuthorizationUrl() == null) {
        service.setStatus(ServiceStatus.NO_AUTHENTICATION);
    }
    project.getNewServices().add(service);
    service.setProject(project);
    long serviceOid = getDatabaseSession().store(service);
    getDatabaseSession().store(action);
    getDatabaseSession().store(project);
    return serviceOid;
}
Also used : Project(org.bimserver.models.store.Project) UserException(org.bimserver.shared.exceptions.UserException)

Example 80 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class AddServiceToProjectDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Project project = getDatabaseSession().get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
    User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
    service.setUser(user);
    for (org.bimserver.models.store.Service existing : project.getServices()) {
        if (existing.getName().equals(service.getName())) {
            throw new UserException("Service name \"" + service.getName() + "\" already used in this project");
        }
    }
    project.getServices().add(service);
    service.setProject(project);
    long serviceOid = getDatabaseSession().store(service);
    getDatabaseSession().store(project);
    return serviceOid;
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) Service(org.bimserver.models.store.Service) UserException(org.bimserver.shared.exceptions.UserException)

Aggregations

UserException (org.bimserver.shared.exceptions.UserException)362 ServerException (org.bimserver.shared.exceptions.ServerException)253 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)241 DatabaseSession (org.bimserver.database.DatabaseSession)227 IOException (java.io.IOException)220 SerializerException (org.bimserver.plugins.serializers.SerializerException)113 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)112 MalformedURLException (java.net.MalformedURLException)109 MessagingException (javax.mail.MessagingException)109 BcfException (org.opensourcebim.bcf.BcfException)109 UnsupportedEncodingException (java.io.UnsupportedEncodingException)108 AddressException (javax.mail.internet.AddressException)108 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)108 User (org.bimserver.models.store.User)65 Project (org.bimserver.models.store.Project)48 Revision (org.bimserver.models.store.Revision)39 ArrayList (java.util.ArrayList)35 Date (java.util.Date)34 SProject (org.bimserver.interfaces.objects.SProject)31 PackageMetaData (org.bimserver.emf.PackageMetaData)30