@Test public void shouldCreateNewConnectorsBasedOnConnectorTemplates() { final Map<String, ConfigurationProperty> properties = new HashMap<>(); properties.put("prop1", new ConfigurationProperty.Builder().build()); final Map<String, ConfigurationProperty> connectorProperties = new HashMap<>(); connectorProperties.put("prop2", new ConfigurationProperty.Builder().build()); connectorProperties.put("prop3", new ConfigurationProperty.Builder().build()); final ConnectorGroup group = new ConnectorGroup.Builder().name("connector template group").build(); final ConnectorTemplate connectorTemplate = new ConnectorTemplate.Builder() .id("connector-template-id") .name("connector template") .properties(properties).connectorProperties(connectorProperties) .connectorGroup(group) .build(); final ConnectorAction action = new ConnectorAction.Builder().name("action").build(); when(dataManager.fetch(ConnectorTemplate.class, "connector-template-id")).thenReturn(connectorTemplate); when(dataManager.create(any(Connector.class))).thenAnswer(invocation -> invocation.getArgument(0)); when(applicationContext.getBean("connector-template-id")).thenReturn(new ConnectorGenerator(new Connector.Builder() .addTags("from-connector") .build()) { @Override public Connector generate(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { return new Connector.Builder().createFrom(baseConnectorFrom(connectorTemplate, connectorSettings)) .putAllProperties(connectorProperties).putConfiguredProperty("prop1", "value1").addAction(action).build(); } @Override public APISummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { return null; } }); final Connector created = new CustomConnectorHandler(dataManager, applicationContext, iconDao).create( new ConnectorSettings.Builder() .connectorTemplateId("connector-template-id") .name("new connector") .description("new connector description") .icon("new connector icon") .putConfiguredProperty("prop1", "value1") .putConfiguredProperty("unknown-prop", "unknown-value") .build()); final Connector expected = new Connector.Builder() .id(created.getId()) .name("new connector") .description("new connector description") .addTag("from-connector") .icon("new connector icon") .connectorGroup(group) .properties(connectorProperties) .putConfiguredProperty("prop1", "value1") .addAction(action) .build(); assertThat(created).isEqualTo(expected); }
@POST @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings`") @ApiResponse(responseCode = "200", description = "Newly created Connector") public Connector create(final ConnectorSettings connectorSettings) { final Connector connector = withGeneratorAndTemplate(connectorSettings.getConnectorTemplateId(), (generator, template) -> generator.generate(template, connectorSettings)); return getDataManager().create(connector); }
CustomConnectorHandler extends BaseConnectorGeneratorHandler { @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings`") @ApiResponse(responseCode = "200", description = "Newly created Connector") public Connector create(final ConnectorSettings connectorSettings) { final Connector connector = withGeneratorAndTemplate(connectorSettings.getConnectorTemplateId(), (generator, template) -> generator.generate(template, connectorSettings)); return getDataManager().create(connector); } }
CustomConnectorHandler extends BaseConnectorGeneratorHandler { @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings`") @ApiResponse(responseCode = "200", description = "Newly created Connector") public Connector create(final ConnectorSettings connectorSettings) { final Connector connector = withGeneratorAndTemplate(connectorSettings.getConnectorTemplateId(), (generator, template) -> generator.generate(template, connectorSettings)); return getDataManager().create(connector); } CustomConnectorHandler(final DataManager dataManager, final ApplicationContext applicationContext, final IconDao iconDao); }
CustomConnectorHandler extends BaseConnectorGeneratorHandler { @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings`") @ApiResponse(responseCode = "200", description = "Newly created Connector") public Connector create(final ConnectorSettings connectorSettings) { final Connector connector = withGeneratorAndTemplate(connectorSettings.getConnectorTemplateId(), (generator, template) -> generator.generate(template, connectorSettings)); return getDataManager().create(connector); } CustomConnectorHandler(final DataManager dataManager, final ApplicationContext applicationContext, final IconDao iconDao); @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings`") @ApiResponse(responseCode = "200", description = "Newly created Connector") Connector create(final ConnectorSettings connectorSettings); @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @Operation(description = "Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings` multipart part, plus optional `icon` file") @ApiResponse(responseCode = "200", description = "Newly created Connector") Connector create(@MultipartForm CustomConnectorFormData customConnectorFormData); @POST @Path("/info") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Provides a summary of the connector as it would be built using a ConnectorTemplate identified by the provided `connector-template-id` and the data given in `connectorSettings`") APISummary info(final ConnectorSettings connectorSettings); @POST @Path("/info") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @Operation(description = "Provides a summary of the connector as it would be built using a ConnectorTemplate identified by the provided `connector-template-id` and the data given in `connectorSettings`") APISummary info(@MultipartForm final CustomConnectorFormData connectorFormData); }
CustomConnectorHandler extends BaseConnectorGeneratorHandler { @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings`") @ApiResponse(responseCode = "200", description = "Newly created Connector") public Connector create(final ConnectorSettings connectorSettings) { final Connector connector = withGeneratorAndTemplate(connectorSettings.getConnectorTemplateId(), (generator, template) -> generator.generate(template, connectorSettings)); return getDataManager().create(connector); } CustomConnectorHandler(final DataManager dataManager, final ApplicationContext applicationContext, final IconDao iconDao); @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings`") @ApiResponse(responseCode = "200", description = "Newly created Connector") Connector create(final ConnectorSettings connectorSettings); @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @Operation(description = "Creates a new Connector based on the ConnectorTemplate identified by the provided `id` and the data given in `connectorSettings` multipart part, plus optional `icon` file") @ApiResponse(responseCode = "200", description = "Newly created Connector") Connector create(@MultipartForm CustomConnectorFormData customConnectorFormData); @POST @Path("/info") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Provides a summary of the connector as it would be built using a ConnectorTemplate identified by the provided `connector-template-id` and the data given in `connectorSettings`") APISummary info(final ConnectorSettings connectorSettings); @POST @Path("/info") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @Operation(description = "Provides a summary of the connector as it would be built using a ConnectorTemplate identified by the provided `connector-template-id` and the data given in `connectorSettings`") APISummary info(@MultipartForm final CustomConnectorFormData connectorFormData); static final String SPECIFICATION; }