class AddOperationsToChain implements GraphHook {

    @Override
    public void preExecute(final OperationChain<?> opChain, final Context context) {
        final List<Operation> newOpList = new ArrayList<>();

        boolean hasAuth = false;
        if (!authorisedOps.isEmpty() && !context.getUser().getOpAuths().isEmpty()) {
            for (final String auth : authorisedOps.keySet()) {
                if (context.getUser().getOpAuths().contains(auth)) {
                    final AdditionalOperations additionalOperations = authorisedOps.get(auth);

                    newOpList.addAll(additionalOperations.getStart());
                    newOpList.addAll(addOperationsToChain(opChain, additionalOperations));
                    newOpList.addAll(additionalOperations.getEnd());

                    hasAuth = true;
                    break;
                }
            }
        }

        if (!hasAuth) {
            newOpList.addAll(defaultOperations.getStart());
            newOpList.addAll(addOperationsToChain(opChain, defaultOperations));
            newOpList.addAll(defaultOperations.getEnd());
        }

        try {
            opChain.updateOperations(newOpList);
        } catch (final Exception e) {
            // ignore exception - this would be caused by the operation list not allowing modifications
        }

    }

}