Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add list of video conference button with external video conference for user and space - EXO-69422 #21

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ public List<ExternalVisioConnectorEntity> getExternalVisioConnectors(boolean ena
}
}

public List<ExternalVisioConnectorEntity> getActiveExternalVisioConnectorsForSpace() {
TypedQuery<ExternalVisioConnectorEntity> query =
getEntityManager().createNamedQuery("ExternalVisioConnector.getActiveExternalVisioConnectorsForSpaces",
ExternalVisioConnectorEntity.class);
public List<ExternalVisioConnectorEntity> getActiveExternalVisioConnectors(boolean forSpaces) {
String queryName = "ExternalVisioConnector.getActiveExternalVisioConnectorsFor";
if (!forSpaces) {
queryName += "Users";
} else {
queryName += "Spaces";
}
TypedQuery<ExternalVisioConnectorEntity> query = getEntityManager().createNamedQuery(queryName,
ExternalVisioConnectorEntity.class);
try {
return query.getResultList();
} catch (NoResultException e) {
return Collections.emptyList();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@Table(name = "EXTERNAL_VISIO_CONNECTOR")
@NamedQuery(name = "ExternalVisioConnector.getExternalVisioConnectors", query = "SELECT connector FROM ExternalVisioConnector connector WHERE connector.enabled = :enabled ORDER BY connector.order ASC")
@NamedQuery(name = "ExternalVisioConnector.getActiveExternalVisioConnectorsForSpaces", query = "SELECT connector FROM ExternalVisioConnector connector WHERE connector.activeForSpaces = true ORDER BY connector.order ASC")
@NamedQuery(name = "ExternalVisioConnector.getActiveExternalVisioConnectorsForUsers", query = "SELECT connector FROM ExternalVisioConnector connector WHERE connector.activeForUsers = true ORDER BY connector.order ASC")
@AllArgsConstructor
@NoArgsConstructor
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.resource.ResourceContainer;
import org.exoplatform.services.security.ConversationState;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.social.core.manager.IdentityManager;
import org.exoplatform.social.core.space.model.Space;
import org.exoplatform.social.core.space.spi.SpaceService;
import org.exoplatform.webconferencing.ActiveCallProvider;
import org.exoplatform.webconferencing.externalvisio.rest.model.ExternalVisioConnector;
import org.exoplatform.webconferencing.externalvisio.rest.model.ExternalVisioConnectors;
import org.exoplatform.webconferencing.externalvisio.rest.util.EntityBuilder;
Expand All @@ -45,8 +51,16 @@ public class ExternalVisioConnectorRest implements ResourceContainer {

private final ExternalVisioConnectorService externalVisioConnectorService;

public ExternalVisioConnectorRest(ExternalVisioConnectorService externalVisioConnectorService) {
private final IdentityManager identityManager;

private final SpaceService spaceService;

public ExternalVisioConnectorRest(ExternalVisioConnectorService externalVisioConnectorService,
IdentityManager identityManager,
SpaceService spaceService) {
this.externalVisioConnectorService = externalVisioConnectorService;
this.identityManager = identityManager;
this.spaceService = spaceService;
}

@POST
Expand Down Expand Up @@ -141,4 +155,37 @@ public Response updateExternalVisioConnector(@Parameter(description = "External
return Response.serverError().entity(e.getMessage()).build();
}
}

@GET
@RolesAllowed("users")
@Path("{identityId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Retrieves the list of configured external visio connectors", method = "GET", description = "Retrieves the list of configured external visio connectors")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Request fulfilled"),
@ApiResponse(responseCode = "400", description = "Invalid query input"),
@ApiResponse(responseCode = "401", description = "Unauthorized"),
@ApiResponse(responseCode = "500", description = "Internal server error"), })
public Response getConfiguredExternalVisioConnectors(@Parameter(description = "identityId", required = true)
@PathParam("identityId")
String identityId) {
String authenticatedUser = ConversationState.getCurrent().getIdentity().getUserId();
Space space = spaceService.getSpaceByPrettyName(identityId);
Identity identity = null;
if (space != null) {
identity = identityManager.getOrCreateSpaceIdentity(identityId);
if (!spaceService.isMember(space, authenticatedUser) && !spaceService.isSuperManager(authenticatedUser)) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
} else {
identity = identityManager.getOrCreateUserIdentity(identityId);
}
try {
List<ExternalVisioConnector> externalVisioConnectors =
externalVisioConnectorService.getConfiguredExternalVisioConnectors(identity);
return Response.ok(externalVisioConnectors).build();
} catch (Exception e) {
LOG.warn("Error retrieving list of configured external visio connectors", e);
return Response.serverError().entity(e.getMessage()).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ExternalVisioConnector {

private String name;

private String url;

private boolean activeForUsers;

private boolean activeForSpaces;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static ExternalVisioConnector fromEntity(ExternalVisioConnectorEntity ext
}
return new ExternalVisioConnector(externalVisioConnectorEntity.getId(),
externalVisioConnectorEntity.getName(),
null,
externalVisioConnectorEntity.isActiveForUsers(),
externalVisioConnectorEntity.isActiveForSpaces(),
externalVisioConnectorEntity.isEnabled(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package org.exoplatform.webconferencing.externalvisio.service;

import org.exoplatform.commons.ObjectAlreadyExistsException;
import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.webconferencing.externalvisio.entity.ExternalVisioConnectorEntity;
import org.exoplatform.webconferencing.externalvisio.rest.model.ExternalVisioConnector;
import org.exoplatform.webconferencing.externalvisio.rest.model.ExternalVisioConnectors;
Expand All @@ -35,4 +35,8 @@ public interface ExternalVisioConnectorService {
ExternalVisioConnector updateExternalVisioConnector(ExternalVisioConnectorEntity externalVisioConnectorEntity) throws ObjectNotFoundException;

List<ExternalVisioConnector> getActiveExternalVisioConnectorsForSpace();

List<ExternalVisioConnector> getActiveExternalVisioConnectorsForUser();

List<ExternalVisioConnector> getConfiguredExternalVisioConnectors(Identity identity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@

import org.apache.commons.collections.CollectionUtils;
import org.exoplatform.commons.ObjectAlreadyExistsException;
import org.exoplatform.commons.api.settings.SettingService;
import org.exoplatform.commons.api.settings.SettingValue;
import org.exoplatform.commons.api.settings.data.Context;
import org.exoplatform.commons.api.settings.data.Scope;
import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.social.core.profileproperty.ProfilePropertyService;
import org.exoplatform.social.core.profileproperty.model.ProfilePropertySetting;
import org.exoplatform.social.core.space.model.Space;
import org.exoplatform.social.core.space.spi.SpaceService;
import org.exoplatform.webconferencing.externalvisio.dao.ExternalVisioConnectorDAO;
import org.exoplatform.webconferencing.externalvisio.entity.ExternalVisioConnectorEntity;
import org.exoplatform.webconferencing.externalvisio.rest.ExternalVisioConnectorRest;
import org.exoplatform.webconferencing.externalvisio.rest.model.ExternalVisioConnector;
import org.exoplatform.webconferencing.externalvisio.rest.model.ExternalVisioConnectors;
import org.exoplatform.webconferencing.externalvisio.rest.util.EntityBuilder;
import org.exoplatform.webconferencing.externalvisio.service.ExternalVisioConnectorService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand All @@ -41,12 +48,19 @@ public class ExternalVisioConnectorServiceImpl implements ExternalVisioConnector
private final ExternalVisioConnectorDAO externalVisioConnectorDAO;

private final ProfilePropertyService profilePropertyService;

private final SettingService settingService;

private final SpaceService spaceService;

public ExternalVisioConnectorServiceImpl(ExternalVisioConnectorDAO externalVisioConnectorDAO,
ProfilePropertyService profilePropertyService) {
ProfilePropertyService profilePropertyService,
SettingService settingService,
SpaceService spaceService) {
this.externalVisioConnectorDAO = externalVisioConnectorDAO;
this.profilePropertyService = profilePropertyService;

this.settingService = settingService;
this.spaceService = spaceService;
}

@Override
Expand Down Expand Up @@ -118,10 +132,42 @@ public ExternalVisioConnector updateExternalVisioConnector(ExternalVisioConnecto

@Override
public List<ExternalVisioConnector> getActiveExternalVisioConnectorsForSpace() {
List<ExternalVisioConnectorEntity> activeVisioConnectorEntityList = externalVisioConnectorDAO.getActiveExternalVisioConnectorsForSpace();
List<ExternalVisioConnectorEntity> activeVisioConnectorEntityList = externalVisioConnectorDAO.getActiveExternalVisioConnectors(true);
return activeVisioConnectorEntityList.stream().map(EntityBuilder::fromEntity).toList();
}

@Override
public List<ExternalVisioConnector> getActiveExternalVisioConnectorsForUser() {
List<ExternalVisioConnectorEntity> activeVisioConnectorEntityList = externalVisioConnectorDAO.getActiveExternalVisioConnectors(false);
return activeVisioConnectorEntityList.stream().map(EntityBuilder::fromEntity).toList();
}

@Override
public List<ExternalVisioConnector> getConfiguredExternalVisioConnectors(Identity identity) {
List<ExternalVisioConnectorEntity> externalVisioConnectors = identity.isSpace()
|| identity.isUser() ? externalVisioConnectorDAO.getActiveExternalVisioConnectors(identity.isSpace()) : new ArrayList<>();
return externalVisioConnectors.stream().map(EntityBuilder::fromEntity).map(p -> {
p.setUrl(getExternalVisioConnectorsUrl(identity, p));
return p;
}).filter(p -> p.getUrl() != null).toList();
}

public String getExternalVisioConnectorsUrl(Identity identity, ExternalVisioConnector externalVisioConnector) {
String url = null;
if (identity.isSpace()) {
Space space = spaceService.getSpaceByPrettyName(identity.getRemoteId());
SettingValue<?> settingValue = settingService.get(Context.GLOBAL,
Scope.SPACE.id(space.getId()),
String.valueOf(externalVisioConnector.getId()));
if (settingValue != null) {
url = String.valueOf(settingValue.getValue());
}
} else if (identity.isUser()) {
url = (String) identity.getProfile().getProperty(externalVisioConnector.getName());
}
return url;
}

public void createPropertySetting(ExternalVisioConnectorEntity externalVisioConnectorEntity) {
ProfilePropertySetting profilePropertySetting = new ProfilePropertySetting();
profilePropertySetting.setActive(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ externalVisio.label.spaceModuleConnector.description=The space host will be able
externalVisio.tooltip.spaceModuleConnector.enable=Enable this web conferencing for spaces
externalVisio.tooltip.spaceModuleConnector.disable=Disable this web conferencing for spaces
externalVisio.label.btn.cancel=Cancel
externalVisio.label.btn.Save=Save
externalVisio.label.btn.Save=Save
externalVisio.label.btn.StartCall=Start a call
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ externalVisio.label.spaceModuleConnector.description=L'hôte de l'espace pourra
externalVisio.tooltip.spaceModuleConnector.enable=Activer cette conférence web pour les espaces
externalVisio.tooltip.spaceModuleConnector.disable=Désactiver cette conférence web pour les espaces
externalVisio.label.btn.cancel=Annuler
externalVisio.label.btn.Save=Enregistrer
externalVisio.label.btn.Save=Enregistrer
externalVisio.label.btn.StartCall=Démarrer un appel
24 changes: 24 additions & 0 deletions webapp/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<depends>
<module>webConferencing</module>
</depends>
<depends>
<module>webConferencing_VisioConnectorMeet</module>
<as>callButton</as>
</depends>
</module>

<module>
Expand All @@ -66,4 +70,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</depends>
</module>

<module>
<name>webConferencing_VisioConnectorMeet</name>
<load-group>webConferencingJitsiGRP</load-group>
<script>
<path>/js/callButton.bundle.js</path>
</script>
<depends>
<module>webConferencing</module>
</depends>
<depends>
<module>vue</module>
</depends>
<depends>
<module>vuetify</module>
</depends>
<depends>
<module>eXoVueI18n</module>
</depends>
</module>

</gatein-resources>
70 changes: 69 additions & 1 deletion webapp/src/main/webapp/js/webconferencing-externalvisio.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,76 @@
}
};

var getActiveProviders = function(identityId) {
return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/v1/externalVisio/${identityId}`, {
credentials: 'include',
method: 'GET'
}).then(resp => {
if (resp.ok) {
return resp.json();
} else {
throw new Error('Error when retrieving active providers');
}
});
}
var startCall = function(url) {
if (!url.match(/^(https?:\/\/|\/portal\/)/)) {
url = `//${url}`;
}
window.open(url, '_blank');
}

this.callButton = function(context, buttonType) {
var button = $.Deferred();
if (context && context.currentUser) {
context.details().then(target => {
if (!buttonType || buttonType === "vue") {
let activeButtons = [];
const identityId = context.isSpace ? context.spaceId : context.userId;
getActiveProviders(identityId)
.then((activeProviders) => {
activeButtons = activeProviders;
const buttonComponents = []; // Créer une liste pour stocker les composants Vue
activeButtons.forEach(p => {
const callSettings = {};
callSettings.target = target;
callSettings.context = context;
callSettings.provider = self;
callSettings.nameConnector = p.name;
callSettings.urlConnector = p.url;
callSettings.onCallOpen = () => {
startCall(callSettings.urlConnector);
};
callButton.init(callSettings).then(comp => {
// Ajouter le composant Vue à la liste
buttonComponents.push(comp);

if (buttonComponents.length === activeButtons.length) {
button.resolve(buttonComponents);
}
});
});
});
} else {
const message = "Button type not supported: " + buttonType;
log.error(message);
button.reject(message);
}
}).catch(err => {
// Gérer les erreurs
if (err && err.code == "NOT_FOUND_ERROR") {
button.reject(err.message);
} else {
var msg = "Error getting context details";
log.error(msg, err);
button.reject(msg, err);
}
});
} else {
var msg = "Not configured or empty context";
log.error(msg);
button.reject(msg);
}
return button.promise();
};

Expand All @@ -104,4 +172,4 @@
window.console
.log("WARN: webConferencing not given and eXo.webConferencing not defined. ExternalVisio provider registration skipped.");
}
})($, webConferencing);
})($, webConferencing, callButton);
Loading
Loading