Commit d037e641 authored by michael.simon's avatar michael.simon
Browse files

Add bulk group connector

parent afe5ebff
package edu.kit.scc.webreg.job;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.service.LocalGroupService;
import edu.kit.scc.webreg.service.ServiceService;
public class BulkConnectLocalGroups extends AbstractExecutableJob {
private static final long serialVersionUID = 1L;
@Override
public void execute() {
Logger logger = LoggerFactory.getLogger(BulkConnectLocalGroups.class);
logger.info("Starting BulkConnectLocalGroups");
if (! getJobStore().containsKey("ssn_from")) {
logger.warn("BulkConnectLocalGroups Job is not configured correctly. ssn_from Parameter is missing in JobMap");
return;
}
if (! getJobStore().containsKey("ssn_to")) {
logger.warn("BulkConnectLocalGroups Job is not configured correctly. ssn_to Parameter is missing in JobMap");
return;
}
String ssnFrom = getJobStore().get("ssn_from");
String ssnTo = getJobStore().get("ssn_to");
String filterRegex = getJobStore().getOrDefault("filter_regex", "^.*$");
try {
InitialContext ic = new InitialContext();
ServiceService serviceService = (ServiceService) ic.lookup("global/bwreg/bwreg-service/ServiceServiceImpl!edu.kit.scc.webreg.service.ServiceService");
LocalGroupService service = (LocalGroupService) ic.lookup("global/bwreg/bwreg-service/LocalGroupServiceImpl!edu.kit.scc.webreg.service.LocalGroupService");
ServiceEntity fromService = serviceService.findByShortName(ssnFrom);
ServiceEntity toService = serviceService.findByShortName(ssnTo);
if (fromService == null || toService == null) {
logger.warn("BulkConnectLocalGroups Job cannot find service by ssn");
return;
}
service.createServiceGroupFlagsBulk(fromService, toService, filterRegex);
} catch (NamingException e) {
logger.warn("Could not BulkConnectLocalGroups: {}", e);
}
}
}
......@@ -30,4 +30,5 @@ public interface LocalGroupService extends BaseService<LocalGroupEntity, Long> {
LocalGroupEntity findWithUsersAndChildren(Long id);
void createServiceGroupFlagsBulk(ServiceEntity fromService, ServiceEntity toService, String filterRegex);
}
......@@ -15,10 +15,15 @@ import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.LocalGroupDao;
import edu.kit.scc.webreg.dao.ServiceGroupFlagDao;
import edu.kit.scc.webreg.entity.LocalGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.ServiceGroupFlagEntity;
import edu.kit.scc.webreg.entity.ServiceGroupStatus;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.service.LocalGroupService;
import edu.kit.scc.webreg.service.group.LocalGroupCreator;
......@@ -28,17 +33,54 @@ public class LocalGroupServiceImpl extends BaseServiceImpl<LocalGroupEntity, Lon
private static final long serialVersionUID = 1L;
@Inject
private Logger logger;
@Inject
private LocalGroupDao dao;
@Inject
private LocalGroupCreator creator;
@Inject
private ServiceGroupFlagDao groupFlagDao;
@Override
public LocalGroupEntity createNew(ServiceEntity service) {
return creator.createNew(service);
}
@Override
public void createServiceGroupFlagsBulk(ServiceEntity fromService, ServiceEntity toService, String filterRegex) {
List<ServiceGroupFlagEntity> fromFlagList = groupFlagDao.findLocalGroupsForService(fromService);
for (ServiceGroupFlagEntity fromFlag : fromFlagList) {
if (fromFlag.getGroup() instanceof LocalGroupEntity) {
LocalGroupEntity group = (LocalGroupEntity) fromFlag.getGroup();
if (group.getName().matches(filterRegex)) {
List<ServiceGroupFlagEntity> toFlagList = groupFlagDao.findByGroupAndService(group, toService);
if (toFlagList.size() == 0) {
logger.info("Creating group flags for group {} and service {}", group.getName(), toService.getShortName());
ServiceGroupFlagEntity groupFlag = groupFlagDao.createNew();
groupFlag.setService(toService);
groupFlag.setGroup(group);
groupFlag.setStatus(ServiceGroupStatus.DIRTY);
groupFlag = groupFlagDao.persist(groupFlag);
}
else {
logger.info("Skipping group flags for group {} and service {}, they already exist", group.getName(), toService.getShortName());
}
}
else {
logger.info("Skipping group {}. Doesn't match regex {}", group.getName(), filterRegex);
}
}
}
}
@Override
public LocalGroupEntity save(LocalGroupEntity entity, ServiceEntity service) {
return creator.save(entity, service);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment