Search in sources :

Example 1 with PointImpl

use of cern.modesti.point.PointImpl 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 2 with PointImpl

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

the class TestUtil method getDummyPoints.

private static List<Point> getDummyPoints() {
    ArrayList<Point> points = new ArrayList<>();
    Point point1 = new PointImpl();
    Point point2 = new PointImpl();
    point1.setProperties(Maps.newHashMap(ImmutableMap.of("id", "1", "pointDescription", "TEST POINT 1", "pointDatatype", "Boolean")));
    point2.setProperties(Maps.newHashMap(ImmutableMap.of("id", "2", "pointDescription", "TEST POINT 2", "pointDatatype", "Boolean")));
    points.add(point1);
    points.add(point2);
    return points;
}
Also used : ArrayList(java.util.ArrayList) Point(cern.modesti.point.Point) PointImpl(cern.modesti.point.PointImpl)

Example 3 with PointImpl

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

the class RequestServiceImpl method insert.

/**
 * Insert (create) a new request.
 * <p>
 * Creating a new request performs the following actions:
 * <ul>
 * <li>
 * Asserts that the currently logged-in user is authorised to create a
 * request for the domain of the request
 * </li>
 * <li>
 * Sets the currently logged-in user as the creator of the request
 * </li>
 * <li>Generates a request id</li>
 * <li>Adds some empty points to the request if none were specified</li>
 * <li>Starts a new workflow process instance using the workflow key of the
 * plugin associated with the request domain</li>
 * </ul>
 *
 * @param request the request to create
 * @return the newly created request with all properties set
 */
@Override
public Request insert(Request request) {
    // Do not create a request if there is no appropriate domain
    RequestProvider plugin = requestProviderRegistry.getPluginFor(request, new UnsupportedRequestException(request));
    User user = userService.getCurrentUser();
    // Assert that the current user is allowed to create a request for this domain
    if (!authService.canCreate(plugin, request, user)) {
        throw new NotAuthorisedException(format("User \"%s\" is not authorised to create requests for domain \"%s\". " + "Authorisation group is \"%s\".", user.getUsername(), request.getDomain(), plugin.getMetadata().getAuthorisationGroup(request)));
    }
    // Set the creator as the current logged in user
    request.setCreator(user.getUsername());
    ((RequestImpl) request).setRequestId(counterService.getNextSequence(CounterService.REQUEST_ID_SEQUENCE).toString());
    log.trace(format("generated request id: %s", request.getRequestId()));
    ((RequestImpl) request).setCreatedAt(new DateTime());
    if (request.getPoints() == null) {
        request.setPoints(new ArrayList<>());
    }
    // Apply formatting to the request points
    requestFormatter.format(request);
    // Add some empty points if there aren't any yet
    if (request.getPoints().isEmpty()) {
        for (int i = 0; i < 50; i++) {
            Point point = new PointImpl((long) (i + 1));
            request.addPoint(point);
        }
    }
    for (Point point : request.getPoints()) {
        if (point.getLineNo() == null) {
            point.setLineNo((long) (request.getPoints().indexOf(point) + 1));
        }
    }
    request = repository.save((RequestImpl) request);
    if (request.getType().equals(RequestType.UPDATE)) {
        // Store an initial, empty change history
        ((RequestHistoryServiceImpl) historyService).initialiseChangeHistory(request);
    }
    // Kick off the workflow process
    workflowService.startProcessInstance(request);
    return request;
}
Also used : User(cern.modesti.user.User) NotAuthorisedException(cern.modesti.workflow.task.NotAuthorisedException) RequestProvider(cern.modesti.plugin.RequestProvider) Point(cern.modesti.point.Point) UnsupportedRequestException(cern.modesti.plugin.UnsupportedRequestException) DateTime(org.joda.time.DateTime) Point(cern.modesti.point.Point) PointImpl(cern.modesti.point.PointImpl) RequestHistoryServiceImpl(cern.modesti.request.history.RequestHistoryServiceImpl)

Aggregations

Point (cern.modesti.point.Point)3 PointImpl (cern.modesti.point.PointImpl)3 RequestProvider (cern.modesti.plugin.RequestProvider)1 UnsupportedRequestException (cern.modesti.plugin.UnsupportedRequestException)1 RequestHistoryServiceImpl (cern.modesti.request.history.RequestHistoryServiceImpl)1 User (cern.modesti.user.User)1 NotAuthorisedException (cern.modesti.workflow.task.NotAuthorisedException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1