Search in sources :

Example 1 with SLogAction

use of org.bimserver.interfaces.objects.SLogAction 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 SLogAction

use of org.bimserver.interfaces.objects.SLogAction 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)

Example 3 with SLogAction

use of org.bimserver.interfaces.objects.SLogAction in project BIMserver by opensourceBIM.

the class GetLogs method start.

private void start() {
    try (JsonBimServerClientFactory factory = new JsonBimServerClientFactory(null, "[ADD]")) {
        client = factory.create(new UsernamePasswordAuthenticationInfo("[ADD]", "[ADD]"));
        List<SLogAction> logs = client.getAdminInterface().getLogs();
        Path file = Paths.get("log.txt");
        writer = new PrintWriter(file.toFile());
        try {
            for (SLogAction sLogAction : logs) {
                if (sLogAction instanceof SDatabaseCreated) {
                    write(sLogAction, "Database created");
                } else if (sLogAction instanceof SUserAddedToProject) {
                    SUserAddedToProject sUserAddedToProject = (SUserAddedToProject) sLogAction;
                    SProject project = getProject(sUserAddedToProject.getProjectId());
                    SUser user = getUser(sUserAddedToProject.getUserId());
                    write(sLogAction, "User " + user.getUsername() + " added to project " + project.getName());
                } else if (sLogAction instanceof SUserRemovedFromProject) {
                    SUserRemovedFromProject sUserRemovedFromProject = (SUserRemovedFromProject) sLogAction;
                    SProject project = getProject(sUserRemovedFromProject.getProjectId());
                    SUser user = getUser(sUserRemovedFromProject.getUserId());
                    write(sLogAction, "User " + user.getUsername() + " removed from project " + project.getName());
                } else if (sLogAction instanceof SNewUserAdded) {
                    SNewUserAdded sNewUserAdded = (SNewUserAdded) sLogAction;
                    SUser user = getUser(sNewUserAdded.getUserId());
                    write(sLogAction, "User " + user.getUsername() + " created");
                } else if (sLogAction instanceof SNewProjectAdded) {
                    SNewProjectAdded sNewProject = (SNewProjectAdded) sLogAction;
                    SProject project = getProject(sNewProject.getProjectId());
                    write(sLogAction, "Project " + project.getName() + " created");
                } else if (sLogAction instanceof SNewRevisionAdded) {
                    SNewRevisionAdded sNewRevisionAdded = (SNewRevisionAdded) sLogAction;
                    SProject project = getProject(sNewRevisionAdded.getProjectId());
                    SRevision revision = getRevision(sNewRevisionAdded.getRevisionId());
                    write(sLogAction, "Revision " + revision.getId() + " with comment " + revision.getComment() + " added to project " + project.getName());
                } else if (sLogAction instanceof SProjectUpdated) {
                    SProjectUpdated sProjectUpdated = (SProjectUpdated) sLogAction;
                    SProject project = getProject(sProjectUpdated.getProjectId());
                    write(sLogAction, "Project " + project.getName() + " updated");
                } else if (sLogAction instanceof SProjectDeleted) {
                    SProjectDeleted sProjectDeleted = (SProjectDeleted) sLogAction;
                    SProject project = getProject(sProjectDeleted.getProjectId());
                    write(sLogAction, "Project " + project.getName() + " deleted");
                } else if (sLogAction instanceof SUserChanged) {
                    SUserChanged sUserChanged = (SUserChanged) sLogAction;
                    SUser user = getUser(sUserChanged.getUserId());
                    write(sLogAction, "User " + user.getUsername() + " updated");
                } else if (sLogAction instanceof SServerStarted) {
                    write(sLogAction, "Server started");
                } else {
                    write(sLogAction, "NOT IMPL " + sLogAction.getClass().getSimpleName());
                }
            }
        } finally {
            writer.close();
        }
    } catch (ServiceException | ChannelConnectionException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) SUser(org.bimserver.interfaces.objects.SUser) FileNotFoundException(java.io.FileNotFoundException) SProject(org.bimserver.interfaces.objects.SProject) SNewUserAdded(org.bimserver.interfaces.objects.SNewUserAdded) SUserChanged(org.bimserver.interfaces.objects.SUserChanged) SDatabaseCreated(org.bimserver.interfaces.objects.SDatabaseCreated) PrintWriter(java.io.PrintWriter) Path(java.nio.file.Path) SUserRemovedFromProject(org.bimserver.interfaces.objects.SUserRemovedFromProject) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) SProjectUpdated(org.bimserver.interfaces.objects.SProjectUpdated) SProjectDeleted(org.bimserver.interfaces.objects.SProjectDeleted) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) FileNotFoundException(java.io.FileNotFoundException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) SUserAddedToProject(org.bimserver.interfaces.objects.SUserAddedToProject) SRevision(org.bimserver.interfaces.objects.SRevision) SNewRevisionAdded(org.bimserver.interfaces.objects.SNewRevisionAdded) ServiceException(org.bimserver.shared.exceptions.ServiceException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) SLogAction(org.bimserver.interfaces.objects.SLogAction) SServerStarted(org.bimserver.interfaces.objects.SServerStarted) SNewProjectAdded(org.bimserver.interfaces.objects.SNewProjectAdded)

Aggregations

SLogAction (org.bimserver.interfaces.objects.SLogAction)3 ServerException (org.bimserver.shared.exceptions.ServerException)3 UserException (org.bimserver.shared.exceptions.UserException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 DatabaseSession (org.bimserver.database.DatabaseSession)2 SProject (org.bimserver.interfaces.objects.SProject)2 SUser (org.bimserver.interfaces.objects.SUser)2 LogAction (org.bimserver.models.log.LogAction)2 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 Path (java.nio.file.Path)1 List (java.util.List)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1 BimBotsException (org.bimserver.bimbots.BimBotsException)1 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)1