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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations