Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
metas-dev committed Apr 7, 2017
2 parents 94fdfc6 + a181e7b commit d72c3d9
Show file tree
Hide file tree
Showing 11 changed files with 377 additions and 204 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/metas/ui/web/WebRestApiApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public static boolean isProfileActive(final String profile)
private ApplicationContext applicationContext;

@Bean
public Adempiere adempiere()
public Adempiere adempiere(final WebRestApiContextProvider webuiContextProvider)
{
Env.setContextProvider(new WebRestApiContextProvider());
Env.setContextProvider(webuiContextProvider);

InterfaceWrapperHelper.registerHelper(new DocumentInterfaceWrapperHelper());

Expand Down
45 changes: 23 additions & 22 deletions src/main/java/de/metas/ui/web/debug/DebugRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.stream.Stream;

import org.adempiere.ad.dao.IQueryStatisticsLogger;
import org.adempiere.util.Check;
Expand All @@ -27,6 +24,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand Down Expand Up @@ -54,7 +52,6 @@
import de.metas.ui.web.view.IDocumentViewsRepository;
import de.metas.ui.web.view.json.JSONDocumentViewResult;
import de.metas.ui.web.window.WindowConstants;
import de.metas.ui.web.window.datatypes.json.JSONOptions;
import de.metas.ui.web.window.model.DocumentCollection;
import de.metas.ui.web.window.model.lookup.LookupDataSourceFactory;
import de.metas.ui.web.window.model.sql.SqlDocumentsRepository;
Expand Down Expand Up @@ -136,23 +133,25 @@ private static final void logResourceValueChanged(final String name, final Objec
@RequestMapping(value = "/showColumnNamesForCaption", method = RequestMethod.PUT)
public void setShowColumnNamesForCaption(@RequestBody final String showColumnNamesForCaptionStr)
{
final boolean showColumnNamesForCaption = DisplayType.toBoolean(showColumnNamesForCaptionStr);
final Object showColumnNamesForCaptionOldObj = userSession.setProperty(JSONOptions.SESSION_ATTR_ShowColumnNamesForCaption, showColumnNamesForCaption);
logResourceValueChanged("showColumnNamesForCaption", showColumnNamesForCaption, showColumnNamesForCaptionOldObj);
final boolean showColumnNamesForCaption_Old = userSession.isShowColumnNamesForCaption();
userSession.setShowColumnNamesForCaption(DisplayType.toBoolean(showColumnNamesForCaptionStr));
final boolean showColumnNamesForCaption_New = userSession.isShowColumnNamesForCaption();
logResourceValueChanged("showColumnNamesForCaption", showColumnNamesForCaption_New, showColumnNamesForCaption_Old);
}

@RequestMapping(value = "/disableDeprecatedRestAPI", method = RequestMethod.PUT)
public void setDisableDeprecatedRestAPI(@RequestBody final String disableDeprecatedRestAPIStr)
@RequestMapping(value = "/allowDeprecatedRestAPI", method = RequestMethod.PUT)
public void setAllowDeprecatedRestAPI(@RequestBody final String allowDeprecatedRestAPI)
{
final boolean disableDeprecatedRestAPI = DisplayType.toBoolean(disableDeprecatedRestAPIStr);
final Object disableDeprecatedRestAPIOldObj = userSession.setProperty(UserSession.PARAM_DisableDeprecatedRestAPI, disableDeprecatedRestAPI);
logResourceValueChanged(UserSession.PARAM_DisableDeprecatedRestAPI, disableDeprecatedRestAPI, disableDeprecatedRestAPIOldObj);
final boolean allowDeprecatedRestAPI_Old = userSession.isAllowDeprecatedRestAPI();
userSession.setAllowDeprecatedRestAPI(DisplayType.toBoolean(allowDeprecatedRestAPI));
final boolean allowDeprecatedRestAPI_New = userSession.isAllowDeprecatedRestAPI();
logResourceValueChanged("Allow Deprecated REST API", allowDeprecatedRestAPI_New, allowDeprecatedRestAPI_Old);
}

@RequestMapping(value = "/disableDeprecatedRestAPI", method = RequestMethod.GET)
public boolean isDisableDeprecatedRestAPI()
public boolean isAllowDeprecatedRestAPI()
{
return userSession.getPropertyAsBoolean(UserSession.PARAM_DisableDeprecatedRestAPI, false);
return userSession.isAllowDeprecatedRestAPI();
}

@RequestMapping(value = "/traceSqlQueries", method = RequestMethod.GET)
Expand Down Expand Up @@ -315,14 +314,6 @@ public String getLoggerName()
{
return loggerName;
}

public static final LoggingModule forLoggerName(final String loggerName)
{
return Stream.of(values())
.filter(value -> Objects.equals(value.loggerName, loggerName))
.findFirst()
.orElseThrow(() -> new NoSuchElementException(loggerName));
}
}

@GetMapping("/logger/_setLevel/{level}")
Expand Down Expand Up @@ -365,4 +356,14 @@ public void setLoggerLevel(
}
}

@PutMapping("/language")
public String setAD_Language(@RequestBody final String adLanguage)
{
final String adLanguageOld = userSession.setAD_Language(adLanguage);
final String adLanguageNew = userSession.getAD_Language();
logResourceValueChanged("AD_Language", adLanguageNew, adLanguageOld);

return adLanguageNew;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.messaging.simp.SimpMessagingTemplate;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import de.metas.logging.LogManager;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class UserNotificationsQueue
private static final Logger logger = LogManager.getLogger(UserNotificationsQueue.class);

private final int adUserId;
private final String adLanguage;
private String adLanguage;
private final SimpMessagingTemplate websocketMessagingTemplate;
private final String websocketEndpoint;

Expand Down Expand Up @@ -199,4 +200,10 @@ public int getUnreadCount()
return unreadCount.get();
}

public void setLanguage(final String adLanguage)
{
Preconditions.checkNotNull(adLanguage, "language");
this.adLanguage = adLanguage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import org.adempiere.util.Services;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import de.metas.event.Event;
import de.metas.event.IEventBus;
import de.metas.event.IEventBusFactory;
import de.metas.logging.LogManager;
import de.metas.ui.web.session.UserSession.LanguagedChangedEvent;

/*
* #%L
Expand All @@ -27,11 +29,11 @@
*
* This program 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
Expand All @@ -48,6 +50,16 @@ public class UserNotificationsService

private final AtomicBoolean subscribedToEventBus = new AtomicBoolean(false);

@EventListener
private void onUserLanguageChanged(final LanguagedChangedEvent event)
{
final UserNotificationsQueue notificationsQueue = adUserId2notifications.get(event.getAdUserId());
if(notificationsQueue != null)
{
notificationsQueue.setLanguage(event.getAdLanguage());
}
}

private void subscribeToEventTopicsIfNeeded()
{
if (!subscribedToEventBus.getAndSet(true))
Expand All @@ -63,7 +75,7 @@ private void subscribeToEventTopicsIfNeeded()
public synchronized void enableForSession(final String sessionId, final int adUserId, final String adLanguage)
{
logger.trace("Enabling for sessionId={}, adUserId={}, adLanguage={}", sessionId, adUserId, adLanguage);

final UserNotificationsQueue notificationsQueue = adUserId2notifications.computeIfAbsent(adUserId,
theSessionId -> new UserNotificationsQueue(adUserId, adLanguage, websocketMessagingTemplate));
notificationsQueue.addActiveSessionId(sessionId);
Expand Down Expand Up @@ -99,7 +111,7 @@ public UserNotificationsList getNotifications(final int adUserId, final int limi
private void forwardEventToNotificationsQueues(final IEventBus eventBus, final Event event)
{
logger.trace("Got event from {}: {}", eventBus, event);

final UserNotification notification = UserNotification.of(event);
if (event.isAllRecipients())
{
Expand All @@ -112,12 +124,12 @@ private void forwardEventToNotificationsQueues(final IEventBus eventBus, final E
for (final int recipientUserId : event.getRecipientUserIds())
{
final UserNotificationsQueue notificationsQueue = adUserId2notifications.get(recipientUserId);
if(notificationsQueue == null)
if (notificationsQueue == null)
{
logger.trace("No notification queue was found for recipientUserId={}", recipientUserId);
continue;
}

notificationsQueue.addNotification(notification.copy());
}
}
Expand Down
Loading

0 comments on commit d72c3d9

Please sign in to comment.