Skip to content

Commit

Permalink
[#1370] Operator fails on startup
Browse files Browse the repository at this point in the history
Rework UserDomainRegistry
  • Loading branch information
ruspl-afed committed May 23, 2024
1 parent 9a56b92 commit 13d66e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="org.eclipse.passage.loc.internal.users.core.UserDomainRegistry">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="load" deactivate="unload" name="org.eclipse.passage.loc.internal.users.core.UserDomainRegistry">
<property name="org.eclipse.passage.lic.emf.edit.domain.name" value="users"/>
<property name="org.eclipse.passage.lic.emf.edit.file.extension" value="users_xmi"/>
<service>
<provide interface="org.eclipse.passage.loc.internal.users.UserRegistry"/>
<provide interface="org.eclipse.passage.loc.internal.emf.EditingDomainRegistry"/>
</service>
<reference bind="bindEventAdmin" interface="org.osgi.service.event.EventAdmin" name="EventAdmin" unbind="unbindEventAdmin"/>
<reference bind="bindEventAdmin" cardinality="1..1" interface="org.osgi.service.event.EventAdmin" name="EventAdmin" unbind="unbindEventAdmin"/>
<reference bind="bindGear" interface="org.eclipse.passage.loc.internal.api.OperatorGearSupplier" name="Gear" unbind="unbindGear"/>
<implementation class="org.eclipse.passage.loc.internal.users.core.UserDomainRegistry"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -45,26 +46,27 @@
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.event.EventAdmin;

@SuppressWarnings("restriction")
@Component(property = { EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME + '=' + UsersPackage.eNAME,
EditingDomainRegistryAccess.PROPERTY_FILE_EXTENSION + '=' + "users_xmi" })
public class UserDomainRegistry extends BaseDomainRegistry<UserOrigin>
public final class UserDomainRegistry extends BaseDomainRegistry<UserOrigin>
implements UserRegistry, EditingDomainRegistry<UserOrigin> {

private final Map<String, UserOrigin> origins = new HashMap<>();
private final Map<String, User> users = new HashMap<>();

private EventAdmin events;
private final List<EventAdmin> events = new ArrayList<>();

@Reference
@Reference(cardinality = ReferenceCardinality.MANDATORY)
public void bindEventAdmin(EventAdmin admin) {
this.events = admin;
this.events.add(admin);
}

public void unbindEventAdmin(@SuppressWarnings("unused") EventAdmin admin) {
this.events = null;
public void unbindEventAdmin(EventAdmin admin) {
this.events.remove(admin);
}

@Override
Expand All @@ -78,15 +80,13 @@ public void unbindGear(OperatorGearSupplier supplier) {
super.unbindGear(supplier);
}

@Override
@Activate
public void activate(Map<String, Object> properties) {
public void load(Map<String, Object> properties) {
super.activate(properties);
}

@Deactivate
@Override
public void deactivate(Map<String, Object> properties) {
public void unload(Map<String, Object> properties) {
users.clear();
origins.clear();
super.deactivate(properties);
Expand Down Expand Up @@ -138,7 +138,7 @@ void registerUserOrigin(UserOrigin origin) {
Platform.getLog(getClass())
.warn(NLS.bind(UsersCoreMessages.UserDomain_instance_duplication_message, existing, origin));
}
events.postEvent(new EquinoxEvent(UserRegistryEvents.USER_ORIGIN_CREATE, origin).get());
events().postEvent(new EquinoxEvent(UserRegistryEvents.USER_ORIGIN_CREATE, origin).get());
origin.getUsers().forEach(u -> registerUser(u));
}

Expand All @@ -148,24 +148,28 @@ void registerUser(User user) {
Platform.getLog(getClass())
.warn(NLS.bind(UsersCoreMessages.UserDomain_instance_duplication_message, existing, user));
}
events.postEvent(new EquinoxEvent(UserRegistryEvents.USER_CREATE, user).get());
events().postEvent(new EquinoxEvent(UserRegistryEvents.USER_CREATE, user).get());
}

void unregisterUserOrigin(String id) {
UserOrigin removed = origins.remove(id);
if (removed != null) {
events.postEvent(new EquinoxEvent(UserRegistryEvents.USER_ORIGIN_DELETE, removed).get());
events().postEvent(new EquinoxEvent(UserRegistryEvents.USER_ORIGIN_DELETE, removed).get());
removed.getUsers().forEach(u -> unregisterUser(u.getContact().getEmail()));
}
}

void unregisterUser(String userId) {
User removed = users.remove(userId);
if (removed != null) {
events.postEvent(new EquinoxEvent(UserRegistryEvents.USER_DELETE, removed).get());
events().postEvent(new EquinoxEvent(UserRegistryEvents.USER_DELETE, removed).get());
}
}

private EventAdmin events() {
return events.stream().findAny().get();
}

@Override
public EClass getContentClassifier() {
return UsersPackage.eINSTANCE.getUserOrigin();
Expand Down

0 comments on commit 13d66e5

Please sign in to comment.