All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.imunity.upman.front.views.groups.GroupService Maven / Gradle / Ivy
/*
* Copyright (c) 2018 Bixbit - Krzysztof Benedyczak. All rights reserved.
* See LICENCE.txt file for licensing information.
*/
package io.imunity.upman.front.views.groups;
import io.imunity.upman.front.model.Group;
import io.imunity.upman.front.model.ProjectGroup;
import io.imunity.vaadin.elements.NotificationPresenter;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import pl.edu.icm.unity.base.i18n.I18nString;
import pl.edu.icm.unity.base.message.MessageSource;
import pl.edu.icm.unity.base.utils.Log;
import pl.edu.icm.unity.engine.api.project.DelegatedGroupManagement;
import pl.edu.icm.unity.engine.api.project.SubprojectGroupDelegationConfiguration;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
@Service
class GroupService
{
private static final Logger log = Log.getLogger(Log.U_SERVER_UPMAN, GroupService.class);
private final DelegatedGroupManagement delGroupMan;
private final MessageSource msg;
private final NotificationPresenter notificationPresenter;
public GroupService(MessageSource msg, DelegatedGroupManagement delGroupMan, NotificationPresenter notificationPresenter)
{
this.msg = msg;
this.delGroupMan = delGroupMan;
this.notificationPresenter = notificationPresenter;
}
public void addGroup(ProjectGroup projectGroup, Group group, Map names, boolean isPublic)
{
I18nString i18nString = cretaei18nString(names);
try
{
delGroupMan.addGroup(projectGroup.path, group.path, i18nString, isPublic);
} catch (Exception e)
{
log.warn("Can not add group " + projectGroup.path, e);
notificationPresenter.showError(msg.getMessage("ServerFaultExceptionCaption"), msg.getMessage("ContactSupport"));
}
}
public void deleteGroup(ProjectGroup projectGroup, Group group)
{
try
{
delGroupMan.removeGroup(projectGroup.path, group.path);
} catch (Exception e)
{
log.warn("Can not remove group " + group, e);
notificationPresenter.showError(msg.getMessage("ServerFaultExceptionCaption"), msg.getMessage("ContactSupport"));
}
}
public void deleteSubProjectGroup(ProjectGroup projectGroup, Group group)
{
try
{
delGroupMan.removeProject(projectGroup.path, group.path);
} catch (Exception e)
{
log.warn("Can not remove sub-project group " + group.path, e);
notificationPresenter.showError(msg.getMessage("ServerFaultExceptionCaption"), msg.getMessage("ContactSupport"));
}
}
public void setGroupAccessMode(ProjectGroup projectGroup, Group group, boolean isPublic)
{
try
{
delGroupMan.setGroupAccessMode(projectGroup.path, group.path, isPublic);
} catch (Exception e)
{
log.warn("Can not set group access mode for " + group.path, e);
if (!projectGroup.path.equals(group.path))
{
notificationPresenter.showError(msg.getMessage("ServerFaultExceptionCaption"), msg.getMessage("ContactSupport"));
} else
{
notificationPresenter.showError(msg.getMessage("GroupsController.projectGroupAccessModeChangeError"), msg.getMessage("GroupsController.projectGroupAccessModeChangeErrorDetails"));
}
}
}
public void updateGroupName(ProjectGroup projectGroup, Group group, Map names)
{
I18nString i18nString = cretaei18nString(names);
try
{
delGroupMan.setGroupDisplayedName(projectGroup.path, group.path, i18nString);
} catch (Exception e)
{
log.warn("Can not rename group " + group.path, e);
notificationPresenter.showError(msg.getMessage("ServerFaultExceptionCaption"), msg.getMessage("ContactSupport"));
}
}
private I18nString cretaei18nString(Map names)
{
I18nString i18nString = new I18nString();
Map values = names.entrySet().stream()
.filter(entry -> !entry.getValue().isBlank())
.collect(Collectors.toMap(entry -> entry.getKey().getLanguage(), Map.Entry::getValue));
i18nString.addAllValues(values);
return i18nString;
}
public void setGroupDelegationConfiguration(ProjectGroup projectGroup, Group group, boolean enabled, boolean enableSubProjects, String logUrl)
{
SubprojectGroupDelegationConfiguration config = new SubprojectGroupDelegationConfiguration(enabled, enableSubProjects, logUrl);
try
{
delGroupMan.setGroupDelegationConfiguration(projectGroup.path, group.path, config);
} catch (Exception e)
{
log.warn("Can not set group delegation configuration in " + group.path, e);
notificationPresenter.showError(msg.getMessage("ServerFaultExceptionCaption"), msg.getMessage("ContactSupport"));
}
}
}