Skip to content

Commit

Permalink
introduce ViewCloseReason
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Nov 15, 2017
1 parent b18a3df commit c222f79
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.metas.ui.web.exceptions.EntityNotFoundException;
import de.metas.ui.web.process.view.ViewActionDescriptorsList;
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.ViewCloseReason;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.ViewResult;
import de.metas.ui.web.view.event.ViewChangesCollector;
Expand Down Expand Up @@ -167,7 +168,7 @@ public long size()
}

@Override
public void close()
public void close(final ViewCloseReason reason)
{
invalidateAllNoNotify();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import de.metas.ui.web.document.filter.DocumentFilter;
import de.metas.ui.web.exceptions.EntityNotFoundException;
import de.metas.ui.web.view.IEditableView;
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.ViewResult;
Expand Down Expand Up @@ -54,7 +53,7 @@

public class OLCandView implements IEditableView
{
public static OLCandView cast(final IView view)
public static OLCandView cast(final Object view)
{
return (OLCandView)view;
}
Expand Down Expand Up @@ -113,11 +112,6 @@ public long size()
return rows.size();
}

@Override
public void close()
{
}

@Override
public int getQueryLimit()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.metas.ui.web.order.purchase.view;

/*
* #%L
* metasfresh-webui-api
* %%
* Copyright (C) 2017 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* 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
* 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
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

public class OLCandViewService
{
public void createOLCandRecords(final OLCandView view)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalNotification;
import com.google.common.collect.ImmutableList;

import de.metas.interfaces.I_C_BPartner_Product;
Expand All @@ -23,6 +24,7 @@
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewFactory;
import de.metas.ui.web.view.IViewsIndexStorage;
import de.metas.ui.web.view.ViewCloseReason;
import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.descriptor.ViewLayout;
Expand Down Expand Up @@ -61,6 +63,7 @@ public class SalesOrderToOLCandViewFactory implements IViewFactory, IViewsIndexS

private final Cache<ViewId, OLCandView> views = CacheBuilder.newBuilder()
.expireAfterAccess(1, TimeUnit.HOURS)
.removalListener(notification -> onViewRemoved(notification))
.build();

@Override
Expand Down Expand Up @@ -112,6 +115,13 @@ public void removeById(final ViewId viewId)
views.cleanUp(); // also cleanup to prevent views cache to grow.
}

private final void onViewRemoved(final RemovalNotification<Object, Object> notification)
{
final OLCandView view = OLCandView.cast(notification.getValue());
final ViewCloseReason closeReason = ViewCloseReason.fromCacheEvictedFlag(notification.wasEvicted());
view.close(closeReason);
}

@Override
public Stream<IView> streamAllViews()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import de.metas.ui.web.picking.pickingslot.PickingSlotView;
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.view.ViewCloseReason;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.ViewResult;
import de.metas.ui.web.view.event.ViewChangesCollector;
Expand Down Expand Up @@ -156,7 +157,7 @@ public long size()
}

@Override
public void close()
public void close(final ViewCloseReason reason)
{
final List<Integer> shipmentScheduleIds = getRows()
.values().stream()
Expand Down Expand Up @@ -317,9 +318,13 @@ public void setPickingSlotView(@NonNull final DocumentId rowId, @NonNull final P
pickingSlotsViewByRowId.put(rowId, pickingSlotView);
}

public void removePickingSlotView(@NonNull final DocumentId rowId)
public void removePickingSlotView(@NonNull final DocumentId rowId, @NonNull final ViewCloseReason viewCloseReason)
{
pickingSlotsViewByRowId.remove(rowId);
final PickingSlotView view = pickingSlotsViewByRowId.remove(rowId);
if (view != null)
{
view.close(viewCloseReason);
}
}

public PickingSlotView getPickingSlotViewOrNull(@NonNull final DocumentId rowId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ public long size()
return rows.size();
}

@Override
public void close()
{
}

@Override
public int getQueryLimit()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewsIndexStorage;
import de.metas.ui.web.view.IViewsRepository;
import de.metas.ui.web.view.ViewCloseReason;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.event.ViewChangesCollector;
import de.metas.ui.web.view.json.JSONViewDataType;
Expand Down Expand Up @@ -166,7 +167,7 @@ public void removeById(@NonNull final ViewId pickingSlotViewId)
{
final DocumentId rowId = extractRowId(pickingSlotViewId);
final PackageableView packageableView = getPackageableViewByPickingSlotViewId(pickingSlotViewId);
packageableView.removePickingSlotView(rowId);
packageableView.removePickingSlotView(rowId, ViewCloseReason.USER_REQUEST);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.view.IViewRowOverrides;
import de.metas.ui.web.view.ViewCloseReason;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.ViewResult;
import de.metas.ui.web.view.event.ViewChangesCollector;
Expand Down Expand Up @@ -139,12 +140,6 @@ public long size()
return rows.size();
}

@Override
public void close()
{
// nothing
}

@Override
public int getQueryLimit()
{
Expand Down Expand Up @@ -266,7 +261,7 @@ public synchronized void clearAfterPickingHUView()

if (afterPickingHUView != null)
{
afterPickingHUView.close();
afterPickingHUView.close(ViewCloseReason.USER_REQUEST);
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/de/metas/ui/web/pporder/PPOrderLinesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.metas.ui.web.exceptions.EntityNotFoundException;
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.view.ViewCloseReason;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.ViewResult;
import de.metas.ui.web.view.event.ViewChangesCollector;
Expand Down Expand Up @@ -197,7 +198,7 @@ public long size()
}

@Override
public void close()
public void close(final ViewCloseReason reason)
{
invalidateAllNoNotify();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/metas/ui/web/view/DefaultView.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public List<DocumentFilter> getAllFilters()
}

@Override
public void close()
public void close(final ViewCloseReason reason)
{
if (closed.getAndSet(true))
{
Expand All @@ -271,7 +271,7 @@ public void close()
// nothing now.
// TODO in future me might notify somebody to remove the temporary selections from database

logger.debug("View closed: {}", this);
logger.debug("View closed with reason={}: {}", reason, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public WindowId getWindowId()
private final void onViewRemoved(final RemovalNotification<Object, Object> notification)
{
final IView view = (IView)notification.getValue();
view.close();
final ViewCloseReason closeReason = ViewCloseReason.fromCacheEvictedFlag(notification.wasEvicted());
view.close(closeReason);
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/de/metas/ui/web/view/IView.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ default boolean isIncludedView()

long size();

void close();
default void close(final ViewCloseReason reason)
{
// nothing
}

int getQueryLimit();

Expand Down
36 changes: 36 additions & 0 deletions src/main/java/de/metas/ui/web/view/ViewCloseReason.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package de.metas.ui.web.view;

/*
* #%L
* metasfresh-webui-api
* %%
* Copyright (C) 2017 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* 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
* 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
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

public enum ViewCloseReason
{
/** Closed because user requested it */
USER_REQUEST,
/** Closed because it was removed automatically from cache (expired, cache size exceeded etc) */
CLEANUP;

public static ViewCloseReason fromCacheEvictedFlag(final boolean wasEvicted)
{
return wasEvicted ? ViewCloseReason.CLEANUP : ViewCloseReason.USER_REQUEST;
}
}

1 comment on commit c222f79

@teosarca
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task: #677

Please sign in to comment.