Search in sources :

Example 26 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class GetAllProjectsDatabaseAction method execute.

@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getUserByUoid(authorization.getUoid());
    Not notStoreProject = new Not(new AttributeCondition(StorePackage.eINSTANCE.getProject_Name(), new StringLiteral(Database.STORE_PROJECT_NAME)));
    HasReferenceToCondition authorized = new HasReferenceToCondition(StorePackage.eINSTANCE.getProject_HasAuthorizedUsers(), user);
    Condition condition = new IsOfTypeCondition(StorePackage.eINSTANCE.getProject()).and(notStoreProject);
    // }
    if (onlyActive) {
        condition = new AndCondition(condition, new AttributeCondition(StorePackage.eINSTANCE.getProject_State(), new EnumLiteral(ObjectState.ACTIVE)));
    }
    if (user.getUserType() != UserType.ADMIN && user.getUserType() != UserType.SYSTEM) {
        condition = condition.and(authorized);
        condition = condition.and(new AttributeCondition(StorePackage.eINSTANCE.getProject_State(), new EnumLiteral(ObjectState.ACTIVE)));
    }
    Map<Long, Project> results = getDatabaseSession().query(condition, Project.class, OldQuery.getDefault());
    Set<Project> resultSet = new HashSet<Project>();
    for (Project p : results.values()) {
        if (p.getParent() == null || !onlyTopLevel) {
            resultSet.add(p);
        }
    }
    for (Project project : results.values()) {
        addParentProjects(resultSet, project);
    }
    return resultSet;
}
Also used : IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) Condition(org.bimserver.database.query.conditions.Condition) AndCondition(org.bimserver.database.query.conditions.AndCondition) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) User(org.bimserver.models.store.User) IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) AndCondition(org.bimserver.database.query.conditions.AndCondition) Project(org.bimserver.models.store.Project) Not(org.bimserver.database.query.conditions.Not) StringLiteral(org.bimserver.database.query.literals.StringLiteral) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) EnumLiteral(org.bimserver.database.query.literals.EnumLiteral) HashSet(java.util.HashSet)

Example 27 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class GetAllProjectsSmallDatabaseAction method execute.

@Override
public List<SProjectSmall> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    List<SProjectSmall> list = new ArrayList<SProjectSmall>();
    User user = getUserByUoid(authorization.getUoid());
    IfcModelInterface model = getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
    List<Project> projects = model.getAll(Project.class);
    for (Project project : projects) {
        if (project.getParent() == null && !project.getName().equals(Database.STORE_PROJECT_NAME)) {
            Project rootProject = getRootProject(project);
            addProjects(list, rootProject, user);
        }
    }
    return list;
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ArrayList(java.util.ArrayList) SProjectSmall(org.bimserver.interfaces.objects.SProjectSmall)

Example 28 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class LowLevelServiceImpl method startTransaction.

@Override
public Long startTransaction(Long poid) throws UserException, ServerException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    int pid = -1;
    int rid = -1;
    long roid = -1;
    try {
        Project project = (Project) session.get(poid, OldQuery.getDefault());
        if (project == null) {
            throw new UserException("No project found with poid " + poid);
        }
        pid = project.getId();
        if (project.getLastRevision() != null) {
            Revision revision = project.getLastRevision();
            ConcreteRevision lastConcreteRevision = revision.getLastConcreteRevision();
            rid = lastConcreteRevision.getId();
            roid = revision.getOid();
        }
        LongTransaction longTransaction = getBimServer().getLongTransactionManager().newLongTransaction(getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema()), poid, pid, rid, roid);
        return longTransaction.getTid();
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) DatabaseSession(org.bimserver.database.DatabaseSession) UserException(org.bimserver.shared.exceptions.UserException) LongTransaction(org.bimserver.webservices.LongTransaction) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 29 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class NewServicesImpl method listAvailableOutputFormats.

@Override
public List<SFormatSerializerMap> listAvailableOutputFormats(Long poid) throws ServerException, UserException {
    Map<String, SFormatSerializerMap> outputs = new HashMap<>();
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        Project project = session.get(poid, OldQuery.getDefault());
        try {
            List<SSerializerPluginConfiguration> allSerializersForPoids = getServiceMap().get(PluginInterface.class).getAllSerializersForPoids(true, Collections.singleton(poid));
            for (SSerializerPluginConfiguration pluginConfiguration : allSerializersForPoids) {
                PluginDescriptor pluginDescriptor = session.get(pluginConfiguration.getPluginDescriptorId(), OldQuery.getDefault());
                Plugin plugin = getBimServer().getPluginManager().getPlugin(pluginDescriptor.getIdentifier(), true);
                String outputFormat = null;
                // TODO For now only streaming serializers
                if (plugin instanceof StreamingSerializerPlugin) {
                    outputFormat = ((StreamingSerializerPlugin) plugin).getOutputFormat(Schema.valueOf(project.getSchema().toUpperCase()));
                }
                if (outputFormat != null) {
                    SFormatSerializerMap map = outputs.get(outputFormat);
                    if (map == null) {
                        map = new SFormatSerializerMap();
                        map.setFormat(outputFormat);
                        outputs.put(outputFormat, map);
                    }
                    map.getSerializers().add(pluginConfiguration);
                }
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (UserException e) {
            e.printStackTrace();
        }
        return new ArrayList<>(outputs.values());
    } catch (BimserverDatabaseException e) {
        return handleException(e);
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) HashMap(java.util.HashMap) DatabaseSession(org.bimserver.database.DatabaseSession) PluginInterface(org.bimserver.shared.interfaces.PluginInterface) ArrayList(java.util.ArrayList) SFormatSerializerMap(org.bimserver.interfaces.objects.SFormatSerializerMap) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) Project(org.bimserver.models.store.Project) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) Plugin(org.bimserver.plugins.Plugin)

Example 30 with Project

use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.

the class OAuthServiceImpl method authorize.

@Override
public String authorize(Long oAuthServerOid, SAuthorization authorization) throws ServerException, UserException {
    try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
        if (authorization instanceof SSingleProjectAuthorization) {
            User user = session.get(getCurrentUser().getOid(), OldQuery.getDefault());
            SSingleProjectAuthorization sSingleProjectAuthorization = (SSingleProjectAuthorization) authorization;
            SingleProjectAuthorization singleProjectAuthorization = session.create(SingleProjectAuthorization.class);
            Project project = session.get(sSingleProjectAuthorization.getProjectId(), OldQuery.getDefault());
            if (project == null) {
                throw new UserException("No project found with poid " + sSingleProjectAuthorization.getProjectId());
            }
            singleProjectAuthorization.setProject(project);
            OAuthAuthorizationCode code = session.create(OAuthAuthorizationCode.class);
            org.bimserver.webservices.authorization.Authorization auth = new org.bimserver.webservices.authorization.SingleProjectAuthorization(getBimServer(), user.getOid(), project.getOid());
            String asHexToken = auth.asHexToken(getBimServer().getEncryptionKey());
            code.setCode(asHexToken);
            code.setOauthServer(session.get(oAuthServerOid, OldQuery.getDefault()));
            code.setAuthorization(singleProjectAuthorization);
            code.setUser(user);
            user.getOAuthIssuedAuthorizationCodes().add(code);
            session.store(user);
            session.store(singleProjectAuthorization);
            session.commit();
            return code.getCode();
        } else if (authorization instanceof SRunServiceAuthorization) {
            SRunServiceAuthorization serviceAuthorization = (SRunServiceAuthorization) authorization;
            User user = session.get(getCurrentUser().getOid(), OldQuery.getDefault());
            RunServiceAuthorization runServiceAuth = session.create(RunServiceAuthorization.class);
            InternalServicePluginConfiguration conf = session.get(serviceAuthorization.getServiceId(), OldQuery.getDefault());
            if (conf == null) {
                throw new UserException("No service found with soid " + serviceAuthorization.getServiceId());
            }
            runServiceAuth.setService(conf);
            OAuthAuthorizationCode code = session.create(OAuthAuthorizationCode.class);
            org.bimserver.webservices.authorization.Authorization auth = new org.bimserver.webservices.authorization.RunServiceAuthorization(getBimServer(), user.getOid(), conf.getOid());
            String asHexToken = auth.asHexToken(getBimServer().getEncryptionKey());
            code.setCode(asHexToken);
            code.setOauthServer(session.get(oAuthServerOid, OldQuery.getDefault()));
            code.setAuthorization(runServiceAuth);
            code.setUser(user);
            user.getOAuthIssuedAuthorizationCodes().add(code);
            session.store(user);
            session.store(code);
            session.store(runServiceAuth);
            session.commit();
            return code.getCode();
        } else {
            throw new UserException("Unimplemented type of authorization " + authorization.getClass().getSimpleName());
        }
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) SSingleProjectAuthorization(org.bimserver.interfaces.objects.SSingleProjectAuthorization) SingleProjectAuthorization(org.bimserver.models.store.SingleProjectAuthorization) SRunServiceAuthorization(org.bimserver.interfaces.objects.SRunServiceAuthorization) RunServiceAuthorization(org.bimserver.models.store.RunServiceAuthorization) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SAuthorization(org.bimserver.interfaces.objects.SAuthorization) Authorization(org.bimserver.models.store.Authorization) SRunServiceAuthorization(org.bimserver.interfaces.objects.SRunServiceAuthorization) RunServiceAuthorization(org.bimserver.models.store.RunServiceAuthorization) SSingleProjectAuthorization(org.bimserver.interfaces.objects.SSingleProjectAuthorization) SingleProjectAuthorization(org.bimserver.models.store.SingleProjectAuthorization) SSingleProjectAuthorization(org.bimserver.interfaces.objects.SSingleProjectAuthorization) Project(org.bimserver.models.store.Project) InternalServicePluginConfiguration(org.bimserver.models.store.InternalServicePluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) SRunServiceAuthorization(org.bimserver.interfaces.objects.SRunServiceAuthorization) OAuthAuthorizationCode(org.bimserver.models.store.OAuthAuthorizationCode) SOAuthAuthorizationCode(org.bimserver.interfaces.objects.SOAuthAuthorizationCode)

Aggregations

Project (org.bimserver.models.store.Project)80 UserException (org.bimserver.shared.exceptions.UserException)48 User (org.bimserver.models.store.User)46 DatabaseSession (org.bimserver.database.DatabaseSession)25 Revision (org.bimserver.models.store.Revision)23 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)22 ServerException (org.bimserver.shared.exceptions.ServerException)20 Date (java.util.Date)18 ArrayList (java.util.ArrayList)14 SProject (org.bimserver.interfaces.objects.SProject)14 IOException (java.io.IOException)13 PackageMetaData (org.bimserver.emf.PackageMetaData)13 HashSet (java.util.HashSet)12 IfcModelInterface (org.bimserver.emf.IfcModelInterface)12 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)11 OldQuery (org.bimserver.database.OldQuery)10 PostCommitAction (org.bimserver.database.PostCommitAction)10 SConverter (org.bimserver.interfaces.SConverter)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 MalformedURLException (java.net.MalformedURLException)8