Search in sources :

Example 1 with RouteToDashboardEvent

use of de.catma.ui.events.routing.RouteToDashboardEvent in project catma by forTEXT.

the class ConflictedProjectView method showNextConflict.

// TODO: refactor! (consider implementing a state machine)
private void showNextConflict() {
    try {
        if (// tag/tagset conflict resolution not applied yet
        (this.tagManager == null) && // all tagset conflicts resolved by the user
        ((tagsetConflictsIterator == null) || !this.tagsetConflictsIterator.hasNext()) && ((tagConflictIterator == null) || !this.tagConflictIterator.hasNext())) {
            // all tag conflicts resolved by the user
            // apply tag/tagset conflict resolutions
            conflictedProject.resolveTagsetConflicts(this.tagsetConflicts);
            // load tagsets
            this.tagManager = new TagManager(new TagLibrary());
            conflictedProject.getTagsets().stream().forEach(tagset -> tagManager.addTagsetDefinition(tagset));
        }
        if ((tagConflictIterator != null) && tagConflictIterator.hasNext()) {
            showNextTagConflict();
        } else if ((tagsetConflictsIterator != null) && tagsetConflictsIterator.hasNext()) {
            showNextTagsetConflict();
        } else if (annotationConflictIterator != null && annotationConflictIterator.hasNext()) {
            showNextAnnotationConflict();
        } else if (collectionConflictIterator != null && collectionConflictIterator.hasNext()) {
            showNextCollectionConflict();
        } else {
            conflictedProject.resolveCollectionConflict(this.collectionConflicts, this.tagManager.getTagLibrary());
            // TODO: this may not be the right place to be doing this
            conflictedProject.resolveSourceDocumentConflicts(sourceDocumentConflicts);
            try {
                Collection<DeletedResourceConflict> deletedReourceConflicts = conflictedProject.resolveRootConflicts();
                if (!deletedReourceConflicts.isEmpty()) {
                    showDeletedResourceConflicts(deletedReourceConflicts);
                    return;
                }
            } catch (Exception e) {
                if (ExceptionUtil.stackTraceContains(CommitMissingException.class.getName(), e)) {
                    Notification.show("Error", ExceptionUtil.getMessageFor(CommitMissingException.class.getName(), e), Type.ERROR_MESSAGE);
                    eventBus.post(new RouteToDashboardEvent());
                    return;
                } else {
                    // rethrow unexpected error
                    throw new Exception(e);
                }
            }
            // TODO: check if there everything is pushed, remote state might have prevented a push
            eventBus.post(new RouteToProjectEvent(conflictedProject.getProjectReference(), true));
        }
    } catch (Exception e) {
        ((ErrorHandler) UI.getCurrent()).showAndLogError("Error showing next conflict!", e);
    }
}
Also used : CommitMissingException(de.catma.repository.git.CommitMissingException) TagLibrary(de.catma.tag.TagLibrary) RouteToProjectEvent(de.catma.ui.events.routing.RouteToProjectEvent) TagManager(de.catma.tag.TagManager) Collection(java.util.Collection) RouteToDashboardEvent(de.catma.ui.events.routing.RouteToDashboardEvent) CommitMissingException(de.catma.repository.git.CommitMissingException) IOException(java.io.IOException)

Example 2 with RouteToDashboardEvent

use of de.catma.ui.events.routing.RouteToDashboardEvent in project catma by forTEXT.

the class CatmaApplication method handleRequestOauth.

private void handleRequestOauth(VaadinRequest request) {
    if (request.getParameter("code") != null && VaadinSession.getCurrent().getAttribute("OAUTHTOKEN") != null) {
        handleOauth(request);
        try {
            Component mainView = initService.newEntryPage(eventBus, loginservice, hazelCastService, sqliteService);
            UI.getCurrent().setContent(mainView);
            eventBus.post(new RouteToDashboardEvent());
            getCurrent().getPage().pushState("/catma/");
        } catch (IOException e) {
            showAndLogError("can't login properly", e);
        }
    }
}
Also used : IOException(java.io.IOException) Component(com.vaadin.ui.Component) RouteToDashboardEvent(de.catma.ui.events.routing.RouteToDashboardEvent)

Example 3 with RouteToDashboardEvent

use of de.catma.ui.events.routing.RouteToDashboardEvent in project catma by forTEXT.

the class CatmaApplication method init.

@Override
protected void init(VaadinRequest request) {
    eventBus = new EventBus();
    initService = new Vaadin8InitializationService();
    loginservice = new GitlabLoginService(new IRemoteGitManagerFactory() {

        @Override
        public IRemoteGitManagerRestricted createFromUsernameAndPassword(String username, String password) throws IOException {
            return new GitlabManagerRestricted(eventBus, initService.acquireBackgroundService(), username, password);
        }

        @Override
        public IRemoteGitManagerRestricted createFromImpersonationToken(String userImpersonationToken) throws IOException {
            return new GitlabManagerRestricted(eventBus, initService.acquireBackgroundService(), userImpersonationToken);
        }
    });
    hazelCastService = new HazelCastService();
    this.eventBus.register(this);
    try {
        sqliteService = new SqliteService();
    } catch (Exception e) {
        showAndLogError("error initialising sqlite service", e);
    }
    logger.info("Session: " + request.getWrappedSession().getId());
    storeParameters(request.getParameterMap());
    Page.getCurrent().setTitle("CATMA " + Version.LATEST);
    try {
        Component component = initService.newEntryPage(eventBus, loginservice, hazelCastService, sqliteService);
        setContent(component);
    } catch (IOException e) {
        showAndLogError("error creating landing page", e);
    }
    eventBus.post(new RouteToDashboardEvent());
    // A fresh UI and session doesn't have a request handler registered yet.
    // we need to verify tokens here too.
    handleRequestToken(request);
    handleRequestOauth(request);
}
Also used : IRemoteGitManagerFactory(de.catma.ui.di.IRemoteGitManagerFactory) Vaadin8InitializationService(de.catma.ui.login.Vaadin8InitializationService) GitlabManagerRestricted(de.catma.repository.git.managers.GitlabManagerRestricted) GitlabLoginService(de.catma.ui.login.GitlabLoginService) EventBus(com.google.common.eventbus.EventBus) IOException(java.io.IOException) SqliteService(de.catma.sqlite.SqliteService) Component(com.vaadin.ui.Component) RouteToDashboardEvent(de.catma.ui.events.routing.RouteToDashboardEvent) HazelCastService(de.catma.hazelcast.HazelCastService) IOException(java.io.IOException)

Example 4 with RouteToDashboardEvent

use of de.catma.ui.events.routing.RouteToDashboardEvent in project catma by forTEXT.

the class CatmaHeader method initComponents.

private void initComponents(IRemoteGitManagerPrivileged gitManagerPrivileged) {
    addStyleName("header");
    setWidth("100%");
    btHome = new Button("Catma " + Version.LATEST);
    btHome.addClickListener((evt) -> eventBus.post(new RouteToDashboardEvent()));
    btHome.addStyleNames(ValoTheme.BUTTON_LINK, ValoTheme.LABEL_H3);
    btHome.addStyleName("header-home-button");
    addComponent(btHome);
    setComponentAlignment(btHome, Alignment.MIDDLE_LEFT);
    contextInformation.addStyleName("header__context");
    addComponent(contextInformation);
    setComponentAlignment(contextInformation, Alignment.MIDDLE_CENTER);
    setExpandRatio(contextInformation, 1f);
    IconButton btnAccount = new IconButton(VaadinIcons.USER);
    btnAccount.setDescription(loginService.getAPI().getUser().getName());
    ContextMenu ctxAccount = new ContextMenu(btnAccount, true);
    ctxAccount.addItem("Edit Account", (item) -> {
        EditAccountDialog editAccount = new EditAccountDialog(gitManagerPrivileged, loginService, eventBus);
        editAccount.show();
    });
    ctxAccount.addItem("Get Access Token", (item) -> {
        AccessTokenDialog accessTokenDialog = new AccessTokenDialog(gitManagerPrivileged, loginService);
        accessTokenDialog.show();
    });
    ctxAccount.addItem("Sign Out", (item) -> {
        loginService.logout();
    });
    btnAccount.addClickListener((evt) -> ctxAccount.open(evt.getClientX(), evt.getClientY()));
    addComponent(btnAccount);
    setComponentAlignment(btHome, Alignment.MIDDLE_RIGHT);
}
Also used : EditAccountDialog(de.catma.ui.module.account.EditAccountDialog) AccessTokenDialog(de.catma.ui.module.account.AccessTokenDialog) IconButton(de.catma.ui.component.IconButton) Button(com.vaadin.ui.Button) IconButton(de.catma.ui.component.IconButton) ContextMenu(com.vaadin.contextmenu.ContextMenu) RouteToDashboardEvent(de.catma.ui.events.routing.RouteToDashboardEvent)

Example 5 with RouteToDashboardEvent

use of de.catma.ui.events.routing.RouteToDashboardEvent in project catma by forTEXT.

the class AuthenticationDialog method initActions.

private void initActions() {
    addActionHandler(this);
    btCancel.addClickListener(click -> close());
    btLogin.addClickListener(click -> {
        try {
            if (pfPersonalAccessToken.isVisible()) {
                loginservice.login(pfPersonalAccessToken.getValue());
            } else {
                loginservice.login(tfUsername.getValue(), pfPassword.getValue());
            }
            Component mainView = initService.newEntryPage(eventBus, loginservice, hazelCastService, sqliteService);
            UI.getCurrent().setContent(mainView);
            eventBus.post(new RouteToDashboardEvent());
            close();
        } catch (IOException e) {
            Notification.show("Login error", "Username or password wrong!", Notification.Type.ERROR_MESSAGE);
            String message = ExceptionUtil.getMessageFor("org.gitlab4j.api.GitLabApiException", e);
            if (message != null && !message.equals("invalid_grant")) {
                logger.log(Level.SEVERE, "login services", e);
            }
        }
    });
    googleLogInLink.addClickListener(event -> {
        try {
            UI.getCurrent().getPage().setLocation(createLogInClick(CATMAPropertyKey.Google_oauthAuthorizationCodeRequestURL.getValue(), CATMAPropertyKey.Google_oauthClientId.getValue(), CATMAPropertyKey.Google_oauthClientSecret.getValue()));
            close();
        } catch (Exception e) {
            ((ErrorHandler) UI.getCurrent()).showAndLogError("Error during authentication!", e);
        }
    });
}
Also used : IOException(java.io.IOException) RouteToDashboardEvent(de.catma.ui.events.routing.RouteToDashboardEvent) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

RouteToDashboardEvent (de.catma.ui.events.routing.RouteToDashboardEvent)5 IOException (java.io.IOException)4 Component (com.vaadin.ui.Component)2 EventBus (com.google.common.eventbus.EventBus)1 ContextMenu (com.vaadin.contextmenu.ContextMenu)1 Button (com.vaadin.ui.Button)1 HazelCastService (de.catma.hazelcast.HazelCastService)1 CommitMissingException (de.catma.repository.git.CommitMissingException)1 GitlabManagerRestricted (de.catma.repository.git.managers.GitlabManagerRestricted)1 SqliteService (de.catma.sqlite.SqliteService)1 TagLibrary (de.catma.tag.TagLibrary)1 TagManager (de.catma.tag.TagManager)1 IconButton (de.catma.ui.component.IconButton)1 IRemoteGitManagerFactory (de.catma.ui.di.IRemoteGitManagerFactory)1 RouteToProjectEvent (de.catma.ui.events.routing.RouteToProjectEvent)1 GitlabLoginService (de.catma.ui.login.GitlabLoginService)1 Vaadin8InitializationService (de.catma.ui.login.Vaadin8InitializationService)1 AccessTokenDialog (de.catma.ui.module.account.AccessTokenDialog)1 EditAccountDialog (de.catma.ui.module.account.EditAccountDialog)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1