Skip to content

Commit

Permalink
Move publishing of BeforeAccountRemoveEvent to manager instead of ent…
Browse files Browse the repository at this point in the history
…ity listener (eclipse-che#4856)
  • Loading branch information
Sergii Leschenko authored Apr 20, 2017
1 parent a8bb308 commit 6ecec78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
*******************************************************************************/
package org.eclipse.che.account.api;

import org.eclipse.che.account.event.BeforeAccountRemovedEvent;
import org.eclipse.che.account.shared.model.Account;
import org.eclipse.che.account.spi.AccountDao;
import org.eclipse.che.account.spi.AccountImpl;
import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.notification.EventService;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand All @@ -30,11 +32,13 @@
@Singleton
public class AccountManager {

private final AccountDao accountDao;
private final AccountDao accountDao;
private final EventService eventService;

@Inject
public AccountManager(AccountDao accountDao) {
public AccountManager(AccountDao accountDao, EventService eventService) {
this.accountDao = accountDao;
this.eventService = eventService;
}

/**
Expand Down Expand Up @@ -121,6 +125,12 @@ public Account getByName(String name) throws NotFoundException, ServerException
*/
public void remove(String id) throws ServerException {
requireNonNull(id, "Required non-null account id");
accountDao.remove(id);
try {
AccountImpl toRemove = accountDao.getById(id);
eventService.publish(new BeforeAccountRemovedEvent(toRemove)).propagateException();
accountDao.remove(id);
} catch (NotFoundException ignored) {
//account is already removed
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
package org.eclipse.che.account.spi;

import org.eclipse.che.account.shared.model.Account;
import org.eclipse.che.account.spi.jpa.AccountEntityListener;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
Expand All @@ -38,7 +36,6 @@
}
)
@Table(name = "account")
@EntityListeners(AccountEntityListener.class)
public class AccountImpl implements Account {

@Id
Expand Down

This file was deleted.

0 comments on commit 6ecec78

Please sign in to comment.