Skip to content

Commit

Permalink
Replace Old SearchService and Move Unified search to legacy-intranet …
Browse files Browse the repository at this point in the history
…addon
  • Loading branch information
boubaker committed Jun 17, 2020
1 parent e2a14de commit 0655733
Show file tree
Hide file tree
Showing 18 changed files with 702 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ node_modules/
.classpath
.project
*.log
.factorypath

# OS
.DS_Store
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.exoplatform.social.core.jpa.search.listener;

import org.exoplatform.commons.search.index.IndexingService;
import org.exoplatform.commons.utils.CommonsUtils;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.component.RequestLifeCycle;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.organization.UserProfile;
import org.exoplatform.services.organization.UserProfileEventListener;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
import org.exoplatform.social.core.jpa.search.ProfileIndexingServiceConnector;
import org.exoplatform.social.core.manager.IdentityManager;

public class IDMProfileESListenerImpl extends UserProfileEventListener {

private static final Log LOG = ExoLogger.getLogger(IDMProfileESListenerImpl.class);

@Override
public void postSave(UserProfile user, boolean isNew) throws Exception {
RequestLifeCycle.begin(PortalContainer.getInstance());
try {
IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
IdentityManager identityManager = CommonsUtils.getService(IdentityManager.class);
Identity identity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, user.getUserName());

if (identity != null) {
LOG.debug("Notifying indexing service for IDM user profile update id={}", identity.getId());
indexingService.reindex(ProfileIndexingServiceConnector.TYPE, identity.getId());
}
} finally {
RequestLifeCycle.end();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,37 @@
import java.util.List;

/**
* Created by The eXo Platform SAS
* Author : eXoPlatform
* [email protected]
* Oct 1, 2015
* Created by The eXo Platform SAS Author : eXoPlatform [email protected] Oct
* 1, 2015
*/
public class UserESListenerImpl extends UserEventListener {
private static final Log LOG = ExoLogger.getLogger(UserESListenerImpl.class);
public class IDMUserESListenerImpl extends UserEventListener {
private static final Log LOG = ExoLogger.getLogger(IDMUserESListenerImpl.class);

@Override
public void preDelete(final User user) throws Exception {
RequestLifeCycle.begin(PortalContainer.getInstance());
try{
try {
IdentityManager idm = CommonsUtils.getService(IdentityManager.class);
Identity identity = idm.getOrCreateIdentity(OrganizationIdentityProvider.NAME, user.getUserName(), false);
Identity identity = idm.getOrCreateIdentity(OrganizationIdentityProvider.NAME, user.getUserName());

LOG.info("Notifying indexing service for user deletion id={}", identity.getId());
LOG.debug("Notifying indexing service for user deletion id={}", identity.getId());

CommonsUtils.getService(IndexingService.class).unindex(ProfileIndexingServiceConnector.TYPE, identity.getId());
reIndexAllConnector(identity);
} finally {
RequestLifeCycle.end();
}
}

@Override
public void postSetEnabled(User user) throws Exception {
RequestLifeCycle.begin(PortalContainer.getInstance());
try {
IdentityManager idm = CommonsUtils.getService(IdentityManager.class);
Identity identity = idm.getOrCreateIdentity(OrganizationIdentityProvider.NAME, user.getUserName(), false);

LOG.info("Notifying indexing service for user enable status change id={}", identity.getId());
Identity identity = idm.getOrCreateIdentity(OrganizationIdentityProvider.NAME, user.getUserName());

if (! user.isEnabled()) {
LOG.debug("Notifying indexing service for user enable status change id={}", identity.getId());
if (!user.isEnabled()) {
CommonsUtils.getService(IndexingService.class).unindex(ProfileIndexingServiceConnector.TYPE, identity.getId());
} else {
CommonsUtils.getService(IndexingService.class).reindex(ProfileIndexingServiceConnector.TYPE, identity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,29 @@
import org.exoplatform.social.core.profile.ProfileListenerPlugin;

/**
* Created by The eXo Platform SAS
* Author : eXoPlatform
* [email protected]
* Sep 29, 2015
* Created by The eXo Platform SAS Author : eXoPlatform [email protected] Sep
* 29, 2015
*/
public class ProfileESListenerImpl extends ProfileListenerPlugin {

private static final Log LOG = ExoLogger.getLogger(ProfileESListenerImpl.class);

@Override
public void headerSectionUpdated(ProfileLifeCycleEvent event) {
IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
String id = event.getProfile().getIdentity().getId();

LOG.debug("Notifying indexing service for profile header information update id={}", id);

indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id);
}

@Override
public void avatarUpdated(ProfileLifeCycleEvent event) {
IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
String id = event.getProfile().getIdentity().getId();

LOG.info("Notifying indexing service for profile avatar update id={}", id);
LOG.debug("Notifying indexing service for profile avatar update id={}", id);

indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id);
}
Expand All @@ -49,12 +57,22 @@ public void bannerUpdated(ProfileLifeCycleEvent event) {
LOG.debug("Profile banner of user {} has been updated", event.getProfile().getIdentity().getId());
}

@Override
public void basicInfoUpdated(ProfileLifeCycleEvent event) {
IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
String id = event.getProfile().getIdentity().getId();

LOG.debug("Notifying indexing service for the basic information update id={}", id);

indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id);
}

@Override
public void contactSectionUpdated(ProfileLifeCycleEvent event) {
IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
String id = event.getProfile().getIdentity().getId();

LOG.info("Notifying indexing service for the profile contact update id={}", id);
LOG.debug("Notifying indexing service for the profile contact update id={}", id);

indexingService.reindex(ProfileIndexingServiceConnector.TYPE, id);
}
Expand All @@ -63,7 +81,7 @@ public void contactSectionUpdated(ProfileLifeCycleEvent event) {
public void aboutMeUpdated(ProfileLifeCycleEvent event) {
String id = event.getProfile().getIdentity().getId();

LOG.info("Notifying indexing service for the profile aboutme update id={}", id);
LOG.debug("Notifying indexing service for the profile aboutme update id={}", id);

CommonsUtils.getService(IndexingService.class).reindex(ProfileIndexingServiceConnector.TYPE, id);
}
Expand All @@ -72,7 +90,7 @@ public void aboutMeUpdated(ProfileLifeCycleEvent event) {
public void experienceSectionUpdated(ProfileLifeCycleEvent event) {
String id = event.getProfile().getIdentity().getId();

LOG.info("Notifying indexing service for the profile experience update id={}", id);
LOG.debug("Notifying indexing service for the profile experience update id={}", id);

CommonsUtils.getService(IndexingService.class).reindex(ProfileIndexingServiceConnector.TYPE, id);
}
Expand All @@ -82,7 +100,7 @@ public void createProfile(ProfileLifeCycleEvent event) {
IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
String id = event.getProfile().getIdentity().getId();

LOG.info("Notifying indexing service for the profile creation id={}", id);
LOG.debug("Notifying indexing service for the profile creation id={}", id);

indexingService.index(ProfileIndexingServiceConnector.TYPE, id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ public void spaceRenamed(SpaceLifeCycleEvent event) {
reindex(event, "space renaming");
}

private void reindex(SpaceLifeCycleEvent event, String cause) {
IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
String id = event.getSpace().getId();

LOG.info("Notifying indexing service for {} id={}", cause, id);

indexingService.reindex(SpaceIndexingServiceConnector.TYPE, id);
}

@Override
public void spaceAccessEdited(SpaceLifeCycleEvent event) {
reindex(event, "space access edited");
Expand All @@ -63,69 +54,71 @@ public void spaceRegistrationEdited(SpaceLifeCycleEvent event) {

@Override
public void spaceBannerEdited(SpaceLifeCycleEvent event) {
// Banner not indexed
}

@Override
public void applicationActivated(SpaceLifeCycleEvent event) {
// TODO Auto-generated method stub

reindex(event, "space application activated");
}

@Override
public void applicationAdded(SpaceLifeCycleEvent event) {
// TODO Auto-generated method stub

reindex(event, "space application added");
}

@Override
public void applicationDeactivated(SpaceLifeCycleEvent event) {
// TODO Auto-generated method stub

reindex(event, "space application disabled");
}

@Override
public void applicationRemoved(SpaceLifeCycleEvent event) {
// TODO Auto-generated method stub

reindex(event, "space application removed");
}

@Override
public void grantedLead(SpaceLifeCycleEvent event) {
// TODO Auto-generated method stub

reindex(event, "space member granted as manager");
}

@Override
public void joined(SpaceLifeCycleEvent event) {
reindex(event, "space joined");
reindex(event, "space member joined");
}

@Override
public void left(SpaceLifeCycleEvent event) {
reindex(event, "space left");
reindex(event, "space member left");
}

@Override
public void revokedLead(SpaceLifeCycleEvent event) {
// TODO Auto-generated method stub

reindex(event, "space member revoked as manager");
}

@Override
public void spaceAvatarEdited(SpaceLifeCycleEvent event) {
// TODO Auto-generated method stub

reindex(event, "space avatar updated");
}

@Override
public void addInvitedUser(SpaceLifeCycleEvent event) {
// TODO Auto-generated method stub

reindex(event, "user invited to space");
}

@Override
public void addPendingUser(SpaceLifeCycleEvent event) {
// TODO Auto-generated method stub
reindex(event, "user requested access to space");
}

private void reindex(SpaceLifeCycleEvent event, String cause) {
IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
String id = event.getSpace().getId();

LOG.debug("Notifying indexing service for {} id={}", cause, id);

indexingService.reindex(SpaceIndexingServiceConnector.TYPE, id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 Meeds Association
* [email protected]
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.exoplatform.social.core.search;

/**
* An object defining a plugged search connector
*/
public class SearchConnector implements Cloneable {

private String name;

private String uri;

private boolean enabled;

public SearchConnector() {
}

public SearchConnector(String name, String uri, boolean enabled) {
this.name = name;
this.uri = uri;
this.enabled = enabled;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri = uri;
}

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SearchConnector other = (SearchConnector) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name)) {
return false;
}
return true;
}

@Override
public SearchConnector clone() { // NOSONAR
return new SearchConnector(name, uri, enabled);
}
}
Loading

0 comments on commit 0655733

Please sign in to comment.