Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OC 5754 #40

Merged
merged 1 commit into from
Jun 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.openclinica.ns.rules.v31.RuleRefType;
import org.openclinica.ns.rules.v31.ShowActionType;
import org.openclinica.ns.rules.v31.EventActionType;
import org.openclinica.ns.rules.v31.RuleDefType;
import org.springframework.util.AutoPopulatingList;

import java.util.ArrayList;
Expand Down Expand Up @@ -58,7 +59,6 @@ public LazyRuleRefType2(RuleRefType ruleRef) {
}

public void lazyToNonLazy() {

reAlignDiscrepancyNoteActions();
reAlignEmailActions();
reAlignLazyShowActions();
Expand All @@ -67,6 +67,67 @@ public void lazyToNonLazy() {
reAlignLazyEventActions();
}

public List<LazyRuleRefType2> splitRuleRef(RuleRefType ruleRef) {
List<LazyRuleRefType2> listLazy = new ArrayList<LazyRuleRefType2>();
int count = 0;
for (EmailActionType ea : ruleRef.getEmailAction()) {
LazyRuleRefType2 rr = new LazyRuleRefType2();
rr.setOID(ruleRef.getOID()+"_"+count);
rr.getEmailAction().add(ea);
count++;
listLazy.add(rr);
}
for (DiscrepancyNoteActionType ea : ruleRef.getDiscrepancyNoteAction()) {
LazyRuleRefType2 rr = new LazyRuleRefType2();
rr.setOID(ruleRef.getOID()+"_"+count);
rr.getDiscrepancyNoteAction().add(ea);
count++;
listLazy.add(rr);
}
for (ShowActionType ea : ruleRef.getShowAction()) {
LazyRuleRefType2 rr = new LazyRuleRefType2();
rr.setOID(ruleRef.getOID()+"_"+count);
rr.getShowAction().add(ea);
count++;
listLazy.add(rr);
}
for (HideActionType ea : ruleRef.getHideAction()) {
LazyRuleRefType2 rr = new LazyRuleRefType2();
rr.setOID(ruleRef.getOID()+"_"+count);
rr.getHideAction().add(ea);
count++;
listLazy.add(rr);
}
for (InsertActionType ea : ruleRef.getInsertAction()) {
LazyRuleRefType2 rr = new LazyRuleRefType2();
rr.setOID(ruleRef.getOID()+"_"+count);
rr.getInsertAction().add(ea);
count++;
listLazy.add(rr);
}
for (EventActionType ea : ruleRef.getEventAction()) {
LazyRuleRefType2 rr = new LazyRuleRefType2();
rr.setOID(ruleRef.getOID()+"_"+count);
rr.getEventAction().add(ea);
count++;
listLazy.add(rr);
}
return listLazy;
}

public List<RuleDefType> splitRuleDef(RuleDefType ruleDef, int size) {
List<RuleDefType> listRdt = new ArrayList<RuleDefType>();
for (int i = 0; i < size; i++) {
RuleDefType rdt = new RuleDefType();
rdt.setOID(ruleDef.getOID()+"_"+i);
rdt.setExpression(ruleDef.getExpression());
rdt.setName(ruleDef.getOID()+"_"+i);
rdt.setDescription(ruleDef.getOID()+"_"+i);
listRdt.add(rdt);
}
return listRdt;
}

/**
* Based on the rule's result check if any action will fire
* @param result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.openclinica.ns.response.v31.MessagesType;
import org.openclinica.ns.response.v31.Response;
import org.openclinica.ns.rules.v31.RuleAssignmentType;
import org.openclinica.ns.rules.v31.RuleDefType;
import org.openclinica.ns.rules.v31.Rules;
import org.openclinica.ns.rules_test.v31.ParameterType;
import org.openclinica.ns.rules_test.v31.RulesTest;
Expand Down Expand Up @@ -87,7 +88,6 @@ public static boolean isAjaxUploadRequest(HttpServletRequest request) {

@RequestMapping(method = RequestMethod.GET)
public String getCreateForm(Model model, HttpSession session, HttpServletRequest request) throws IOException {

final String ruleOid = request.getParameter("ruleOid");
final String target = request.getParameter("target");

Expand All @@ -102,7 +102,6 @@ public String getCreateForm(Model model, HttpSession session, HttpServletRequest
@RequestMapping(value = "/ruleBuilderFormA", method = RequestMethod.GET)
public void form(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, Model model,
@RequestParam(value = PARAM_RESET, required = false) String resetParam) {

RulesCommand form = (RulesCommand) session.getAttribute(SESSION_ATTR_FORM) != null ? (RulesCommand) session.getAttribute(SESSION_ATTR_FORM) : null;

if (form == null || (resetParam != null && resetParam.equals("true"))) {
Expand All @@ -122,7 +121,6 @@ public void form(@RequestHeader(value = "X-Requested-With", required = false) St
public @ResponseBody
ArrayList<Message> processDesignTabToTest(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @Valid RulesCommand form,
BindingResult result, HttpSession session, Model model) throws IOException {

ArrayList<Message> messages = new ArrayList<Message>();
UIODMContainer uiODMContainer = (UIODMContainer) session.getAttribute(SESSION_ATTR_UIODMCONTAINER);
// TODO: See if there is a way to move this to one place currently happens here and in Validator.
Expand Down Expand Up @@ -181,7 +179,6 @@ String processDesignTabSubmit(@RequestHeader(value = "X-Requested-With", require
@RequestMapping(value = "/ruleBuilderFormA", method = RequestMethod.POST)
public String processSubmit(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @Valid RulesCommand form,
BindingResult result, HttpSession session, Model model) throws IOException {

logger.debug("Validating form ...");
ArrayList<Message> messages = new ArrayList<Message>();
UIODMContainer uiODMContainer = (UIODMContainer) session.getAttribute(SESSION_ATTR_UIODMCONTAINER);
Expand Down Expand Up @@ -246,7 +243,6 @@ public String saveRuleFromDesignerTab(@RequestHeader(value = "X-Requested-With",
@RequestMapping(value = "/xmlForm", method = RequestMethod.GET)
public void processSubmit(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, Model model,
@RequestParam(value = PARAM_RESET, required = false) String resetParam) throws IOException {

RulesCommand form = (RulesCommand) session.getAttribute(SESSION_ATTR_FORM);
if (resetParam != null && resetParam.equals("true")) {
form = new RulesCommand();
Expand Down Expand Up @@ -285,7 +281,6 @@ public void processSubmit(@RequestHeader(value = "X-Requested-With", required =
@RequestMapping(value = "/xmlForm", method = RequestMethod.POST)
public String processXmlFormSubmit(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, RulesCommand form,
BindingResult result, HttpSession session, Model model, @RequestParam("ignoreDuplicates") Boolean ignoreDuplicates) throws IOException {

UIODMContainer uiODMContainer = (UIODMContainer) session.getAttribute(SESSION_ATTR_UIODMCONTAINER);
ArrayList<Message> messages = new ArrayList<Message>();

Expand Down Expand Up @@ -433,7 +428,6 @@ ArrayList<Message> processXmlTabSubmit(@RequestHeader(value = "X-Requested-With"
@RequestMapping(value = "/testForm", method = RequestMethod.GET)
public String testForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, Model model)
throws IOException {

ArrayList<Message> messages = new ArrayList<Message>();
RulesCommand form = (RulesCommand) session.getAttribute(SESSION_ATTR_FORM);
form.getRuleRef().lazyToNonLazy();
Expand Down Expand Up @@ -476,7 +470,6 @@ public String testForm(@RequestHeader(value = "X-Requested-With", required = fal
@RequestMapping(value = "/testForm", method = RequestMethod.POST)
public String processTestSubmit(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @Valid RulesCommand form,
BindingResult result, HttpSession session, Model model) throws IOException {

UIODMContainer uiODMContainer = (UIODMContainer) session.getAttribute(SESSION_ATTR_UIODMCONTAINER);
UIODMBuilder uiODMBuilder = new UIODMBuilder(uiODMContainer);

Expand Down Expand Up @@ -567,17 +560,21 @@ private ArrayList<Message> saveRule(UIODMContainer uiODMContainer, Rules rule, R
* Convert RulesCommand to Rules Object
*/
private Rules rulesCommandToRules(RulesCommand form) {
form.getRuleRef().lazyToNonLazy();
RulesCommand rc = new RulesCommand(form);
rc.getRuleRef().setOID(form.getRuleDef().getOID());
LazyRuleRefType2 lzRuleRef = new LazyRuleRefType2();
List<LazyRuleRefType2> listLzRuleRef = lzRuleRef.splitRuleRef(rc.getRuleRef());
RuleAssignmentType ra = new RuleAssignmentType();
form.getTarget().setValue(form.getTarget().getValue() == null ? "" : form.getTarget().getValue().trim());
ra.setTarget(form.getTargetCurated(form.getTarget()));
ra.getRuleRef().add(form.getRuleRef());
ra.getRuleRef().get(0).setOID(form.getRuleDef().getOID());
Rules r = new Rules();
for (LazyRuleRefType2 lrr : listLzRuleRef) {
ra.getRuleRef().add(lrr);
}
r.getRuleAssignment().add(ra);
r.getRuleDef().add(form.getRuleDefCurated());
r.getRuleDef().get(0).setName(r.getRuleDef().get(0).getOID());
r.getRuleDef().get(0).setDescription(r.getRuleDef().get(0).getOID());
for(RuleDefType rdt : lzRuleRef.splitRuleDef(form.getRuleDefCurated(), listLzRuleRef.size())) {
r.getRuleDef().add(rdt);
}
return r;

}
Expand All @@ -604,7 +601,6 @@ private RulesTest createRulesTestFromCommand(RulesCommand form) {
* Convert XML which is represented as a String to Rules Object
*/
private Rules loadRulesFromString(String rulesString) throws UnMarshallingException {

StringReader reader = new StringReader(rulesString);
Rules rules = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public RulesCommand() {
ruleDef = new RuleDefType();
}

public RulesCommand(RulesCommand rule) {
ruleRef = rule.getRuleRef();
target = rule.getTarget();
addActions = rule.getAddActions();
xml = rule.getXml();
rulePropertiesHtml = rule.getRulePropertiesHtml();
ruleProperties = rule.getRuleProperties();
testRulesResults = rule.getTestRulesResults();
testWillActionsRun = rule.getTestWillActionsRun();
}

public LazyRuleRefType2 getRuleRef() {
return ruleRef;
}
Expand Down