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 6905 #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 45 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven-central</id>
<url>http://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>Akaza Dev Repository</id>
<url>http://svn.akazaresearch.com/ocrepository/repository</url>
Expand Down Expand Up @@ -330,6 +334,21 @@
<artifactId>tiles-jsp</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-template</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
Expand Down Expand Up @@ -493,6 +512,11 @@
<scope>compile</scope>
</dependency>
<!-- Jackson JSON Mapper -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
Expand All @@ -515,21 +539,41 @@
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth</artifactId>
<version>1.0.0.M2</version>
</dependency>
<dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils-core</artifactId>
<version>1.8.3</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,12 @@ public String testForm(@RequestHeader(value = "X-Requested-With", required = fal
* session.setAttribute(SESSION_ATTR_TESTINPUTFIELDS, inputFields);
*/

testRules(form, uiODMBuilder, new TestRulesGetResponseHandler());
ArrayList<TestRulesResponseHandler> responseHandlers = new ArrayList();
responseHandlers.add(new TestRulesGetResponseHandler());
responseHandlers.add(new TestRulesSubmitResponseHandler());

testRules(form, uiODMBuilder, responseHandlers);
form.populateTestWillActionsRun();
session.setAttribute(SESSION_ATTR_TESTINPUTFIELDS, form.getRulePropertiesHtml());

// success response handling
Expand All @@ -471,6 +476,10 @@ 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 {
ArrayList<Message> messages = new ArrayList<Message>();
form.getRuleRef().lazyToNonLazy();
form.setTestRulesResults(new HashMap<String, String>());

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

Expand All @@ -486,10 +495,11 @@ public String processTestSubmit(@RequestHeader(value = "X-Requested-With", requi
return null;
}

form.getRuleRef().lazyToNonLazy();
ArrayList<Message> messages = new ArrayList<Message>();
ArrayList<TestRulesResponseHandler> responseHandlers = new ArrayList();
responseHandlers.add(new TestRulesGetResponseHandler());
responseHandlers.add(new TestRulesSubmitResponseHandler());

testRules(form, uiODMBuilder, new TestRulesSubmitResponseHandler());
testRules(form, uiODMBuilder, responseHandlers);
form.populateTestWillActionsRun();
session.setAttribute(SESSION_ATTR_FORM, form);

Expand All @@ -509,13 +519,15 @@ private Message createRestExceptionMessage(Exception e) {
return new Message(MessageType.error, "Could not submit to OC instance because :: " + message);
}

private void testRules(RulesCommand form, UIODMBuilder uiODMBuilder, TestRulesResponseHandler responseHandler) {
private void testRules(RulesCommand form, UIODMBuilder uiODMBuilder, ArrayList<TestRulesResponseHandler> responseHandlers) {
ArrayList<Message> messages = new ArrayList<Message>();
RulesTest resp = null;
try {
resp =
userPreferences.getRestTemplate().postForObject(userPreferences.getValidateAndTestRuleURL(), createRulesTestFromCommand(form), RulesTest.class);
responseHandler.handle(form, resp, uiODMBuilder);
for (TestRulesResponseHandler responseHandler : responseHandlers) {
responseHandler.handle(form, resp, uiODMBuilder);
}
return;
} catch (Exception e) {
messages.add(createRestExceptionMessage(e));
Expand Down Expand Up @@ -568,8 +580,9 @@ private Rules rulesCommandToRules(RulesCommand form) {
RuleAssignmentType ra = new RuleAssignmentType();
form.getTarget().setValue(form.getTarget().getValue() == null ? "" : form.getTarget().getValue().trim());
ra.setTarget(form.getTargetCurated(form.getTarget()));
if (!form.getRunOnSchedule().getTime().equals(""))
if (form.getRunOnSchedule() != null && !form.getRunOnSchedule().getTime().equals("")) {
ra.setRunOnSchedule(form.getRunOnSchedule());
}
Rules r = new Rules();
for (LazyRuleRefType2 lrr : listLzRuleRef) {
ra.getRuleRef().add(lrr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.akaza.openclinica.designer.web.controller;

import org.apache.commons.validator.routines.EmailValidator;
import org.openclinica.ns.rules.v31.DiscrepancyNoteActionType;
import org.openclinica.ns.rules.v31.EmailActionType;
import org.openclinica.ns.rules.v31.HideActionType;
Expand Down Expand Up @@ -82,17 +83,15 @@ private void validateEmailAction(LazyRuleRefType2 action, Errors e) {
if (emailAction.getTo() == null || emailAction.getTo().trim().length() == 0) {
e.rejectValue("ruleRef.lazyEmailActions[" + action.getEmailAction().indexOf(emailAction) + "].to", "email.to.empty");
} else {
Pattern pattern = Pattern.compile("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
EmailValidator validator = EmailValidator.getInstance();
StringTokenizer tokenizer = new StringTokenizer(emailAction.getTo(), ",");
if (tokenizer.countTokens() == 0) {
Matcher matcher = pattern.matcher(emailAction.getTo());
if (!matcher.matches()) {
if (!validator.isValid(emailAction.getTo())) {
e.rejectValue("ruleRef.lazyEmailActions[" + action.getEmailAction().indexOf(emailAction) + "].to", "email.to.not.valid");
}
} else {
while (tokenizer.hasMoreTokens()) {
Matcher matcher = pattern.matcher(tokenizer.nextToken().trim());
if (!matcher.matches()) {
if (!validator.isValid(tokenizer.nextToken().trim())) {
e.rejectValue("ruleRef.lazyEmailActions[" + action.getEmailAction().indexOf(emailAction) + "].to", "email.to.not.valid");
break;
}
Expand Down