Skip to content

Commit

Permalink
Add validate on json request
Browse files Browse the repository at this point in the history
  • Loading branch information
mspasiano committed Jan 18, 2018
1 parent b4c2223 commit 6fa09fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package it.cnr.contab.util.servlet;

import it.cnr.jada.comp.ComponentException;
import it.cnr.jada.persistency.sql.SQLBuilder;

import java.util.List;
import java.util.Optional;

public class JSONRequest extends JSONRESTRequest{
private Integer activePage;
Expand Down Expand Up @@ -115,6 +117,24 @@ else if (operator.equalsIgnoreCase("isnotnull"))
return SQLBuilder.ISNOTNULL;
return SQLBuilder.EQUALS;
}

@Override
public String toString() {
return "Clause {" +
"condition='" + condition + '\'' +
", fieldName='" + fieldName + '\'' +
", operator='" + operator + '\'' +
", fieldValue=" + fieldValue +
'}';
}

public void validate() throws ComponentException{
if (!Optional.ofNullable(getSQLOperator()).isPresent() || !Optional.ofNullable(getFieldName()).isPresent())
throw new ComponentException("Cannot add clause " + this);
if (!(getSQLOperator() == SQLBuilder.ISNULL || getSQLOperator() == SQLBuilder.ISNOTNULL) &&
!Optional.ofNullable(getFieldValue()).isPresent())
throw new ComponentException("Cannot add clause " + this);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import it.cnr.jada.comp.ApplicationException;
import it.cnr.jada.comp.ComponentException;
import it.cnr.jada.persistency.sql.CompoundFindClause;
import it.cnr.jada.persistency.sql.SQLBuilder;
import it.cnr.jada.util.OrderConstants;
import it.cnr.jada.util.RemoteIterator;
import it.cnr.jada.util.action.ConsultazioniBP;
Expand Down Expand Up @@ -141,7 +142,12 @@ protected void execute(HttpServletRequest req, HttpServletResponse resp, String
CompoundFindClause compoundFindClause = new CompoundFindClause();
for (Clause clause : jsonRequest.getClauses()) {
logger.info("RequestedSessionId: "+req.getRequestedSessionId() + ". Clause. Condition: "+clause.getCondition()+", fieldName: "+clause.getFieldName()+", Operator: "+clause.getOperator()+", fieldValue: "+clause.getFieldValue());
compoundFindClause.addClause(clause.getCondition(), clause.getFieldName(), clause.getSQLOperator(), clause.getFieldValue());
clause.validate();
compoundFindClause.addClause(
clause.getCondition(),
clause.getFieldName(),
clause.getSQLOperator(),
clause.getFieldValue());
}
consBP.setFindclause(compoundFindClause);
}
Expand Down

0 comments on commit 6fa09fb

Please sign in to comment.