001// Generated by delombok at Mon Oct 12 22:51:05 BST 2020 002/* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020package org.apache.isis.viewer.restfulobjects.rendering.domainobjects; 021 022import org.apache.isis.commons.collections.Can; 023import org.apache.isis.core.metamodel.facets.collections.CollectionFacet; 024import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet; 025import org.apache.isis.core.metamodel.interactions.managed.ActionInteraction; 026import org.apache.isis.core.metamodel.spec.ManagedObject; 027import org.apache.isis.core.metamodel.spec.ObjectSpecification; 028import org.apache.isis.core.metamodel.spec.feature.ObjectAction; 029import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; 030import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ActionResultRepresentation; 031import lombok.NonNull; 032 033public class ObjectAndActionInvocation { 034 public static ObjectAndActionInvocation of(@NonNull ActionInteraction.Result actionInteractionResult, @NonNull JsonRepresentation argsJsonRepr, @NonNull ActionResultReprRenderer.SelfLink selfLink) { 035 if (actionInteractionResult == null) { 036 throw new java.lang.NullPointerException("actionInteractionResult is marked non-null but is null"); 037 } 038 if (argsJsonRepr == null) { 039 throw new java.lang.NullPointerException("argsJsonRepr is marked non-null but is null"); 040 } 041 if (selfLink == null) { 042 throw new java.lang.NullPointerException("selfLink is marked non-null but is null"); 043 } 044 return new ObjectAndActionInvocation(actionInteractionResult.getManagedAction().getOwner(), actionInteractionResult.getManagedAction().getAction(), argsJsonRepr, actionInteractionResult.getParameterList(), actionInteractionResult.getActionReturnedObject(), selfLink); 045 } 046 047 private final ManagedObject objectAdapter; 048 private final ObjectAction action; 049 private final JsonRepresentation arguments; 050 private final Can<ManagedObject> argAdapters; 051 private final ManagedObject returnedAdapter; 052 private final ActionResultReprRenderer.SelfLink selfLink; 053 054 public ObjectAndActionInvocation(final ManagedObject objectAdapter, final ObjectAction action, final JsonRepresentation arguments, final Can<ManagedObject> argAdapters, final ManagedObject returnedAdapter, final ActionResultReprRenderer.SelfLink selfLink) { 055 this.objectAdapter = objectAdapter; 056 this.action = action; 057 this.arguments = arguments; 058 this.argAdapters = argAdapters; 059 this.returnedAdapter = returnedAdapter; 060 this.selfLink = selfLink; 061 } 062 063 public ManagedObject getObjectAdapter() { 064 return objectAdapter; 065 } 066 067 public ObjectAction getAction() { 068 return action; 069 } 070 071 public JsonRepresentation getArguments() { 072 return arguments; 073 } 074 075 public Can<ManagedObject> getArgAdapters() { 076 return argAdapters; 077 } 078 079 public ManagedObject getReturnedAdapter() { 080 return returnedAdapter; 081 } 082 083 public ActionResultReprRenderer.SelfLink getSelfLink() { 084 return selfLink; 085 } 086 087 /** 088 * not API 089 */ 090 public ActionResultRepresentation.ResultType determineResultType() { 091 final ObjectSpecification returnType = this.action.getReturnType(); 092 if (returnType.getCorrespondingClass() == void.class) { 093 return ActionResultRepresentation.ResultType.VOID; 094 } 095 final CollectionFacet collectionFacet = returnType.getFacet(CollectionFacet.class); 096 if (collectionFacet != null) { 097 return ActionResultRepresentation.ResultType.LIST; 098 } 099 final EncodableFacet encodableFacet = returnType.getFacet(EncodableFacet.class); 100 if (encodableFacet != null) { 101 return ActionResultRepresentation.ResultType.SCALAR_VALUE; 102 } 103 // else 104 return ActionResultRepresentation.ResultType.DOMAIN_OBJECT; 105 } 106}