Search in sources :

Example 1 with LogAction

use of org.bimserver.models.log.LogAction in project BIMserver by opensourceBIM.

the class AdminServiceImpl method getLogs.

@Override
public List<SLogAction> getLogs() throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        BimDatabaseAction<List<LogAction>> action = new GetLogsDatabaseAction(session, getInternalAccessMethod(), getAuthorization());
        List<LogAction> logs = session.executeAndCommitAction(action);
        List<SLogAction> convertToSListLogAction = getBimServer().getSConverter().convertToSListLogAction(logs);
        Collections.sort(convertToSListLogAction, new SLogComparator(true));
        return convertToSListLogAction;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : SLogAction(org.bimserver.interfaces.objects.SLogAction) LogAction(org.bimserver.models.log.LogAction) DatabaseSession(org.bimserver.database.DatabaseSession) GetLogsDatabaseAction(org.bimserver.database.actions.GetLogsDatabaseAction) SLogComparator(org.bimserver.webservices.SLogComparator) List(java.util.List) ArrayList(java.util.ArrayList) SLogAction(org.bimserver.interfaces.objects.SLogAction) UserException(org.bimserver.shared.exceptions.UserException) BimBotsException(org.bimserver.bimbots.BimBotsException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 2 with LogAction

use of org.bimserver.models.log.LogAction in project BIMserver by opensourceBIM.

the class GetLogsDatabaseAction method execute.

@Override
public List<LogAction> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getUserByUoid(authorization.getUoid());
    if (user.getUserType() != UserType.ADMIN) {
        throw new UserException("Only admin users can retrieve log");
    }
    Map<Long, LogAction> query = getDatabaseSession().query(new IsOfTypeCondition(LogPackage.eINSTANCE.getLogAction()), LogAction.class, OldQuery.getDefault());
    ArrayList<LogAction> list = new ArrayList<LogAction>(query.values());
    return list;
}
Also used : User(org.bimserver.models.store.User) LogAction(org.bimserver.models.log.LogAction) IsOfTypeCondition(org.bimserver.database.query.conditions.IsOfTypeCondition) ArrayList(java.util.ArrayList) UserException(org.bimserver.shared.exceptions.UserException)

Example 3 with LogAction

use of org.bimserver.models.log.LogAction 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

ArrayList (java.util.ArrayList)3 LogAction (org.bimserver.models.log.LogAction)3 UserException (org.bimserver.shared.exceptions.UserException)3 IOException (java.io.IOException)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 DatabaseSession (org.bimserver.database.DatabaseSession)2 SLogAction (org.bimserver.interfaces.objects.SLogAction)2 User (org.bimserver.models.store.User)2 ServerException (org.bimserver.shared.exceptions.ServerException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 List (java.util.List)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1 BimBotsException (org.bimserver.bimbots.BimBotsException)1 GetLogsDatabaseAction (org.bimserver.database.actions.GetLogsDatabaseAction)1 IsOfTypeCondition (org.bimserver.database.query.conditions.IsOfTypeCondition)1 IdEObject (org.bimserver.emf.IdEObject)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 SProject (org.bimserver.interfaces.objects.SProject)1