Exemple #1
0
  private static void objectGraph(
      final ObjectAdapter adapter,
      final int level,
      final List<ObjectAdapter> ignoreAdapters,
      final DebugBuilder s,
      final AuthenticationSession authenticationSession) {
    ignoreAdapters.add(adapter);

    try {
      // work through all its fields
      final List<ObjectAssociation> fields =
          adapter.getSpecification().getAssociations(Contributed.EXCLUDED);
      for (int i = 0; i < fields.size(); i++) {
        final ObjectAssociation field = fields.get(i);
        final ObjectAdapter obj = field.get(adapter);
        final String name = field.getId();
        graphIndent(level, s);

        if (field.isVisible(authenticationSession, adapter, where).isVetoed()) {
          s.append(name + ": (not visible)");
          s.append("\n");
        } else {
          if (obj == null) {
            s.append(name + ": null\n");
            /*
             * } else if (obj.getSpecification().isParseable()) {
             * s.append(name + ": " + obj.titleString());
             * s.append("\n");
             */ } else {
            if (ignoreAdapters.contains(obj)) {
              s.append(name + ": " + obj + "*\n");
            } else {
              s.append(name + ": " + obj);
              graph(obj, level + 1, ignoreAdapters, authenticationSession, s);
            }
          }
        }
      }
    } catch (final RuntimeException e) {
      s.appendException(e);
    }
  }
  @Override
  public void process(final Request request) {
    final TableBlock tableBlock = (TableBlock) request.getBlockContent();
    final String id = request.getOptionalProperty(OBJECT);
    final String fieldName = request.getRequiredProperty(FIELD);
    final String linkView = request.getOptionalProperty(LINK_VIEW);
    String className = request.getOptionalProperty(CLASS);
    className = className == null ? "" : " class=\"" + className + "\"";
    RequestContext context = request.getContext();
    final ObjectAdapter object = context.getMappedObjectOrVariable(id, tableBlock.getElementName());
    final ObjectAssociation field = object.getSpecification().getAssociation(fieldName);
    if (field == null) {
      throw new ScimpiException(
          "No field " + fieldName + " in " + object.getSpecification().getFullIdentifier());
    }
    request.appendHtml("<td" + className + ">");
    if (field.isVisible(IsisContext.getAuthenticationSession(), object, where).isAllowed()) {
      final ObjectAdapter fieldReference = field.get(object);
      final String source =
          fieldReference == null ? "" : context.mapObject(fieldReference, Scope.REQUEST);
      final String name = request.getOptionalProperty(RESULT_NAME, fieldName);
      context.addVariable(name, Request.getEncoder().encoder(source), Scope.REQUEST);

      if (linkView != null) {
        final String linkId = context.mapObject(object, Scope.REQUEST);
        final String linkName = request.getOptionalProperty(LINK_NAME, RequestContext.RESULT);
        final String linkObject = request.getOptionalProperty(LINK_OBJECT, linkId);
        request.appendHtml(
            "<a href=\""
                + linkView
                + "?"
                + linkName
                + "="
                + linkObject
                + context.encodedInteractionParameters()
                + "\">");
      } else if (tableBlock.getlinkView() != null) {
        String linkObjectInVariable = tableBlock.getElementName();
        final String linkId = (String) context.getVariable(linkObjectInVariable);
        request.appendHtml(
            "<a href=\""
                + tableBlock.getlinkView()
                + "?"
                + tableBlock.getlinkName()
                + "="
                + linkId
                + context.encodedInteractionParameters()
                + "\">");
      }
      request.pushNewBuffer();
      request.processUtilCloseTag();
      final String buffer = request.popBuffer();
      if (buffer.trim().length() == 0) {
        request.appendAsHtmlEncoded(fieldReference == null ? "" : fieldReference.titleString());
      } else {
        request.appendHtml(buffer);
      }
      if (linkView != null) {
        request.appendHtml("</a>");
      }
    } else {
      request.skipUntilClose();
    }
    request.appendHtml("</td>");
  }
Exemple #3
0
  @Override
  public void process(final RequestContext context) throws IOException {
    AuthenticationSession session = context.getSession();
    if (session == null) {
      session = new AnonymousSession();
    }

    try {
      final String objectId = context.getParameter("_" + OBJECT);
      final String version = context.getParameter("_" + VERSION);
      final String formId = context.getParameter("_" + FORM_ID);
      String resultName = context.getParameter("_" + RESULT_NAME);
      resultName = resultName == null ? RequestContext.RESULT : resultName;
      final String override = context.getParameter("_" + RESULT_OVERRIDE);
      String message = context.getParameter("_" + MESSAGE);

      final ObjectAdapter adapter = context.getMappedObject(objectId);

      final List<ObjectAssociation> fields =
          adapter
              .getSpecification()
              .getAssociations(
                  Contributed.EXCLUDED,
                  ObjectAssociation.Filters.dynamicallyVisible(session, adapter, where));

      for (final ObjectAssociation objectAssociation : fields) {
        if (objectAssociation.isVisible(session, adapter, where).isVetoed()) {
          throw new NotLoggedInException();
        }
      }

      final FormState entryState = validateObject(context, adapter, fields);
      final Version adapterVersion = adapter.getVersion();
      final Version formVersion = context.getVersion(version);
      if (formVersion != null && adapterVersion.different(formVersion)) {

        IsisContext.getMessageBroker()
            .addMessage(
                "The "
                    + adapter.getSpecification().getSingularName()
                    + " was edited "
                    + "by another user ("
                    + adapterVersion.getUser()
                    + "). Please  make your changes based on their changes.");

        final String view = context.getParameter("_" + ERROR);
        context.setRequestPath(view, Dispatcher.EDIT);

        entryState.setForm(formId);
        context.addVariable(ENTRY_FIELDS, entryState, Scope.REQUEST);
        context.addVariable(resultName, objectId, Scope.REQUEST);
        if (override != null) {
          context.addVariable(resultName, override, Scope.REQUEST);
        }

      } else if (entryState.isValid()) {
        changeObject(context, adapter, entryState, fields);

        if (adapter.isTransient()) {
          IsisContext.getPersistenceSession().makePersistent(adapter);
          context.unmapObject(adapter, Scope.REQUEST);
        }

        String view = context.getParameter("_" + VIEW);

        final String id = context.mapObject(adapter, Scope.REQUEST);
        context.addVariable(resultName, id, Scope.REQUEST);
        if (override != null) {
          context.addVariable(resultName, override, Scope.REQUEST);
        }

        final int questionMark = view == null ? -1 : view.indexOf("?");
        if (questionMark > -1) {
          final String params = view.substring(questionMark + 1);
          final int equals = params.indexOf("=");
          context.addVariable(
              params.substring(0, equals), params.substring(equals + 1), Scope.REQUEST);
          view = view.substring(0, questionMark);
        }
        context.setRequestPath(view);
        if (message == null) {
          message = "Saved changes to " + adapter.getSpecification().getSingularName();
        } else if (message.equals("")) {
          message = null;
        }
        if (message != null) {
          final MessageBroker messageBroker = IsisContext.getMessageBroker();
          messageBroker.addMessage(message);
        }

      } else {
        final String view = context.getParameter("_" + ERROR);
        context.setRequestPath(view, Dispatcher.EDIT);

        entryState.setForm(formId);
        context.addVariable(ENTRY_FIELDS, entryState, Scope.REQUEST);
        context.addVariable(resultName, objectId, Scope.REQUEST);
        if (override != null) {
          context.addVariable(resultName, override, Scope.REQUEST);
        }

        final MessageBroker messageBroker = IsisContext.getMessageBroker();
        messageBroker.addWarning(entryState.getError());
      }

    } catch (final RuntimeException e) {
      IsisContext.getMessageBroker().getMessages();
      IsisContext.getMessageBroker().getWarnings();
      throw e;
    }
  }