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

add group autoconnect feature

parent a6a3b14c
......@@ -13,12 +13,15 @@ package edu.kit.scc.webreg.entity;
import java.util.Map;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyColumn;
import javax.persistence.OneToMany;
......@@ -30,7 +33,6 @@ import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Type;
import edu.kit.scc.webreg.entity.as.AttributeSourceServiceEntity;
import edu.kit.scc.webreg.entity.project.ProjectAdminRoleEntity;
@Entity(name = "ServiceEntity")
@Table(name = "service")
......@@ -120,7 +122,14 @@ public class ServiceEntity extends AbstractBaseEntity {
@Column(name = "hidden")
private Boolean hidden;
@ManyToMany(targetEntity=ServiceEntity.class, cascade = CascadeType.ALL)
@JoinTable(name = "service_autoconnect_group",
joinColumns = @JoinColumn(name="from_service_id"),
inverseJoinColumns = @JoinColumn(name="to_service_id")
)
private Set<ServiceEntity> groupAutoconnectServices;
public Set<PolicyEntity> getPolicies() {
return policies;
}
......@@ -315,4 +324,12 @@ public class ServiceEntity extends AbstractBaseEntity {
public void setSshPubKeyApproverRole(SshPubKeyApproverRoleEntity sshPubKeyApproverRole) {
this.sshPubKeyApproverRole = sshPubKeyApproverRole;
}
public Set<ServiceEntity> getGroupAutoconnectServices() {
return groupAutoconnectServices;
}
public void setGroupAutoconnectServices(Set<ServiceEntity> groupAutoconnectServices) {
this.groupAutoconnectServices = groupAutoconnectServices;
}
}
......@@ -10,6 +10,7 @@ import org.slf4j.Logger;
import edu.kit.scc.webreg.dao.LocalGroupDao;
import edu.kit.scc.webreg.dao.SerialDao;
import edu.kit.scc.webreg.dao.ServiceDao;
import edu.kit.scc.webreg.dao.ServiceGroupFlagDao;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.GroupStatus;
......@@ -36,6 +37,9 @@ public class LocalGroupCreator implements Serializable {
@Inject
private SerialDao serialDao;
@Inject
private ServiceDao serviceDao;
public LocalGroupEntity createNew(ServiceEntity service) {
return createNew(null, service);
}
......@@ -53,6 +57,8 @@ public class LocalGroupCreator implements Serializable {
}
public LocalGroupEntity save(LocalGroupEntity entity, ServiceEntity service) {
service = serviceDao.findById(service.getId());
entity.setGidNumber(serialDao.next("gid-number-serial").intValue());
entity.setGroupStatus(GroupStatus.ACTIVE);
......@@ -65,6 +71,17 @@ public class LocalGroupCreator implements Serializable {
groupFlag = groupFlagDao.persist(groupFlag);
if (service.getGroupAutoconnectServices() != null) {
for (ServiceEntity sink : service.getGroupAutoconnectServices()) {
groupFlag = groupFlagDao.createNew();
groupFlag.setService(sink);
groupFlag.setGroup(entity);
groupFlag.setStatus(ServiceGroupStatus.CLEAN);
groupFlag = groupFlagDao.persist(groupFlag);
}
}
return entity;
}
}
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