Skip to content

Commit

Permalink
LPS-174018 Unregistry ScreenNavigationCategory and ScreenNavigationEn…
Browse files Browse the repository at this point in the history
…try on deleter
  • Loading branch information
MarinhoFeliphe committed Jan 31, 2023
1 parent 8bb683f commit 9949af3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ public class ObjectLayoutTabScreenNavigationEntry
implements ScreenNavigationEntry<ObjectLayoutTab> {

public ObjectLayoutTabScreenNavigationEntry(
String categoryKey, ObjectLayoutTab objectLayoutTab,
String screenNavigationKey) {
ObjectLayoutTab objectLayoutTab) {

_categoryKey = categoryKey;
_objectLayoutTab = objectLayoutTab;
_screenNavigationKey = screenNavigationKey;
}

@Override
public String getCategoryKey() {
return _categoryKey;
return String.valueOf(_objectLayoutTab.getObjectLayoutTabId());
}

@Override
Expand All @@ -56,7 +53,7 @@ public String getLabel(Locale locale) {

@Override
public String getScreenNavigationKey() {
return _screenNavigationKey;
return String.valueOf(_objectLayoutTab.getObjectLayoutId());
}

@Override
Expand All @@ -66,8 +63,6 @@ public void render(
throws IOException {
}

private final String _categoryKey;
private final ObjectLayoutTab _objectLayoutTab;
private final String _screenNavigationKey;

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@
import com.liferay.portal.kernel.util.Validator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
Expand Down Expand Up @@ -401,24 +404,24 @@ private ObjectLayoutTab _addObjectLayoutTab(
user, objectDefinitionId,
objectLayoutTab.getObjectLayoutTabId(), objectLayoutBoxes));

ScreenNavigationCategory screenNavigationCategory =
new ObjectLayoutTabScreenNavigationCategory(objectLayoutTab);

_bundleContext.registerService(
ScreenNavigationCategory.class, screenNavigationCategory,
HashMapDictionaryBuilder.<String, Object>put(
"screen.navigation.category.order:Integer",
objectLayoutTab.getObjectLayoutTabId()
).build());
_bundleContext.registerService(
ScreenNavigationEntry.class,
new ObjectLayoutTabScreenNavigationEntry(
screenNavigationCategory.getCategoryKey(), objectLayoutTab,
screenNavigationCategory.getScreenNavigationKey()),
HashMapDictionaryBuilder.<String, Object>put(
"screen.navigation.entry.order:Integer",
objectLayoutTab.getObjectLayoutTabId()
).build());
_serviceRegistrationsMap.put(
String.valueOf(objectLayoutTab.getObjectLayoutTabId()),
Arrays.asList(
_bundleContext.registerService(
ScreenNavigationCategory.class,
new ObjectLayoutTabScreenNavigationCategory(
objectLayoutTab),
HashMapDictionaryBuilder.<String, Object>put(
"screen.navigation.category.order:Integer",
objectLayoutTab.getObjectLayoutTabId()
).build()),
_bundleContext.registerService(
ScreenNavigationEntry.class,
new ObjectLayoutTabScreenNavigationEntry(objectLayoutTab),
HashMapDictionaryBuilder.<String, Object>put(
"screen.navigation.entry.order:Integer",
objectLayoutTab.getObjectLayoutTabId()
).build())));

return objectLayoutTab;
}
Expand All @@ -441,14 +444,23 @@ private void _deleteObjectLayoutBoxes(
List<ObjectLayoutTab> objectLayoutTabs) {

for (ObjectLayoutTab objectLayoutTab : objectLayoutTabs) {
List<ObjectLayoutBox> objectLayoutBoxes =
_deleteObjectLayoutRows(
_objectLayoutBoxPersistence.findByObjectLayoutTabId(
objectLayoutTab.getObjectLayoutTabId());
objectLayoutTab.getObjectLayoutTabId()));

_objectLayoutBoxPersistence.removeByObjectLayoutTabId(
objectLayoutTab.getObjectLayoutTabId());

_deleteObjectLayoutRows(objectLayoutBoxes);
for (ServiceRegistration<?> serviceRegistration :
_serviceRegistrationsMap.get(
String.valueOf(
objectLayoutTab.getObjectLayoutTabId()))) {

serviceRegistration.unregister();
}

_serviceRegistrationsMap.remove(
String.valueOf(objectLayoutTab.getObjectLayoutTabId()));
}
}

Expand Down Expand Up @@ -661,6 +673,9 @@ private void _validate(
@Reference
private ObjectLayoutTabPersistence _objectLayoutTabPersistence;

private final Map<String, List<ServiceRegistration<?>>>
_serviceRegistrationsMap = new ConcurrentHashMap<>();

@Reference
private UserLocalService _userLocalService;

Expand Down

0 comments on commit 9949af3

Please sign in to comment.