Commit 8b3de976 authored by michael.simon's avatar michael.simon
Browse files

add function to regex replace strings in alle rules

parent 6448da74
......@@ -21,4 +21,7 @@ public interface BusinessRuleService extends BaseService<BusinessRuleEntity, Lon
List<BusinessRuleEntity> findAllKnowledgeBaseNotNull();
void replaceRegexSingle(Long ruleId, String regex, String replace);
void replaceRegex(String regex, String replace);
}
......@@ -16,6 +16,8 @@ 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.BusinessRuleDao;
import edu.kit.scc.webreg.entity.BusinessRuleEntity;
......@@ -26,6 +28,9 @@ public class BusinessRuleServiceImpl extends BaseServiceImpl<BusinessRuleEntity,
private static final long serialVersionUID = 1L;
@Inject
private Logger logger;
@Inject
private BusinessRuleDao dao;
......@@ -43,4 +48,26 @@ public class BusinessRuleServiceImpl extends BaseServiceImpl<BusinessRuleEntity,
protected BaseDao<BusinessRuleEntity, Long> getDao() {
return dao;
}
@Override
public void replaceRegexSingle(Long ruleId, String regex, String replace) {
BusinessRuleEntity rule = dao.findById(ruleId);
if (rule != null) {
replaceRegexIntern(rule, regex, replace);
}
}
@Override
public void replaceRegex(String regex, String replace) {
List<BusinessRuleEntity> ruleList = dao.findAll();
for (BusinessRuleEntity rule : ruleList) {
replaceRegexIntern(rule, regex, replace);
}
}
private void replaceRegexIntern(BusinessRuleEntity rule, String regex, String replace) {
logger.info("Processing rule {}", rule.getName());
String newRule = rule.getRule().replaceAll(regex, replace);
rule.setRule(newRule);;
}
}
......@@ -20,6 +20,7 @@ import javax.inject.Named;
import edu.kit.scc.webreg.entity.BusinessRulePackageEntity;
import edu.kit.scc.webreg.service.BusinessRulePackageService;
import edu.kit.scc.webreg.service.BusinessRuleService;
@Named("listBusinessRuleBean")
@RequestScoped
......@@ -29,9 +30,15 @@ public class ListBusinessRuleBean implements Serializable {
private List<BusinessRulePackageEntity> list;
private String regex;
private String replace;
@Inject
private BusinessRulePackageService service;
@Inject
private BusinessRuleService businessRuleService;
@PostConstruct
public void init() {
list = service.findAllWithRules();
......@@ -41,4 +48,23 @@ public class ListBusinessRuleBean implements Serializable {
return list;
}
public void regexReplace() {
businessRuleService.replaceRegex(regex, replace);
}
public String getRegex() {
return regex;
}
public void setRegex(String regex) {
this.regex = regex;
}
public String getReplace() {
return replace;
}
public void setReplace(String replace) {
this.replace = replace;
}
}
......@@ -364,3 +364,6 @@ bwidm_org_id=Organisationsk\u00FCrzel
affiliation=Zugeh\u00F6rigkeit
compare_child_registries=Child Registries abgleichen
regex=Regex
replace=Ersetzen
regex_replace=Regex ersetzen
......@@ -363,3 +363,7 @@ uid=Local user ID
bwidm_org_id=Org short name
affiliation=Affiliation
compare_child_registries=Compare child registries
regex=Regex
replace=Replace
regex_replace=Regex replace
......@@ -5,11 +5,18 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:bw="http://www.scc.kit.edu/bwfacelets"
xmlns:p="http://primefaces.org/ui">
xmlns:p="http://primefaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<head>
<title></title>
</head>
<body>
<f:view>
<f:metadata>
<f:event type="javax.faces.event.PreRenderViewEvent"
listener="#{listUserBean.preRenderView}" />
</f:metadata>
<ui:composition template="/template/default-admin.xhtml">
<ui:param name="title" value="#{messages.title}"/>
......@@ -18,7 +25,8 @@
<h:form id="form">
<p:dataTable id="dataTable" var="entity" value="#{listBusinessRuleBean.list}">
<p:dataTable id="dataTable" var="entity" value="#{listBusinessRuleBean.list}" paginator="true"
lazy="true" rows="15">
<p:column>
<f:facet name="header">
<h:outputText value="#{messages.id}" />
......@@ -52,9 +60,24 @@
<h:link outcome="add-rule-package.xhtml" value="#{messages.add_rule_package}"/><br/>
<h:link outcome="add-business-rule.xhtml" value="#{messages.add_business_rule}"/><br/>
<div id="panelInline">
<p:panel header="#{messages.tools}">
<bw:inputText id="regexField" label="#{messages.regex}"
value="#{listBusinessRuleBean.regex}" required="true"/>
<bw:inputText id="replaceField" label="#{messages.replace}"
value="#{listBusinessRuleBean.replace}" required="true"/>
<p:commandButton id="rr" action="#{listBusinessRuleBean.regexReplace}" value="#{messages.regex_replace}"
ajax="false"/>
</p:panel>
</div>
</h:form>
</ui:define>
</ui:composition>
</ui:composition>
</f:view>
</body>
</html>
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