/** * Returns the name of the method for getting an {@link com.sap.cloud.yaas.rammler.commons.builder.ActionBuilder}, * e.g. " {@code prepareDelete}". * * @param ramlAction the action for which the method name should be built * @return the name of the method for getting the action builder */ public static String buildActionBuilderMethodName(final Action ramlAction) { if (ramlAction == null) { return null; } return "prepare" + buildName(ramlAction.getType() != null ? ramlAction.getType().toString() : "Any"); }
/** * Build a suitable Java type name for an {@link com.sap.cloud.yaas.rammler.commons.builder.ActionBuilder}, e.g. " * {@code GetActionBuilder}". * * @param ramlAction the RAML {@link Action} * @return a corresponding Java type name */ public static String buildActionBuilderName(final Action ramlAction) { return ramlAction != null ? buildName(ramlAction.getType().toString()) + "ActionBuilder" : null; }
String type = action.getType().toString().toLowerCase();
public static String buildResourceMethodName(final Action action, final MimeType bodyMimeType) { final String methodBaseName = buildJavaFriendlyName(action.getResource() .getUri() .replace("{", " By ")); return action.getType().toString().toLowerCase() + buildMimeTypeInfix(bodyMimeType) + methodBaseName; }
/** * <p>buildResourceMethodName.</p> * * @param action a {@link org.raml.model.Action} object. * @param bodyMimeType a {@link org.raml.model.MimeType} object. * @return a {@link java.lang.String} object. */ public static String buildResourceMethodName(final Action action, final MimeType bodyMimeType) { final String methodBaseName = buildJavaFriendlyName(action.getResource() .getUri() .replace("{", " By ")); return action.getType().toString().toLowerCase() + buildMimeTypeInfix(bodyMimeType) + methodBaseName; }
private String actionString() { return new Message("action", action.getType(), action.getResource().getUri()).toString(); } }
public ActionMethod(ReqSpecField reqFieldName, RespSpecField respFieldName, UriConst uriConst, Action action) { this.reqFieldName = reqFieldName.name(); this.respFieldName = respFieldName.name(); this.uriConst = uriConst.name(); this.action = action; this.httpMethod = action.getType().name().toLowerCase(); this.name = defaultIfEmpty(action.getDisplayName(), httpMethod); }
if (action.isValid()) if (action.getType() == Action.e_GoTo)
/** * Creates a specific constructor body. * * @param ramlAction an action which the body reflects * @param codeModel the code model to access JCodeModel functionality * @param constructorBody target block to filled in */ protected void createConstructorBody(final Action ramlAction, final JCodeModel codeModel, final JBlock constructorBody) { final JInvocation setHttpMethodInvocation = constructorBody.invoke("setHttpMethod"); final JClass httpMethodEnum = codeModel.ref(HttpMethod.class); setHttpMethodInvocation.arg(httpMethodEnum.staticRef(ramlAction.getType().toString())); }
static Usage.Action actionUsage(Usage usage, Action action) { return usage.resource(action.getResource().getUri()).action(action.getType().name()); }
@Override public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException { final Action a = (Action) o; switch (propertyName) { case "securitySchemes": if (a.getSecuredBy() != null && !a.getSecuredBy().isEmpty()) { return a.getSecuredBy(); } if (a.getResource().getSecuredBy() != null && !a.getResource().getSecuredBy().isEmpty()) { return a.getResource().getSecuredBy(); } if (raml.getSecuredBy() != null && !raml.getSecuredBy().isEmpty()) { return raml.getSecuredBy(); } return Collections.emptyList(); case "type": return a.getType().toString(); case "responses": return new TreeMap<>(a.getResponses()); case "queryParameters": return new TreeMap<>(a.getQueryParameters()); case "headers": return new TreeMap<>(a.getHeaders()); case "body": return a.getBody() == null ? null : new TreeMap<>(a.getBody()); default: return super.getProperty(interp, self, o, property, propertyName); } } }
/** * {@inheritDoc} * <p/> * This implementation adds accessor methods to the {@code builderForParent} class. These accessor methods create a * new instane of the procreated {@code builder} based on the state of the {@code builderForParent}. The name of the * accessor method will be based on the HTTP method that is declared in the {@code ramlAction}. */ @Override protected void createHooksInParentBuilder( final Action ramlAction, final JDefinedClass builderForParent, final JDefinedClass builder, final Context<Object, JDeclaration> context ) { final String hookMethodName = JavaNameUtils.buildActionBuilderMethodName(ramlAction); final JMethod hookMethod = builderForParent.method(JMod.PUBLIC, builder, hookMethodName); final JBlock hookMethodBody = hookMethod.body(); hookMethodBody._return(JExpr._new(builder).arg(JExpr.invoke("getTarget")).arg(JExpr.invoke("getRequestParams"))); // attach the Javadoc hookMethod.javadoc().append(JavaDocs.METHOD_PREPARE_ACTION.fillTemplate(ActionBuilder.class.getCanonicalName(), ramlAction.getType() != null ? ramlAction.getType() : "any", builder.name())); }
final JMethod method = context.createResourceMethod(resourceInterface, methodName, resourceMethodReturnType); context.addHttpMethodAnnotation(action.getType().toString(), method); addParamAnnotation(resourceInterfacePath, action, method); addConsumesAnnotation(bodyMimeType, method);
context.addHttpMethodAnnotation(action.getType().toString(), method);
protected void addResourceMethod(final JDefinedClass resourceInterface, final String resourceInterfacePath, final Action action, final MimeType bodyMimeType, final boolean addBodyMimeTypeInMethodName, final Collection<MimeType> uniqueResponseMimeTypes) throws Exception { final String methodName = Names.buildResourceMethodName(action, addBodyMimeTypeInMethodName ? bodyMimeType : null); final JType resourceMethodReturnType = getResourceMethodReturnType(methodName, action, uniqueResponseMimeTypes.isEmpty(), resourceInterface); // the actually created unique method name should be needed in the previous method but // no way of doing this :( final JMethod method = context.createResourceMethod(resourceInterface, methodName, resourceMethodReturnType); Configuration contiguration = context.getConfiguration(); if (contiguration.getMethodThrowException() != null ) { method._throws(contiguration.getMethodThrowException()); } context.addHttpMethodAnnotation(action.getType().toString(), method); addParamAnnotation(resourceInterfacePath, action, method); addConsumesAnnotation(bodyMimeType, method); addProducesAnnotation(uniqueResponseMimeTypes, method); final JDocComment javadoc = addBaseJavaDoc(action, method); addPathParameters(action, method, javadoc); addHeaderParameters(action, method, javadoc); addQueryParameters(action, method, javadoc); addBodyParameters(bodyMimeType, method, javadoc); }
.append( JavaDocs.TOP_CLASS.fillTemplate(builder.name(), ActionBuilder.class.getCanonicalName(), ramlAction.getType()));