Commit 88de291c authored by michael.simon's avatar michael.simon
Browse files

Add a filter regex for autoconnect groups

parent d037e641
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity(name = "ServiceAutoconnectGroupEntity")
@Table(name = "service_autoconnect_group")
public class ServiceAutoconnectGroupEntity extends AbstractBaseEntity {
private static final long serialVersionUID = 1L;
@ManyToOne(targetEntity = ServiceEntity.class)
private ServiceEntity fromService;
@ManyToOne(targetEntity = ServiceEntity.class)
private ServiceEntity toService;
@Column(name = "filter_regex", length = 1024)
private String filterRegex;
public ServiceEntity getFromService() {
return fromService;
}
public void setFromService(ServiceEntity fromService) {
this.fromService = fromService;
}
public ServiceEntity getToService() {
return toService;
}
public void setToService(ServiceEntity toService) {
this.toService = toService;
}
public String getFilterRegex() {
return filterRegex;
}
public void setFilterRegex(String filterRegex) {
this.filterRegex = filterRegex;
}
}
......@@ -123,12 +123,8 @@ 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;
@OneToMany(targetEntity = ServiceAutoconnectGroupEntity.class, mappedBy = "fromService")
private Set<ServiceAutoconnectGroupEntity> groupAutoconnectServices;
public Set<PolicyEntity> getPolicies() {
return policies;
......@@ -325,11 +321,12 @@ public class ServiceEntity extends AbstractBaseEntity {
this.sshPubKeyApproverRole = sshPubKeyApproverRole;
}
public Set<ServiceEntity> getGroupAutoconnectServices() {
public Set<ServiceAutoconnectGroupEntity> getGroupAutoconnectServices() {
return groupAutoconnectServices;
}
public void setGroupAutoconnectServices(Set<ServiceEntity> groupAutoconnectServices) {
public void setGroupAutoconnectServices(Set<ServiceAutoconnectGroupEntity> groupAutoconnectServices) {
this.groupAutoconnectServices = groupAutoconnectServices;
}
}
......@@ -16,6 +16,7 @@ import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.GroupStatus;
import edu.kit.scc.webreg.entity.LocalGroupEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.entity.ServiceAutoconnectGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.ServiceGroupFlagEntity;
import edu.kit.scc.webreg.entity.ServiceGroupStatus;
......@@ -72,13 +73,15 @@ 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);
for (ServiceAutoconnectGroupEntity sink : service.getGroupAutoconnectServices()) {
if (entity.getName().matches(sink.getFilterRegex())) {
groupFlag = groupFlagDao.createNew();
groupFlag.setService(sink.getToService());
groupFlag.setGroup(entity);
groupFlag.setStatus(ServiceGroupStatus.CLEAN);
groupFlag = groupFlagDao.persist(groupFlag);
}
}
}
......
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