@Override
  public void debugData(final DebugBuilder debug) {
    facetDecoratorSet.debugData(debug);
    debug.appendln();

    debug.appendTitle("Specifications");
    final List<ObjectSpecification> specs = Lists.newArrayList(allSpecifications());
    Collections.sort(specs, ObjectSpecification.COMPARATOR_SHORT_IDENTIFIER_IGNORE_CASE);
    for (final ObjectSpecification spec : specs) {
      StringBuffer str = new StringBuffer();
      str.append(spec.isAbstract() ? "A" : ".");
      str.append(spec.isService() ? "S" : ".");
      str.append(ChoicesFacetUtils.hasChoices(spec) ? "B" : ".");
      str.append(spec.isParentedOrFreeCollection() ? "C" : ".");
      str.append(spec.isNotCollection() ? "O" : ".");
      str.append(spec.isParseable() ? "P" : ".");
      str.append(spec.isEncodeable() ? "E" : ".");
      str.append(spec.isValueOrIsParented() ? "A" : ".");

      final boolean hasIdentity =
          !(spec.isParentedOrFreeCollection() || spec.isParented() || spec.isValue());
      str.append(hasIdentity ? "I" : ".");
      str.append("  ");
      str.append(spec.getFullIdentifier());

      debug.appendPreformatted(spec.getShortIdentifier(), str.toString());
    }
  }
Example #2
0
 public String getClassType() {
   boolean service = false;
   for (ObjectSpecification subspecs : spec.subclasses()) {
     service = service || subspecs.isService();
   }
   return service || spec.isService()
       ? "2 Service"
       : spec.isValue()
           ? "3 Value"
           : spec.isParentedOrFreeCollection() ? "4 Collection" : "1 Object";
 }
Example #3
0
  void appendObjectPathsAndDefinitions() {
    // take copy to avoid concurrent modification exception
    final Collection<ObjectSpecification> allSpecs =
        Lists.newArrayList(specificationLoader.allSpecifications());
    for (final ObjectSpecification objectSpec : allSpecs) {

      final DomainServiceFacet domainServiceFacet = objectSpec.getFacet(DomainServiceFacet.class);
      if (domainServiceFacet != null) {
        continue;
      }
      final MixinFacet mixinFacet = objectSpec.getFacet(MixinFacet.class);
      if (mixinFacet != null) {
        continue;
      }
      if (visibility.isPublic() && !Util.isVisibleForPublic(objectSpec)) {
        continue;
      }
      if (objectSpec.isAbstract()) {
        continue;
      }
      if (objectSpec.isValue()) {
        continue;
      }
      // special cases
      if (classExcluder.exclude(objectSpec)) {
        continue;
      }

      final List<OneToOneAssociation> objectProperties = Util.propertiesOf(objectSpec, visibility);
      final List<OneToManyAssociation> objectCollections =
          Util.collectionsOf(objectSpec, visibility);
      final List<ObjectAction> objectActions =
          Util.actionsOf(objectSpec, visibility, classExcluder);

      if (objectProperties.isEmpty() && objectCollections.isEmpty()) {
        continue;
      }
      final ModelImpl isisModel = appendObjectPathAndModelDefinitions(objectSpec);
      updateObjectModel(isisModel, objectSpec, objectProperties, objectCollections);

      for (final OneToManyAssociation objectCollection : objectCollections) {
        appendCollectionTo(objectSpec, objectCollection);
      }

      for (final ObjectAction objectAction : objectActions) {
        appendObjectActionInvokePath(objectSpec, objectAction);
      }
    }
  }
Example #4
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)));
  }
Example #5
0
  private static void specificationFields(
      final ObjectSpecification specification, final DebugBuilder debugBuilder) {
    final List<ObjectAssociation> fields = specification.getAssociations(Contributed.EXCLUDED);
    debugBuilder.appendln("All");
    debugBuilder.indent();
    for (int i = 0; i < fields.size(); i++) {
      debugBuilder.appendln((i + 1) + "." + fields.get(i).getId());
    }
    debugBuilder.unindent();

    final List<ObjectAssociation> fields2 =
        specification.getAssociations(
            Contributed.EXCLUDED, ObjectAssociation.Filters.VISIBLE_AT_LEAST_SOMETIMES);
    debugBuilder.appendln("Static");
    debugBuilder.indent();
    for (int i = 0; i < fields2.size(); i++) {
      debugBuilder.appendln((i + 1) + "." + fields2.get(i).getId());
    }
    debugBuilder.unindent();
    debugBuilder.appendln();

    try {
      if (fields.size() == 0) {
        debugBuilder.appendln("none");
      } else {
        for (int i = 0; i < fields.size(); i++) {

          final ObjectAssociation field = fields.get(i);
          debugBuilder.appendln(
              (i + 1) + "." + field.getId() + "  (" + field.getClass().getName() + ")");

          debugBuilder.indent();
          final String description = field.getDescription();
          if (description != null && !description.equals("")) {
            debugBuilder.appendln("Description", description);
          }
          final String help = field.getHelp();
          if (help != null && !help.equals("")) {
            debugBuilder.appendln(
                "Help",
                help.substring(0, Math.min(30, help.length())) + (help.length() > 30 ? "..." : ""));
          }

          debugBuilder.appendln("ID", field.getIdentifier());
          debugBuilder.appendln("Short ID", field.getId());
          debugBuilder.appendln("Name", field.getName());
          final String type =
              field.isOneToManyAssociation()
                  ? "Collection"
                  : field.isOneToOneAssociation() ? "Object" : "Unknown";
          debugBuilder.appendln("Type", type);
          final ObjectSpecification fieldSpec = field.getSpecification();
          final boolean hasIdentity =
              !(fieldSpec.isParentedOrFreeCollection()
                  || fieldSpec.isParented()
                  || fieldSpec.isValue());
          debugBuilder.appendln("Has identity", hasIdentity);
          debugBuilder.appendln("Spec", fieldSpec.getFullIdentifier());

          debugBuilder.appendln(
              "Flags",
              (field.isAlwaysHidden() ? "" : "Visible ")
                  + (field.isNotPersisted() ? "Not Persisted " : " ")
                  + (field.isMandatory() ? "Mandatory " : ""));

          final Class<? extends Facet>[] facets = field.getFacetTypes();
          if (facets.length > 0) {
            debugBuilder.appendln("Facets");
            debugBuilder.indent();
            boolean none = true;
            for (final Class<? extends Facet> facet : facets) {
              debugBuilder.appendln(field.getFacet(facet).toString());
              none = false;
            }
            if (none) {
              debugBuilder.appendln("none");
            }
            debugBuilder.unindent();
          }

          debugBuilder.appendln(field.debugData());

          debugBuilder.unindent();
        }
      }
    } catch (final RuntimeException e) {
      debugBuilder.appendException(e);
    }
  }