Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Fix save editor option
Browse files Browse the repository at this point in the history
https://bugzilla.redhat.com/show_bug.cgi?id=1222710

Squashed commit of the following:

commit 8db6ac4
Author: Alex Eng <aeng@redhat.com>
Date:   Tue May 19 13:14:02 2015 +1000

    Add notification for save options, load options and restore to default options

commit 5924c54
Merge: 2e68ba0 a149bba
Author: Alex Eng <aeng@redhat.com>
Date:   Tue May 19 12:34:35 2015 +1000

    Merge branch 'integration/master' into rhbz1222710

commit 2e68ba0
Author: Alex Eng <aeng@redhat.com>
Date:   Tue May 19 10:54:56 2015 +1000

    Changed load user option message

commit fe75a58
Author: Alex Eng <aeng@redhat.com>
Date:   Tue May 19 08:55:21 2015 +1000

    Fix save editor option: https://bugzilla.redhat.com/show_bug.cgi?id=1222710
  • Loading branch information
Alex Eng committed May 20, 2015
1 parent ee7b454 commit cac3875
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/release-notes.md
Expand Up @@ -32,6 +32,7 @@ Example usage in html file: `<link rel="shortcut icon" href="#{assets['img/logo/
* [1205512](https://bugzilla.redhat.com/show_bug.cgi?id=1205512) - Run validation in editor document list is disabled when it should not be
* [903964](https://bugzilla.redhat.com/show_bug.cgi?id=903964) - Error message not propagated to client when push fails
* [1218002](https://bugzilla.redhat.com/show_bug.cgi?id=1218002) - Disable Google Open Id option
* [1222710](https://bugzilla.redhat.com/show_bug.cgi?id=1222710) - Editor option save fails due to ClassCastException
* [1222358](https://bugzilla.redhat.com/show_bug.cgi?id=1222358) - User profile page dropdown will not work in firefox

-----------------------
Expand Down
41 changes: 41 additions & 0 deletions zanata-war/src/main/java/org/zanata/dao/AccountOptionDAO.java
@@ -0,0 +1,41 @@
/*
* Copyright 2015, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.dao;

import org.hibernate.Session;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.zanata.model.HAccountOption;

@Name("accountOptionDAO")
@AutoCreate
@Scope(ScopeType.STATELESS)
public class AccountOptionDAO extends AbstractDAOImpl<HAccountOption, Long> {
public AccountOptionDAO() {
super(HAccountOption.class);
}

public AccountOptionDAO(Session session) {
super(HAccountOption.class, session);
}
}
Expand Up @@ -29,6 +29,7 @@
import org.zanata.webtrans.client.events.UserConfigChangeEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEventHandler;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.UserOptionsService;
import org.zanata.webtrans.client.view.DocumentListOptionsDisplay;
Expand All @@ -49,17 +50,19 @@ public class DocumentListOptionsPresenter extends
private final CachingDispatchAsync dispatcher;
private final UserWorkspaceContext userWorkspaceContext;
private final UserOptionsService userOptionsService;
private final WebTransMessages messages;

@Inject
public DocumentListOptionsPresenter(DocumentListOptionsDisplay display,
public DocumentListOptionsPresenter(WebTransMessages messages,
DocumentListOptionsDisplay display,
EventBus eventBus, UserWorkspaceContext userWorkspaceContext,
CachingDispatchAsync dispatcher,
UserOptionsService userOptionsService) {
super(display, eventBus);
this.userWorkspaceContext = userWorkspaceContext;
this.dispatcher = dispatcher;
this.userOptionsService = userOptionsService;

this.messages = messages;
}

@Override
Expand Down Expand Up @@ -111,7 +114,7 @@ public void onRevealDisplay() {
@Override
public void persistOptionChange() {
userOptionsService.persistOptionChange(userOptionsService
.getDocumentListOptions());
.getDocumentListOptions());
}

@Override
Expand All @@ -138,7 +141,7 @@ public void onSuccess(LoadOptionsResult result) {
eventBus.fireEvent(UserConfigChangeEvent.DOCUMENT_CONFIG_CHANGE_EVENT);
eventBus.fireEvent(new NotificationEvent(
NotificationEvent.Severity.Warning,
"Loaded user options"));
messages.loadedUserOptions()));
}
});
}
Expand All @@ -151,6 +154,6 @@ public void loadDefaultOptions() {
eventBus.fireEvent(UserConfigChangeEvent.DOCUMENT_CONFIG_CHANGE_EVENT);
eventBus.fireEvent(new NotificationEvent(
NotificationEvent.Severity.Warning,
"Loaded default user options."));
messages.restoreToDefaultOptions()));
}
}
Expand Up @@ -34,6 +34,7 @@
import org.zanata.webtrans.client.events.UserConfigChangeEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEventHandler;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.UserOptionsService;
import org.zanata.webtrans.client.view.EditorOptionsDisplay;
Expand All @@ -57,9 +58,11 @@ public class EditorOptionsPresenter extends
private final UserWorkspaceContext userWorkspaceContext;
private final CachingDispatchAsync dispatcher;
private final UserOptionsService userOptionsService;
private final WebTransMessages messages;

@Inject
public EditorOptionsPresenter(EditorOptionsDisplay display,
public EditorOptionsPresenter(WebTransMessages messages,
EditorOptionsDisplay display,
EventBus eventBus, UserWorkspaceContext userWorkspaceContext,
ValidationOptionsPresenter validationDetailsPresenter,
ChangeReferenceLangPresenter changeReferenceLangPresenter,
Expand All @@ -71,6 +74,7 @@ public EditorOptionsPresenter(EditorOptionsDisplay display,
this.userWorkspaceContext = userWorkspaceContext;
this.dispatcher = dispatcher;
this.userOptionsService = userOptionsService;
this.messages = messages;
display.setListener(this);
}

Expand Down Expand Up @@ -244,6 +248,9 @@ public void onFailure(Throwable caught) {
public void onSuccess(LoadOptionsResult result) {
userOptionsService.getConfigHolder().setState(
result.getConfiguration());
eventBus.fireEvent(new NotificationEvent(
NotificationEvent.Severity.Warning,
messages.loadedUserOptions()));
refreshOptions();
}
});
Expand All @@ -254,6 +261,9 @@ public void loadDefaultOptions() {
userOptionsService.loadEditorDefaultOptions();
changeReferenceLangPresenter.loadDefaultOption();
refreshOptions();
eventBus.fireEvent(new NotificationEvent(
NotificationEvent.Severity.Warning,
messages.restoreToDefaultOptions()));
}

@Override
Expand All @@ -267,8 +277,5 @@ public void onReloadUserConfigUI(ReloadUserConfigUIEvent event) {
private void refreshOptions() {
display.setOptionsState(userOptionsService.getConfigHolder().getState());
eventBus.fireEvent(UserConfigChangeEvent.EDITOR_CONFIG_CHANGE_EVENT);
eventBus.fireEvent(new NotificationEvent(
NotificationEvent.Severity.Warning,
"Loaded default editor options."));
}
}
Expand Up @@ -552,4 +552,15 @@ String undoUnsuccessful(@PluralCount int unsuccessfulCount,

@DefaultMessage("Project ID or version ID has changed. Please copy your unsaved work into clipboard. Editor will reload in 10 seconds.")
String workspaceUrlHasChanged();

@DefaultMessage("Loaded user options")
String loadedUserOptions();

@DefaultMessage("Restore to default options")
String restoreToDefaultOptions();

@DefaultMessage("Saved user options")
String savedOptions();


}
Expand Up @@ -29,6 +29,7 @@

import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.presenter.UserConfigHolder;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.shared.model.UserOptions;
import org.zanata.webtrans.shared.model.ValidationId;
Expand All @@ -51,13 +52,15 @@ public class UserOptionsService {
private final EventBus eventBus;
private final CachingDispatchAsync dispatcher;
private final UserConfigHolder configHolder;
private final WebTransMessages messages;

@Inject
public UserOptionsService(EventBus eventBus,
public UserOptionsService(WebTransMessages messages, EventBus eventBus,
CachingDispatchAsync dispatcher, UserConfigHolder configHolder) {
this.eventBus = eventBus;
this.dispatcher = dispatcher;
this.configHolder = configHolder;
this.messages = messages;
}

public void persistOptionChange(Map<UserOptions, String> optsMap) {
Expand All @@ -74,7 +77,8 @@ public void onFailure(Throwable caught) {
@Override
public void onSuccess(SaveOptionsResult result) {
eventBus.fireEvent(new NotificationEvent(
NotificationEvent.Severity.Info, "Saved user options"));
NotificationEvent.Severity.Warning,
messages.savedOptions()));
}
});
}
Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.security.management.JpaIdentityStore;
import org.zanata.dao.AccountDAO;
import org.zanata.dao.AccountOptionDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HAccountOption;
import org.zanata.webtrans.server.ActionHandlerFor;
Expand All @@ -53,6 +54,9 @@ public class SaveOptionsHandler extends
@In
private AccountDAO accountDAO;

@In
private AccountOptionDAO accountOptionDAO;

@Override
public SaveOptionsResult execute(SaveOptionsAction action,
ExecutionContext context) throws ActionException {
Expand All @@ -61,12 +65,12 @@ public SaveOptionsResult execute(SaveOptionsAction action,

for (Entry<UserOptions, String> entry : action.getConfigurationMap()
.entrySet()) {
this.setOrCreateOptionValue(account, entry.getKey(),
entry.getValue());
HAccountOption option = updateOrCreateOption(account, entry.getKey(),
entry.getValue());
accountOptionDAO.makePersistent(option);
}

accountDAO.makePersistent(account);
accountDAO.flush();
accountOptionDAO.flush();

SaveOptionsResult result = new SaveOptionsResult();
result.setSuccess(true);
Expand All @@ -79,7 +83,7 @@ public void rollback(SaveOptionsAction action, SaveOptionsResult result,
ExecutionContext context) throws ActionException {
}

private void setOrCreateOptionValue(HAccount account, UserOptions name,
private HAccountOption updateOrCreateOption(HAccount account, UserOptions name,
String newVal) {
HAccountOption option =
account.getEditorOptions().get(name.getPersistentName());
Expand All @@ -91,5 +95,6 @@ private void setOrCreateOptionValue(HAccount account, UserOptions name,
} else {
option.setValue(newVal);
}
return option;
}
}
Expand Up @@ -22,6 +22,7 @@
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.UserConfigChangeEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEvent;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.UserOptionsService;
import org.zanata.webtrans.client.view.DocumentListOptionsDisplay;
Expand Down Expand Up @@ -53,6 +54,8 @@ public class DocumentListOptionsPresenterTest {
private CachingDispatchAsync dispatcher;
@Mock
private UserOptionsService userOptionsService;
@Mock
private WebTransMessages messages;
@Captor
private ArgumentCaptor<UserConfigChangeEvent> eventCaptor;

Expand All @@ -64,7 +67,7 @@ public void beforeMethod() {
MockitoAnnotations.initMocks(this);

presenter =
new DocumentListOptionsPresenter(display, eventBus,
new DocumentListOptionsPresenter(messages, display, eventBus,
userWorkspaceContext, dispatcher, userOptionsService);
when(userOptionsService.getConfigHolder()).thenReturn(configHolder);

Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.zanata.webtrans.client.events.RefreshPageEvent;
import org.zanata.webtrans.client.events.UserConfigChangeEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEvent;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.UserOptionsService;
import org.zanata.webtrans.client.view.EditorOptionsDisplay;
Expand Down Expand Up @@ -65,6 +66,8 @@ public class EditorOptionsPresenterTest {
private ArgumentCaptor<UserConfigChangeEvent> eventCaptor;
@Mock
private UserOptionsService userOptionsService;
@Mock
private WebTransMessages messages;

private UserConfigHolder configHolder = new UserConfigHolder();

Expand All @@ -76,7 +79,7 @@ public void beforeMethod() {
when(userOptionsService.getConfigHolder()).thenReturn(configHolder);

presenter =
new EditorOptionsPresenter(display, eventBus,
new EditorOptionsPresenter(messages, display, eventBus,
userWorkspaceContext, validationDetailsPresenter,
changeReferenceLangPresenter,
dispatcher, userOptionsService);
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.testng.annotations.Test;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.presenter.UserConfigHolder;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.shared.model.UserOptions;
import org.zanata.webtrans.shared.rpc.NavOption;
Expand All @@ -60,14 +61,16 @@ public class UserOptionsServiceTest {
private EventBus eventBus;
@Mock
private CachingDispatchAsync dispatcher;
@Mock
private WebTransMessages messages;

private UserConfigHolder configHolder = new UserConfigHolder();

@BeforeMethod
public void beforeMethod() {
MockitoAnnotations.initMocks(this);

service = new UserOptionsService(eventBus, dispatcher, configHolder);
service = new UserOptionsService(messages, eventBus, dispatcher, configHolder);
}

@Test
Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.testng.annotations.Test;
import org.zanata.ZanataDbunitJpaTest;
import org.zanata.dao.AccountDAO;
import org.zanata.dao.AccountOptionDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HAccountOption;
import org.zanata.seam.SeamAutowire;
Expand All @@ -31,6 +32,8 @@ public class LoadOptionsHandlerTest extends ZanataDbunitJpaTest {
private LoadOptionsHandler handler;
private SaveOptionsHandler saveHandler;

private final static SeamAutowire seam = SeamAutowire.instance();

@Override
protected void prepareDBUnitOperations() {
beforeTestOperations.add(new DataSetOperation(
Expand All @@ -45,15 +48,20 @@ protected void prepareDBUnitOperations() {
@BeforeMethod
public void setUp() throws Exception {
AccountDAO accountDAO = new AccountDAO(getSession());
AccountOptionDAO accountOptionDAO = new AccountOptionDAO(getSession());
HAccount authenticatedAccount = getEm().find(HAccount.class, 1L);
// @formatter:off
handler = SeamAutowire.instance()
handler = seam
.reset()
.use(JpaIdentityStore.AUTHENTICATED_USER, authenticatedAccount)
.use("accountDAO", accountDAO)
.autowire(LoadOptionsHandler.class);

saveHandler = SeamAutowire.instance()
.reset()
.use(JpaIdentityStore.AUTHENTICATED_USER, authenticatedAccount)
.use("accountDAO", accountDAO)
.use("accountOptionDAO", accountOptionDAO)
.autowire(SaveOptionsHandler.class);
// @formatter:on
}
Expand Down

0 comments on commit cac3875

Please sign in to comment.