use of org.raml.model.ActionType in project microservice_framework by CJSCommonPlatform.
the class JaxRsImplementationGenerator method methodsFor.
/**
* Process the body or bodies for each httpAction.
*
* @param action the httpAction to process
* @param component
* @return the list of {@link MethodSpec} that represents each method for the httpAction
*/
private List<MethodSpec> methodsFor(final Action action, final Optional<String> component) {
final ActionType actionType = action.getType();
final String responseStrategyName = nameOfResponseStrategyFor(action, component);
if (isSupportedActionType(actionType)) {
if (isSupportedActionTypeWithResponseTypeOnly(actionType)) {
return singletonList(processNoActionBody(action, responseStrategyName));
} else {
return processOneOrMoreActionBodies(action, responseStrategyName);
}
}
throw new IllegalStateException(format("Unsupported httpAction type %s", actionType));
}
use of org.raml.model.ActionType in project microservice_framework by CJSCommonPlatform.
the class EventFilterCodeGeneratorTest method shouldGenerateCorrectEventFilterJavaCode.
@Test
public void shouldGenerateCorrectEventFilterJavaCode() throws Exception {
final String serviceName = "my-context";
final String componentName = "EVENT_LISTENER";
final String jmsUri = "jms:topic:my-context.handler.command";
final Event event_1 = event().withName("my-context.events.something-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-happened.json").build();
final Event event_2 = event().withName("my-context.events.something-else-happened").withSchemaUri("http://justice.gov.uk/json/schemas/domains/example/my-context.events.something-else-happened.json").build();
final Subscription subscription = subscription().withName("subscription").withEvent(event_1).withEvent(event_2).withEventsource(eventsource().withName("eventsource").withLocation(location().withJmsUri(jmsUri).withRestUri("http://localhost:8080/example/event-source-api/rest").build()).build()).build();
final SubscriptionDescriptor subscriptionDescriptor = subscriptionDescriptor().withSpecVersion("1.0.0").withService(serviceName).withServiceComponent(componentName).withSubscription(subscription).build();
final SubscriptionDescriptorDef subscriptionDescriptorDef = subscriptionDescriptorDef().withSubscriptionDescriptor(subscriptionDescriptor).build();
final HashMap<ActionType, Action> actions = new HashMap<>();
final Resource resource = new Resource();
resource.setActions(actions);
final Action action = mock(Action.class, RETURNS_DEEP_STUBS.get());
actions.put(POST, action);
final MimeType mimeType_1 = new MimeType("application/vnd.my-context.events.something-happened+json");
final MimeType mimeType_2 = new MimeType("application/vnd.my-context.events.something-else-happened+json");
final String basePackageName = "uk.gov.moj.base.package.name";
when(action.getBody().values()).thenReturn(asList(mimeType_1, mimeType_2));
final ClassNameFactory classNameFactory = new ClassNameFactory(basePackageName, serviceName, componentName, jmsUri);
final TypeSpec typeSpec = eventFilterCodeGenerator.generate(subscription, classNameFactory);
assertThat(typeSpec.toString(), is("@javax.enterprise.context.ApplicationScoped\n" + "public class MyContextEventListenerMyContextHandlerCommandEventFilter extends uk.gov.justice.services.event.buffer.api.AbstractEventFilter {\n" + " public MyContextEventListenerMyContextHandlerCommandEventFilter() {\n" + " super(\"my-context.events.something-happened\",\"my-context.events.something-else-happened\");}\n" + "}\n"));
}
use of org.raml.model.ActionType in project microservice_framework by CJSCommonPlatform.
the class ResourceBuilder method build.
public Resource build() {
final Resource resource = new Resource();
resource.setParentUri(parentUri);
resource.setRelativeUri(relativeUri);
resource.setUriParameters(uriParameters);
final Map<ActionType, Action> actions = new HashMap<>();
for (final HttpActionBuilder httpActionBuilder : httpActionBuilders) {
final Action action = httpActionBuilder.build();
action.setResource(resource);
actions.put(action.getType(), action);
}
resource.setActions(actions);
return resource;
}
use of org.raml.model.ActionType in project microservice_framework by CJSCommonPlatform.
the class ActionMappingGenerator method mapperConstructorCodeFor.
private CodeBlock mapperConstructorCodeFor(final Resource resource) {
final CodeBlock.Builder constructorCode = CodeBlock.builder().addStatement("this.$L = $L", ACTION_MAPPER_HELPER_FIELD, ACTION_MAPPER_HELPER_FIELD);
// NOTE: there's a bit of ambiguity here: ramlActions (http methods) are not framework actions
resource.getActions().values().forEach(ramlAction -> {
final List<ActionMapping> actionMappings = new ActionMappingParser().listOf(ramlAction.getDescription());
final ActionType actionType = ramlAction.getType();
if (isSupportedActionType(actionType)) {
actionMappings.forEach(actionMapping -> {
final String mediaType = actionMapping.mimeTypeFor(ramlAction.getType());
constructorCode.addStatement("$L.add($S, $S, $S)", ACTION_MAPPER_HELPER_FIELD, methodNameForAction(ramlAction, actionType, mediaType), mediaType, actionMapping.getName());
});
} else {
throw new IllegalStateException(format("Http Method of type %s is not supported by the Action Mapper", actionType.toString()));
}
});
return constructorCode.build();
}
Aggregations