private void cleanupMethods (Resource resource, Map<ActionType, Action> actions) { final HashSet<String> methods = new HashSet<>(); for (ActionType action : actions.keySet()) { methods.add(action.toString()); } for (Method m : resource.getResourceMethods().values()) { String httpMethod = m.getHttpMethod().toUpperCase(); if (!methods.contains(httpMethod)) { LOG.info(format("Removing deleted method %s for resource %s", httpMethod, resource.getId())); m.deleteMethod(); } } }
/** * 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; }
/** * 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"); }
/** * 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())); }
Method method; if (update && methodExists(resource, httpMethod.toString())) { method = resource.getMethodByHttpMethod(httpMethod.toString()); createReplaceOperation("/authorizationType", getAuthorizationTypeFromConfig(resource, httpMethod.toString(), this.config)), createReplaceOperation("/apiKeyRequired", "false")); input.setAuthorizationType(getAuthorizationTypeFromConfig(resource, httpMethod.toString(), this.config)); input.setRequestModels(new HashMap<>()); method = resource.putMethod(input, httpMethod.toString());
@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); } } }
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); }