Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean violatesProfileConstraint(Employee employee, int shiftId) {
- List<RawProfileConstraint> rawProfileConstraintList = shiftMapper.getAssociatedProfile(shiftId);
- RawEmployee rawEmp = employee.getRawEmployee();
- boolean result = true;
- for (RawProfileConstraint rpc : rawProfileConstraintList) {
- try {
- Field tempField = rawEmp.getClass().getDeclaredField(rpc.getField());
- tempField.setAccessible(true);
- Object fieldNameValue = tempField.get(rawEmp);
- Field tempField2 = rawEmp.getClass().getDeclaredField(rpc.getOperator());
- tempField2.setAccessible(true);
- Object operator = tempField2.get(rawEmp);
- if (tempField.getType().isAssignableFrom(Number.class)) {
- float num1 = (float) fieldNameValue;
- float constraintVal = Float.valueOf(rpc.getValue());
- if (rpc.getOperator().equals("gt")) {
- result = (num1 > constraintVal);
- } else if (rpc.getOperator().equals("equal")) {
- result = (num1 == constraintVal);
- } else if (rpc.getOperator().equals("lt")) {
- result = (num1 < constraintVal);
- }
- } else if (tempField.getType().isAssignableFrom(String.class)) {
- String string1 = fieldNameValue.toString();
- String constraintVal = rpc.getValue();
- if (rpc.getOperator().equals("equal")) {
- result = string1.equals(constraintVal);
- } else if (rpc.getOperator().equals("equal")) {
- result = !string1.equals(constraintVal);
- }
- } else if (tempField.getType().isAssignableFrom(Date.class)) {
- DateFormat df = new SimpleDateFormat();
- Date date1 = (Date) fieldNameValue;
- Date constraintVal = (Date) df.parse(rpc.getValue());
- if (rpc.getOperator().equals("isBefore")) {
- result = (date1.before(constraintVal));
- } else if (rpc.getOperator().equals("equal")) {
- result = (date1.equals(constraintVal));
- } else if (rpc.getOperator().equals("isAfter")) {
- result = (date1.after(constraintVal));
- } else if (rpc.getOperator().equals("not equal")) {
- result = !(date1.equals(constraintVal));
- }
- }
- //&& f.getName().equals(rpc.getOperator()) && f.getName().equals(rpc.getValue())
- } catch (Exception e) {
- //
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement