Search in sources :

Example 1 with Point

use of cern.modesti.point.Point in project modesti by jlsalmon.

the class CoreWorkflowServiceImpl method splitRequest.

/**
 * Split a set of points from a request into a child request.
 * <p>
 * The points to split must be specified in an execution variable named
 * {@literal points} which is a list of line numbers corresponding to the
 * lines to be split.
 *
 * @param requestId the id of the request to split
 * @param execution the Activiti execution object
 */
public void splitRequest(String requestId, DelegateExecution execution) {
    log.info(format("splitting request id %s...", requestId));
    List<Long> pointsToSplit = execution.getVariable("points", List.class);
    log.info(format("splitting points [%s]", StringUtils.join(pointsToSplit, ", ")));
    Request parent = getRequest(requestId);
    List<Point> childPoints = new ArrayList<>();
    // Give the split points to the child.
    for (Long lineNo : pointsToSplit) {
        Point pointToSplit = null;
        for (Point point : parent.getPoints()) {
            if (point.getLineNo().equals(lineNo)) {
                pointToSplit = point;
                break;
            }
        }
        if (pointToSplit != null) {
            childPoints.add(pointToSplit);
            parent.getPoints().remove(pointToSplit);
            pointToSplit.setLineNo((long) (childPoints.indexOf(pointToSplit) + 1));
        }
    }
    // Rebase the point IDs back to starting from 1.
    for (Point point : parent.getPoints()) {
        // if (pointIdsToSplit.contains(point.getId())) {
        point.setLineNo((long) (parent.getPoints().indexOf(point) + 1));
    // }
    }
    // Generate a request ID for the new child
    String childRequestId = counterService.getNextSequence(CounterService.REQUEST_ID_SEQUENCE).toString();
    // Create the new child
    Request child = createChildRequest(childRequestId, parent, childPoints);
    // Set back reference to the child
    parent.getChildRequestIds().add(childRequestId);
    // Store the requests
    requestRepository.save((RequestImpl) parent);
    requestRepository.save((RequestImpl) child);
    // Add variables to the execution so that they are available to the
    // recursive process invocation
    execution.setVariable("childRequestId", child.getRequestId());
    execution.setVariable("childCreator", child.getCreator());
}
Also used : Request(cern.modesti.request.Request) ArrayList(java.util.ArrayList) Point(cern.modesti.point.Point)

Example 2 with Point

use of cern.modesti.point.Point in project modesti by jlsalmon.

the class RequestDifferTest method createPoint.

private Point createPoint(int id, int numProperties) {
    Point p = new PointImpl();
    p.setLineNo(Integer.valueOf(id).longValue());
    Map<String, Object> props = new HashMap<>();
    props.put("id", String.valueOf(id));
    for (int j = 0; j < numProperties; j++) {
        props.put("Property_" + j, "Value_" + j);
    }
    p.setProperties(props);
    return p;
}
Also used : HashMap(java.util.HashMap) Point(cern.modesti.point.Point) PointImpl(cern.modesti.point.PointImpl) Point(cern.modesti.point.Point)

Example 3 with Point

use of cern.modesti.point.Point in project modesti by jlsalmon.

the class Constraints method validateXnorConstraint.

private static boolean validateXnorConstraint(Constraint constraint, Request request, Category category) {
    boolean valid = true;
    for (Point point : request.getNonEmptyPoints()) {
        // Constraints are only applied if the category is editable.
        boolean editable = Conditionals.evaluate(category.getEditable(), point, request);
        if (!editable) {
            continue;
        }
        // Get all the fields specified as members of the constraint
        List<Field> fields = category.getFields(constraint.getMembers());
        // Get a list of fields for the constraint that are empty
        List<Field> emptyFields = point.getEmptyFields(fields);
        if (emptyFields.size() != 0 && emptyFields.size() != constraint.getMembers().size()) {
            point.setValid(false);
            valid = false;
            for (Field emptyField : emptyFields) {
                point.addErrorMessage(category.getId(), emptyField.getId(), "'" + emptyField.getName() + "' is required for group '" + category.getName() + "'");
            }
        }
    }
    return valid;
}
Also used : Field(cern.modesti.schema.field.Field) Point(cern.modesti.point.Point)

Example 4 with Point

use of cern.modesti.point.Point in project modesti by jlsalmon.

the class Constraints method validateAndConstraint.

private static boolean validateAndConstraint(Constraint constraint, Request request, Category category) {
    boolean valid = true;
    for (Point point : request.getNonEmptyPoints()) {
        // Constraints are only applied if the category is editable.
        boolean editable = Conditionals.evaluate(category.getEditable(), point, request);
        if (!editable) {
            continue;
        }
        // Get all the fields specified as members of the constraint
        List<Field> fields = category.getFields(constraint.getMembers());
        // Get a list of fields for the constraint that are empty
        List<Field> emptyFields = point.getEmptyFields(fields);
        if (emptyFields.size() > 0) {
            point.setValid(false);
            valid = false;
            for (Field emptyField : emptyFields) {
                point.addErrorMessage(category.getId(), emptyField.getId(), "'" + emptyField.getName() + "' is required for group '" + category.getName() + "'");
            }
        }
    }
    return valid;
}
Also used : Field(cern.modesti.schema.field.Field) Point(cern.modesti.point.Point)

Example 5 with Point

use of cern.modesti.point.Point in project modesti by jlsalmon.

the class Constraints method validateOrConstraint.

private static boolean validateOrConstraint(Constraint constraint, Request request, Category category) {
    boolean valid = true;
    for (Point point : request.getNonEmptyPoints()) {
        // Constraints are only applied if the category is editable.
        boolean editable = Conditionals.evaluate(category.getEditable(), point, request);
        if (!editable) {
            continue;
        }
        // Get all the fields specified as members of the constraint
        List<Field> fields = category.getFields(constraint.getMembers());
        // Get a list of fields for the constraint that are empty
        List<Field> emptyFields = point.getEmptyFields(fields);
        if (emptyFields.size() == constraint.getMembers().size()) {
            point.setValid(false);
            valid = false;
            // TODO: set category to invalid
            // point.properties.valid = category.valid = valid = false;
            List<String> fieldNames = category.getFieldNames(constraint.getMembers());
            for (Field emptyField : emptyFields) {
                point.addErrorMessage(category.getId(), emptyField.getId(), "At least one of '" + String.join(", ", fieldNames) + "' is required for group '" + category.getName() + "'");
            }
        }
    }
    return valid;
}
Also used : Field(cern.modesti.schema.field.Field) Point(cern.modesti.point.Point)

Aggregations

Point (cern.modesti.point.Point)15 Field (cern.modesti.schema.field.Field)5 ArrayList (java.util.ArrayList)5 Request (cern.modesti.request.Request)4 PointImpl (cern.modesti.point.PointImpl)3 RequestImpl (cern.modesti.request.RequestImpl)3 Category (cern.modesti.schema.category.Category)3 DateTime (org.joda.time.DateTime)3 RequestProvider (cern.modesti.plugin.RequestProvider)2 RequestHistoryServiceImpl (cern.modesti.request.history.RequestHistoryServiceImpl)2 AutocompleteField (cern.modesti.schema.field.AutocompleteField)2 OptionsField (cern.modesti.schema.field.OptionsField)2 ObjectDiffer (de.danielbechler.diff.ObjectDiffer)2 DiffNode (de.danielbechler.diff.node.DiffNode)2 UnsupportedRequestException (cern.modesti.plugin.UnsupportedRequestException)1 RequestEventHandler (cern.modesti.request.spi.RequestEventHandler)1 Schema (cern.modesti.schema.Schema)1 Constraint (cern.modesti.schema.category.Constraint)1 User (cern.modesti.user.User)1 NotAuthorisedException (cern.modesti.workflow.task.NotAuthorisedException)1