Exemplo n.º 1
0
 @Override
 public Integer getScale(ScalarModel scalarModel) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   final BigDecimalValueFacet facet = actionParameter.getFacet(BigDecimalValueFacet.class);
   return facet != null ? facet.getScale() : null;
 }
 /** @param serviceAction - number of the parameter that matches, or -1 if none. */
 private int contributeeParameterMatchOf(final ObjectAction serviceAction) {
   final List<ObjectActionParameter> params = serviceAction.getParameters();
   for (final ObjectActionParameter param : params) {
     if (isOfType(param.getSpecification())) {
       return param.getNumber();
     }
   }
   return -1;
 }
Exemplo n.º 3
0
 @Override
 public int getAutoCompleteOrChoicesMinLength(ScalarModel scalarModel) {
   if (scalarModel.hasAutoComplete()) {
     final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
     final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
     return actionParameter.getAutoCompleteMinLength();
   } else {
     return 0;
   }
 }
 private Object argValueFor(final int i) {
   if (objectMember.isContributed()) {
     final ObjectActionParameter actionParameter = objectMember.getParameters().get(i);
     if (actionParameter.getSpecification().isOfType(objectAdapter.getSpecification())) {
       return DomainObjectReprRenderer.newLinkToBuilder(rendererContext, Rel.VALUE, objectAdapter)
           .build();
     }
   }
   // force a null into the map
   return NullNode.getInstance();
 }
Exemplo n.º 5
0
 @Override
 public List<ObjectAdapter> getChoices(
     final ScalarModel scalarModel, final ObjectAdapter[] argumentsIfAvailable) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   final ObjectAdapter[] choices =
       actionParameter.getChoices(
           scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK),
           argumentsIfAvailable);
   return choicesAsList(choices);
 }
Exemplo n.º 6
0
 @Override
 public List<ObjectAdapter> getAutoComplete(
     final ScalarModel scalarModel, final String searchArg) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   final ObjectAdapter[] choices =
       actionParameter.getAutoComplete(
           scalarModel.parentObjectAdapterMemento.getObjectAdapter(
               ConcurrencyChecking.NO_CHECK),
           searchArg);
   return choicesAsList(choices);
 }
Exemplo n.º 7
0
  /**
   * Creates a model representing an action parameter of an action of a parent object, with the
   * {@link #getObject() value of this model} to be default value (if any) of that action parameter.
   */
  public ScalarModel(
      final ObjectAdapterMemento parentObjectAdapterMemento, final ActionParameterMemento apm) {
    this.kind = Kind.PARAMETER;
    this.parentObjectAdapterMemento = parentObjectAdapterMemento;
    this.parameterMemento = apm;

    final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
    // REVIEW: is no checking ok here?
    final ObjectAdapter defaultAdapter =
        actionParameter.getDefault(
            parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.NO_CHECK));
    setObject(defaultAdapter);

    setMode(Mode.EDIT);
  }
 private Object paramDetails(final ObjectActionParameter param) {
   final JsonRepresentation paramRep = JsonRepresentation.newMap();
   paramRep.mapPut("num", param.getNumber());
   paramRep.mapPut("id", param.getId());
   paramRep.mapPut("name", param.getName());
   paramRep.mapPut("description", param.getDescription());
   final Object paramChoices = choicesFor(param);
   if (paramChoices != null) {
     paramRep.mapPut("choices", paramChoices);
   }
   final Object paramDefault = defaultFor(param);
   if (paramDefault != null) {
     paramRep.mapPut("default", paramDefault);
   }
   return paramRep;
 }
Exemplo n.º 9
0
 public String getAutoComplete() {
   if (memberType == MemberType.PROPERTY) {
     return interpretRowAndFacet(PropertyAutoCompleteFacet.class);
   } else if (memberType == MemberType.COLLECTION) {
     return "";
   } else {
     final List<ObjectActionParameter> parameters = this.action.getParameters();
     final SortedSet<String> interpretations = Sets.newTreeSet();
     for (ObjectActionParameter param : parameters) {
       final ActionParameterAutoCompleteFacet facet =
           param.getFacet(ActionParameterAutoCompleteFacet.class);
       addIfNotEmpty(interpretFacet(facet), interpretations);
     }
     return !interpretations.isEmpty() ? Joiner.on(";").join(interpretations) : "";
   }
 }
Exemplo n.º 10
0
 private Object defaultFor(final ObjectActionParameter param) {
   final ObjectAdapter defaultAdapter = param.getDefault(objectAdapter);
   if (defaultAdapter == null) {
     return null;
   }
   // REVIEW: previously was using the spec of the parameter, but think instead it should be the
   // spec of the adapter itself
   // final ObjectSpecification defaultSpec = param.getSpecification();
   final ObjectSpecification defaultSpec = defaultAdapter.getSpecification();
   return DomainObjectReprRenderer.valueOrRef(rendererContext, defaultAdapter, defaultSpec);
 }
Exemplo n.º 11
0
 @Override
 public String parseAndValidate(
     final ScalarModel scalarModel, final String proposedPojoAsStr) {
   final ObjectActionParameter parameter =
       scalarModel.getParameterMemento().getActionParameter();
   ParseableFacet parseableFacet = parameter.getFacet(ParseableFacet.class);
   if (parseableFacet == null) {
     parseableFacet = parameter.getSpecification().getFacet(ParseableFacet.class);
   }
   try {
     final ObjectAdapter parentAdapter =
         scalarModel.parentObjectAdapterMemento.getObjectAdapter(ConcurrencyChecking.CHECK);
     Localization localization = IsisContext.getLocalization();
     final String invalidReasonIfAny =
         parameter.isValid(parentAdapter, proposedPojoAsStr, localization);
     return invalidReasonIfAny;
   } catch (final Exception ex) {
     return ex.getLocalizedMessage();
   }
 }
Exemplo n.º 12
0
 private Object choicesFor(final ObjectActionParameter param) {
   final ObjectAdapter[] choiceAdapters = param.getChoices(objectAdapter);
   if (choiceAdapters == null || choiceAdapters.length == 0) {
     return null;
   }
   final List<Object> list = Lists.newArrayList();
   for (final ObjectAdapter choiceAdapter : choiceAdapters) {
     // REVIEW: previously was using the spec of the parameter, but think instead it should be the
     // spec of the adapter itself
     // final ObjectSpecification choiceSpec = param.getSpecification();
     final ObjectSpecification choiceSpec = choiceAdapter.getSpecification();
     list.add(DomainObjectReprRenderer.valueOrRef(rendererContext, choiceAdapter, choiceSpec));
   }
   return list;
 }
Exemplo n.º 13
0
  void appendObjectActionInvokePath(
      final ObjectSpecification objectSpec, final ObjectAction objectAction) {

    final String objectType = objectTypeFor(objectSpec);
    final String actionId = objectAction.getId();

    final List<ObjectActionParameter> parameters = objectAction.getParameters();
    final Path path = new Path();
    swagger.path(
        String.format("/objects/%s/{objectId}/actions/%s/invoke", objectType, actionId), path);

    final String tag = tagFor(objectType, null);
    final Operation invokeOperation =
        new Operation()
            .tag(tag)
            .description(
                Util.roSpec("19.1") + ": (invoke) resource of " + objectType + "#" + actionId)
            .parameter(new PathParameter().name("objectId").type("string"))
            .produces("application/json;profile=urn:org.apache.isis/v1")
            .produces("application/json;profile=urn:org.apache.isis/v1;suppress=true")
            .produces("application/json;profile=urn:org.restfulobjects:repr-types/action-result");

    final ActionSemantics.Of semantics = objectAction.getSemantics();
    if (semantics.isSafeInNature()) {
      path.get(invokeOperation);

      for (final ObjectActionParameter parameter : parameters) {
        invokeOperation.parameter(
            new QueryParameter()
                .name(parameter.getId())
                .description(
                    Util.roSpec("2.9.1")
                        + (!Strings.isNullOrEmpty(parameter.getDescription())
                            ? (": " + parameter.getDescription())
                            : ""))
                .required(false)
                .type("string"));
      }
      if (!parameters.isEmpty()) {
        invokeOperation.parameter(
            new QueryParameter()
                .name("x-isis-querystring")
                .description(
                    Util.roSpec("2.10") + ": all (formal) arguments as base64 encoded string")
                .required(false)
                .type("string"));
      }

    } else {
      if (semantics.isIdempotentInNature()) {
        path.put(invokeOperation);
      } else {
        path.post(invokeOperation);
      }

      final ModelImpl bodyParam = new ModelImpl().type("object");
      for (final ObjectActionParameter parameter : parameters) {

        final ObjectSpecification specification = parameter.getSpecification();
        final Property valueProperty =
            specification.isValue() ? modelFor(specification) : refToLinkModel();
        bodyParam.property(
            parameter.getId(), new ObjectProperty().property("value", valueProperty));
      }

      invokeOperation
          .consumes("application/json")
          .parameter(new BodyParameter().name("body").schema(bodyParam));
    }

    invokeOperation.response(
        200,
        new Response()
            .description(objectType + "#" + actionId)
            .schema(actionReturnTypeFor(objectAction)));
  }
Exemplo n.º 14
0
  void appendServiceActionInvokePath(
      final ObjectSpecification serviceSpec, final ObjectAction serviceAction) {

    final String serviceId = serviceIdFor(serviceSpec);
    final String actionId = serviceAction.getId();

    final List<ObjectActionParameter> parameters = serviceAction.getParameters();
    final Path path = new Path();
    swagger.path(String.format("/services/%s/actions/%s/invoke", serviceId, actionId), path);

    final String tag = tagFor(serviceId, "> services");
    final Operation invokeOperation =
        new Operation()
            .tag(tag)
            .description(
                Util.roSpec("19.1") + ": (invoke) resource of " + serviceId + "#" + actionId)
            .produces("application/json;profile=urn:org.apache.isis/v1")
            .produces("application/json;profile=urn:org.apache.isis/v1;suppress=true")
            .produces("application/json;profile=urn:org.restfulobjects:repr-types/action-result");

    final ActionSemantics.Of semantics = serviceAction.getSemantics();
    if (semantics.isSafeInNature()) {
      path.get(invokeOperation);

      for (final ObjectActionParameter parameter : parameters) {
        invokeOperation.parameter(
            new QueryParameter()
                .name(parameter.getId())
                .description(
                    Util.roSpec("2.9.1")
                        + (!Strings.isNullOrEmpty(parameter.getDescription())
                            ? (": " + parameter.getDescription())
                            : ""))
                .required(false)
                .type("string"));
      }
      if (!parameters.isEmpty()) {
        invokeOperation.parameter(
            new QueryParameter()
                .name("x-isis-querystring")
                .description(
                    Util.roSpec("2.10") + ": all (formal) arguments as base64 encoded string")
                .required(false)
                .type("string"));
      }

    } else {
      if (semantics.isIdempotentInNature()) {
        path.put(invokeOperation);
      } else {
        path.post(invokeOperation);
      }

      final ModelImpl bodyParam = new ModelImpl().type("object");
      for (final ObjectActionParameter parameter : parameters) {

        final Property valueProperty;
        // TODO: need to switch on parameter's type and create appropriate impl of valueProperty
        // if(parameter.getSpecification().isValue()) ...
        valueProperty = stringProperty();

        bodyParam.property(
            parameter.getId(), new ObjectProperty().property("value", valueProperty));
      }

      invokeOperation
          .consumes("application/json")
          .parameter(new BodyParameter().name("body").schema(bodyParam));
    }

    invokeOperation.response(
        200,
        new Response()
            .description(
                serviceId
                    + "#"
                    + actionId
                    + " , if Accept: application/json;profile=urn:org.apache.isis/v1")
            .schema(actionReturnTypeFor(serviceAction)));
  }
Exemplo n.º 15
0
 @Override
 public String getDescribedAs(final ScalarModel scalarModel) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   return actionParameter.getDescription();
 }
Exemplo n.º 16
0
 @Override
 public boolean hasAutoComplete(final ScalarModel scalarModel) {
   final ActionParameterMemento parameterMemento = scalarModel.getParameterMemento();
   final ObjectActionParameter actionParameter = parameterMemento.getActionParameter();
   return actionParameter.hasAutoComplete();
 }